ChatOps - Using New Relic in Campfire

Written By : Josh Nichols

Just awhile back, I wrote about how to build a Campfire bot with hubot. I’ve been doing a lot of work on our very own hubot since then (Claptrap, by name), and it’s been a pretty rad experience.

You’d think that hubot is all fun & lulz if you take a look at the Hubot Script Catalog, but there are definitely some ‘productive’ hubot-scripts in the mix. Today, we’re going to checkout one in particular that is totally #opslife.

Meet newrelic.coffee

We are huge fans of New Relic in general, but it’s even better when you can have easy access to it from Campfire. Check it:

There’s just a few steps to get going. First, we head to New Relic to collect some information:

  • Login at https://rpm.newrelic.com
  • You’ll be redirected to a URL like https://rpm.newrelic.com/accounts/XXXXXX/applications
    • Make note of XXXXXX, we’ll be using it for HUBOT_NEWRELIC_ACCOUNT_ID
  • Click through to one of your applications, and you’ll be at a URL like https://rpm.newrelic.com/accounts/XXXXXX/applications/YYYYYY
    • Make note of YYYYYY, we’ll be using it for HUBOT_NEWRELIC_APP_ID
  • From the topbar, click on your account name, then Account Settings
    • Select the ‘Data sharing’ tab
    • ‘Enable API access’ if it’s not enabled
    • Make note of the API Key: 12345, we’ll be using it for HUBOT_NEWRELIC_API_KEY
    • If you don’t see Account Settings, you’ll need to get an account admin to do this, or make you an admin

With this information, we can apply it the shell environment:

export HUBOT_NEWRELIC_ACCOUNT_ID=XXXXXX
export HUBOT_NEWRELIC_APP_ID=YYYYYY
export HUBOT_NEWRELIC_API_KEY=12345

And then update hubot-scripts.json to include newrelic:

[
  # other scripts here
  'newrelic.coffee',
  # even more scripts here
]

Restart hubot, and you’re good to go!

Our Special Sauce

One thing you may have noticed about the NewRelic hubot-script is that you can only configure a single application. We highly recommend NewRelic for our managed hosting customers, so this was immediately a problem for us.

To work around, I’ve taken the normal script, and lovingly seasoned it with data from our internal servers. By doing this, we can go from any server on our infrastructure to correct application in NewRelic:

Wrapping up

All in all, we’re pretty happy with this action so far. There’s always room for improvement, but fortunately, we’re just consuming the NewRelic REST API , so it’s only a matter of writing some code to have even more awesomeness in Campfire.