Skip to content

Instantly share code, notes, and snippets.

@jellis
Created August 25, 2016 04:23
Show Gist options
  • Save jellis/fe5c4f7a31dfaedbd9896040c119b001 to your computer and use it in GitHub Desktop.
Save jellis/fe5c4f7a31dfaedbd9896040c119b001 to your computer and use it in GitHub Desktop.
Pingdom to HipChat communication
<?php
$hc_subdomain = 'my-subdomain';
$room = '12345';
$room_token = 'the-room-token';
if (!empty($_REQUEST['message'])) {
$message = json_decode($_REQUEST['message']);
if (!empty($message->description) && $message->description == 'down') {
$deliver = [
'color' => 'red',
'notify' => true,
'message' => 'Failed check [' . $message->checkname . '] at <a href="' . $message->host . '">' . $message->host . '</a> [Incident: #' . $message->incidentid . ']',
];
}
}
if (!empty($deliver)) {
$auth = 'Authorization: Bearer ' . $room_token;
// Initialise the curl request
$ch = curl_init('https://' . $hc_subdomain . '.hipchat.com/v2/room/' . $room . '/notification');
// Set configs and send request
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json' , $auth]);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($deliver));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_exec($ch);
curl_close($ch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment