Skip to content

Instantly share code, notes, and snippets.

View ryanhoskin's full-sized avatar

Ryan Hoskin ryanhoskin

View GitHub Profile
#!/usr/bin/env python
import requests
SUBDOMAIN='pdt-dank'
API_ACCESS_KEY='HjEs6A6KozribnKqm1tX'
def get_incidents():
headers = {
@ryanhoskin
ryanhoskin / get_on_call.py
Last active August 29, 2015 14:02
Get who's on-call for an escalation policy
#!/usr/bin/env python
import requests
SUBDOMAIN='pdt-dank'
API_ACCESS_KEY='HjEs6A6KozribnKqm1tX'
def get_escalation_policy_oncall():
url = 'https://{0}.pagerduty.com/api/v1/escalation_policies/on_call'.format(SUBDOMAIN)
define contact {
contact_name pagerduty
alias PagerDuty Pseudo-Contact
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,r
service_notification_commands notify-service-by-pagerduty
host_notification_commands notify-host-by-pagerduty
pager 1ebf75f79c8d495ca90a64e18c3e93c5
@ryanhoskin
ryanhoskin / query_incidents.py
Last active August 29, 2015 14:01
Query all PagerDuty incidents within a specified time period
#!/usr/bin/env python
import requests
import sys
import json
import time
from datetime import date, timedelta
#Your PagerDuty API key. A read-only key will work for this.
AUTH_TOKEN = 'YOUR_API_KEY'
#!/usr/bin/env python
import requests
import sys
import json
from datetime import date, timedelta
import csv
#Your PagerDuty API key. A read-only key will work for this.
AUTH_TOKEN = 'YOURKEYHERE'
@ryanhoskin
ryanhoskin / heartbeat.ps1
Created March 31, 2014 17:02
Trigger and resolve incidents within PagerDuty forever... Heartbeat
#This script can trigger and resolve incidents within PagerDuty every 10 minutes
#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)
@ryanhoskin
ryanhoskin / pagerduty_nagios_webhooks.php
Created January 15, 2014 21:37
PagerDuty webhooks email script for Nagios.
<?php
//Nagios alerts with a custom subject line that includes the HOSTNAME, SERVICESTATE, SERVICEDESC, HOSTSTATE and PagerDuty incident status fields.
$messages = json_decode($HTTP_RAW_POST_DATA);
if ($messages) foreach ($messages->messages as $webhook) {
$service = $webhook->data->incident->service->name;
$description = $webhook->data->incident->trigger_summary_data->subject." ".$webhook->data->incident->trigger_summary_data->description;
$status = $webhook->data->incident->status;
$link = $webhook->data->incident->html_url;
$emailAddress = ($webhook->type == "incident.resolve" ? $webhook->data->incident->last_status_change_by->email : $webhook->data->incident->assigned_to_user->email);
$body = "PagerDuty Update\n\nAn incident has been $status.\n\nDetails: $description on service $service\n\nClick here for more details: $link\n";
@ryanhoskin
ryanhoskin / get_user_activity.py
Last active December 31, 2015 21:39
Get the latest activity for all users within a PagerDuty account.
#Get the latest activity for all users within a PagerDuty account.
#This script is not supported by PagerDuty.
#!/usr/bin/env python
import datetime
import requests
import sys
#Your PagerDuty API key. A read-only key will work for this.
Sample PHP code to accept PagerDuty webhooks and send out notifications by email on state changes.
For more information, see http://developer.pagerduty.com/documentation/rest/webhooks
This example sends emails to the assigned user for all status changes except resolved. Resolved incidents will email the user who last changed the incident status.
This code is unsupported by PagerDuty.
<?php
$messages = json_decode($HTTP_RAW_POST_DATA); // alternately, try file_get_contents('php://input');
@ryanhoskin
ryanhoskin / Get Recent Incidents
Created December 3, 2013 21:39
Get incidents from PagerDuty that have been queued up for several days.
# Copyright (c) 2011-2013, PagerDuty, Inc. <info@pagerduty.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.