Webhook / HTTP Alert Channel
The Webhook / HTTP channel makes an HTTP POST request to the specified URL, encapsulating the alert data in an XML string, JSON object, or Serialized-PHP array.
This enables you to invoke a Remote Procedure Call (RPC) within your system, allowing applications to automatically take action when Wormly alerts are triggered.
Bear in mind that your URL should point to a different webserver than the one being monitored, since sending HTTP alerts to a crashed server will obviously fail. The HTTP timeout for sending alerts is 5 seconds
What's in the HTTP request?
Wormly will make a single HTTP POST request to the specified URL. Depending on the data format you have specified, this variable will contain either an XML string, a JSON object, or a serialized PHP array.
What information is provided with the alert?
All three data formats include the following components:
hostid (integer)
A unique ID identifying the Wormly host from which the alert has been triggered.name (string)
The customer-specified name of the Wormly host.isrecovery (integer)
0 if this alert indicates a failure, 1 if the alert indicates that the host has recovered from a prior failure.downtime (integer)
The amount of time (in seconds) for which the host has been down.alertlevel (integer)
A unique ID identifying the current alert escalation level.alertlevel_name (string)
The textual name describing the current alert escalation level.failedsensors (array)
An array of the hosts' sensors which have failed their tests.
Contents of "failedsensors" array elements
type (string)
The sensor type, e.g. HTTP, POP3, etc.sensorid (integer)
A globally unique ID identifying this sensor.message (string)
The error message indicating why this sensor failed the test.
JSON Data Format Format
An example of this data in JSON format is shown below:
{ "downtime" : 300, "hostid" : 5112, "failedsensors" : [ { "sensorid" : 501, "message" : "Wanted string: \"Copyright\" not found in response.", "type" : "HTTP" } ], "isrecovery" : 0, "alertlevel_name" : "Continued Error", "alertlevel" : 2, "name" : "The host name" }
Parsing JSON alerts
Here's a simple NodeJS example which creates an HTTP server on port 3000 to receive Wormly JSON alerts:
const port = 3000
require('http').createServer(function (req, res) {
var alert = '';
req.on('data', function (chunk) { alert += chunk.toString() });
req.on('end', function () {
if (req.headers['content-type'] === 'application/json') {
alert = JSON.parse(alert);
}
console.log(alert);
res.end('OK');
});
}).listen(port)
Within PHP (versions 5.2 and later), the task is trivial:
<?php
$alertdata = json_decode($_POST["wormlyalert"]);
?>
XML Data Format
An example of this data in XML format is shown below:
<?xml version="1.0" encoding="UTF-8"?> <wormlyalert> <hostid>5112</hostid> <name>WWW Server-7</name> <isrecovery>0</isrecovery> <downtime>300</downtime> <alertlevel>2</alertlevel> <alertlevel_name>Continued Error</alertlevel_name> <failedsensors> <sensor> <type>HTTP</type> <sensorid>501</sensorid> <message>Failed to connect to TCP port 80.</message> </sensor> </failedsensors> </wormlyalert>
Serialized PHP Array Format
To receive alerts with a PHP script, you simply need to unserialize the alert data as follows:
<?php
$alertdata = unserialize($_POST["wormlyalert"]);
?>
Downtime Hurts. Start monitoring and stop worrying.
Our monitoring service continually tests your servers & web sites to keep you online and performing fast. Fully-featured plans start from just $44 / month.
But don't listen to our spiel - Decide for yourself with a free trial »