Skip to content

Latest commit

 

History

History
124 lines (65 loc) · 4.48 KB

README.md

File metadata and controls

124 lines (65 loc) · 4.48 KB

cachet-manager

  • Cachet is an open source web application used by IT establishments to communicate downtime and system outages to their customers, teams and shareholders. Read more about cachet on their official page http://cachethq.io/.

  • This is a PHP script to Manage Updates on the Cachet Status Page by Hammed Olalekan Osanyinpeju aka Successtar

  • It is one of the third party application for automating systems status update on the status page. Other similar third party application available at https://docs.cachethq.io/docs/addons

  • This script serve as an agent to update status of components on cachet status page when the host is inactive and when it is active

To get the best out of this script, take note of the following

  • The script assume all your components are grouped into at least three categories which are Websites with group id = 1, API's with group id = 2 and Services with group id = 3

  • All Components are checked if they are up or down with necessary update made on cachet status page based on the result obtain from the script

  • Response Time and Uptime metrics are auto-generated by the script for all components in the API, Sevices, and other groups with group_id greater or equal to 2. Therefore, metrics are not expected to be created from the cachet dashboard for consistency.

  • On the script, you are to provide access token that the script will need to update components and the hostname of where the status page is hosted as shown below.

    private $access_token = "TYPE YOUR ACCESS TOKEN HERE";		//set access token
    
    private $myhost = "https://myStatusPageDomain.com/";	//status page base url, replace myStatusPageDomain.com with your page domain name
    
  • To make the script functional, you need to set a cron job that will execute this script at five minutes interval for uptimum performance of the script. The cron job looks like this,

     */5 * * * *      /usr/bin/php -q -f /path/to/update.php &>/dev/null
    

    or

     */5 * * * *     /usr/local/bin/php -q -f /path/to/update.php &>/dev/null
    

depending on your host configuration

  • Once the script is up and running, go to your cachet dashboard and modify the metrics generated by the script by changing the value of "Calculation of metrics" to "average".

  • With this, be rest assured of positive response, the scripts will be checking all your components in the interval of five minutes.

    POINT TO NOTE

    The script check host availabilty using a ping command using exec() function which might not be allowed for some shared hosting due to security reasons. Verify if your host allow the function by running the script below;

The code is as follow

<?php

 exec("ping -c 1 google.com", $out);

if ($out){
	echo "exec() command is allowed on this host. Nothing to worry about.";
}
?>

If you get "exec() command is allowed on this host. Nothing to worry about." as response without any error after running the php code above, the script should work perfectly for you.

Hence, if you get error message or warning it means you will have to modify the script before it can work for you.

Go to the script, change

	public function pingUrl($url){
		
		/* Filter url leaving the host name for pinging */
 		
		$url = str_replace("https://", "", str_replace("http://", "", str_replace("www.", "", $url)));
		
		$url_host = explode("/", $url);
		
		/* Ping the host name and set the time before and after pinging to measure load time */
		
		$startTime = microtime(true) * 1000;
		
		exec("ping -c 1  ".$url_host[0], $out);
		
		$stopTime = microtime(true) * 1000;
		
		/* If pinging is successful return the time taken for the transaction else return false */
		
		if ($out){
		
			return ($stopTime - $startTime);
		}
		else{
			return false;
		}
	}

TO

	public function pingUrl($url){
	
		/* Load url header */
		
		$startTime = microtime(true) * 1000;
		
		$check_header = @get_headers($url);
		
		$stopTime = microtime(true) * 1000;
		
		/* If headers were obtain successfully, calculate and return time difference */
		
		if ($check_header){
		
			return ($stopTime - $startTime);
		}
		else{
			return false;
		}
	}

This will still work but only for url that can be accessed via https or http and lower performance compare to when ping is used.

  • Finally, if you follow the guide properly, the script should work for you. Suggestion, correction and critics are highly welcome.

  • For further enquiries, you can reach me on 2347061855688 or [email protected].

  • Thanks...