diff options
| author | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-09-18 22:59:46 +0200 |
|---|---|---|
| committer | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-09-18 22:59:46 +0200 |
| commit | 0e70e81133c25274fe2dd2309556b41357dd759b (patch) | |
| tree | 9a680b36788ee1ad4e7ecc5ccfeb4494db9fdc72 /plugins-scripts | |
| parent | ce355c80cf6054bfa5e1dcf81f9e2183ef963ee1 (diff) | |
| parent | 2ddc75e69db5a3dd379c896d8420c9af20ec1cee (diff) | |
| download | monitoring-plugins-0e70e81133c25274fe2dd2309556b41357dd759b.tar.gz | |
Merge branch 'master' into mysql_detect_mysqldump
Diffstat (limited to 'plugins-scripts')
| -rw-r--r-- | plugins-scripts/Makefile.am | 4 | ||||
| -rwxr-xr-x | plugins-scripts/check_breeze.pl | 3 | ||||
| -rw-r--r--[-rwxr-xr-x] | plugins-scripts/check_disk_smb.pl | 23 | ||||
| -rwxr-xr-x | plugins-scripts/check_file_age.pl | 2 | ||||
| -rwxr-xr-x | plugins-scripts/check_ifoperstatus.pl | 8 | ||||
| -rwxr-xr-x | plugins-scripts/check_ifstatus.pl | 2 | ||||
| -rwxr-xr-x | plugins-scripts/check_ircd.pl | 4 | ||||
| -rwxr-xr-x | plugins-scripts/check_log.sh | 168 | ||||
| -rwxr-xr-x | plugins-scripts/check_mailq.pl | 84 | ||||
| -rwxr-xr-x | plugins-scripts/check_oracle.sh | 244 | ||||
| -rwxr-xr-x | plugins-scripts/check_rpc.pl | 2 | ||||
| -rwxr-xr-x | plugins-scripts/check_sensors.sh | 34 | ||||
| -rwxr-xr-x | plugins-scripts/check_uptime.pl | 19 | ||||
| -rwxr-xr-x | plugins-scripts/check_wave.pl | 15 | ||||
| -rw-r--r-- | plugins-scripts/t/check_log.t | 82 | ||||
| -rw-r--r-- | plugins-scripts/t/check_uptime.t | 22 | ||||
| -rw-r--r-- | plugins-scripts/utils.pm.in | 1 |
17 files changed, 450 insertions, 267 deletions
diff --git a/plugins-scripts/Makefile.am b/plugins-scripts/Makefile.am index 088a4459..7879791f 100644 --- a/plugins-scripts/Makefile.am +++ b/plugins-scripts/Makefile.am | |||
| @@ -16,13 +16,13 @@ VPATH=$(top_srcdir) $(top_srcdir)/plugins-scripts $(top_srcdir)/plugins-scripts/ | |||
| 16 | libexec_SCRIPTS = check_breeze check_disk_smb check_flexlm check_ircd \ | 16 | libexec_SCRIPTS = check_breeze check_disk_smb check_flexlm check_ircd \ |
| 17 | check_log check_oracle check_rpc check_sensors check_wave \ | 17 | check_log check_oracle check_rpc check_sensors check_wave \ |
| 18 | check_ifstatus check_ifoperstatus check_mailq check_file_age \ | 18 | check_ifstatus check_ifoperstatus check_mailq check_file_age \ |
| 19 | check_uptime \ | 19 | check_uptime check_mssql \ |
| 20 | utils.sh utils.pm | 20 | utils.sh utils.pm |
| 21 | 21 | ||
| 22 | EXTRA_DIST=check_breeze.pl check_disk_smb.pl check_flexlm.pl check_ircd.pl \ | 22 | EXTRA_DIST=check_breeze.pl check_disk_smb.pl check_flexlm.pl check_ircd.pl \ |
| 23 | check_log.sh check_oracle.sh check_rpc.pl check_sensors.sh \ | 23 | check_log.sh check_oracle.sh check_rpc.pl check_sensors.sh \ |
| 24 | check_ifstatus.pl check_ifoperstatus.pl check_wave.pl check_mailq.pl check_file_age.pl \ | 24 | check_ifstatus.pl check_ifoperstatus.pl check_wave.pl check_mailq.pl check_file_age.pl \ |
| 25 | check_uptime.pl \ | 25 | check_uptime.pl check_mssql.pl \ |
| 26 | utils.sh.in utils.pm.in t | 26 | utils.sh.in utils.pm.in t |
| 27 | 27 | ||
| 28 | EDIT = sed \ | 28 | EDIT = sed \ |
diff --git a/plugins-scripts/check_breeze.pl b/plugins-scripts/check_breeze.pl index 05b99203..531625c4 100755 --- a/plugins-scripts/check_breeze.pl +++ b/plugins-scripts/check_breeze.pl | |||
| @@ -14,8 +14,9 @@ sub print_help (); | |||
| 14 | sub print_usage (); | 14 | sub print_usage (); |
| 15 | 15 | ||
| 16 | $ENV{'PATH'}='@TRUSTED_PATH@'; | 16 | $ENV{'PATH'}='@TRUSTED_PATH@'; |
| 17 | $ENV{'BASH_ENV'}=''; | 17 | $ENV{'BASH_ENV'}=''; |
| 18 | $ENV{'ENV'}=''; | 18 | $ENV{'ENV'}=''; |
| 19 | $ENV{'CDPATH'}=''; | ||
| 19 | 20 | ||
| 20 | Getopt::Long::Configure('bundling'); | 21 | Getopt::Long::Configure('bundling'); |
| 21 | GetOptions | 22 | GetOptions |
diff --git a/plugins-scripts/check_disk_smb.pl b/plugins-scripts/check_disk_smb.pl index 28c49e84..f4d33a7b 100755..100644 --- a/plugins-scripts/check_disk_smb.pl +++ b/plugins-scripts/check_disk_smb.pl | |||
| @@ -22,13 +22,13 @@ require 5.004; | |||
| 22 | use POSIX qw(setsid); | 22 | use POSIX qw(setsid); |
| 23 | use strict; | 23 | use strict; |
| 24 | use Getopt::Long; | 24 | use Getopt::Long; |
| 25 | use vars qw($opt_P $opt_V $opt_h $opt_H $opt_s $opt_W $opt_u $opt_p $opt_w $opt_c $opt_a $verbose); | 25 | use vars qw($opt_P $opt_V $opt_h $opt_H $opt_s $opt_W $opt_u $opt_p $opt_w $opt_c $opt_a $opt_C $opt_t $verbose); |
| 26 | use vars qw($PROGNAME); | 26 | use vars qw($PROGNAME); |
| 27 | use FindBin; | 27 | use FindBin; |
| 28 | use lib "$FindBin::Bin"; | 28 | use lib "$FindBin::Bin"; |
| 29 | use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); | 29 | use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); |
| 30 | 30 | ||
| 31 | # make us session leader which makes all childs exit if we do | 31 | # make us session leader which makes all children exit if we do |
| 32 | setsid; | 32 | setsid; |
| 33 | 33 | ||
| 34 | sub print_help (); | 34 | sub print_help (); |
| @@ -43,6 +43,7 @@ $ENV{'ENV'}=''; | |||
| 43 | Getopt::Long::Configure('bundling'); | 43 | Getopt::Long::Configure('bundling'); |
| 44 | GetOptions | 44 | GetOptions |
| 45 | ("v" => \$verbose, "verbose" => \$verbose, | 45 | ("v" => \$verbose, "verbose" => \$verbose, |
| 46 | "t=i" => \$opt_t, "timeout=i" => \$opt_t, | ||
| 46 | "P=s" => \$opt_P, "port=s" => \$opt_P, | 47 | "P=s" => \$opt_P, "port=s" => \$opt_P, |
| 47 | "V" => \$opt_V, "version" => \$opt_V, | 48 | "V" => \$opt_V, "version" => \$opt_V, |
| 48 | "h" => \$opt_h, "help" => \$opt_h, | 49 | "h" => \$opt_h, "help" => \$opt_h, |
| @@ -53,7 +54,8 @@ GetOptions | |||
| 53 | "s=s" => \$opt_s, "share=s" => \$opt_s, | 54 | "s=s" => \$opt_s, "share=s" => \$opt_s, |
| 54 | "W=s" => \$opt_W, "workgroup=s" => \$opt_W, | 55 | "W=s" => \$opt_W, "workgroup=s" => \$opt_W, |
| 55 | "H=s" => \$opt_H, "hostname=s" => \$opt_H, | 56 | "H=s" => \$opt_H, "hostname=s" => \$opt_H, |
| 56 | "a=s" => \$opt_a, "address=s" => \$opt_a); | 57 | "a=s" => \$opt_a, "address=s" => \$opt_a, |
| 58 | "C=s" => \$opt_C, "configfile=s" => \$opt_C); | ||
| 57 | 59 | ||
| 58 | if ($opt_V) { | 60 | if ($opt_V) { |
| 59 | print_revision($PROGNAME,'@NP_VERSION@'); #' | 61 | print_revision($PROGNAME,'@NP_VERSION@'); #' |
| @@ -91,6 +93,12 @@ my $warn = $1 if ($opt_w =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/); | |||
| 91 | my $crit = $1 if ($opt_c =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/); | 93 | my $crit = $1 if ($opt_c =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/); |
| 92 | ($crit) || usage("Invalid critical threshold: $opt_c\n"); | 94 | ($crit) || usage("Invalid critical threshold: $opt_c\n"); |
| 93 | 95 | ||
| 96 | ($opt_C) || ($opt_C = shift @ARGV) || ($opt_C = ""); | ||
| 97 | my $configfile = $opt_C if ($opt_C); | ||
| 98 | usage("Unable to read config file $configfile\n") if ($configfile) && (! -r $configfile); | ||
| 99 | |||
| 100 | if ($opt_t && $opt_t =~ /^([0-9]+)$/) { $TIMEOUT = $1; } | ||
| 101 | |||
| 94 | # Execute the given command line and return anything it writes to STDOUT and/or | 102 | # Execute the given command line and return anything it writes to STDOUT and/or |
| 95 | # STDERR. (This might be useful for other plugins, too, so it should possibly | 103 | # STDERR. (This might be useful for other plugins, too, so it should possibly |
| 96 | # be moved to utils.pm.) | 104 | # be moved to utils.pm.) |
| @@ -193,6 +201,7 @@ my @cmd = ( | |||
| 193 | defined($workgroup) ? ("-W", $workgroup) : (), | 201 | defined($workgroup) ? ("-W", $workgroup) : (), |
| 194 | defined($address) ? ("-I", $address) : (), | 202 | defined($address) ? ("-I", $address) : (), |
| 195 | defined($opt_P) ? ("-p", $opt_P) : (), | 203 | defined($opt_P) ? ("-p", $opt_P) : (), |
| 204 | defined($configfile) ? ("-s", $configfile) : (), | ||
| 196 | "-c", "du" | 205 | "-c", "du" |
| 197 | ); | 206 | ); |
| 198 | 207 | ||
| @@ -292,7 +301,8 @@ exit $ERRORS{$state}; | |||
| 292 | 301 | ||
| 293 | sub print_usage () { | 302 | sub print_usage () { |
| 294 | print "Usage: $PROGNAME -H <host> -s <share> -u <user> -p <password> | 303 | print "Usage: $PROGNAME -H <host> -s <share> -u <user> -p <password> |
| 295 | -w <warn> -c <crit> [-W <workgroup>] [-P <port>] [-a <IP>]\n"; | 304 | -w <warn> -c <crit> [-W <workgroup>] [-P <port>] [-a <IP>] [-t timeout] |
| 305 | [-C <configfile>]\n"; | ||
| 296 | } | 306 | } |
| 297 | 307 | ||
| 298 | sub print_help () { | 308 | sub print_help () { |
| @@ -318,11 +328,14 @@ Perl Check SMB Disk plugin for monitoring | |||
| 318 | Password to log in to server. (Defaults to an empty password) | 328 | Password to log in to server. (Defaults to an empty password) |
| 319 | -w, --warning=INTEGER or INTEGER[kMG] | 329 | -w, --warning=INTEGER or INTEGER[kMG] |
| 320 | Percent of used space at which a warning will be generated (Default: 85%) | 330 | Percent of used space at which a warning will be generated (Default: 85%) |
| 321 | |||
| 322 | -c, --critical=INTEGER or INTEGER[kMG] | 331 | -c, --critical=INTEGER or INTEGER[kMG] |
| 323 | Percent of used space at which a critical will be generated (Defaults: 95%) | 332 | Percent of used space at which a critical will be generated (Defaults: 95%) |
| 333 | -t, --timeout=INTEGER | ||
| 334 | Seconds before connection times out (Default: 15) | ||
| 324 | -P, --port=INTEGER | 335 | -P, --port=INTEGER |
| 325 | Port to be used to connect to. Some Windows boxes use 139, others 445 (Defaults to smbclient default) | 336 | Port to be used to connect to. Some Windows boxes use 139, others 445 (Defaults to smbclient default) |
| 337 | -C, --configfile=STRING | ||
| 338 | Path to configfile which should be used by smbclient (Defaults to smb.conf of your smb installation) | ||
| 326 | 339 | ||
| 327 | If thresholds are followed by either a k, M, or G then check to see if that | 340 | If thresholds are followed by either a k, M, or G then check to see if that |
| 328 | much disk space is available (kilobytes, Megabytes, Gigabytes) | 341 | much disk space is available (kilobytes, Megabytes, Gigabytes) |
diff --git a/plugins-scripts/check_file_age.pl b/plugins-scripts/check_file_age.pl index 01b854a6..26281ddd 100755 --- a/plugins-scripts/check_file_age.pl +++ b/plugins-scripts/check_file_age.pl | |||
| @@ -147,7 +147,7 @@ sub print_help () { | |||
| 147 | print "\n"; | 147 | print "\n"; |
| 148 | print " -i | --ignore-missing : return OK if the file does not exist\n"; | 148 | print " -i | --ignore-missing : return OK if the file does not exist\n"; |
| 149 | print " <secs> File must be no more than this many seconds old (default: warn 240 secs, crit 600)\n"; | 149 | print " <secs> File must be no more than this many seconds old (default: warn 240 secs, crit 600)\n"; |
| 150 | print " <size> File must be at least this many bytes long (default: crit 0 bytes)\n\n"; | 150 | print " <size> File must be at least this many bytes long (default: file size is ignored (0 bytes))\n\n"; |
| 151 | print " Both <secs> and <size> can specify a range using the standard plugin syntax\n"; | 151 | print " Both <secs> and <size> can specify a range using the standard plugin syntax\n"; |
| 152 | print " If any of the warning and critical arguments are in range syntax (not just bare numbers)\n"; | 152 | print " If any of the warning and critical arguments are in range syntax (not just bare numbers)\n"; |
| 153 | print " then all warning and critical arguments will be interpreted as ranges.\n"; | 153 | print " then all warning and critical arguments will be interpreted as ranges.\n"; |
diff --git a/plugins-scripts/check_ifoperstatus.pl b/plugins-scripts/check_ifoperstatus.pl index c190ce95..e335cdad 100755 --- a/plugins-scripts/check_ifoperstatus.pl +++ b/plugins-scripts/check_ifoperstatus.pl | |||
| @@ -134,7 +134,7 @@ if (defined $ifdescr || defined $iftype) { | |||
| 134 | } | 134 | } |
| 135 | if ($status==0) { | 135 | if ($status==0) { |
| 136 | $state = "UNKNOWN"; | 136 | $state = "UNKNOWN"; |
| 137 | printf "$state: could not retrive ifdescr/iftype snmpkey - $status-$snmpkey\n"; | 137 | printf "$state: could not retrieve ifdescr/iftype snmpkey - $status-$snmpkey\n"; |
| 138 | $session->close; | 138 | $session->close; |
| 139 | exit $ERRORS{$state}; | 139 | exit $ERRORS{$state}; |
| 140 | } | 140 | } |
| @@ -187,7 +187,7 @@ if (defined $ifXTable) { | |||
| 187 | $name = $response->{$snmpIfDescr} ; | 187 | $name = $response->{$snmpIfDescr} ; |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | ## if AdminStatus is down - some one made a consious effort to change config | 190 | ## if AdminStatus is down - some one made a conscious effort to change config |
| 191 | ## | 191 | ## |
| 192 | if ( not ($response->{$snmpIfAdminStatus} == 1) ) { | 192 | if ( not ($response->{$snmpIfAdminStatus} == 1) ) { |
| 193 | $answer = "Interface $name (index $snmpkey) is administratively down."; | 193 | $answer = "Interface $name (index $snmpkey) is administratively down."; |
| @@ -286,7 +286,7 @@ sub print_usage() { | |||
| 286 | printf "check_ifoperstatus -k <IF_KEY> -H <HOSTNAME> [-C <community>]\n"; | 286 | printf "check_ifoperstatus -k <IF_KEY> -H <HOSTNAME> [-C <community>]\n"; |
| 287 | printf "Copyright (C) 2000 Christoph Kron\n"; | 287 | printf "Copyright (C) 2000 Christoph Kron\n"; |
| 288 | printf "check_ifoperstatus.pl comes with ABSOLUTELY NO WARRANTY\n"; | 288 | printf "check_ifoperstatus.pl comes with ABSOLUTELY NO WARRANTY\n"; |
| 289 | printf "This programm is licensed under the terms of the "; | 289 | printf "This program is licensed under the terms of the "; |
| 290 | printf "GNU General Public License\n(check source code for details)\n"; | 290 | printf "GNU General Public License\n(check source code for details)\n"; |
| 291 | printf "\n\n"; | 291 | printf "\n\n"; |
| 292 | } | 292 | } |
| @@ -424,7 +424,7 @@ sub process_arguments() { | |||
| 424 | if (defined $seclevel && defined $secname) { | 424 | if (defined $seclevel && defined $secname) { |
| 425 | $session_opts{'-username'} = $secname; | 425 | $session_opts{'-username'} = $secname; |
| 426 | 426 | ||
| 427 | # Must define a security level even though defualt is noAuthNoPriv | 427 | # Must define a security level even though default is noAuthNoPriv |
| 428 | unless ( grep /^$seclevel$/, qw(noAuthNoPriv authNoPriv authPriv) ) { | 428 | unless ( grep /^$seclevel$/, qw(noAuthNoPriv authNoPriv authPriv) ) { |
| 429 | usage("Must define a valid security level even though default is noAuthNoPriv"); | 429 | usage("Must define a valid security level even though default is noAuthNoPriv"); |
| 430 | } | 430 | } |
diff --git a/plugins-scripts/check_ifstatus.pl b/plugins-scripts/check_ifstatus.pl index 32984e53..38b87fcc 100755 --- a/plugins-scripts/check_ifstatus.pl +++ b/plugins-scripts/check_ifstatus.pl | |||
| @@ -354,7 +354,7 @@ sub process_arguments() { | |||
| 354 | if (defined $seclevel && defined $secname) { | 354 | if (defined $seclevel && defined $secname) { |
| 355 | $session_opts{'-username'} = $secname; | 355 | $session_opts{'-username'} = $secname; |
| 356 | 356 | ||
| 357 | # Must define a security level even though defualt is noAuthNoPriv | 357 | # Must define a security level even though default is noAuthNoPriv |
| 358 | unless ( grep /^$seclevel$/, qw(noAuthNoPriv authNoPriv authPriv) ) { | 358 | unless ( grep /^$seclevel$/, qw(noAuthNoPriv authNoPriv authPriv) ) { |
| 359 | usage("Must define a valid security level even though default is noAuthNoPriv"); | 359 | usage("Must define a valid security level even though default is noAuthNoPriv"); |
| 360 | } | 360 | } |
diff --git a/plugins-scripts/check_ircd.pl b/plugins-scripts/check_ircd.pl index d869ae7b..84f20229 100755 --- a/plugins-scripts/check_ircd.pl +++ b/plugins-scripts/check_ircd.pl | |||
| @@ -60,7 +60,7 @@ sub print_usage (); | |||
| 60 | sub connection ($$$$); | 60 | sub connection ($$$$); |
| 61 | sub bindRemote ($$); | 61 | sub bindRemote ($$); |
| 62 | 62 | ||
| 63 | # -------------------------------------------------------------[ Enviroment ]-- | 63 | # -------------------------------------------------------------[ Environment ]-- |
| 64 | 64 | ||
| 65 | $ENV{'PATH'}='@TRUSTED_PATH@'; | 65 | $ENV{'PATH'}='@TRUSTED_PATH@'; |
| 66 | $ENV{'BASH_ENV'}=''; | 66 | $ENV{'BASH_ENV'}=''; |
| @@ -208,7 +208,7 @@ MAIN: | |||
| 208 | 208 | ||
| 209 | # Just in case of problems, let's not hang the monitoring system | 209 | # Just in case of problems, let's not hang the monitoring system |
| 210 | $SIG{'ALRM'} = sub { | 210 | $SIG{'ALRM'} = sub { |
| 211 | print "Somthing is Taking a Long Time, Increase Your TIMEOUT (Currently Set At $TIMEOUT Seconds)\n"; | 211 | print "Something is Taking a Long Time, Increase Your TIMEOUT (Currently Set At $TIMEOUT Seconds)\n"; |
| 212 | exit $ERRORS{"UNKNOWN"}; | 212 | exit $ERRORS{"UNKNOWN"}; |
| 213 | }; | 213 | }; |
| 214 | 214 | ||
diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index d28c8d0a..8ecdd316 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh | |||
| @@ -1,8 +1,7 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | # | 2 | # |
| 3 | # Log file pattern detector plugin for monitoring | 3 | # Log file pattern detector plugin for monitoring |
| 4 | # Written by Ethan Galstad (nagios@nagios.org) | 4 | # Written originally by Ethan Galstad (nagios@nagios.org) |
| 5 | # Last Modified: 07-31-1999 | ||
| 6 | # | 5 | # |
| 7 | # Usage: ./check_log <log_file> <old_log_file> <pattern> | 6 | # Usage: ./check_log <log_file> <old_log_file> <pattern> |
| 8 | # | 7 | # |
| @@ -19,7 +18,7 @@ | |||
| 19 | # On the first run of the plugin, it will return an OK state with a message | 18 | # On the first run of the plugin, it will return an OK state with a message |
| 20 | # of "Log check data initialized". On successive runs, it will return an OK | 19 | # of "Log check data initialized". On successive runs, it will return an OK |
| 21 | # state if *no* pattern matches have been found in the *difference* between the | 20 | # state if *no* pattern matches have been found in the *difference* between the |
| 22 | # log file and the older copy of the log file. If the plugin detects any | 21 | # log file and the older copy of the log file. If the plugin detects any |
| 23 | # pattern matches in the log diff, it will return a CRITICAL state and print | 22 | # pattern matches in the log diff, it will return a CRITICAL state and print |
| 24 | # out a message is the following format: "(x) last_match", where "x" is the | 23 | # out a message is the following format: "(x) last_match", where "x" is the |
| 25 | # total number of pattern matches found in the file and "last_match" is the | 24 | # total number of pattern matches found in the file and "last_match" is the |
| @@ -44,6 +43,10 @@ | |||
| 44 | # check the same <log_file> for pattern matches. This is necessary | 43 | # check the same <log_file> for pattern matches. This is necessary |
| 45 | # because of the way the script operates. | 44 | # because of the way the script operates. |
| 46 | # | 45 | # |
| 46 | # 4. This plugin does NOT have an understanding of logrotation or similar | ||
| 47 | # mechanisms. Therefore bad timing could lead to missing events | ||
| 48 | # | ||
| 49 | # | ||
| 47 | # Examples: | 50 | # Examples: |
| 48 | # | 51 | # |
| 49 | # Check for login failures in the syslog... | 52 | # Check for login failures in the syslog... |
| @@ -60,20 +63,26 @@ | |||
| 60 | 63 | ||
| 61 | PATH="@TRUSTED_PATH@" | 64 | PATH="@TRUSTED_PATH@" |
| 62 | export PATH | 65 | export PATH |
| 63 | PROGNAME=`basename $0` | 66 | PROGNAME=$(basename "$0") |
| 64 | PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` | 67 | PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,') |
| 65 | REVISION="@NP_VERSION@" | 68 | REVISION="@NP_VERSION@" |
| 66 | 69 | ||
| 67 | . $PROGPATH/utils.sh | 70 | . "$PROGPATH"/utils.sh |
| 68 | 71 | ||
| 69 | print_usage() { | 72 | print_usage() { |
| 70 | echo "Usage: $PROGNAME -F logfile -O oldlog -q query" | 73 | echo "Usage: $PROGNAME -F logfile -O oldlog -q query" |
| 71 | echo "Usage: $PROGNAME --help" | 74 | echo "Usage: $PROGNAME --help" |
| 72 | echo "Usage: $PROGNAME --version" | 75 | echo "Usage: $PROGNAME --version" |
| 76 | echo "" | ||
| 77 | echo "Other parameters:" | ||
| 78 | echo " -a|--all : Print all matching lines" | ||
| 79 | echo " --exclude: Exclude a pattern (-p or -e also applies here when used)" | ||
| 80 | echo " -p|--perl-regex : Use perl style regular expressions in the query" | ||
| 81 | echo " -e|--extended-regex : Use extended style regular expressions in the query (not necessary for GNU grep)" | ||
| 73 | } | 82 | } |
| 74 | 83 | ||
| 75 | print_help() { | 84 | print_help() { |
| 76 | print_revision $PROGNAME $REVISION | 85 | print_revision "$PROGNAME" "$REVISION" |
| 77 | echo "" | 86 | echo "" |
| 78 | print_usage | 87 | print_usage |
| 79 | echo "" | 88 | echo "" |
| @@ -87,81 +96,89 @@ print_help() { | |||
| 87 | 96 | ||
| 88 | if [ $# -lt 1 ]; then | 97 | if [ $# -lt 1 ]; then |
| 89 | print_usage | 98 | print_usage |
| 90 | exit $STATE_UNKNOWN | 99 | exit "$STATE_UNKNOWN" |
| 91 | fi | 100 | fi |
| 92 | 101 | ||
| 93 | # Grab the command line arguments | 102 | # Grab the command line arguments |
| 94 | |||
| 95 | #logfile=$1 | ||
| 96 | #oldlog=$2 | ||
| 97 | #query=$3 | ||
| 98 | exitstatus=$STATE_WARNING #default | 103 | exitstatus=$STATE_WARNING #default |
| 99 | while test -n "$1"; do | 104 | while test -n "$1"; do |
| 100 | case "$1" in | 105 | case "$1" in |
| 101 | --help) | 106 | -h | --help) |
| 102 | print_help | 107 | print_help |
| 103 | exit $STATE_OK | 108 | exit "$STATE_UNKNOWN" |
| 104 | ;; | 109 | ;; |
| 105 | -h) | 110 | -V | --version) |
| 106 | print_help | 111 | print_revision "$PROGNAME" "$REVISION" |
| 107 | exit $STATE_OK | 112 | exit "$STATE_UNKNOWN" |
| 108 | ;; | ||
| 109 | --version) | ||
| 110 | print_revision $PROGNAME $REVISION | ||
| 111 | exit $STATE_OK | ||
| 112 | ;; | ||
| 113 | -V) | ||
| 114 | print_revision $PROGNAME $REVISION | ||
| 115 | exit $STATE_OK | ||
| 116 | ;; | ||
| 117 | --filename) | ||
| 118 | logfile=$2 | ||
| 119 | shift | ||
| 120 | ;; | 113 | ;; |
| 121 | -F) | 114 | -F | --filename) |
| 122 | logfile=$2 | 115 | logfile=$2 |
| 123 | shift | 116 | shift 2 |
| 124 | ;; | 117 | ;; |
| 125 | --oldlog) | 118 | -O | --oldlog) |
| 126 | oldlog=$2 | 119 | oldlog=$2 |
| 127 | shift | 120 | shift 2 |
| 128 | ;; | 121 | ;; |
| 129 | -O) | 122 | -q | --query) |
| 130 | oldlog=$2 | ||
| 131 | shift | ||
| 132 | ;; | ||
| 133 | --query) | ||
| 134 | query=$2 | 123 | query=$2 |
| 135 | shift | 124 | shift 2 |
| 136 | ;; | 125 | ;; |
| 137 | -q) | 126 | --exclude) |
| 138 | query=$2 | 127 | exclude=$2 |
| 139 | shift | 128 | shift 2 |
| 140 | ;; | 129 | ;; |
| 141 | -x) | 130 | -x | --exitstatus) |
| 142 | exitstatus=$2 | 131 | exitstatus=$2 |
| 132 | shift 2 | ||
| 133 | ;; | ||
| 134 | -e | --extended-regex) | ||
| 135 | ERE=1 | ||
| 143 | shift | 136 | shift |
| 144 | ;; | 137 | ;; |
| 145 | --exitstatus) | 138 | -p | --perl-regex) |
| 146 | exitstatus=$2 | 139 | PRE=1 |
| 140 | shift | ||
| 141 | ;; | ||
| 142 | -a | --all) | ||
| 143 | ALL=1 | ||
| 147 | shift | 144 | shift |
| 148 | ;; | 145 | ;; |
| 149 | *) | 146 | *) |
| 150 | echo "Unknown argument: $1" | 147 | echo "Unknown argument: $1" |
| 151 | print_usage | 148 | print_usage |
| 152 | exit $STATE_UNKNOWN | 149 | exit "$STATE_UNKNOWN" |
| 153 | ;; | 150 | ;; |
| 154 | esac | 151 | esac |
| 155 | shift | ||
| 156 | done | 152 | done |
| 157 | 153 | ||
| 154 | # Parameter sanity check | ||
| 155 | if [ $ERE ] && [ $PRE ] ; then | ||
| 156 | echo "Can not use extended and perl regex at the same time" | ||
| 157 | exit "$STATE_UNKNOWN" | ||
| 158 | fi | ||
| 159 | |||
| 160 | GREP="grep" | ||
| 161 | |||
| 162 | if [ $ERE ]; then | ||
| 163 | GREP="grep -E" | ||
| 164 | fi | ||
| 165 | |||
| 166 | if [ $PRE ]; then | ||
| 167 | GREP="grep -P" | ||
| 168 | fi | ||
| 169 | |||
| 158 | # If the source log file doesn't exist, exit | 170 | # If the source log file doesn't exist, exit |
| 159 | 171 | ||
| 160 | if [ ! -e $logfile ]; then | 172 | if [ ! -e "$logfile" ]; then |
| 161 | echo "Log check error: Log file $logfile does not exist!" | 173 | echo "Log check error: Log file $logfile does not exist!" |
| 162 | exit $STATE_UNKNOWN | 174 | exit "$STATE_UNKNOWN" |
| 163 | elif [ ! -r $logfile ] ; then | 175 | elif [ ! -r "$logfile" ] ; then |
| 164 | echo "Log check error: Log file $logfile is not readable!" | 176 | echo "Log check error: Log file $logfile is not readable!" |
| 177 | exit "$STATE_UNKNOWN" | ||
| 178 | fi | ||
| 179 | # If no oldlog was given this can not work properly, abort then | ||
| 180 | if [ -z "$oldlog" ]; then | ||
| 181 | echo "Oldlog parameter is needed" | ||
| 165 | exit $STATE_UNKNOWN | 182 | exit $STATE_UNKNOWN |
| 166 | fi | 183 | fi |
| 167 | 184 | ||
| @@ -169,10 +186,10 @@ fi | |||
| 169 | # we're running this test, so copy the original log file over to | 186 | # we're running this test, so copy the original log file over to |
| 170 | # the old diff file and exit | 187 | # the old diff file and exit |
| 171 | 188 | ||
| 172 | if [ ! -e $oldlog ]; then | 189 | if [ ! -e "$oldlog" ]; then |
| 173 | cat $logfile > $oldlog | 190 | cat "$logfile" > "$oldlog" |
| 174 | echo "Log check data initialized..." | 191 | echo "Log check data initialized..." |
| 175 | exit $STATE_OK | 192 | exit "$STATE_OK" |
| 176 | fi | 193 | fi |
| 177 | 194 | ||
| 178 | # The old log file exists, so compare it to the original log now | 195 | # The old log file exists, so compare it to the original log now |
| @@ -180,31 +197,48 @@ fi | |||
| 180 | # The temporary file that the script should use while | 197 | # The temporary file that the script should use while |
| 181 | # processing the log file. | 198 | # processing the log file. |
| 182 | if [ -x /bin/mktemp ]; then | 199 | if [ -x /bin/mktemp ]; then |
| 183 | tempdiff=`/bin/mktemp /tmp/check_log.XXXXXXXXXX` | 200 | |
| 201 | tempdiff=$(/bin/mktemp /tmp/check_log.XXXXXXXXXX) | ||
| 184 | else | 202 | else |
| 185 | tempdiff=`/bin/date '+%H%M%S'` | 203 | tempdiff=$(/bin/date '+%H%M%S') |
| 186 | tempdiff="/tmp/check_log.${tempdiff}" | 204 | tempdiff="/tmp/check_log.${tempdiff}" |
| 187 | touch $tempdiff | 205 | touch "$tempdiff" |
| 188 | chmod 600 $tempdiff | 206 | chmod 600 "$tempdiff" |
| 189 | fi | 207 | fi |
| 190 | 208 | ||
| 191 | diff $logfile $oldlog | grep -v "^>" > $tempdiff | 209 | diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff" |
| 210 | |||
| 192 | 211 | ||
| 193 | # Count the number of matching log entries we have | 212 | if [ $ALL ]; then |
| 194 | count=`grep -c "$query" $tempdiff` | 213 | # Get all matching entries in the diff file |
| 214 | if [ -n "$exclude" ]; then | ||
| 215 | entry=$($GREP "$query" "$tempdiff" | $GREP -v "$exclude") | ||
| 216 | count=$($GREP "$query" "$tempdiff" | $GREP -vc "$exclude") | ||
| 217 | else | ||
| 218 | entry=$($GREP "$query" "$tempdiff") | ||
| 219 | count=$($GREP -c "$query" "$tempdiff") | ||
| 220 | fi | ||
| 195 | 221 | ||
| 196 | # Get the last matching entry in the diff file | 222 | else |
| 197 | lastentry=`grep "$query" $tempdiff | tail -1` | 223 | # Get the last matching entry in the diff file |
| 224 | if [ -n "$exclude" ]; then | ||
| 225 | entry=$($GREP "$query" "$tempdiff" | $GREP -v "$exclude" | tail -1) | ||
| 226 | count=$($GREP "$query" "$tempdiff" | $GREP -vc "$exclude") | ||
| 227 | else | ||
| 228 | entry=$($GREP "$query" "$tempdiff" | tail -1) | ||
| 229 | count=$($GREP -c "$query" "$tempdiff") | ||
| 230 | fi | ||
| 231 | fi | ||
| 198 | 232 | ||
| 199 | rm -f $tempdiff | 233 | rm -f "$tempdiff" |
| 200 | cat $logfile > $oldlog | 234 | cat "$logfile" > "$oldlog" |
| 201 | 235 | ||
| 202 | if [ "$count" = "0" ]; then # no matches, exit with no error | 236 | if [ "$count" = "0" ]; then # no matches, exit with no error |
| 203 | echo "Log check ok - 0 pattern matches found" | 237 | echo "Log check ok - 0 pattern matches found" |
| 204 | exitstatus=$STATE_OK | 238 | exitstatus=$STATE_OK |
| 205 | else # Print total matche count and the last entry we found | 239 | else # Print total match count and the last entry we found |
| 206 | echo "($count) $lastentry" | 240 | echo "($count) $entry" |
| 207 | exitstatus=$STATE_CRITICAL | 241 | exitstatus=$STATE_CRITICAL |
| 208 | fi | 242 | fi |
| 209 | 243 | ||
| 210 | exit $exitstatus | 244 | exit "$exitstatus" |
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl index aac1310e..49156af3 100755 --- a/plugins-scripts/check_mailq.pl +++ b/plugins-scripts/check_mailq.pl | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | # transmittal. | 4 | # transmittal. |
| 5 | # | 5 | # |
| 6 | # Initial version support sendmail's mailq command | 6 | # Initial version support sendmail's mailq command |
| 7 | # Support for mutiple sendmail queues (Carlos Canau) | 7 | # Support for multiple sendmail queues (Carlos Canau) |
| 8 | # Support for qmail (Benjamin Schmid) | 8 | # Support for qmail (Benjamin Schmid) |
| 9 | 9 | ||
| 10 | # License Information: | 10 | # License Information: |
| @@ -28,9 +28,9 @@ | |||
| 28 | use POSIX; | 28 | use POSIX; |
| 29 | use strict; | 29 | use strict; |
| 30 | use Getopt::Long; | 30 | use Getopt::Long; |
| 31 | use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t $opt_s | 31 | use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t $opt_s $opt_d |
| 32 | $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $mailq @lines | 32 | $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $mailq $mailq_args |
| 33 | %srcdomains %dstdomains); | 33 | @lines %srcdomains %dstdomains); |
| 34 | use FindBin; | 34 | use FindBin; |
| 35 | use lib "$FindBin::Bin"; | 35 | use lib "$FindBin::Bin"; |
| 36 | use utils qw(%ERRORS &print_revision &support &usage ); | 36 | use utils qw(%ERRORS &print_revision &support &usage ); |
| @@ -48,6 +48,8 @@ $PROGNAME = "check_mailq"; | |||
| 48 | $mailq = 'sendmail'; # default | 48 | $mailq = 'sendmail'; # default |
| 49 | $msg_q = 0 ; | 49 | $msg_q = 0 ; |
| 50 | $msg_p = 0 ; | 50 | $msg_p = 0 ; |
| 51 | # If appended, must start with a space | ||
| 52 | $mailq_args = '' ; | ||
| 51 | $state = $ERRORS{'UNKNOWN'}; | 53 | $state = $ERRORS{'UNKNOWN'}; |
| 52 | 54 | ||
| 53 | Getopt::Long::Configure('bundling'); | 55 | Getopt::Long::Configure('bundling'); |
| @@ -68,6 +70,10 @@ if ($opt_s) { | |||
| 68 | $sudo = ""; | 70 | $sudo = ""; |
| 69 | } | 71 | } |
| 70 | 72 | ||
| 73 | if ($opt_d) { | ||
| 74 | $mailq_args = $mailq_args . ' -C ' . $opt_d; | ||
| 75 | } | ||
| 76 | |||
| 71 | $SIG{'ALRM'} = sub { | 77 | $SIG{'ALRM'} = sub { |
| 72 | print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n"); | 78 | print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n"); |
| 73 | exit $ERRORS{"WARNING"}; | 79 | exit $ERRORS{"WARNING"}; |
| @@ -143,7 +149,26 @@ if ($mailq eq "sendmail") { | |||
| 143 | ##/var/spool/mqueue/qF/df is empty | 149 | ##/var/spool/mqueue/qF/df is empty |
| 144 | ## Total Requests: 1 | 150 | ## Total Requests: 1 |
| 145 | 151 | ||
| 146 | 152 | # separate submission/transport queues, empty | |
| 153 | ## MSP Queue status... | ||
| 154 | ## /var/spool/mqueue-client is empty | ||
| 155 | ## Total requests: 0 | ||
| 156 | ## MTA Queue status... | ||
| 157 | ## /var/spool/mqueue is empty | ||
| 158 | ## Total requests: 0 | ||
| 159 | # separate submission/transport queues: 1 | ||
| 160 | ## MSP Queue status... | ||
| 161 | ## /var/spool/mqueue-client (1 request) | ||
| 162 | ## -----Q-ID----- --Size-- -----Q-Time----- ------------Sender/Recipient----------- | ||
| 163 | ## oAJEfhdW014123 5 Fri Nov 19 14:41 jwm | ||
| 164 | ## (Deferred: Connection refused by [127.0.0.1]) | ||
| 165 | ## root | ||
| 166 | ## Total requests: 1 | ||
| 167 | ## MTA Queue status... | ||
| 168 | ## /var/spool/mqueue is empty | ||
| 169 | ## Total requests: 0 | ||
| 170 | |||
| 171 | my $this_msg_q = 0; | ||
| 147 | while (<MAILQ>) { | 172 | while (<MAILQ>) { |
| 148 | 173 | ||
| 149 | # match email addr on queue listing | 174 | # match email addr on queue listing |
| @@ -183,13 +208,18 @@ if ($mailq eq "sendmail") { | |||
| 183 | # | 208 | # |
| 184 | # single queue: first line | 209 | # single queue: first line |
| 185 | # multi queue: one for each queue. overwrite on multi queue below | 210 | # multi queue: one for each queue. overwrite on multi queue below |
| 186 | $msg_q = $1 ; | 211 | $this_msg_q = $1 ; |
| 212 | $msg_q += $1 ; | ||
| 187 | } | 213 | } |
| 188 | } elsif (/^\s+Total\sRequests:\s(\d+)$/i) { | 214 | } elsif (/^\s+Total\sRequests:\s(\d+)$/i) { |
| 189 | print "$utils::PATH_TO_MAILQ = $_ \n" if $verbose ; | 215 | if ($this_msg_q) { |
| 190 | # | 216 | $this_msg_q = 0 ; |
| 191 | # multi queue: last line | 217 | } else { |
| 192 | $msg_q = $1 ; | 218 | print "$utils::PATH_TO_MAILQ = $_ \n" if $verbose ; |
| 219 | # | ||
| 220 | # multi queue: last line | ||
| 221 | $msg_q += $1 ; | ||
| 222 | } | ||
| 193 | } | 223 | } |
| 194 | 224 | ||
| 195 | } | 225 | } |
| @@ -309,8 +339,8 @@ elsif ( $mailq eq "postfix" ) { | |||
| 309 | 339 | ||
| 310 | ## open mailq | 340 | ## open mailq |
| 311 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { | 341 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { |
| 312 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { | 342 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ$mailq_args | " ) ) { |
| 313 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; | 343 | print "ERROR: could not open $utils::PATH_TO_MAILQ$mailq_args \n"; |
| 314 | exit $ERRORS{'UNKNOWN'}; | 344 | exit $ERRORS{'UNKNOWN'}; |
| 315 | } | 345 | } |
| 316 | }elsif( defined $utils::PATH_TO_MAILQ){ | 346 | }elsif( defined $utils::PATH_TO_MAILQ){ |
| @@ -330,7 +360,7 @@ elsif ( $mailq eq "postfix" ) { | |||
| 330 | close MAILQ; | 360 | close MAILQ; |
| 331 | 361 | ||
| 332 | if ( $? ) { | 362 | if ( $? ) { |
| 333 | print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/; | 363 | print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ$mailq_args",$/; |
| 334 | exit $ERRORS{CRITICAL}; | 364 | exit $ERRORS{CRITICAL}; |
| 335 | } | 365 | } |
| 336 | 366 | ||
| @@ -343,7 +373,7 @@ elsif ( $mailq eq "postfix" ) { | |||
| 343 | }elsif ($lines[0]=~/Mail queue is empty/) { | 373 | }elsif ($lines[0]=~/Mail queue is empty/) { |
| 344 | $msg_q = 0; | 374 | $msg_q = 0; |
| 345 | }else{ | 375 | }else{ |
| 346 | print "Couldn't match $utils::PATH_TO_MAILQ output\n"; | 376 | print "Couldn't match $utils::PATH_TO_MAILQ$mailq_args output\n"; |
| 347 | exit $ERRORS{'UNKNOWN'}; | 377 | exit $ERRORS{'UNKNOWN'}; |
| 348 | } | 378 | } |
| 349 | 379 | ||
| @@ -531,9 +561,9 @@ elsif ( $mailq eq "nullmailer" ) { | |||
| 531 | } | 561 | } |
| 532 | 562 | ||
| 533 | while (<MAILQ>) { | 563 | while (<MAILQ>) { |
| 534 | #2006-06-22 16:00:00 282 bytes | 564 | #2022-08-25 01:30:40 502 bytes from <user@example.com> |
| 535 | 565 | ||
| 536 | if (/^[1-9][0-9]*-[01][0-9]-[0-3][0-9]\s[0-2][0-9]\:[0-2][0-9]\:[0-2][0-9]\s{2}[0-9]+\sbytes$/) { | 566 | if (/^\d{4}-\d{2}-\d{2}\s+\d{2}\:\d{2}\:\d{2}\s+\d+\sbytes/) { |
| 537 | $msg_q++ ; | 567 | $msg_q++ ; |
| 538 | } | 568 | } |
| 539 | } | 569 | } |
| @@ -561,16 +591,17 @@ exit $state; | |||
| 561 | 591 | ||
| 562 | sub process_arguments(){ | 592 | sub process_arguments(){ |
| 563 | GetOptions | 593 | GetOptions |
| 564 | ("V" => \$opt_V, "version" => \$opt_V, | 594 | ("V" => \$opt_V, "version" => \$opt_V, |
| 565 | "v" => \$opt_v, "verbose" => \$opt_v, | 595 | "v" => \$opt_v, "verbose" => \$opt_v, |
| 566 | "h" => \$opt_h, "help" => \$opt_h, | 596 | "h" => \$opt_h, "help" => \$opt_h, |
| 567 | "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail) | 597 | "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail) |
| 568 | "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number | 598 | "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number |
| 569 | "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number | 599 | "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number |
| 600 | "W=i" => \$opt_W, "warning-domain=i" => \$opt_W, # Warning if above this number | ||
| 601 | "C=i" => \$opt_C, "critical-domain=i" => \$opt_C, # Critical if above this number | ||
| 570 | "t=i" => \$opt_t, "timeout=i" => \$opt_t, | 602 | "t=i" => \$opt_t, "timeout=i" => \$opt_t, |
| 571 | "s" => \$opt_s, "sudo" => \$opt_s, | 603 | "s" => \$opt_s, "sudo" => \$opt_s, |
| 572 | "W=i" => \$opt_W, # warning if above this number | 604 | "d:s" => \$opt_d, "configdir:s" => \$opt_d, |
| 573 | "C=i" => \$opt_C, # critical if above this number | ||
| 574 | ); | 605 | ); |
| 575 | 606 | ||
| 576 | if ($opt_V) { | 607 | if ($opt_V) { |
| @@ -651,7 +682,7 @@ sub process_arguments(){ | |||
| 651 | } | 682 | } |
| 652 | 683 | ||
| 653 | sub print_usage () { | 684 | sub print_usage () { |
| 654 | print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-v]\n"; | 685 | print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-d <CONFIGDIR>] [-v]\n"; |
| 655 | } | 686 | } |
| 656 | 687 | ||
| 657 | sub print_help () { | 688 | sub print_help () { |
| @@ -664,14 +695,15 @@ sub print_help () { | |||
| 664 | print " Feedback/patches to support non-sendmail mailqueue welcome\n\n"; | 695 | print " Feedback/patches to support non-sendmail mailqueue welcome\n\n"; |
| 665 | print "-w (--warning) = Min. number of messages in queue to generate warning\n"; | 696 | print "-w (--warning) = Min. number of messages in queue to generate warning\n"; |
| 666 | print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n"; | 697 | print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n"; |
| 667 | print "-W = Min. number of messages for same domain in queue to generate warning\n"; | 698 | print "-W (--warning-domain) = Min. number of messages for same domain in queue to generate warning\n"; |
| 668 | print "-C = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; | 699 | print "-C (--critical-domain) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; |
| 669 | print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; | 700 | print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; |
| 670 | print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; | 701 | print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; |
| 671 | print "-s (--sudo) = Use sudo to call the mailq command\n"; | 702 | print "-s (--sudo) = Use sudo to call the mailq command\n"; |
| 703 | print "-d (--configdir) = Config file or directory\n"; | ||
| 672 | print "-h (--help)\n"; | 704 | print "-h (--help)\n"; |
| 673 | print "-V (--version)\n"; | 705 | print "-V (--version)\n"; |
| 674 | print "-v (--verbose) = debugging output\n"; | 706 | print "-v (--verbose) = debugging output\n"; |
| 675 | print "\n\n"; | 707 | print "\n\n"; |
| 676 | print "Note: -w and -c are required arguments. -W and -C are optional.\n"; | 708 | print "Note: -w and -c are required arguments. -W and -C are optional.\n"; |
| 677 | print " -W and -C are applied to domains listed on the queues - both FROM and TO. (sendmail)\n"; | 709 | print " -W and -C are applied to domains listed on the queues - both FROM and TO. (sendmail)\n"; |
diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh index 96078aca..59981386 100755 --- a/plugins-scripts/check_oracle.sh +++ b/plugins-scripts/check_oracle.sh | |||
| @@ -8,11 +8,11 @@ | |||
| 8 | 8 | ||
| 9 | PATH="@TRUSTED_PATH@" | 9 | PATH="@TRUSTED_PATH@" |
| 10 | export PATH | 10 | export PATH |
| 11 | PROGNAME=`basename $0` | 11 | PROGNAME=$(basename "$0") |
| 12 | PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` | 12 | PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,') |
| 13 | REVISION="@NP_VERSION@" | 13 | REVISION="@NP_VERSION@" |
| 14 | 14 | ||
| 15 | . $PROGPATH/utils.sh | 15 | . "$PROGPATH"/utils.sh |
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | print_usage() { | 18 | print_usage() { |
| @@ -29,7 +29,7 @@ print_usage() { | |||
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | print_help() { | 31 | print_help() { |
| 32 | print_revision $PROGNAME $REVISION | 32 | print_revision "$PROGNAME" "$REVISION" |
| 33 | echo "" | 33 | echo "" |
| 34 | print_usage | 34 | print_usage |
| 35 | echo "" | 35 | echo "" |
| @@ -86,48 +86,48 @@ esac | |||
| 86 | # Information options | 86 | # Information options |
| 87 | case "$cmd" in | 87 | case "$cmd" in |
| 88 | --help) | 88 | --help) |
| 89 | print_help | 89 | print_help |
| 90 | exit $STATE_OK | 90 | exit "$STATE_UNKNOWN" |
| 91 | ;; | 91 | ;; |
| 92 | -h) | 92 | -h) |
| 93 | print_help | 93 | print_help |
| 94 | exit $STATE_OK | 94 | exit "$STATE_UNKNOWN" |
| 95 | ;; | 95 | ;; |
| 96 | --version) | 96 | --version) |
| 97 | print_revision $PROGNAME $REVISION | 97 | print_revision "$PROGNAME" "$REVISION" |
| 98 | exit $STATE_OK | 98 | exit "$STATE_UNKNOWN" |
| 99 | ;; | 99 | ;; |
| 100 | -V) | 100 | -V) |
| 101 | print_revision $PROGNAME $REVISION | 101 | print_revision "$PROGNAME" "$REVISION" |
| 102 | exit $STATE_OK | 102 | exit "$STATE_UNKNOWN" |
| 103 | ;; | 103 | ;; |
| 104 | esac | 104 | esac |
| 105 | 105 | ||
| 106 | # Hunt down a reasonable ORACLE_HOME | 106 | # Hunt down a reasonable ORACLE_HOME |
| 107 | if [ -z "$ORACLE_HOME" ] ; then | 107 | if [ -z "$ORACLE_HOME" ] ; then |
| 108 | # Adjust to taste | 108 | # Adjust to taste |
| 109 | for oratab in /var/opt/oracle/oratab /etc/oratab | 109 | for oratab in /var/opt/oracle/oratab /etc/oratab |
| 110 | do | 110 | do |
| 111 | [ ! -f $oratab ] && continue | 111 | [ ! -f $oratab ] && continue |
| 112 | ORACLE_HOME=`IFS=: | 112 | ORACLE_HOME=`IFS=: |
| 113 | while read SID ORACLE_HOME junk; | 113 | while read -r SID ORACLE_HOME junk; |
| 114 | do | 114 | do |
| 115 | if [ "$SID" = "$2" -o "$SID" = "*" ] ; then | 115 | if [ "$SID" = "$2" ] || [ "$SID" = "*" ] ; then |
| 116 | echo $ORACLE_HOME; | 116 | echo "$ORACLE_HOME"; |
| 117 | exit; | 117 | exit; |
| 118 | fi; | 118 | fi; |
| 119 | done < $oratab` | 119 | done < $oratab` |
| 120 | [ -n "$ORACLE_HOME" ] && break | 120 | [ -n "$ORACLE_HOME" ] && break |
| 121 | done | 121 | done |
| 122 | fi | 122 | fi |
| 123 | # Last resort | 123 | # Last resort |
| 124 | [ -z "$ORACLE_HOME" -a -d $PROGPATH/oracle ] && ORACLE_HOME=$PROGPATH/oracle | 124 | [ -z "$ORACLE_HOME" ] && [ -d "$PROGPATH"/oracle ] && ORACLE_HOME=$PROGPATH/oracle |
| 125 | 125 | ||
| 126 | if [ "$cmd" != "--db" ]; then | 126 | if [ "$cmd" != "--db" ]; then |
| 127 | if [ -z "$ORACLE_HOME" -o ! -d "$ORACLE_HOME" ] ; then | 127 | if [ -z "$ORACLE_HOME" ] || [ ! -d "$ORACLE_HOME" ] ; then |
| 128 | echo "Cannot determine ORACLE_HOME for sid $2" | 128 | echo "Cannot determine ORACLE_HOME for sid $2" |
| 129 | exit $STATE_UNKNOWN | 129 | exit "$STATE_UNKNOWN" |
| 130 | fi | 130 | fi |
| 131 | fi | 131 | fi |
| 132 | PATH=$PATH:$ORACLE_HOME/bin | 132 | PATH=$PATH:$ORACLE_HOME/bin |
| 133 | LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib | 133 | LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib |
| @@ -135,81 +135,81 @@ export ORACLE_HOME PATH LD_LIBRARY_PATH | |||
| 135 | 135 | ||
| 136 | case "$cmd" in | 136 | case "$cmd" in |
| 137 | --tns) | 137 | --tns) |
| 138 | tnschk=` tnsping $2` | 138 | tnschk=$(tnsping "$2") |
| 139 | tnschk2=` echo $tnschk | grep -c OK` | 139 | tnschk2=$(echo "$tnschk" | grep -c OK) |
| 140 | if [ ${tnschk2} -eq 1 ] ; then | 140 | if [ "${tnschk2}" -eq 1 ] ; then |
| 141 | tnschk3=${tnschk##*(}; tnschk3=${tnschk3%)*} | 141 | tnschk3=${tnschk##*(}; tnschk3=${tnschk3%)*} |
| 142 | echo "OK - reply time ${tnschk3} from $2" | 142 | echo "OK - reply time ${tnschk3} from $2" |
| 143 | exit $STATE_OK | 143 | exit "$STATE_OK" |
| 144 | else | 144 | else |
| 145 | echo "No TNS Listener on $2" | 145 | echo "No TNS Listener on $2" |
| 146 | exit $STATE_CRITICAL | 146 | exit "$STATE_CRITICAL" |
| 147 | fi | 147 | fi |
| 148 | ;; | 148 | ;; |
| 149 | --oranames) | 149 | --oranames) |
| 150 | namesctl status $2 | awk ' | 150 | namesctl status "$2" | awk ' |
| 151 | /Server has been running for:/ { | 151 | /Server has been running for:/ { |
| 152 | msg = "OK: Up" | 152 | msg = "OK: Up" |
| 153 | for (i = 6; i <= NF; i++) { | 153 | for (i = 6; i <= NF; i++) { |
| 154 | msg = msg " " $i | 154 | msg = msg " " $i |
| 155 | } | 155 | } |
| 156 | status = '$STATE_OK' | 156 | status = '"$STATE_OK"' |
| 157 | } | 157 | } |
| 158 | /error/ { | 158 | /error/ { |
| 159 | msg = "CRITICAL: " $0 | 159 | msg = "CRITICAL: " $0 |
| 160 | status = '$STATE_CRITICAL' | 160 | status = '"$STATE_CRITICAL"' |
| 161 | } | 161 | } |
| 162 | END { | 162 | END { |
| 163 | print msg | 163 | print msg |
| 164 | exit status | 164 | exit status |
| 165 | }' | 165 | }' |
| 166 | ;; | 166 | ;; |
| 167 | --db) | 167 | --db) |
| 168 | pmonchk=`ps -ef | grep -v grep | grep -E -c "(asm|ora)_pmon_${2}$"` | 168 | pmonchk=$(pgrep -f "(asm|ora)_pmon_${2}$") |
| 169 | if [ ${pmonchk} -ge 1 ] ; then | 169 | if [ "${pmonchk}" -ge 1 ] ; then |
| 170 | echo "${2} OK - ${pmonchk} PMON process(es) running" | 170 | echo "${2} OK - ${pmonchk} PMON process(es) running" |
| 171 | exit $STATE_OK | 171 | exit "$STATE_OK" |
| 172 | #if [ -f $ORACLE_HOME/dbs/sga*${2}* ] ; then | 172 | #if [ -f $ORACLE_HOME/dbs/sga*${2}* ] ; then |
| 173 | #if [ ${pmonchk} -eq 1 ] ; then | 173 | #if [ ${pmonchk} -eq 1 ] ; then |
| 174 | #utime=`ls -la $ORACLE_HOME/dbs/sga*$2* | cut -c 43-55` | 174 | #utime=`ls -la $ORACLE_HOME/dbs/sga*$2* | cut -c 43-55` |
| 175 | #echo "${2} OK - running since ${utime}" | 175 | #echo "${2} OK - running since ${utime}" |
| 176 | #exit $STATE_OK | 176 | #exit $STATE_OK |
| 177 | #fi | 177 | #fi |
| 178 | else | 178 | else |
| 179 | echo "${2} Database is DOWN" | 179 | echo "${2} Database is DOWN" |
| 180 | exit $STATE_CRITICAL | 180 | exit "$STATE_CRITICAL" |
| 181 | fi | 181 | fi |
| 182 | ;; | 182 | ;; |
| 183 | --login) | 183 | --login) |
| 184 | loginchk=`sqlplus dummy/user@$2 < /dev/null` | 184 | loginchk=$(sqlplus dummy/user@"$2" < /dev/null) |
| 185 | loginchk2=` echo $loginchk | grep -c ORA-01017` | 185 | loginchk2=$(echo "$loginchk" | grep -c ORA-01017) |
| 186 | if [ ${loginchk2} -eq 1 ] ; then | 186 | if [ "${loginchk2}" -eq 1 ] ; then |
| 187 | echo "OK - dummy login connected" | 187 | echo "OK - dummy login connected" |
| 188 | exit $STATE_OK | 188 | exit "$STATE_OK" |
| 189 | else | 189 | else |
| 190 | loginchk3=` echo "$loginchk" | grep "ORA-" | head -1` | 190 | loginchk3=$(echo "$loginchk" | grep "ORA-" | head -1) |
| 191 | echo "CRITICAL - $loginchk3" | 191 | echo "CRITICAL - $loginchk3" |
| 192 | exit $STATE_CRITICAL | 192 | exit "$STATE_CRITICAL" |
| 193 | fi | 193 | fi |
| 194 | ;; | 194 | ;; |
| 195 | --connect) | 195 | --connect) |
| 196 | connectchk=`sqlplus $2 < /dev/null` | 196 | connectchk=$(sqlplus "$2" < /dev/null) |
| 197 | connectchk2=` echo $connectchk | grep -c ORA-` | 197 | connectchk2=$(echo "$connectchk" | grep -c ORA-) |
| 198 | if [ ${connectchk2} -eq 0 ] ; then | 198 | if [ "${connectchk2}" -eq 0 ] ; then |
| 199 | echo "OK - login successful" | 199 | echo "OK - login successful" |
| 200 | exit $STATE_OK | 200 | exit "$STATE_OK" |
| 201 | else | 201 | else |
| 202 | connectchk3=` echo "$connectchk" | grep "ORA-" | head -1` | 202 | connectchk3=$(echo "$connectchk" | grep "ORA-" | head -1) |
| 203 | echo "CRITICAL - $connectchk3" | 203 | echo "CRITICAL - $connectchk3" |
| 204 | exit $STATE_CRITICAL | 204 | exit "$STATE_CRITICAL" |
| 205 | fi | 205 | fi |
| 206 | ;; | 206 | ;; |
| 207 | --cache) | 207 | --cache) |
| 208 | if [ ${5} -gt ${6} ] ; then | 208 | if [ "${5}" -gt "${6}" ] ; then |
| 209 | echo "UNKNOWN - Warning level is less then Crit" | 209 | echo "UNKNOWN - Warning level is less then Crit" |
| 210 | exit $STATE_UNKNOWN | 210 | exit "$STATE_UNKNOWN" |
| 211 | fi | 211 | fi |
| 212 | result=`sqlplus -s ${3}/${4}@${2} << EOF | 212 | result=`sqlplus -s "${3}"/"${4}"@"${2}" << EOF |
| 213 | set pagesize 0 | 213 | set pagesize 0 |
| 214 | set numf '9999999.99' | 214 | set numf '9999999.99' |
| 215 | select (1-(pr.value/(dbg.value+cg.value)))*100 | 215 | select (1-(pr.value/(dbg.value+cg.value)))*100 |
| @@ -219,48 +219,48 @@ and dbg.name='db block gets' | |||
| 219 | and cg.name='consistent gets'; | 219 | and cg.name='consistent gets'; |
| 220 | EOF` | 220 | EOF` |
| 221 | 221 | ||
| 222 | if [ -n "`echo $result | grep ORA-`" ] ; then | 222 | if echo "$result" | grep -q 'ORA-' ; then |
| 223 | error=` echo "$result" | grep "ORA-" | head -1` | 223 | error=$(echo "$result" | grep "ORA-" | head -1) |
| 224 | echo "CRITICAL - $error" | 224 | echo "CRITICAL - $error" |
| 225 | exit $STATE_CRITICAL | 225 | exit "$STATE_CRITICAL" |
| 226 | fi | 226 | fi |
| 227 | 227 | ||
| 228 | buf_hr=`echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}'` | 228 | buf_hr=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}') |
| 229 | buf_hrx=`echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}'` | 229 | buf_hrx=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}') |
| 230 | result=`sqlplus -s ${3}/${4}@${2} << EOF | 230 | result=`sqlplus -s "${3}"/"${4}"@"${2}" << EOF |
| 231 | set pagesize 0 | 231 | set pagesize 0 |
| 232 | set numf '9999999.99' | 232 | set numf '9999999.99' |
| 233 | select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100 | 233 | select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100 |
| 234 | from v\\$librarycache lc; | 234 | from v\\$librarycache lc; |
| 235 | EOF` | 235 | EOF` |
| 236 | 236 | ||
| 237 | if [ -n "`echo $result | grep ORA-`" ] ; then | 237 | if echo "$result" | grep -q 'ORA-' ; then |
| 238 | error=` echo "$result" | grep "ORA-" | head -1` | 238 | error=$(echo "$result" | grep "ORA-" | head -1) |
| 239 | echo "CRITICAL - $error" | 239 | echo "CRITICAL - $error" |
| 240 | exit $STATE_CRITICAL | 240 | exit "$STATE_CRITICAL" |
| 241 | fi | 241 | fi |
| 242 | 242 | ||
| 243 | lib_hr=`echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}'` | 243 | lib_hr=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}') |
| 244 | lib_hrx=`echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}'` | 244 | lib_hrx=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}') |
| 245 | 245 | ||
| 246 | if [ $buf_hr -le ${5} -o $lib_hr -le ${5} ] ; then | 246 | if [ "$buf_hr" -le "${5}" ] || [ "$lib_hr" -le "${5}" ] ; then |
| 247 | echo "${2} CRITICAL - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" | 247 | echo "${2} CRITICAL - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" |
| 248 | exit $STATE_CRITICAL | 248 | exit "$STATE_CRITICAL" |
| 249 | fi | 249 | fi |
| 250 | if [ $buf_hr -le ${6} -o $lib_hr -le ${6} ] ; then | 250 | if [ "$buf_hr" -le "${6}" ] || [ "$lib_hr" -le "${6}" ] ; then |
| 251 | echo "${2} WARNING - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" | 251 | echo "${2} WARNING - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" |
| 252 | exit $STATE_WARNING | 252 | exit "$STATE_WARNING" |
| 253 | fi | 253 | fi |
| 254 | echo "${2} OK - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" | 254 | echo "${2} OK - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" |
| 255 | 255 | ||
| 256 | exit $STATE_OK | 256 | exit "$STATE_OK" |
| 257 | ;; | 257 | ;; |
| 258 | --tablespace) | 258 | --tablespace) |
| 259 | if [ ${6} -lt ${7} ] ; then | 259 | if [ "${6}" -lt "${7}" ] ; then |
| 260 | echo "UNKNOWN - Warning level is more then Crit" | 260 | echo "UNKNOWN - Warning level is more then Crit" |
| 261 | exit $STATE_UNKNOWN | 261 | exit "$STATE_UNKNOWN" |
| 262 | fi | 262 | fi |
| 263 | result=`sqlplus -s ${3}/${4}@${2} << EOF | 263 | result=`sqlplus -s "${3}"/"${4}"@"${2}" << EOF |
| 264 | set pagesize 0 | 264 | set pagesize 0 |
| 265 | set numf '9999999.99' | 265 | set numf '9999999.99' |
| 266 | select NVL(b.free,0.0),a.total,100 - trunc(NVL(b.free,0.0)/a.total * 1000) / 10 prc | 266 | select NVL(b.free,0.0),a.total,100 - trunc(NVL(b.free,0.0)/a.total * 1000) / 10 prc |
| @@ -273,32 +273,32 @@ from dba_free_space group by tablespace_name) B | |||
| 273 | ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${5}'; | 273 | ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${5}'; |
| 274 | EOF` | 274 | EOF` |
| 275 | 275 | ||
| 276 | if [ -n "`echo $result | grep ORA-`" ] ; then | 276 | if echo "$result" | grep -q 'ORA-' ; then |
| 277 | error=` echo "$result" | grep "ORA-" | head -1` | 277 | error=$(echo "$result" | grep "ORA-" | head -1) |
| 278 | echo "CRITICAL - $error" | 278 | echo "CRITICAL - $error" |
| 279 | exit $STATE_CRITICAL | 279 | exit "$STATE_CRITICAL" |
| 280 | fi | 280 | fi |
| 281 | 281 | ||
| 282 | ts_free=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($1)}'` | 282 | ts_free=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($1)}') |
| 283 | ts_total=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}'` | 283 | ts_total=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}') |
| 284 | ts_pct=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}'` | 284 | ts_pct=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}') |
| 285 | ts_pctx=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}'` | 285 | ts_pctx=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}') |
| 286 | if [ "$ts_free" -eq 0 -a "$ts_total" -eq 0 -a "$ts_pct" -eq 0 ] ; then | 286 | if [ "$ts_free" -eq 0 ] && [ "$ts_total" -eq 0 ] && [ "$ts_pct" -eq 0 ] ; then |
| 287 | echo "No data returned by Oracle - tablespace $5 not found?" | 287 | echo "No data returned by Oracle - tablespace $5 not found?" |
| 288 | exit $STATE_UNKNOWN | 288 | exit "$STATE_UNKNOWN" |
| 289 | fi | 289 | fi |
| 290 | if [ "$ts_pct" -ge ${6} ] ; then | 290 | if [ "$ts_pct" -ge "${6}" ] ; then |
| 291 | echo "${2} : ${5} CRITICAL - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" | 291 | echo "${2} : ${5} CRITICAL - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" |
| 292 | exit $STATE_CRITICAL | 292 | exit "$STATE_CRITICAL" |
| 293 | fi | 293 | fi |
| 294 | if [ "$ts_pct" -ge ${7} ] ; then | 294 | if [ "$ts_pct" -ge "${7}" ] ; then |
| 295 | echo "${2} : ${5} WARNING - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" | 295 | echo "${2} : ${5} WARNING - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" |
| 296 | exit $STATE_WARNING | 296 | exit "$STATE_WARNING" |
| 297 | fi | 297 | fi |
| 298 | echo "${2} : ${5} OK - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" | 298 | echo "${2} : ${5} OK - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" |
| 299 | exit $STATE_OK | 299 | exit "$STATE_OK" |
| 300 | ;; | 300 | ;; |
| 301 | *) | 301 | *) |
| 302 | print_usage | 302 | print_usage |
| 303 | exit $STATE_UNKNOWN | 303 | exit "$STATE_UNKNOWN" |
| 304 | esac | 304 | esac |
diff --git a/plugins-scripts/check_rpc.pl b/plugins-scripts/check_rpc.pl index 47d6e49e..8a56b9fc 100755 --- a/plugins-scripts/check_rpc.pl +++ b/plugins-scripts/check_rpc.pl | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | # usage: | 5 | # usage: |
| 6 | # check_rpc host service | 6 | # check_rpc host service |
| 7 | # | 7 | # |
| 8 | # Check if an rpc serice is registered and running | 8 | # Check if an rpc service is registered and running |
| 9 | # using rpcinfo - $proto $host $prognum 2>&1 |"; | 9 | # using rpcinfo - $proto $host $prognum 2>&1 |"; |
| 10 | # | 10 | # |
| 11 | # Use these hosts.cfg entries as examples | 11 | # Use these hosts.cfg entries as examples |
diff --git a/plugins-scripts/check_sensors.sh b/plugins-scripts/check_sensors.sh index f7428301..866e0e0f 100755 --- a/plugins-scripts/check_sensors.sh +++ b/plugins-scripts/check_sensors.sh | |||
| @@ -2,57 +2,57 @@ | |||
| 2 | 2 | ||
| 3 | PATH="@TRUSTED_PATH@" | 3 | PATH="@TRUSTED_PATH@" |
| 4 | export PATH | 4 | export PATH |
| 5 | PROGNAME=`basename $0` | 5 | PROGNAME=$(basename "$0") |
| 6 | PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` | 6 | PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,') |
| 7 | REVISION="@NP_VERSION@" | 7 | REVISION="@NP_VERSION@" |
| 8 | 8 | ||
| 9 | . $PROGPATH/utils.sh | 9 | . "$PROGPATH"/utils.sh |
| 10 | 10 | ||
| 11 | print_usage() { | 11 | print_usage() { |
| 12 | echo "Usage: $PROGNAME" [--ignore-fault] | 12 | echo "Usage: $PROGNAME" [--ignore-fault] |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | print_help() { | 15 | print_help() { |
| 16 | print_revision $PROGNAME $REVISION | 16 | print_revision "$PROGNAME" "$REVISION" |
| 17 | echo "" | 17 | echo "" |
| 18 | print_usage | 18 | print_usage |
| 19 | echo "" | 19 | echo "" |
| 20 | echo "This plugin checks hardware status using the lm_sensors package." | 20 | echo "This plugin checks hardware status using the lm_sensors package." |
| 21 | echo "" | 21 | echo "" |
| 22 | support | 22 | support |
| 23 | exit $STATE_OK | 23 | exit "$STATE_OK" |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | case "$1" in | 26 | case "$1" in |
| 27 | --help) | 27 | --help) |
| 28 | print_help | 28 | print_help |
| 29 | exit $STATE_OK | 29 | exit "$STATE_UNKNOWN" |
| 30 | ;; | 30 | ;; |
| 31 | -h) | 31 | -h) |
| 32 | print_help | 32 | print_help |
| 33 | exit $STATE_OK | 33 | exit "$STATE_UNKNOWN" |
| 34 | ;; | 34 | ;; |
| 35 | --version) | 35 | --version) |
| 36 | print_revision $PROGNAME $REVISION | 36 | print_revision "$PROGNAME" "$REVISION" |
| 37 | exit $STATE_OK | 37 | exit "$STATE_UNKNOWN" |
| 38 | ;; | 38 | ;; |
| 39 | -V) | 39 | -V) |
| 40 | print_revision $PROGNAME $REVISION | 40 | print_revision "$PROGNAME" "$REVISION" |
| 41 | exit $STATE_OK | 41 | exit "$STATE_UNKNOWN" |
| 42 | ;; | 42 | ;; |
| 43 | *) | 43 | *) |
| 44 | sensordata=`sensors 2>&1` | 44 | sensordata=$(sensors 2>&1) |
| 45 | status=$? | 45 | status=$? |
| 46 | if test ${status} -eq 127; then | 46 | if test ${status} -eq 127; then |
| 47 | text="SENSORS UNKNOWN - command not found (did you install lmsensors?)" | 47 | text="SENSORS UNKNOWN - command not found (did you install lmsensors?)" |
| 48 | exit=$STATE_UNKNOWN | 48 | exit=$STATE_UNKNOWN |
| 49 | elif test ${status} -ne 0; then | 49 | elif test "${status}" -ne 0; then |
| 50 | text="WARNING - sensors returned state $status" | 50 | text="WARNING - sensors returned state $status" |
| 51 | exit=$STATE_WARNING | 51 | exit=$STATE_WARNING |
| 52 | elif echo ${sensordata} | egrep ALARM > /dev/null; then | 52 | elif echo "${sensordata}" | grep -E ALARM > /dev/null; then |
| 53 | text="SENSOR CRITICAL - Sensor alarm detected!" | 53 | text="SENSOR CRITICAL - Sensor alarm detected!" |
| 54 | exit=$STATE_CRITICAL | 54 | exit=$STATE_CRITICAL |
| 55 | elif echo ${sensordata} | egrep FAULT > /dev/null \ | 55 | elif echo "${sensordata}" | grep -E FAULT > /dev/null \ |
| 56 | && test "$1" != "-i" -a "$1" != "--ignore-fault"; then | 56 | && test "$1" != "-i" -a "$1" != "--ignore-fault"; then |
| 57 | text="SENSOR UNKNOWN - Sensor reported fault" | 57 | text="SENSOR UNKNOWN - Sensor reported fault" |
| 58 | exit=$STATE_UNKNOWN | 58 | exit=$STATE_UNKNOWN |
| @@ -63,8 +63,8 @@ case "$1" in | |||
| 63 | 63 | ||
| 64 | echo "$text" | 64 | echo "$text" |
| 65 | if test "$1" = "-v" -o "$1" = "--verbose"; then | 65 | if test "$1" = "-v" -o "$1" = "--verbose"; then |
| 66 | echo ${sensordata} | 66 | echo "${sensordata}" |
| 67 | fi | 67 | fi |
| 68 | exit $exit | 68 | exit "$exit" |
| 69 | ;; | 69 | ;; |
| 70 | esac | 70 | esac |
diff --git a/plugins-scripts/check_uptime.pl b/plugins-scripts/check_uptime.pl index 4c9f22da..d73e40e1 100755 --- a/plugins-scripts/check_uptime.pl +++ b/plugins-scripts/check_uptime.pl | |||
| @@ -25,7 +25,7 @@ use POSIX; | |||
| 25 | use strict; | 25 | use strict; |
| 26 | use Getopt::Long; | 26 | use Getopt::Long; |
| 27 | use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c | 27 | use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c |
| 28 | $opt_f $opt_s | 28 | $opt_f $opt_s $opt_d |
| 29 | $lower_warn_threshold $upper_warn_threshold | 29 | $lower_warn_threshold $upper_warn_threshold |
| 30 | $lower_crit_threshold $upper_crit_threshold | 30 | $lower_crit_threshold $upper_crit_threshold |
| 31 | $status $state $msg); | 31 | $status $state $msg); |
| @@ -110,7 +110,7 @@ $pretty_uptime .= sprintf( "%d week%s, ", $weeks, $weeks == 1 ? "" : "s" ) if | |||
| 110 | $pretty_uptime .= sprintf( "%d day%s, ", $days, $days == 1 ? "" : "s" ) if $days; | 110 | $pretty_uptime .= sprintf( "%d day%s, ", $days, $days == 1 ? "" : "s" ) if $days; |
| 111 | $pretty_uptime .= sprintf( "%d hour%s, ", $hours, $hours == 1 ? "" : "s" ) if $hours; | 111 | $pretty_uptime .= sprintf( "%d hour%s, ", $hours, $hours == 1 ? "" : "s" ) if $hours; |
| 112 | $pretty_uptime .= sprintf( "%d minute%s, ", $mins, $mins == 1 ? "" : "s" ) if $mins; | 112 | $pretty_uptime .= sprintf( "%d minute%s, ", $mins, $mins == 1 ? "" : "s" ) if $mins; |
| 113 | # Replace last occurence of comma with "and" | 113 | # Replace last occurrence of comma with "and" |
| 114 | $pretty_uptime =~ s/, $/ and /; | 114 | $pretty_uptime =~ s/, $/ and /; |
| 115 | # Always print the seconds (though it may be 0 seconds) | 115 | # Always print the seconds (though it may be 0 seconds) |
| 116 | $pretty_uptime .= sprintf( "%d second%s", $secs, $secs == 1 ? "" : "s" ); | 116 | $pretty_uptime .= sprintf( "%d second%s", $secs, $secs == 1 ? "" : "s" ); |
| @@ -137,9 +137,20 @@ if ( $uptime_seconds > $upper_crit_threshold ) { | |||
| 137 | $state_str = "OK"; | 137 | $state_str = "OK"; |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | # Prepare uptime value (seconds or days) | ||
| 141 | my $uptime_text = ""; | ||
| 142 | my $uptime_unit = ""; | ||
| 143 | if ( $opt_d ) { | ||
| 144 | $uptime_text = floor($uptime_seconds / 60 / 60 / 24); | ||
| 145 | $uptime_unit = "days"; | ||
| 146 | } else { | ||
| 147 | $uptime_text = $uptime_seconds; | ||
| 148 | $uptime_unit = "seconds"; | ||
| 149 | } | ||
| 150 | |||
| 140 | $msg = "$state_str: "; | 151 | $msg = "$state_str: "; |
| 141 | 152 | ||
| 142 | $msg .= "uptime is $uptime_seconds seconds. "; | 153 | $msg .= "Uptime is $uptime_text $uptime_unit. "; |
| 143 | $msg .= "Exceeds $out_of_bounds_text threshold. " if $out_of_bounds_text; | 154 | $msg .= "Exceeds $out_of_bounds_text threshold. " if $out_of_bounds_text; |
| 144 | $msg .= "Running for $pretty_uptime. " if $opt_f; | 155 | $msg .= "Running for $pretty_uptime. " if $opt_f; |
| 145 | if ( $opt_s ) { | 156 | if ( $opt_s ) { |
| @@ -167,6 +178,7 @@ sub process_arguments(){ | |||
| 167 | "c=s" => \$opt_c, "critical=s" => \$opt_c, # critical if above this number | 178 | "c=s" => \$opt_c, "critical=s" => \$opt_c, # critical if above this number |
| 168 | "f" => \$opt_f, "for" => \$opt_f, # show "running for ..." | 179 | "f" => \$opt_f, "for" => \$opt_f, # show "running for ..." |
| 169 | "s" => \$opt_s, "since" => \$opt_s, # show "running since ..." | 180 | "s" => \$opt_s, "since" => \$opt_s, # show "running since ..." |
| 181 | "d" => \$opt_d, "days" => \$opt_d, # report uptime in days | ||
| 170 | ); | 182 | ); |
| 171 | 183 | ||
| 172 | if ($opt_V) { | 184 | if ($opt_V) { |
| @@ -262,6 +274,7 @@ sub print_help () { | |||
| 262 | print "-c (--critical) = Min. number of uptime to generate critical alert ( w < c )\n"; | 274 | print "-c (--critical) = Min. number of uptime to generate critical alert ( w < c )\n"; |
| 263 | print "-f (--for) = Show uptime in a pretty format (Running for x weeks, x days, ...)\n"; | 275 | print "-f (--for) = Show uptime in a pretty format (Running for x weeks, x days, ...)\n"; |
| 264 | print "-s (--since) = Show last boot in yyyy-mm-dd HH:MM:SS format (output from 'uptime -s')\n"; | 276 | print "-s (--since) = Show last boot in yyyy-mm-dd HH:MM:SS format (output from 'uptime -s')\n"; |
| 277 | print "-d (--days) = Show uptime in days\n"; | ||
| 265 | print "-h (--help)\n"; | 278 | print "-h (--help)\n"; |
| 266 | print "-V (--version)\n"; | 279 | print "-V (--version)\n"; |
| 267 | print "-v (--verbose) = debugging output\n"; | 280 | print "-v (--verbose) = debugging output\n"; |
diff --git a/plugins-scripts/check_wave.pl b/plugins-scripts/check_wave.pl index 41e15f50..c24015c0 100755 --- a/plugins-scripts/check_wave.pl +++ b/plugins-scripts/check_wave.pl | |||
| @@ -19,6 +19,7 @@ sub print_usage (); | |||
| 19 | $ENV{'PATH'}='@TRUSTED_PATH@'; | 19 | $ENV{'PATH'}='@TRUSTED_PATH@'; |
| 20 | $ENV{'BASH_ENV'}=''; | 20 | $ENV{'BASH_ENV'}=''; |
| 21 | $ENV{'ENV'}=''; | 21 | $ENV{'ENV'}=''; |
| 22 | $ENV{'CDPATH'}=''; | ||
| 22 | 23 | ||
| 23 | Getopt::Long::Configure('bundling'); | 24 | Getopt::Long::Configure('bundling'); |
| 24 | GetOptions | 25 | GetOptions |
| @@ -50,34 +51,34 @@ my $critical = $1 if ($opt_c =~ /([0-9]+)/); | |||
| 50 | ($opt_w) || ($opt_w = shift) || ($opt_w = 60); | 51 | ($opt_w) || ($opt_w = shift) || ($opt_w = 60); |
| 51 | my $warning = $1 if ($opt_w =~ /([0-9]+)/); | 52 | my $warning = $1 if ($opt_w =~ /([0-9]+)/); |
| 52 | 53 | ||
| 53 | $low1 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.8.1`; | 54 | $low1 = `$utils::PATH_TO_SNMPGET $host public .1.3.6.1.4.1.74.2.21.1.2.1.8.1`; |
| 54 | @test = split(/ /,$low1); | 55 | @test = split(/ /,$low1); |
| 55 | $low1 = $test[2]; | 56 | $low1 = $test[2]; |
| 56 | 57 | ||
| 57 | $med1 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.9.1`; | 58 | $med1 = `$utils::PATH_TO_SNMPGET $host public .1.3.6.1.4.1.74.2.21.1.2.1.9.1`; |
| 58 | @test = split(/ /,$med1); | 59 | @test = split(/ /,$med1); |
| 59 | $med1 = $test[2]; | 60 | $med1 = $test[2]; |
| 60 | 61 | ||
| 61 | $high1 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.10.1`; | 62 | $high1 = `$utils::PATH_TO_SNMPGET $host public .1.3.6.1.4.1.74.2.21.1.2.1.10.1`; |
| 62 | @test = split(/ /,$high1); | 63 | @test = split(/ /,$high1); |
| 63 | $high1 = $test[2]; | 64 | $high1 = $test[2]; |
| 64 | 65 | ||
| 65 | sleep(2); | 66 | sleep(2); |
| 66 | 67 | ||
| 67 | $snr = `snmpget $host public .1.3.6.1.4.1.762.2.5.2.1.17.1`; | 68 | $snr = `$utils::PATH_TO_SNMPGET $host public .1.3.6.1.4.1.762.2.5.2.1.17.1`; |
| 68 | @test = split(/ /,$snr); | 69 | @test = split(/ /,$snr); |
| 69 | $snr = $test[2]; | 70 | $snr = $test[2]; |
| 70 | $snr = int($snr*25); | 71 | $snr = int($snr*25); |
| 71 | 72 | ||
| 72 | $low2 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.8.1`; | 73 | $low2 = `$utils::PATH_TO_SNMPGET $host public .1.3.6.1.4.1.74.2.21.1.2.1.8.1`; |
| 73 | @test = split(/ /,$low2); | 74 | @test = split(/ /,$low2); |
| 74 | $low2 = $test[2]; | 75 | $low2 = $test[2]; |
| 75 | 76 | ||
| 76 | $med2 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.9.1`; | 77 | $med2 = `$utils::PATH_TO_SNMPGET $host public .1.3.6.1.4.1.74.2.21.1.2.1.9.1`; |
| 77 | @test = split(/ /,$med2); | 78 | @test = split(/ /,$med2); |
| 78 | $med2 = $test[2]; | 79 | $med2 = $test[2]; |
| 79 | 80 | ||
| 80 | $high2 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.10.1`; | 81 | $high2 = `$utils::PATH_TO_SNMPGET $host public .1.3.6.1.4.1.74.2.21.1.2.1.10.1`; |
| 81 | @test = split(/ /,$high2); | 82 | @test = split(/ /,$high2); |
| 82 | $high2 = $test[2]; | 83 | $high2 = $test[2]; |
| 83 | 84 | ||
diff --git a/plugins-scripts/t/check_log.t b/plugins-scripts/t/check_log.t new file mode 100644 index 00000000..b66e0fd8 --- /dev/null +++ b/plugins-scripts/t/check_log.t | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | #!/usr/bin/perl -w -I .. | ||
| 2 | # | ||
| 3 | # check_log tests | ||
| 4 | # | ||
| 5 | # | ||
| 6 | |||
| 7 | use strict; | ||
| 8 | use Test::More; | ||
| 9 | use NPTest; | ||
| 10 | |||
| 11 | my $tests = 18; | ||
| 12 | plan tests => $tests; | ||
| 13 | |||
| 14 | my $firstTimeOutput ='/^Log check data initialized/'; | ||
| 15 | my $okOutput = '/^Log check ok - 0 pattern matches found/'; | ||
| 16 | my $criticalOutput = '/^\(\d+\) < /'; | ||
| 17 | my $multilineOutput = '/\(3\) <.*\n.*\n.*$/'; | ||
| 18 | my $unknownOutput = '/^Usage: /'; | ||
| 19 | my $unknownArgOutput = '/^Unknown argument: /'; | ||
| 20 | my $bothRegexOutput = '/^Can not use extended and perl regex/'; | ||
| 21 | |||
| 22 | my $result; | ||
| 23 | my $temp_file = "/tmp/check_log.tmp"; | ||
| 24 | my $oldlog = "/tmp/oldlog.tmp"; | ||
| 25 | |||
| 26 | open(FH, '>', $temp_file) or die $!; | ||
| 27 | close(FH); | ||
| 28 | |||
| 29 | $result = NPTest->testCmd("./check_log"); | ||
| 30 | cmp_ok( $result->return_code, '==', 3, "Missing parameters" ); | ||
| 31 | like ( $result->output, $unknownOutput, "Output for unknown correct" ); | ||
| 32 | |||
| 33 | $result = NPTest->testCmd("./check_log -f"); | ||
| 34 | cmp_ok( $result->return_code, '==', 3, "Wrong parameters" ); | ||
| 35 | like ( $result->output, $unknownArgOutput, "Output for unknown correct" ); | ||
| 36 | |||
| 37 | $result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Simple match' -e -p"); | ||
| 38 | cmp_ok( $result->return_code, '==', 3, "Both regex parameters" ); | ||
| 39 | like ( $result->output, $bothRegexOutput, "Output for unknown correct" ); | ||
| 40 | |||
| 41 | $result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Simple match'"); | ||
| 42 | cmp_ok( $result->return_code, '==', 0, "First time executing" ); | ||
| 43 | like ( $result->output, $firstTimeOutput, "Output for first time executing correct" ); | ||
| 44 | |||
| 45 | open(FH, '>>', $temp_file) or die $!; | ||
| 46 | print FH "This is some text, that should not match\n"; | ||
| 47 | close(FH); | ||
| 48 | |||
| 49 | $result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'No match'"); | ||
| 50 | cmp_ok( $result->return_code, '==', 0, "No match" ); | ||
| 51 | like ( $result->output, $okOutput, "Output for no match correct" ); | ||
| 52 | |||
| 53 | open(FH, '>>', $temp_file) or die $!; | ||
| 54 | print FH "This text should match\n"; | ||
| 55 | close(FH); | ||
| 56 | |||
| 57 | $result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'should match'"); | ||
| 58 | cmp_ok( $result->return_code, '==', 2, "Pattern match" ); | ||
| 59 | like ( $result->output, $criticalOutput, "Output for match correct" ); | ||
| 60 | |||
| 61 | open(FH, '>>', $temp_file) or die $!; | ||
| 62 | print FH "This text should not match, because it is excluded\n"; | ||
| 63 | close(FH); | ||
| 64 | |||
| 65 | $result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'match' --exclude 'because'"); | ||
| 66 | cmp_ok( $result->return_code, '==', 0, "Exclude a pattern" ); | ||
| 67 | like ( $result->output, $okOutput, "Output for no match correct" ); | ||
| 68 | |||
| 69 | open(FH, '>>', $temp_file) or die $!; | ||
| 70 | print FH "Trying\nwith\nmultiline\nignore me\n"; | ||
| 71 | close(FH); | ||
| 72 | |||
| 73 | $result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Trying\\|with\\|multiline\\|ignore' --exclude 'me' --all"); | ||
| 74 | cmp_ok( $result->return_code, '==', 2, "Multiline pattern match with --all" ); | ||
| 75 | like ( $result->output, $multilineOutput, "Output for multiline match correct" ); | ||
| 76 | |||
| 77 | $result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'match' -a"); | ||
| 78 | cmp_ok( $result->return_code, '==', 0, "Non matching --all" ); | ||
| 79 | like ( $result->output, $okOutput, "Output for no match correct" ); | ||
| 80 | |||
| 81 | unlink($oldlog); | ||
| 82 | unlink($temp_file); | ||
diff --git a/plugins-scripts/t/check_uptime.t b/plugins-scripts/t/check_uptime.t index c395307c..6e81db3c 100644 --- a/plugins-scripts/t/check_uptime.t +++ b/plugins-scripts/t/check_uptime.t | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | # | 5 | # |
| 6 | 6 | ||
| 7 | use strict; | 7 | use strict; |
| 8 | use Test::More tests => 40; | 8 | use Test::More tests => 42; |
| 9 | use NPTest; | 9 | use NPTest; |
| 10 | 10 | ||
| 11 | my $result; | 11 | my $result; |
| @@ -46,29 +46,35 @@ cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" ); | |||
| 46 | like ( $result->output, '/Running since \d+/', "Output for the s parameter correct" ); | 46 | like ( $result->output, '/Running since \d+/', "Output for the s parameter correct" ); |
| 47 | 47 | ||
| 48 | $result = NPTest->testCmd( | 48 | $result = NPTest->testCmd( |
| 49 | "./check_uptime -d -w 1 -c 2" | ||
| 50 | ); | ||
| 51 | cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" ); | ||
| 52 | like ( $result->output, '/CRITICAL: Uptime is \d+ days/', "Output for the d parameter correct" ); | ||
| 53 | |||
| 54 | $result = NPTest->testCmd( | ||
| 49 | "./check_uptime -w 1 -c 2" | 55 | "./check_uptime -w 1 -c 2" |
| 50 | ); | 56 | ); |
| 51 | cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" ); | 57 | cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" ); |
| 52 | like ( $result->output, '/^CRITICAL: uptime is \d+ seconds/', "Output for uptime higher than 2 seconds correct" ); | 58 | like ( $result->output, '/^CRITICAL: Uptime is \d+ seconds/', "Output for uptime higher than 2 seconds correct" ); |
| 53 | 59 | ||
| 54 | $result = NPTest->testCmd( | 60 | $result = NPTest->testCmd( |
| 55 | "./check_uptime -w 1 -c 9999w" | 61 | "./check_uptime -w 1 -c 9999w" |
| 56 | ); | 62 | ); |
| 57 | cmp_ok( $result->return_code, '==', 1, "Uptime lower than 9999 weeks" ); | 63 | cmp_ok( $result->return_code, '==', 1, "Uptime lower than 9999 weeks" ); |
| 58 | like ( $result->output, '/^WARNING: uptime is \d+ seconds/', "Output for uptime lower than 9999 weeks correct" ); | 64 | like ( $result->output, '/^WARNING: Uptime is \d+ seconds/', "Output for uptime lower than 9999 weeks correct" ); |
| 59 | 65 | ||
| 60 | $result = NPTest->testCmd( | 66 | $result = NPTest->testCmd( |
| 61 | "./check_uptime -w 9998w -c 9999w" | 67 | "./check_uptime -w 9998w -c 9999w" |
| 62 | ); | 68 | ); |
| 63 | cmp_ok( $result->return_code, '==', 0, "Uptime lower than 9998 weeks" ); | 69 | cmp_ok( $result->return_code, '==', 0, "Uptime lower than 9998 weeks" ); |
| 64 | like ( $result->output, '/^OK: uptime is \d+ seconds/', "Output for uptime lower than 9998 weeks correct" ); | 70 | like ( $result->output, '/^OK: Uptime is \d+ seconds/', "Output for uptime lower than 9998 weeks correct" ); |
| 65 | like ( $result->output, '/\|uptime=[0-9]+s;6046790400;6047395200;/', "Checking for performance output" ); | 71 | like ( $result->output, '/\|uptime=[0-9]+s;6046790400;6047395200;/', "Checking for performance output" ); |
| 66 | 72 | ||
| 67 | $result = NPTest->testCmd( | 73 | $result = NPTest->testCmd( |
| 68 | "./check_uptime -w 111222d -c 222333d" | 74 | "./check_uptime -w 111222d -c 222333d" |
| 69 | ); | 75 | ); |
| 70 | cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days" ); | 76 | cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days" ); |
| 71 | like ( $result->output, '/^OK: uptime is \d+ seconds/', "Output for uptime lower than 111222 days correct" ); | 77 | like ( $result->output, '/^OK: Uptime is \d+ seconds/', "Output for uptime lower than 111222 days correct" ); |
| 72 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); | 78 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); |
| 73 | 79 | ||
| 74 | # Same as before, hopefully uptime is higher than 2 seconds so no warning | 80 | # Same as before, hopefully uptime is higher than 2 seconds so no warning |
| @@ -76,7 +82,7 @@ $result = NPTest->testCmd( | |||
| 76 | "./check_uptime -w 2:111222d -c 1:222333d" | 82 | "./check_uptime -w 2:111222d -c 1:222333d" |
| 77 | ); | 83 | ); |
| 78 | cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days, and higher 2 seconds" ); | 84 | cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days, and higher 2 seconds" ); |
| 79 | like ( $result->output, '/^OK: uptime is \d+ seconds/', "Output for uptime lower than 111222 days, and higher 2 seconds correct" ); | 85 | like ( $result->output, '/^OK: Uptime is \d+ seconds/', "Output for uptime lower than 111222 days, and higher 2 seconds correct" ); |
| 80 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); | 86 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); |
| 81 | 87 | ||
| 82 | # Same as before, now the low warning should trigger | 88 | # Same as before, now the low warning should trigger |
| @@ -84,7 +90,7 @@ $result = NPTest->testCmd( | |||
| 84 | "./check_uptime -w 111221d:111222d -c 1:222333d" | 90 | "./check_uptime -w 111221d:111222d -c 1:222333d" |
| 85 | ); | 91 | ); |
| 86 | cmp_ok( $result->return_code, '==', 1, "Uptime lower than 111221 days raises warning" ); | 92 | cmp_ok( $result->return_code, '==', 1, "Uptime lower than 111221 days raises warning" ); |
| 87 | like ( $result->output, '/^WARNING: uptime is \d+ seconds/', "Output for uptime lower than 111221 days correct" ); | 93 | like ( $result->output, '/^WARNING: Uptime is \d+ seconds/', "Output for uptime lower than 111221 days correct" ); |
| 88 | like ( $result->output, '/Exceeds lower warn threshold/', "Exceeds text correct" ); | 94 | like ( $result->output, '/Exceeds lower warn threshold/', "Exceeds text correct" ); |
| 89 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); | 95 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); |
| 90 | 96 | ||
| @@ -93,7 +99,7 @@ $result = NPTest->testCmd( | |||
| 93 | "./check_uptime -w 111221d:111222d -c 111220d:222333d" | 99 | "./check_uptime -w 111221d:111222d -c 111220d:222333d" |
| 94 | ); | 100 | ); |
| 95 | cmp_ok( $result->return_code, '==', 2, "Uptime lower than 111220 days raises critical" ); | 101 | cmp_ok( $result->return_code, '==', 2, "Uptime lower than 111220 days raises critical" ); |
| 96 | like ( $result->output, '/^CRITICAL: uptime is \d+ seconds/', "Output for uptime lower than 111220 days correct" ); | 102 | like ( $result->output, '/^CRITICAL: Uptime is \d+ seconds/', "Output for uptime lower than 111220 days correct" ); |
| 97 | like ( $result->output, '/Exceeds lower crit threshold/', "Exceeds text correct" ); | 103 | like ( $result->output, '/Exceeds lower crit threshold/', "Exceeds text correct" ); |
| 98 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); | 104 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); |
| 99 | 105 | ||
diff --git a/plugins-scripts/utils.pm.in b/plugins-scripts/utils.pm.in index 386831eb..c84769fb 100644 --- a/plugins-scripts/utils.pm.in +++ b/plugins-scripts/utils.pm.in | |||
| @@ -23,6 +23,7 @@ $PATH_TO_LMSTAT = "@PATH_TO_LMSTAT@" ; | |||
| 23 | $PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ; | 23 | $PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ; |
| 24 | $PATH_TO_MAILQ = "@PATH_TO_MAILQ@"; | 24 | $PATH_TO_MAILQ = "@PATH_TO_MAILQ@"; |
| 25 | $PATH_TO_QMAIL_QSTAT = "@PATH_TO_QMAIL_QSTAT@"; | 25 | $PATH_TO_QMAIL_QSTAT = "@PATH_TO_QMAIL_QSTAT@"; |
| 26 | $PATH_TO_SNMPGET = "@PATH_TO_SNMPGET@"; | ||
| 26 | 27 | ||
| 27 | ## common variables | 28 | ## common variables |
| 28 | $TIMEOUT = 15; | 29 | $TIMEOUT = 15; |
