Last active
December 20, 2021 09:15
-
-
Save simonfiddaman/f236e2f300d9e01feac8c7d2b57010dd to your computer and use it in GitHub Desktop.
PagerDuty custom event definition for Pingdom alerts
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
// shorten the posted data ref | |
var webhook = PD.inputRequest.body; | |
var event = { | |
// Default to Triggering a new event | |
event_type: PD.Trigger, | |
// use the check_id as the incident key - should only ever be in one state | |
incident_key: webhook.check_id, | |
// set Alert/Incident title | |
description: "Pingdom says " + webhook.check_name + " is " + webhook.current_state + " (" + webhook.description + ")", | |
} | |
// Resolve on state: UP | |
if (webhook.current_state == "UP") { | |
// Resolve the event | |
event.event_type = PD.Resolve; | |
} else { | |
// set our custom Pingdom URL | |
var client = "Custom Pingdom Dash"; | |
var client_url = "https://pingdom.custom.url/check/" + webhook.check_id; | |
// be clear about IPv6 tests in the link text as we can't replicate from the office | |
var link_text = webhook.check_params.ipv6 ? "IPv6: " + webhook.check_params.hostname : webhook.check_params.hostname; | |
// curate the details table | |
event.details = { | |
pingdom_dash: client_url, | |
long_description: webhook.long_description, | |
id: webhook.check_id, | |
name: webhook.check_name, | |
type: webhook.check_type, | |
url: webhook.check_params.full_url, | |
ipv6: webhook.check_params.ipv6, | |
tags: webhook.tags, | |
state: webhook.previous_state + " => " + webhook.current_state, | |
source_a: webhook.first_probe.location, | |
source_b: webhook.second_probe.location, | |
time: webhook.state_changed_utc_time + "Z", | |
importance: webhook.importance_level | |
}; | |
// the "client" link will go to our custom Pingdom URL (set above) | |
event.client = client; | |
event.client_url = client_url; | |
// Add a link to the tested site | |
event.contexts = [{ | |
type: 'link', | |
href: webhook.check_params.full_url, | |
text: link_text | |
}]; | |
}; | |
// do the thing | |
PD.emitGenericEvents([event]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment