Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit a1d6cd3

Browse files
committed
making newrelic plugin able to deal with multiple apps
1 parent fd2e539 commit a1d6cd3

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/scripts/newrelic.coffee

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# HUBOT_NEWRELIC_ACCOUNT_ID
99
# HUBOT_NEWRELIC_APP_ID
1010
# HUBOT_NEWRELIC_API_KEY
11-
#
11+
#
1212
# Commands:
1313
# hubot newrelic me - Returns summary application stats from New Relic
1414
#
@@ -18,17 +18,12 @@
1818
# Given: https://rpm.newrelic.com/accounts/xxx/applications/yyy
1919
# xxx is your Account ID and yyy is your App ID
2020
# Account Settings > API + Web Integrations > API Access > "API key"
21-
#
21+
#
2222
# Author:
2323
# briandoll
2424

2525
module.exports = (robot) ->
26-
robot.respond /newrelic me/i, (msg) ->
27-
accountId = process.env.HUBOT_NEWRELIC_ACCOUNT_ID
28-
appId = process.env.HUBOT_NEWRELIC_APP_ID
29-
apiKey = process.env.HUBOT_NEWRELIC_API_KEY
30-
Parser = require("xml2js").Parser
31-
26+
fetchData = (appId) ->
3227
msg.http("https://rpm.newrelic.com/accounts/#{accountId}/applications/#{appId}/threshold_values?api_key=#{apiKey}")
3328
.get() (err, res, body) ->
3429
if err
@@ -39,5 +34,13 @@ module.exports = (robot) ->
3934
threshold_values = json['threshold-values']['threshold_value'] || []
4035
lines = threshold_values.map (threshold_value) ->
4136
"#{threshold_value['$']['name']}: #{threshold_value['$']['formatted_metric_value']}"
42-
37+
4338
msg.send lines.join("\n"), "https://rpm.newrelic.com/accounts/#{accountId}/applications/#{appId}"
39+
40+
robot.respond /newrelic me/i, (msg) ->
41+
accountId = process.env.HUBOT_NEWRELIC_ACCOUNT_ID
42+
appIds = process.env.HUBOT_NEWRELIC_APP_ID.split(',')
43+
apiKey = process.env.HUBOT_NEWRELIC_API_KEY
44+
Parser = require("xml2js").Parser
45+
fetchData(appId) for appId in appIds
46+

0 commit comments

Comments
 (0)