rendered paste body<?php
include("mssql_connect.php");
$site_id = $argv[1];
$warn = $argv[2];
$crit = $argv[3];
if ( $argc < 4 )
{
echo("Not enough args\n"); exit(3);
}
$records = mssql_query('EXECUTE nagios_GetMinutesSinceLastReading ' . $site_id);
$row = mssql_fetch_array($records);
$rows = mssql_num_rows($records);
if (mssql_num_rows($records) < 1 || ($row[0] == ""))
{
echo("*-*-* No data for site " . $site_id ." *-*-*\n");
%lazy option: repeat this bit as many times as you want to recheck, nesting each time.
%better option would be to do a loop to check it x times before giving up and doing the exit(3) thing
$records = mssql_query('EXECUTE nagios_GetMinutesSinceLastReading ' . $site_id);
$row = mssql_fetch_array($records);
$rows = mssql_num_rows($records);
if (mssql_num_rows($records) < 1 || ($row[0] == ""))
{
echo("*-*-* No data for site " . $site_id ." *-*-*\n");
exit(3);
}
}
$mins = $row[0];
$days = intval($mins / 1440);
$result = "";
if ($days == 1) $result = "1 day ";
if ($days > 1) $result = $days . " days ";
$mm = $mins - $days * 1440;
$result .= sprintf("%02d:%02d", $mm / 60, $mm % 60);
if ( $mins < $warn )
{
echo("OK: " . $result . "\n");
exit(0);
}
elseif ( $mins < $crit )
{
echo("WARN: " . $result . "\n");
exit(1);
}
else
{
echo("CRITICAL: " . $result . "\n");
exit(2);
}
echo("end!");
?>