Skip to content

Instantly share code, notes, and snippets.

View ryanhoskin's full-sized avatar

Ryan Hoskin ryanhoskin

View GitHub Profile
@ryanhoskin
ryanhoskin / Import Users from Active Directory to PagerDuty.ps1
Last active December 11, 2015 04:18
Import users from Active Directory to PagerDuty
# Import users from Active Directory to PagerDuty
# Requires Windows Server 2008 R2
# Users should be members of a security group named "pagerduty"
Import-Module activedirectory
# Import users via the PD API
function POST_Request ($url,$parameters, $api_key) {
$http_request = New-Object -ComObject Msxml2.XMLHTTP
$http_request.open('POST', $url, $false)
@ryanhoskin
ryanhoskin / gist:5225138
Created March 22, 2013 22:03
Test Opsview perl script.
#!/usr/bin/env perl
# Nagios plugin that sends Nagios events to PagerDuty.
#
# Copyright (c) 2011, 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:
@ryanhoskin
ryanhoskin / gist:5392173
Created April 15, 2013 23:32
Icinga Command w/ Environment Variables
define command {
command_name notify-service-by-pagerduty
command_line /usr/local/bin/pagerduty_icinga.pl enqueue -f pd_nagios_object=service -f CONTACTPAGER="$CONTACTPAGER$" -f NOTIFICATIONTYPE="$NOTIFICATIONTYPE$" -f HOSTNAME="$HOSTNAME$" -f SERVICEDESC="$SERVICEDESC$" -f SERVICESTATE="$SERVICESTATE$"
}
define command {
command_name notify-host-by-pagerduty
command_line /usr/local/bin/pagerduty_icinga.pl enqueue -f pd_nagios_object=host -f CONTACTPAGER="$CONTACTPAGER$" -f NOTIFICATIONTYPE="$NOTIFICATIONTYPE$" -f HOSTNAME="$HOSTNAME$" -f HOSTSTATE="$HOSTSTATE$"
}
#!/usr/bin/env python
import time
import datetime
import requests
import sys
import json
from urllib import urlencode
# How many notifications had to be escalated past the primary, due to lack of response?
#!/usr/bin/env python
import time
import datetime
import requests
import sys
import json
from urllib import urlencode
# How many notifications had to be escalated past the primary, due to lack of response?
@ryanhoskin
ryanhoskin / pagerduty.py
Last active December 25, 2015 19:19
Get basic statistics on a PagerDuty service
#!/usr/bin/env python
import time
import datetime
import requests
import sys
import json
from urllib import urlencode
#Your PagerDuty API key. A read-only key will work for this.
@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.
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_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.
@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";