Skip to content

Instantly share code, notes, and snippets.

@fatihky
Forked from gamerlv/uptimerobot-to-zendesk.php
Last active August 29, 2015 14:23
Show Gist options
  • Save fatihky/46cabf4824f6f7627a94 to your computer and use it in GitHub Desktop.
Save fatihky/46cabf4824f6f7627a94 to your computer and use it in GitHub Desktop.
<?php
/*
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <[email protected]>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
*/
// Settings
$zendesk_subdomain = "example";
$username = "[email protected]"; //Your zendesk login username
$password = "token: AABB-XXX"; //Fill in your API token, found in "Settings > Channels > API" or your normal zendesk password
$subject = "SITE DOWN: " . $_GET['monitorFriendlyName'];
$message = "The site monitor ". $_GET['monitorFriendlyName']." went down with the reason ". $_GET['alertDetails'] .".
Details:
Domain: ".$_GET['monitorURL']."
Alert type: ".$_GET['monitorURL']."
Monitor ID: ".$_GET['monitorID']."
";
// == No editing required
$fields = array( "ticket"=> array(
"subject"=> $subject,
"comment"=> array( "body"=> $message ),
"type"=> "incident", // Allowed values are problem, incident, question, or task.
"priority"=>"high", // Allowed values are urgent, high, normal, or low.
"tags"=>array("uptimerobot", "sitedown"),
));
$url = 'https://'.$zendesk_subdomain.'.zendesk.com/api/v2/tickets.json';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.json_encode($value).'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password);
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment