Skip to content

Instantly share code, notes, and snippets.

@ryanhoskin
Created November 21, 2014 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanhoskin/6da5774bbc24dfe09068 to your computer and use it in GitHub Desktop.
Save ryanhoskin/6da5774bbc24dfe09068 to your computer and use it in GitHub Desktop.
Trigger a PagerDuty incident
#This script can trigger an incident in PagerDuty
#Hit the PagerDuty Integrations API, echo results
function POST_Request ($url,$parameters) {
$http_request = New-Object -ComObject Msxml2.XMLHTTP
$http_request.open('POST', $url, $false)
$http_request.setRequestHeader("Content-type", "application/json")
$http_request.setRequestHeader("Content-length", $parameters.length)
$http_request.setRequestHeader("Connection", "close")
$http_request.send($parameters)
Write-Host "Server Response:" $http_request.statusText
}
#Parameters
$service_key = "538e4904f2474722933ee2f4b1051a53"
$description = "heartbeat"
$incident_key = "heartbeat"
$url = "https://events.pagerduty.com/generic/2010-04-15/create_event.json"
$parameters = New-Object Collections.Specialized.NameValueCollection;
#Trigger an incident
Write-Host "Triggering incident"
$event_type = "trigger"
$parameters = "{`"service_key`":`"" + $service_key + "`",`"event_type`":`"" + $event_type + "`",`"description`":`"" + $description + "`",`"incident_key`":`"" + $incident_key + "`"}"
POST_Request $url $parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment