Skip to content

Instantly share code, notes, and snippets.

@bert2002
Last active August 29, 2015 13:56
Show Gist options
  • Save bert2002/9076760 to your computer and use it in GitHub Desktop.
Save bert2002/9076760 to your computer and use it in GitHub Desktop.
small nagios check_disk wrapper to trigger through php
<?php
// global binary
$NAGIOS_DISK = "/usr/lib/nagios/plugins/check_disk";
$DISK_KEY = "Uvg2kFMfy3DU";
if (isset($_GET['key'], $_GET['w'], $_GET['c'])) {
// okay
$key = $_GET['key'];
$warning = $_GET['w'];
$critical = $_GET['c'];
if(! (preg_match('/^[0-9]+%$/', $warning) && preg_match('/^[0-9]+%$/', $critical)) ) {
echo "Critical or Warning values are not a valid value.\n";
header("HTTP/1.0 510 Not Extended");
exit;
}
if ($key == $DISK_KEY ) {
// correct key
$return = shell_exec("$NAGIOS_DISK -l -x /dev/shm -w $warning -c $critical");
if (stripos($return,"OK")) {
print "$return\n";
header("HTTP/1.0 200 Okay");
} else {
print "$return\n";
header("HTTP/1.0 507 Insufficient Storage");
}
} else {
print "ERROR\n";
header("HTTP/1.0 401 Unauthorized");
}
} else {
// error
print "ERROR\n";
header("HTTP/1.0 418 I’m a teapot");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment