View Single Post
Old 10th March 2009, 10:45
steve51184 steve51184 is offline
Join Date: Mar 2008
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts

Originally Posted by id10t View Post
Then I guess you are luck that I do...

Quick and sloppy, simply opens a connection to the destination port and returns an error or an OK. Licensed under GPL v. 2

Copy/paste this to a file, save it on a machine that has php-cli installed and has network access to whatever servers and ports you want to check. Edit it so there is a definition of service name, service host, and service port. Run it manually as a test, then if all is good set it up as a cron job - when you do, redirect stderr to /dev/null and let cron handle sending you email with the stdout ...


// copyright 2009
// this code is licensed for use under the GPL v. 2

// List of services and hosts to check
// Each service needs a name (whatever you like),
// the network port to connect to
// and the hostname to connect to
// Remeber - the machine running this script must
// be able to connect to these services on these hosts








function chkServer($host, $port){  
    $hostip = @gethostbyname($host); 
    if ($hostip == $host){
        echo "Server ".$host." is down or does not exist\n\r";
	return false;
        if (!$x = @fsockopen($hostip, $port, $errno, $errstr, 5)){
            return false;
            if ($x){
                @fclose($x); //close connection
	    return true;

Your host array is incorrect - each service needs a 
description, host name, and port.\n\n");

  $time=date("H:i n-j-y");
    print($time." - Service ".$service_name[$i]." on host ".$service_host[$i].":".$service_port[$i]." is down\n\r");
print("Service check complete.\n\r\n\r");
first off i want to say thank you very much for helping but i think you've misunderstood what i need

what your script does:
checks for a port on a host and email's IF it's not found (although i don't understand how it can email me)

what i need:
i need a way to run a php scrip if the check_services.php finds a service is down (or i can use yours as that seems nice and simple but i need it so IF a host is down it runs a php script)
Reply With Quote