Last active
August 29, 2015 13:56
-
-
Save bert2002/9076760 to your computer and use it in GitHub Desktop.
small nagios check_disk wrapper to trigger through php
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
<?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