Compare commits
No commits in common. "master" and "v1.0" have entirely different histories.
@ -1,8 +0,0 @@
|
|||||||
Version 2.0
|
|
||||||
Rewritten the entire command line parsing code to get rid of the
|
|
||||||
PEAR Console_GetoptPlus dependency.
|
|
||||||
The script sould now be able to run out-of-the-box on most
|
|
||||||
machines without the need for Console_GetoptPlus.
|
|
||||||
|
|
||||||
Version 1.0
|
|
||||||
First version released!
|
|
6
README
6
README
@ -8,6 +8,12 @@ This is a re-write of my previous check_md5 that was written in Bash. The Bash
|
|||||||
version is more tested and should work better. I wrote this this version mainly
|
version is more tested and should work better. I wrote this this version mainly
|
||||||
as a way to practice some PHP.
|
as a way to practice some PHP.
|
||||||
|
|
||||||
|
NOTE: For this script to work you need PEAR Console_GetoptPlus (or
|
||||||
|
Console_Getopt).
|
||||||
|
See http://pear.php.net/package/Console_GetoptPlus for more information on how
|
||||||
|
to install Console_GetoptPlus.
|
||||||
|
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h
|
-h
|
||||||
Print detailed help screen
|
Print detailed help screen
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#!/usr/bin/php
|
#!/usr/bin/php
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# #
|
# #
|
||||||
# Copyright (C) 2013 Jack-Benny Persson <jack-benny@cyberinfo.se> #
|
# Copyright (C) 2013 Jack-Benny Persson <jack-benny@cyberinfo.se> #
|
||||||
@ -26,13 +28,18 @@
|
|||||||
# Nagios plugin to monitor a single files MD5 sum. In case of mismatch #
|
# Nagios plugin to monitor a single files MD5 sum. In case of mismatch #
|
||||||
# the plugin exit with a CRICITAL error code. This behavior can be changed #
|
# the plugin exit with a CRICITAL error code. This behavior can be changed #
|
||||||
# with the --warning argument. #
|
# with the --warning argument. #
|
||||||
# Rewritten in PHP. #
|
# Rewritten in PHP (depending on PEAR ConsoleGetopt. #
|
||||||
# #
|
# #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
$VERSION="2.0";
|
//include PEAR ConsoleGetopt
|
||||||
$AUTHOR="(c) 2014 Jack-Benny Persson (jack-benny@cyberinfo.se)";
|
include ("Console/Getopt.php");
|
||||||
|
|
||||||
|
|
||||||
|
$VERSION="1.0";
|
||||||
|
$AUTHOR="(c) 2013 Jack-Benny Persson (jack-benny@cyberinfo.se)";
|
||||||
|
|
||||||
// Exit codes
|
// Exit codes
|
||||||
$STATE_OK=0;
|
$STATE_OK=0;
|
||||||
@ -82,38 +89,58 @@ EOD;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Command line parsing
|
// Arguments and options (depending on PEAR ConsoleGetopt)
|
||||||
|
$options = new Console_Getopt();
|
||||||
|
|
||||||
$shortoptions = "hV?";
|
$shortoptions = "hV?";
|
||||||
$longoptions = array("warning", "help", "version", "file:", "md5:");
|
$longoptions = array("warning", "help", "version", "file=", "md5=");
|
||||||
|
|
||||||
$options = getopt($shortoptions, $longoptions);
|
$args = $options->readPHPArgv();
|
||||||
|
$ret = $options->getopt($args, $shortoptions, $longoptions);
|
||||||
|
|
||||||
if (isset($options['h']) || isset($options['?']) || isset($options['help']))
|
if (PEAR::isError($ret))
|
||||||
{
|
{
|
||||||
print_help();
|
fwrite(STDERR,$ret->getMessage() . "\n\n");
|
||||||
exit ($STATE_OK);
|
print_help();
|
||||||
|
exit ($STATE_UNKNOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['V']) || isset($options['version']))
|
$opts = $ret[0];
|
||||||
|
|
||||||
|
if(sizeof($opts) > 0)
|
||||||
{
|
{
|
||||||
print_version();
|
foreach($opts as $o)
|
||||||
exit ($STATE_OK);
|
{
|
||||||
|
switch($o[0])
|
||||||
|
{
|
||||||
|
case 'h':
|
||||||
|
case '--help':
|
||||||
|
case '?':
|
||||||
|
print_help();
|
||||||
|
exit ($STATE_OK);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'V':
|
||||||
|
case '--version':
|
||||||
|
print_version();
|
||||||
|
exit ($STATE_OK);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '--file':
|
||||||
|
$filename = $o[1];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '--md5':
|
||||||
|
$md5 = $o[1];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '--warning':
|
||||||
|
$warning = "yes";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['file']))
|
|
||||||
{
|
|
||||||
$filename = $options['file'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($options['md5']))
|
|
||||||
{
|
|
||||||
$md5 = $options['md5'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($options['warning']))
|
|
||||||
{
|
|
||||||
$warning = "yes";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sanity checks
|
// Sanity checks
|
||||||
if (empty($filename))
|
if (empty($filename))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user