Proactively monitoring your PagerDuty Licenses

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:

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


curl \
  --silent \
  --url \
  --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 \
  --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 ]]
    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"
   } ' 

Super cool @JoeCalcada! Thank you so much for writing this up & for sharing it with the community. Always helpful to see examples of a new API endpoint.

1 Like

Thanks Joe.

IMHO, as a customer, a better UX will be:

  • PagerDuty shares it as a metric (eg: licenses count per type)
  • give the ability to push those metrics toward popular services (Datadog, New Relic, AWS CloudWatch, …) OR to be pulled via standard protocols (eg: Prometheus)
  • then we’re able to monitor it and notify (eg: via PagerDuty), having stats over time, …