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 gebruikers vonden dit artikel nuttig
Was dit antwoord nuttig?

Gerelateerde artikelen

Installing the MongoDB pecl extension on a cPanel server

If your cPanel server has /tmp mounted with the noexec option you may run into the following...

Using a custom module name/link for your client area

In order to access the client area of serverping from a custom module name, you will need to...

Terms and Conditions

Terms and Conditions   Agreement between user and serverping.net Welcome to serverping.net....

Setting up Kayako v4 Help Desk Alerts

  ServerPing allows you to offer a monitoring with response service by giving customers the...

Setting up WHMCS to work with the Public Report Page

WHMCS includes the header.tpl and footer.tpl file on every request made from an addon module. In...