Created
March 12, 2013 02:36
-
-
Save stwalkerster/5139853 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
$statusfile = "/var/local/nagios-update-check"; | |
$data = array(); | |
$ret = 0; | |
$updates = exec("/usr/lib/update-notifier/apt-check 2>&1", $data, $ret); | |
$up = explode(";", $updates); | |
$maxupdates = 15; | |
if($ret != 0) | |
{ | |
echo "Apt UNKNOWN: apt-check gave return code $ret.\n"; | |
exit(3); | |
} | |
if( $up[0] == 0 ) | |
{ | |
if(is_file($statusfile)) unlink($statusfile); | |
echo "Apt OK: Nothing to update.\n"; | |
exit(0); | |
} | |
if( $up[0] <= $maxupdates && $up[1] == 0 ) | |
{ | |
if(is_file($statusfile)) unlink($statusfile); | |
echo "Apt OK: $up[0] updates are available.\n"; | |
exit(0); | |
} | |
if( $up[0] > $maxupdates && $up[1] == 0) | |
{ | |
if(is_file($statusfile)) { | |
if(date_diff(new DateTime("@" . filectime($statusfile)), new DateTime())->d >= 1) { | |
echo "Apt WARNING: $up[0] updates are available.\n"; | |
exit(1); | |
} | |
else { | |
echo "Apt OKish: $up[0] updates are available.\n"; | |
exit(0); | |
} | |
} | |
else { | |
touch($statusfile); | |
echo "Apt OKish: $up[0] updates are available.\n"; | |
exit(0); | |
} | |
} | |
if( $up[0] != 0 && $up[1] != 0) | |
{ | |
if(is_file($statusfile)) { | |
if(date_diff(new DateTime("@" . filectime($statusfile)), new DateTime())->d >= 1) { | |
echo "Apt CRITICAL: $up[1] security updates are available, $up[0] total.\n"; | |
exit(2); | |
} | |
else { | |
echo "Apt OKish: $up[1] security updates are available, $up[0] total.\n"; | |
exit(0); | |
} | |
} | |
else { | |
touch($statusfile); | |
echo "Apt OKish: $up[1] security updates are available, $up[0] total.\n"; | |
exit(0); | |
} | |
} | |
echo "Apt UNKNOWN: unspecified error.\n"; | |
exit(3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment