PHP code example to access the Wormly API
Be sure to substitute your API key and HostID(s).
<?php
$conn = curl_init("https://api.wormly.com/");
$postdata["key"] = '__YOUR_KEY__';
$postdata["response"] = 'json';
$postdata["hostids"] = '__HOSTID1__,__HOSTID2__';
$postdata["cmd"] = "getHostStatus";
// Encode the POST data for use with CURL:
foreach ($postdata AS $key => $value)
{
$fields[] = rawurlencode($key)."=".rawurlencode($value);
}
curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($conn, CURLOPT_POST, true);
curl_setopt($conn, CURLOPT_ENCODING, "gzip");
curl_setopt($conn, CURLOPT_POSTFIELDS, join("&", $fields));
// Perform the API request
$response = curl_exec($conn);
// Fetch the HTTP response code so we can verify it
$info = curl_getinfo($conn);
$httpResponseCode = $info['http_code'];
// Decode our JSON response object
$responseObject = json_decode($response);
if ($httpResponseCode == 200)
{
// The API request was successful
$hostid = $responseObject->status[0]->hostid;
$isHostDown = $responseObject->status[0]->uptimeerrors;
}
else
{
// An error occurred
$wormlyErrorCode = $responseObject->errorcode;
$wormlyErrorMessage = $responseObject->errormsg;
}
Not what you were looking for? Try a search: