Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/*
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
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 = "leviv@example.com"; //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
You can’t perform that action at this time.