* @version 1.0 * @package FreeRadius ODBC */ # ========================================================= # SCRIPT SETTINGS # ========================================================= # Global Variables $failure_match = array("Unresponsive child"); $log_file = "/var/log/freeradius/radius.log"; $tail_lines = 10; $ip = "webserver"; $restart_command = "/etc/init.d/freeradius restart"; $sleep = 30; # Include Required Scripts require_once("Net/Ping.php"); $ping = Net_Ping::factory(); # ========================================================= # START MONITORING # ========================================================= while (true) [ # Retrieve Latest Log Entries $p = popen("tail -$tail_lines $log_file ", 'r'); while ($line = fgets($p, 1024)){ $log_data .= $line; } pclose($p); # Check for Error $err = false; foreach ($failure_match as $match){ if (strstr($log_data, $match)) $err = true; } # Parse Log Data if ($err){ # Begin Pinging $response = false; while (!$response) { $reply = $ping->ping($ip); if (isset($reply->_transmitted) && isset($reply->_received)){ if ($reply->_transmitted == $reply->_received){ $response = true; } else { sleep(2); } } else { sleep(10); } } # Restart the FreeRadius Service exec($restart_command); } # Pause for a few seconds before checking the logs again sleep($sleep); } # ========================================================= # THE END # ========================================================= ?>