thegreenrobot / pagerduty_dashing

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

Final_schedule #19

Closed trondvh closed 9 years ago

trondvh commented 9 years ago

Fetching the primary oncall from final_schedule instead of the original schedule to include any overrides.

thegreenrobot commented 9 years ago

Oh hey there!

Thanks for submitting a pull request. Having the right person when an override is scheduled is important.

I made an override on one of my schedules and looked at the final_schedule returned and it was still empty.

        "final_schedule": {
            "name": "Final Schedule",
            "rendered_coverage_percentage": null,
            "rendered_schedule_entries": []
        },

I looked at this in the past and remember not getting the results I wanted and having to contact PagerDuty directly. At the time they recommended making a call to the schedules/overrides endpoint.

https://developer.pagerduty.com/documentation/rest/schedules/overrides/list

curl -H "Content-type: application/json" -H "Authorization: Token token=SCRUBBED" -X GET -G "https://SCRUBBED.pagerduty.com/api/v1/schedules/SCRUBBED/overrides?since=2015-06-17T12:46:00Z&until=2015-06-17T12:47:00Z" | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   207    0   207    0     0     36      0 --:--:--  0:00:05 --:--:--   306
{
    "overrides": [
        {
            "end": "2015-06-18T00:00:00-04:00",
            "id": "SCRUBBED",
            "start": "2015-06-17T08:34:25-04:00",
            "user": {
                "color": "green",
                "email": "matt.green@SCRUBBED",
                "id": "SCRUBBED",
                "name": "Matt Green"
            }
        }
    ],
    "total": 1
}

This call returns the right data but what if there were no overrides in place for the schedule? You'd have to to make two calls:

  1. Make the override call. Are there results? Yes, let's use that person.
  2. Make the override call. Are there results? No, make the regular schedule call.

Seems doable but over complicated. I also use a PagerDuty script for Hubot on my team and I forgot that we have an oncall function in there and it returns the rendered final schedule in one call using the schedule/entries endpoint.

https://developer.pagerduty.com/documentation/rest/schedules/entries

curl -H "Content-type: application/json" -H "Authorization: Token token=SCRUBBED" -X GET -G "https://SCRUBBED.pagerduty.com/api/v1/schedules/SCRUBBED/entries?since=2015-06-17T12:46:00Z&until=2015-06-17T12:47:00Z" | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   180    0   180    0     0    168      0 --:--:--  0:00:01 --:--:--   244
{
    "entries": [
        {
            "end": "2015-06-17T12:47:00Z",
            "start": "2015-06-17T12:46:00Z",
            "user": {
                "color": "green",
                "email": "matt.green@SCRUBBED",
                "id": "PQOBX7Q",
                "name": "Matt Green"
            }
        }
    ],
    "total": 1
}

Seems like schedule/entries with the right since&until is the way to go.

Let me know what you think. Thanks!

Matt

trondvh commented 9 years ago

ohai

That's wierd. final_schedule returns the correct data when I create an override. But without an override it's empty.

Entries looks like the way to go. Did a quick test for the last weeks, and entries seems to present the correct data.

Sorry for the screwup.

Trond

thegreenrobot commented 9 years ago

No worries at all and no screw ups made! I'm just glad someone else might use the dashboard.

Do you want to update this PR to use entries?

Matt

thegreenrobot commented 9 years ago

Made the change under https://github.com/thegreenrobot/pagerduty_dashing/pull/23

Thanks!

Matt