Update New Relic bot #588

Closed
wants to merge 2 commits into
from

Projects

None yet

3 participants

@nwp
nwp commented Oct 7, 2012
  • Move API key from URL to header
  • Correct response parsing
  • Remove redundant echo of URL
@nwp nwp Update to work with current Newrelic API version
* Move API key from URL to header
* Correct response parsing
* Remove redundant echo of URL
0b9130e
@technicalpickles
Member

Curious, what errors were you getting from parsing? I've been using this recently, and hadn't seen any errors.

Also, the echo of the URL is intentional. The values you can output from the API are useful, but I've found almost always want to dig around the web app anyways.

@nwp
nwp commented Oct 31, 2012

We setup a new hubot server and we couldn't get the NR script to work at all until we updated it to be consistant with the API documents (https://newrelic.com/docs/docs/getting-started-with-the-new-relic-rest-api)

Most notably, that meant passing the credentials in as a header vs a query string and updating the names of the output values.

@technicalpickles
Member

Okay, so this is very weird. I was able to use the updated header for the API key, no problem there.

The problem is the data I get back matches up with how the existing script works. I did msg.send inspect json, and here's what I got:

hubot> { '@': { type: 'array' },
  threshold_value: 
   [ { '@': [Object] },
     { '@': [Object] },
     { '@': [Object] },
     { '@': [Object] },
     { '@': [Object] },
     { '@': [Object] },
     { '@': [Object] },
     { '@': [Object] },
     { '@': [Object] } ] }

So, I'm getting back threshold_value with an array of @s back, instead of threshold-values with threshold-value having an array of $s. I can't really explain why this is, but the code could at least plan for this. I have something like:

           threshold_values = json['threshold_value'] || (json['threshold-values'] && json['threshold-values']['threshold_value']) || []


           lines = threshold_values.map (threshold_value) ->
             pair = threshold_value['@'] || threshold_value['$']
             "#{pair['name']}: #{pair['formatted_metric_value']}"

Does this work for you?

@tombell
Contributor
tombell commented Jan 10, 2013

Status on this pull request?

@tombell tombell closed this Feb 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment