Last active
August 29, 2015 13:56
-
-
Save canoedf/9295995 to your computer and use it in GitHub Desktop.
Logicmonitor to osTicket interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> | |
<html> | |
<head> | |
</head> | |
<body> | |
<?php | |
# Logicmonitor to osTicket interface | |
# by Dan Fischer March 1, 2014 | |
# | |
$string = file_get_contents("php://input"); | |
$result = (json_decode($string,true)); | |
# Log some details | |
$tracefile=fopen("/tmp/phplog.log","w+"); | |
echo fputs($tracefile,"LM JSON Contents: " . $string ."\n"); | |
echo fputs($tracefile,"Contents: " . $vardiag ."\n"); | |
# This will process incidents coming from Logicmonitor | |
# Inspect var_dump($result) to determine the API_key fields to retrieve from the Logicmonitor json payload | |
# Prepare to send the alert to osTicket via the API so a ticket is generated | |
$data = array( | |
'name' => ($result["name"]), | |
'email' => ($result["email"]), | |
'subject' => ($result["subject"]), | |
'message' => ($result["message"]), | |
'ip' => ($result["ip"]), | |
'attachments' => array() | |
); | |
$config = array( | |
'url'=>($result["url"]), | |
'key'=>(trim($result["api_key"])) | |
); | |
echo fputs($tracefile,"IP: " . $data['ip'] ."\n"); | |
echo fputs($tracefile,"API: " . $config['key'] ."\n"); | |
echo fputs($tracefile,"URL: " . $config['url'] ."\n"); | |
set_time_limit(30); | |
# ---------------------------------------------------------------------------------------- | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $config['url']); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); | |
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.8'); | |
curl_setopt($ch, CURLOPT_VERBOSE, FALSE); | |
curl_setopt($ch, CURLOPT_HEADER, FALSE); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key'])); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
$result=curl_exec($ch); | |
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
curl_close($ch); | |
# ---------------------------------------------------------------------------------------- | |
echo fputs($tracefile,"RESULT: " . $result ."\n"); | |
echo fputs($tracefile,"CODE: " . $code ."\n"); | |
if ($code != 201) | |
die('Unable to create ticket: '.$code." ".$result); | |
echo "OK"; | |
fclose($tracefile); | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment