-
-
Save smithclay/5299ba54285398ecd583 to your computer and use it in GitHub Desktop.
Recipes for using the PagerDuty On-Call APIs
This file contains 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
# Send an inspirational email to people on-call for an escalation policy. | |
# Node required, tested on Mac OS X. | |
ESCALATION_POLICY_ID=<enter id> ACCOUNT=<enter account> API_TOKEN=<enter token> && curl --silent -H "Authorization: Token token=${API_TOKEN}" "https://${ACCOUNT}.pagerduty.com/api/v1/escalation_policies/${ESCALATION_POLICY_ID}/on_call" | xargs -0 node -e "console.log('mailto:' + JSON.parse(process.argv[1]).escalation_policy.on_call.map(function(oc) { return oc.user.email }).join(',') + '?subject=\"Keep calm and carry on.\"')" | xargs open |
This file contains 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
// Create an on-call overlay with a user's on-call status. | |
// Designed to be used as a bookmarklet. | |
(function() { | |
var el = null, d = document, id = "pd-widget"; | |
var account = "", apiKey = "", userId = ""; | |
function createWidget() { | |
el = d.createElement("table"); | |
d.body.appendChild(el); | |
el.setAttribute("id", id); | |
el.setAttribute("style","position:fixed;top:20px;right:20px;padding:20px;background:#fff;font:12px/20px monospace;z-index:99999;max-height:100%;overflow:auto;border-radius:10px;border:2px solid #000"); | |
el.innerHTML = "<p>Loading...</p>"; | |
el.style.display="block"; | |
} | |
function render(onCall) { | |
var widget = document.getElementById(id); | |
var onCallHTML = "<h3>When am I off-call?</h3>"; | |
onCall.forEach(function(oc) { | |
onCallHTML += "<p>" + oc.escalation_policy.name + " (level " + oc.level + "): " + ((oc.end && new Date(oc.end)) || "never") + "</p>"; | |
}); | |
widget.innerHTML = onCallHTML; | |
} | |
function fetch() { | |
var request = new XMLHttpRequest(); | |
request.open("GET", "https://" + account + ".pagerduty.com/api/v1/users/" + userId + "/on_call" , true); | |
request.setRequestHeader("Authorization", "Token token=" + apiKey); | |
request.onreadystatechange = function() { | |
var done = 4, ok = 200, json = ""; | |
if (request.readyState == done && request.status == ok) { | |
if (request.responseText) { | |
json = JSON.parse(request.responseText); | |
console.log(json.user.on_call); | |
render(json.user.on_call); | |
} | |
} | |
}; | |
request.send(null); | |
} | |
createWidget(); | |
fetch(); | |
})(); |
This file contains 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
# Have Mac OS X 'speak' your on-call status | |
# Node required. | |
USER_ID=<enter id> ACCOUNT=<enter account> API_TOKEN=<enter token> && curl --silent -H "Authorization: Token token=${API_TOKEN}" "https://${ACCOUNT}.pagerduty.com/api/v1/users/${USER_ID}/on_call" | xargs -0 node -e "if(JSON.parse(process.argv[1]).user.on_call.length > 0) { console.log('You are on-call') } else { console.log('You are off-call.') }" | xargs say |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment