Knowledge Base

Publishing Monitoring Results using a PHP Script (Alternative 1)

This article explains how you can access the TEXTFILE interface of IPCheck Server Monitoring using PHP to publish the current monitoring results using an external webserver. This way you can e.g. apply your own look&feel or do your own user accounting.

In some situations the features for monitoring status publishing of IPCheck Server Monitor may not be flexible enough. Using the TEXTLIST interface (which is also used by the Windows GUI) you can access the current monitoring status via HTTP using an external script.

This sample shows a PHP script that requests the monitoring data for one user account from the IPCheck server and publishes the data into a simple HTML file.

With this trick the monitoring status can be shown through another webserver without the need for the final user to have access to the IPCheck server itself (since the username/password is hidden in the PHP script).

Notes:

  • Before you can use the script you must fill in your servername, username and password
  • This sample uses GET requests to access the server. Since the username and passwort is not encrypted when passed inside the GET URL (even when HTTPS is used) we do not recommend to use this feature across the open Internet. For secure communications you would need to change the request into a POST request and pass username and password in the POSTDATA.

Note: There is also another script available in article 107

This screenshot shows the output of both scripts (left: original, right: alternate). Click the image to zoom in.

sample Screen

Original IPCheck Monitoring Status PHP script by Dirk Paessler

<?

// Sample Script to publish monitoring
results of IPCheck Server Monitor using a PHP script
// © 2006 Paessler AG,
www.paessler.com
// V 1.1, April 2006

// V1.0 Initial Release (dp)

// V1.1 Added optional use of the CURL module to get the data (dp)


$protocol="http"; // use "http" or "https" according to your setup

$servername="YOURSERVERNAME"; // enter DNS name or IP address, add ":portnumber" if you do not use
port 80
$username="USERACCOUNT@YOURSERVER.COM"; // account username (email address)
$password="YOURPASSWORD"; // account password

?>

<html>
<head>


<title>IPCheck Server Monitor - Monitoring Results (<? echo
date("F j, Y,
G:i:s"
);?>)</title>


<style>
body,td,p,div
{
font-family:verdana,tahoma,arial,sans-serif; font-size:10px; }

h2 {font-size: 13px; margin:4px;padding:0px;}

h3 {font-size: 11px; margin:4px;padding:0px;}
body
{background-color:#fff; margin:0px;}

td {padding-left:5px;padding-right:5px;border-bottom:1px
solid #eeeeee;}
</style>
</head>

<body>

<?

// Option 1: Using the file() function is the fastest
way, but may not support HTTPS in all situations

$lines=file($protocol."://".$servername."/textlist?login=".$username."&pass=".$password);


// Option 2: Using the CURL library
(must be
// See: http://www.php.net/curl
// See:
http://www.zend.com/manual/ref.curl.php

/* UNCOMMENT THIS!!!

$url = $protocol."://".$servername."/textlist";

$params = "login=".$username."&pass=".$password;

$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows
NT 5.0)";
$ch = curl_init();

curl_setopt($ch, CURLOPT_POST,1);

curl_setopt($ch, CURLOPT_POSTFIELDS,$params);

curl_setopt($ch, CURLOPT_URL,$url);

curl_setopt($ch,
CURLOPT_SSL_VERIFYHOST, FALSE); // Necessary for IPCheck's default
certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
FALSE); // Necessary for IPCheck's default certificate

curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);

curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);


$lines=curl_exec ($ch);

$lines=explode(chr(13),str_replace(chr(10),"",$lines));


if (curl_errno($ch)) { print curl_error($ch); } else {
curl_close($ch);}
curl_close ($ch);
*/

echo('<table cellspacing=0 >');

foreach (
$lines as
$line)

{
$parts=explode(",",substr($line,3,999));


if (
substr($line,0,2)=='Gr' ) //A Group
{

echo
"<tr bgcolor=#dddddd><td
colspan=6><h2>Group: "
.$parts[0]."</h2></td></tr>";
};


if (
substr($line,0,2)=='Sr' ) //A Server
{

echo
"<tr
bgcolor=#eeeeee><td>&nbsp;</td><td
colspan=5><h3>Server: "
.$parts[0]."</h3></td></tr>";
}

if (
substr($line,0,2)=='Sn' ) // A Sensor
{

$Col="white";

if (
$parts[3]=='Up') $Col="lightgreen";

if (
$parts[3]=='Down') $Col="pink";

if (
$parts[3]=='Paused')
$Col="lightblue";

if (
$parts[3]=='Warning')
$Col="yellow";

echo
"<tr bgcolor=#eeeeee
><td>&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;</td><td
bgcolor='"
.$Col."'>Sensor: ".$parts[0]."</td><td
bgcolor='"
.$Col."'>".$parts[2]."</td><td bgcolor='".$Col."'>".$parts[3]."</td><td
bgcolor='"
.$Col."'>".$parts[4]."</td></tr>";
}

if (
substr($line,0,2)=='Me' ) //A Message, we leave the loop here

{

break;

}
}
echo(
'</table><br><br>');



echo(
'<table cellspacing=0 >');
echo
"<tr
bgcolor=#dddddd><td colspan=2><h2>Recent
Messages</h2></td></tr>"
;


$msgs="";
foreach (
$lines
as $line)
{

$parts=explode(",",substr($line,3,999));

if (
substr($line,0,2)=='Me' ) //A Message
{

$Col="white";

if (
strpos($parts[3],'DOWN -')>0) $Col="pink";
if
(
strpos($parts[3],'UP -')>0) $Col="lightgreen";

if (
strpos($parts[3],'WARNING -')>0) $Col="yellow";
if
(
$parts[2]=0) $Col="white";
$msgs="<tr bgcolor=".$Col."><td
nowrap>"
.date("F j, Y, G:i:s",($parts[0]+$parts[1]/10000000-35065)*24*60*60+mktime(0, 0, 0, 1, 1, 1996)."</td>")

.
"<td>".$parts[3]."</td></tr>".$msgs;
}
}

echo(
$msgs.'</table>');

?>
Last Refresh: <? echo
date("F j, Y,
G:i:s"
);
?>

<? //OPTIONAL: This code dumps the data into the browser

// echo("<hr><pre>");
// foreach
($lines as $line) {echo $line;};
// echo("</pre>");

?>

<p
style="font-size:8px">IPCheck Server Monitor 5 © 2005 <a
href="http://www.paessler.com">Paessler AG</a></p>

</body>
</html>