Hi folks, if you’re a PagerDuty admin, or a power user, and want the ability to proactively monitor your pagerduty license counts so that, for instance, you can purchase some more licenses before you run out, then this little utility is for you. It’s using our relatively new API endpoint to gain access to the Full and Stakeholder license allocations. Here is the link to the official documentation: https://developer.pagerduty.com/api-reference/10230a10c519e-list-license-allocations
Below is a small script that can run on a MacOS (should work on Linux as well) that will send me a pagerduty incident when I get low on licenses. The comments in the script give you a bit more information on how to use it.
# The following script can be placed in a cron job or other scheduler to be run every day/week/month
# This utility requires the "jq" json utility to be installed on your system (mine is a MacOS)
# Ensure you have a PD read only API token set in your environment (in my case it is set in "pdtjcalcada")
# replace your events API key with the one you want to receive it on (you can use a global routing key if you like)
# set the "LowerLimit" below to whatever you want (in my case, when it goes below 10 licenses, it will trigger in PD)
# this utility is provided with no warranty, expressed or implied, and is provided for guidance purposes only
LowerLimit=9999
curl \
--silent \
--url https://api.pagerduty.com/licenses \
--header 'Accept: application/vnd.pagerduty+json;version=2' \
--header 'Authorization: Token token='$pdtjcalc \
--header 'Content-Type: application/json' | jq '.licenses[0].allocations_available' > LUSED
curl \
--silent \
--url https://api.pagerduty.com/licenses \
--header 'Accept: application/vnd.pagerduty+json;version=2' \
--header 'Authorization: Token token='$pdtjcalc \
--header 'Content-Type: application/json' | jq '.licenses[1].allocations_available' > SUSED
export PDLIC=`bc -f LUSED`
export PDSLIC=`bc -f SUSED`
if [[ $PDLIC < $LowerLimit ]]
then
curl -H "Content-type: application/json" -X POST \
-d '{
"payload": {
"summary": "PD Remaining Full Licenses:'"$PDLIC"' Stakeholders:'"$PDSLIC"'",
"source": "PD Licenses",
"severity": "info"
},
"routing_key": "YourEventsAPIKey",
"event_action": "trigger"
} ' https://events.pagerduty.com/v2/enqueue
fi