Sample Custom Check Script

 

/* Sample Custom Check

 

Upload this PHP script to your server to a directory that is accessable via a domain and supports php.

Add a custom check script type check and put the full url to the php script and include your selected key in the path.

e.g. http://mydomain.com/check/serverstatus.php?key=1234abc

 

Your custom check can run any tests you would like, the only requirement is that it returns a json string with three variables:

result
error_message
response_time

 

The result should be true if the test passes and false if the test fails.

The error_message should be the error messsage you would like to log and be send in the email alerts.

The response time measures how long it took the script/check to execute.

 

*/

 

// User Configured Variables

 

$key = "1234abc";

$disk_percentage_threshold = "80"; // When disk usage reaches this perctange an error will be returned.
$disk_path = "/"; // The path to check.

$load_threshold = "5";

 

if ($_GET['key'] == $key ) {

$error_message = "";
$pass = true;

// Start Response Time

$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$start_time = $mtime;

// Disk Space Test

$disk_percentage_used = ((disk_free_space($disk_path) / disk_total_space($disk_path)))*100;

$disk_percentage_used = 100 - $disk_percentage_used;

if ($disk_percentage_used >= $disk_percentage_threshold) {

if($pass) {

$error_message = "Disk usage is at " . $disk_percentage_used . "%";

}

else {

$error_message = $error_message . ", Disk usage is at " . $disk_percentage_used . "%";

}

$pass = false;

}

// Load Test

$uptime = @exec('uptime');

preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$uptime,$avgs);

if ($avgs[1] >= $load_threshold) {

if($pass) {

$error_message = "Server Load is at ". $avgs[1];

}

else {

$error_message = $error_message . ", Server Load is at ". $avgs[1];

}

$pass = false;

}

// End Reponse Time

$mtime = microtime();

$mtime = explode(" ",$mtime);

$mtime = $mtime[1] + $mtime[0];

$end_time = $mtime;

$response_time = round(($end_time - $start_time), 3);

$results = array("result" => $pass, "error_message" =>$error_message, "response_time" => $response_time);

echo json_encode($results);

}

else {

echo "Access Denied";

}

 

?>

 

  • 60 Users Found This Useful
Was this answer helpful?

Related Articles

Installation Guide

Requirements You will need at least one Cent OS 6 (64 bit recommended) VPS/Dedicated server with...

Adding ServerPing Package

  Login to your WHMCS Admin Area and go to Setup->Products/Services->Products/Services...

Adding a SMS Credits Package

Login to your WHMCS Admin Area and go to Setup->Products/Services->Products/Services...

Adding ServerPing to your Client Area template

You will need to provide a link to the SeverPing module from your client area. We recommend...

System Requirements

Requirements You will need at least one Cent OS 6 (64 bit recommended) VPS/Dedicated server with...