thegreenrobot / pagerduty_dashing

A Dashing dashboard for PagerDuty Services & Schedules
MIT License
44 stars 23 forks source link

Is there a way to switch services to escalation policies? #24

Closed razorrazing closed 8 years ago

razorrazing commented 8 years ago

I'd like to be able to roll up the totals for all services in each escalation policy.

Example: Service 1 and Service 2 are under "Dev Team"

I'd like to see how many triggered alerts there are for Dev Team in one dashing object. Is that possible?

thegreenrobot commented 8 years ago

Hi, sorry for the delayed response.

Yes I think this is possible but it would require you do make some changes. Looking at the API, it does not look like you can get counts by escalation policy but you can get them by team. I wasn't aware of the team functionality as my PagerDuty account does not have them b/c we're on some old legacy plan.

Looking at the API documentation this should work:

curl -H "Content-type: application/json" -H "Authorization: Token token=$YOUR_TOKEN" -X GET -G \
    --data-urlencode "since=2015-04-01" \
    --data-urlencode "until=2015-05-01" \
    --data-urlencode "teams=$DEVTEAM_ID" \
    --data-urlencode "status=triggered" \
    "https://acme.pagerduty.com/api/v1/incidents/count"

https://developer.pagerduty.com/documentation/rest/incidents/count

You could modify the pagerduty_incidents.rb job to something like the following:

SCHEDULER.every '30s' do
    conn = Faraday.new(url: "#{url}") do |faraday|
      faraday.request :url_encoded
      faraday.adapter Faraday.default_adapter
      faraday.headers['Content-type'] = 'application/json'
      faraday.headers['Authorization'] = "Token token=#{api_key}"
      faraday.params['teams'] = 'YOUR_TEAM'
      faraday.params[''status] = 'triggered'
    end

    response = conn.get "/api/v1/incidents/count"
    json = JSON.parse(response.body)

    total = json['total']

    send_event(team-triggered, value: triggered)
end

Give it a try, and let me know. I like the idea of creating a new dashboard for teams.

Thanks, Matt