#!/usr/bin/php -q -p -s \n\n"; exit(3); } $ENCODER_IP = $_SERVER["argv"][2]; // Fetch the ENCODER_IP we are looking for $PORT = intval($_SERVER["argv"][4]); // Fetch port (intval - could be tainted) $STREAMS = $_SERVER["argv"][6]; // We would expect to see this number of sockets // if things are good $identified_established_sockets = 0; // Our counter variable $netstat = shell_exec("netstat -an | grep $PORT"); // Fetch the relevant lines from netstat command $lines = split("\n", $netstat); // Split returned value by newline char foreach($lines as $line){ // Cyce through the lines if(preg_match("/$ENCODER_IP/", $line) > 0){ // Is this connection from the encoder? if(preg_match("/ESTABLISHED/", $line) > 0){ // If so is it ESTABLISHED? $identified_established_sockets += 1; // If so increment our counter by 1 } } } if($identified_established_sockets >= $STREAMS){ // Do we have the number of established // sockets that we'd expect? print "Encoder OK - Getting $identified_established_sockets". // Output something Nagios likes " streams from $ENCODER_IP | streams=$identified_established_sockets\n"; exit(0); // Return 0 - nice } else { // Otherwise.... things are bad print "Encoder problem - Getting $identified_established_sockets". // Output something Nagios likes " stream from $ENCODER_IP | streams=$identified_established_sockets\n"; exit(2); // Now that's just silly.. } ?>