Skip to content

Instantly share code, notes, and snippets.

@timbirk
Last active August 16, 2018 08:15
Show Gist options
  • Save timbirk/5774e4930436858f3773ab04f1e2bced to your computer and use it in GitHub Desktop.
Save timbirk/5774e4930436858f3773ab04f1e2bced to your computer and use it in GitHub Desktop.
Add this to your ~/.bash_profile to see who's currently on-call on PagerDuty
#!/usr/bin/env bash
scheduleid=XXXXXX
apikey=XXXXXXXXXXXXXXXXXX
# No need to edit below
touch ~/.on_call
blue=`tput setaf 4`
reset=`tput sgr0`
today=$(date +'%Y-%m-%d')T09:00:00Z
cache_date=$(cut -f 1 -d ',' ~/.on_call)
# If dates are different, get the PE name and cache the results.
[ "${today}" != "${cache_date}" ] \
&& on_call=$(curl -s -X GET --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'Authorization: Token token='${apikey} 'https://api.pagerduty.com/schedules/'${scheduleid}'?time_zone=UTC&since='${today}'&until='${today} | jq -r '.[].final_schedule.rendered_schedule_entries | first | .user.summary') \
&& [[ ! -z "${on_call}" ]] && echo "${today},${on_call}" > ~/.on_call
echo "${blue}On-call: $(cut -f 2 -d ',' ~/.on_call)${reset}"
@timbirk
Copy link
Author

timbirk commented Jun 7, 2018

I'm on a "Primary Platform Engineer" schedule managed in PagerDuty. I always forget it's me so I thought I should put it in my shell every time I open one.

This script snippet hits the PagerDuty API and caches the response in a file ~/.on_call so that it only hits the API once per day and speeds up my shell load time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment