Last active
August 29, 2015 13:57
-
-
Save canoedf/9421161 to your computer and use it in GitHub Desktop.
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 | |
# This will process incidents coming from Logicmonitor storing in a database table | |
# The table can drive a standalone monitoring console without the overhead of the LM UI | |
# ---------------------------------------------------------------------------------------- | |
$string = file_get_contents("php://input"); | |
$result = (json_decode($string,true)); | |
$subject = $result["subject"]; | |
$message = $result["message"]; | |
# Now prepare arrays to access pieces of the "subject" and "message" JSON fields | |
# ------------------------------------------------------------------------------ | |
$pieces1 = explode(",", $subject); | |
$pieces2 = explode(",", $message); | |
# these fields get stored in the database | |
# --------------------------------------- | |
$name = $pieces2[0]; | |
$time = $pieces2[1]; | |
$host = $pieces2[3]; | |
$monitor = $pieces1[2] . " " . $pieces1[3]; | |
$status = $pieces1[0]; | |
$event = $pieces1[6] . " " . $pieces2[5]; | |
$alert = $pieces1[5]; | |
# ---------------------------------------------------------------------------------------- | |
# update the logmon table here | |
$dbhost = 'FQDN'; | |
$dbuser = 'USER'; | |
$dbpass = 'PASS'; | |
$conn = mysql_connect($dbhost, $dbuser, $dbpass); | |
# Log some results below in /tmp/phplogDB.log | |
# ------------------------------------------- | |
$tracefile=fopen("/tmp/phplogDB.log","a"); | |
if(! $conn ) | |
{ | |
echo fputs($tracefile,date(DATE_W3C) . " Failed to connect: " . $dbhost . "\n"); | |
fclose($tracefile); | |
die('Could not connect: ' . $dbhost . "\n"); | |
} | |
echo fputs($tracefile,date(DATE_W3C) . " Connected to " . $dbhost . "\n"); | |
$sql="INSERT INTO logmon_alerts(Time, Name, Host, Monitor, Threshold, Event, Alert)" . | |
"VALUES('$time', '$name', '$host', '$monitor', '$event', '$status', '$alert')"; | |
mysql_select_db('DATABASE'); | |
$retval = mysql_query( $sql, $conn ); | |
if(! $retval ) | |
{ | |
echo fputs($tracefile,date(DATE_W3C) . " Failed to enter data successfully" . "\n"); | |
fclose($tracefile); | |
mysql_close($conn); | |
die('Could not enter data: ' . "\n"); | |
} | |
echo fputs($tracefile,date(DATE_W3C) . " Entered data successfully" . "\n"); | |
mysql_close($conn); | |
fclose($tracefile); | |
?> | |
</body> | |
</html> |
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
Name: Logmon | |
HTTP Method: HTTP Post | |
URL: http://FQDN/logmon/ | |
Alert Data: | |
{ | |
"subject": "##LEVEL##,##HOST##,##DATASOURCE##,##DATAPOINT##,##ALERTTYPE##,##ALERTSTATUS##,##VALUE##", | |
"message": "##ALERTID##,##START##,##DURATION##,##HOST##,##DATASOURCE##,##THRESHOLD##" | |
} | |
Data Format: JSON |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment