Restrict queries to a particular service

Fixes #31

Our PagerDuty instance has numerous services that receive alerts, but we only want our Hubot to query against a subset of those. This adds a `HUBOT_PAGERDUTY_SERVICES` environment variable that accepts a comma separated list of service identifiers. This list is then added as a `service` key on all of the `pagerDutyGet` method calls to apply that filter.
This commit is contained in:
Stephen Yeargin 2015-03-02 00:15:46 -06:00
Родитель 8c2ae433f5
Коммит fa10773410
2 изменённых файлов: 5 добавлений и 0 удалений

Просмотреть файл

@ -22,6 +22,7 @@ Then add **hubot-pager-me** to your `external-scripts.json`:
* HUBOT_PAGERDUTY_USER_ID - The user id of a PagerDuty user for your bot. This is only required if you want chat users to be able to trigger incidents without their own PagerDuty user * HUBOT_PAGERDUTY_USER_ID - The user id of a PagerDuty user for your bot. This is only required if you want chat users to be able to trigger incidents without their own PagerDuty user
* HUBOT_PAGERDUTY_API_KEY - Get one from https://<your subdomain>.pagerduty.com/api_keys * HUBOT_PAGERDUTY_API_KEY - Get one from https://<your subdomain>.pagerduty.com/api_keys
* HUBOT_PAGERDUTY_SERVICE_API_KEY - Service API Key from a 'General API Service'. This should be assigned to a dummy escalation policy that doesn't actually notify, as hubot will trigger on this before reassigning it * HUBOT_PAGERDUTY_SERVICE_API_KEY - Service API Key from a 'General API Service'. This should be assigned to a dummy escalation policy that doesn't actually notify, as hubot will trigger on this before reassigning it
* HUBOT_PAGERDUTY_SERVICES - (optional) Provide a comma separated list of service identifiers (e.g. `PFGPBFY`) to restrict queries to only those services.
### Webhook ### Webhook

Просмотреть файл

@ -43,6 +43,7 @@ pagerDutyApiKey = process.env.HUBOT_PAGERDUTY_API_KEY
pagerDutySubdomain = process.env.HUBOT_PAGERDUTY_SUBDOMAIN pagerDutySubdomain = process.env.HUBOT_PAGERDUTY_SUBDOMAIN
pagerDutyBaseUrl = "https://#{pagerDutySubdomain}.pagerduty.com/api/v1" pagerDutyBaseUrl = "https://#{pagerDutySubdomain}.pagerduty.com/api/v1"
pagerDutyServiceApiKey = process.env.HUBOT_PAGERDUTY_SERVICE_API_KEY pagerDutyServiceApiKey = process.env.HUBOT_PAGERDUTY_SERVICE_API_KEY
pagerDutyServices = process.env.HUBOT_PAGERDUTY_SERVICES
pagerRoom = process.env.HUBOT_PAGERDUTY_ROOM pagerRoom = process.env.HUBOT_PAGERDUTY_ROOM
# Webhook listener endpoint. Set it to whatever URL you want, and make sure it matches your pagerduty service settings # Webhook listener endpoint. Set it to whatever URL you want, and make sure it matches your pagerduty service settings
pagerEndpoint = process.env.HUBOT_PAGERDUTY_ENDPOINT || "/hook" pagerEndpoint = process.env.HUBOT_PAGERDUTY_ENDPOINT || "/hook"
@ -454,6 +455,9 @@ module.exports = (robot) ->
if missingEnvironmentForApi(msg) if missingEnvironmentForApi(msg)
return return
if pagerDutyServices? && url.match /\/incidents/
query['service'] = pagerDutyServices
auth = "Token token=#{pagerDutyApiKey}" auth = "Token token=#{pagerDutyApiKey}"
msg.http(pagerDutyBaseUrl + url) msg.http(pagerDutyBaseUrl + url)
.query(query) .query(query)