Last active
August 16, 2018 08:15
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.