diff options
Diffstat (limited to 'plugins-scripts')
-rw-r--r-- | plugins-scripts/Makefile.am | 2 | ||||
-rwxr-xr-x | plugins-scripts/check_ifoperstatus.pl | 2 | ||||
-rwxr-xr-x | plugins-scripts/check_ircd.pl | 4 | ||||
-rwxr-xr-x | plugins-scripts/check_log.sh | 136 | ||||
-rwxr-xr-x | plugins-scripts/check_mailq.pl | 8 | ||||
-rwxr-xr-x | plugins-scripts/check_uptime.pl | 315 | ||||
-rw-r--r-- | plugins-scripts/t/check_file_age.t | 103 | ||||
-rw-r--r-- | plugins-scripts/t/check_uptime.t | 129 |
8 files changed, 585 insertions, 114 deletions
diff --git a/plugins-scripts/Makefile.am b/plugins-scripts/Makefile.am index ea65aed1..088a4459 100644 --- a/plugins-scripts/Makefile.am +++ b/plugins-scripts/Makefile.am | |||
@@ -16,11 +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 | utils.sh utils.pm | 20 | utils.sh utils.pm |
20 | 21 | ||
21 | 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 \ |
22 | 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 \ |
23 | 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 \ | ||
24 | utils.sh.in utils.pm.in t | 26 | utils.sh.in utils.pm.in t |
25 | 27 | ||
26 | EDIT = sed \ | 28 | EDIT = sed \ |
diff --git a/plugins-scripts/check_ifoperstatus.pl b/plugins-scripts/check_ifoperstatus.pl index 9ede1633..c190ce95 100755 --- a/plugins-scripts/check_ifoperstatus.pl +++ b/plugins-scripts/check_ifoperstatus.pl | |||
@@ -124,10 +124,10 @@ if (!defined($session)) { | |||
124 | ## map ifdescr to ifindex - should look at being able to cache this value | 124 | ## map ifdescr to ifindex - should look at being able to cache this value |
125 | 125 | ||
126 | if (defined $ifdescr || defined $iftype) { | 126 | if (defined $ifdescr || defined $iftype) { |
127 | # escape "/" in ifdescr - very common in the Cisco world | ||
128 | if (defined $iftype) { | 127 | if (defined $iftype) { |
129 | $status=fetch_ifindex($snmpIfType, $iftype); | 128 | $status=fetch_ifindex($snmpIfType, $iftype); |
130 | } else { | 129 | } else { |
130 | # escape "/" in ifdescr - very common in the Cisco world | ||
131 | $ifdescr =~ s/\//\\\//g; | 131 | $ifdescr =~ s/\//\\\//g; |
132 | $status=fetch_ifindex($snmpIfDescr, $ifdescr); # if using on device with large number of interfaces | 132 | $status=fetch_ifindex($snmpIfDescr, $ifdescr); # if using on device with large number of interfaces |
133 | # recommend use of SNMP v2 (get-bulk) | 133 | # recommend use of SNMP v2 (get-bulk) |
diff --git a/plugins-scripts/check_ircd.pl b/plugins-scripts/check_ircd.pl index 22d21c2e..d869ae7b 100755 --- a/plugins-scripts/check_ircd.pl +++ b/plugins-scripts/check_ircd.pl | |||
@@ -69,7 +69,9 @@ $ENV{'ENV'}=''; | |||
69 | # -----------------------------------------------------------------[ Global ]-- | 69 | # -----------------------------------------------------------------[ Global ]-- |
70 | 70 | ||
71 | $PROGNAME = "check_ircd"; | 71 | $PROGNAME = "check_ircd"; |
72 | my $NICK="ircd$$"; | 72 | # nickname shouldn't be longer than 9 chars, this might happen with large PIDs |
73 | # To prevent this, we cut of the part over 10000 | ||
74 | my $NICK="ircd" . $$ % 10000; | ||
73 | my $USER_INFO="monitor localhost localhost : "; | 75 | my $USER_INFO="monitor localhost localhost : "; |
74 | 76 | ||
75 | # -------------------------------------------------------------[ connection ]-- | 77 | # -------------------------------------------------------------[ connection ]-- |
diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index d28c8d0a..382bd72c 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 | # |
@@ -60,20 +59,25 @@ | |||
60 | 59 | ||
61 | PATH="@TRUSTED_PATH@" | 60 | PATH="@TRUSTED_PATH@" |
62 | export PATH | 61 | export PATH |
63 | PROGNAME=`basename $0` | 62 | PROGNAME=$(basename "$0") |
64 | PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` | 63 | PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,') |
65 | REVISION="@NP_VERSION@" | 64 | REVISION="@NP_VERSION@" |
66 | 65 | ||
67 | . $PROGPATH/utils.sh | 66 | . "$PROGPATH"/utils.sh |
68 | 67 | ||
69 | print_usage() { | 68 | print_usage() { |
70 | echo "Usage: $PROGNAME -F logfile -O oldlog -q query" | 69 | echo "Usage: $PROGNAME -F logfile -O oldlog -q query" |
71 | echo "Usage: $PROGNAME --help" | 70 | echo "Usage: $PROGNAME --help" |
72 | echo "Usage: $PROGNAME --version" | 71 | echo "Usage: $PROGNAME --version" |
72 | echo "" | ||
73 | echo "Other parameters:" | ||
74 | echo " -a|--all : Print all matching lines" | ||
75 | echo " -p|--perl-regex : Use perl style regular expressions in the query" | ||
76 | echo " -e|--extended-regex : Use extended style regular expressions in the query (not necessary for GNU grep)" | ||
73 | } | 77 | } |
74 | 78 | ||
75 | print_help() { | 79 | print_help() { |
76 | print_revision $PROGNAME $REVISION | 80 | print_revision "$PROGNAME" "$REVISION" |
77 | echo "" | 81 | echo "" |
78 | print_usage | 82 | print_usage |
79 | echo "" | 83 | echo "" |
@@ -87,7 +91,7 @@ print_help() { | |||
87 | 91 | ||
88 | if [ $# -lt 1 ]; then | 92 | if [ $# -lt 1 ]; then |
89 | print_usage | 93 | print_usage |
90 | exit $STATE_UNKNOWN | 94 | exit "$STATE_UNKNOWN" |
91 | fi | 95 | fi |
92 | 96 | ||
93 | # Grab the command line arguments | 97 | # Grab the command line arguments |
@@ -100,79 +104,118 @@ while test -n "$1"; do | |||
100 | case "$1" in | 104 | case "$1" in |
101 | --help) | 105 | --help) |
102 | print_help | 106 | print_help |
103 | exit $STATE_OK | 107 | exit "$STATE_OK" |
104 | ;; | 108 | ;; |
105 | -h) | 109 | -h) |
106 | print_help | 110 | print_help |
107 | exit $STATE_OK | 111 | exit "$STATE_OK" |
108 | ;; | 112 | ;; |
109 | --version) | 113 | --version) |
110 | print_revision $PROGNAME $REVISION | 114 | print_revision "$PROGNAME" "$REVISION" |
111 | exit $STATE_OK | 115 | exit "$STATE_OK" |
112 | ;; | 116 | ;; |
113 | -V) | 117 | -V) |
114 | print_revision $PROGNAME $REVISION | 118 | print_revision "$PROGNAME" "$REVISION" |
115 | exit $STATE_OK | 119 | exit "$STATE_OK" |
116 | ;; | 120 | ;; |
117 | --filename) | 121 | --filename) |
118 | logfile=$2 | 122 | logfile=$2 |
119 | shift | 123 | shift 2 |
120 | ;; | 124 | ;; |
121 | -F) | 125 | -F) |
122 | logfile=$2 | 126 | logfile=$2 |
123 | shift | 127 | shift 2 |
124 | ;; | 128 | ;; |
125 | --oldlog) | 129 | --oldlog) |
126 | oldlog=$2 | 130 | oldlog=$2 |
127 | shift | 131 | shift 2 |
128 | ;; | 132 | ;; |
129 | -O) | 133 | -O) |
130 | oldlog=$2 | 134 | oldlog=$2 |
131 | shift | 135 | shift 2 |
132 | ;; | 136 | ;; |
133 | --query) | 137 | --query) |
134 | query=$2 | 138 | query=$2 |
135 | shift | 139 | shift 2 |
136 | ;; | 140 | ;; |
137 | -q) | 141 | -q) |
138 | query=$2 | 142 | query=$2 |
139 | shift | 143 | shift 2 |
140 | ;; | 144 | ;; |
141 | -x) | 145 | -x) |
142 | exitstatus=$2 | 146 | exitstatus=$2 |
143 | shift | 147 | shift 2 |
144 | ;; | 148 | ;; |
145 | --exitstatus) | 149 | --exitstatus) |
146 | exitstatus=$2 | 150 | exitstatus=$2 |
151 | shift 2 | ||
152 | ;; | ||
153 | --extended-regex) | ||
154 | ERE=1 | ||
155 | shift | ||
156 | ;; | ||
157 | -e) | ||
158 | ERE=1 | ||
159 | shift | ||
160 | ;; | ||
161 | --perl-regex) | ||
162 | PRE=1 | ||
163 | shift | ||
164 | ;; | ||
165 | -p) | ||
166 | PRE=1 | ||
167 | shift | ||
168 | ;; | ||
169 | --all) | ||
170 | ALL=1 | ||
171 | shift | ||
172 | ;; | ||
173 | -a) | ||
174 | ALL=1 | ||
147 | shift | 175 | shift |
148 | ;; | 176 | ;; |
149 | *) | 177 | *) |
150 | echo "Unknown argument: $1" | 178 | echo "Unknown argument: $1" |
151 | print_usage | 179 | print_usage |
152 | exit $STATE_UNKNOWN | 180 | exit "$STATE_UNKNOWN" |
153 | ;; | 181 | ;; |
154 | esac | 182 | esac |
155 | shift | ||
156 | done | 183 | done |
157 | 184 | ||
185 | # Parameter sanity check | ||
186 | if [ $ERE ] && [ $PRE ] ; then | ||
187 | echo "Can not use extended and perl regex at the same time" | ||
188 | exit "$STATE_UNKNOWN" | ||
189 | fi | ||
190 | |||
191 | GREP="grep" | ||
192 | |||
193 | if [ $ERE ]; then | ||
194 | GREP="grep -E" | ||
195 | fi | ||
196 | |||
197 | if [ $PRE ]; then | ||
198 | GREP="grep -P" | ||
199 | fi | ||
200 | |||
158 | # If the source log file doesn't exist, exit | 201 | # If the source log file doesn't exist, exit |
159 | 202 | ||
160 | if [ ! -e $logfile ]; then | 203 | if [ ! -e "$logfile" ]; then |
161 | echo "Log check error: Log file $logfile does not exist!" | 204 | echo "Log check error: Log file $logfile does not exist!" |
162 | exit $STATE_UNKNOWN | 205 | exit "$STATE_UNKNOWN" |
163 | elif [ ! -r $logfile ] ; then | 206 | elif [ ! -r "$logfile" ] ; then |
164 | echo "Log check error: Log file $logfile is not readable!" | 207 | echo "Log check error: Log file $logfile is not readable!" |
165 | exit $STATE_UNKNOWN | 208 | exit "$STATE_UNKNOWN" |
166 | fi | 209 | fi |
167 | 210 | ||
168 | # If the old log file doesn't exist, this must be the first time | 211 | # If the old log file doesn't exist, this must be the first time |
169 | # we're running this test, so copy the original log file over to | 212 | # we're running this test, so copy the original log file over to |
170 | # the old diff file and exit | 213 | # the old diff file and exit |
171 | 214 | ||
172 | if [ ! -e $oldlog ]; then | 215 | if [ ! -e "$oldlog" ]; then |
173 | cat $logfile > $oldlog | 216 | cat "$logfile" > "$oldlog" |
174 | echo "Log check data initialized..." | 217 | echo "Log check data initialized..." |
175 | exit $STATE_OK | 218 | exit "$STATE_OK" |
176 | fi | 219 | fi |
177 | 220 | ||
178 | # The old log file exists, so compare it to the original log now | 221 | # The old log file exists, so compare it to the original log now |
@@ -180,31 +223,40 @@ fi | |||
180 | # The temporary file that the script should use while | 223 | # The temporary file that the script should use while |
181 | # processing the log file. | 224 | # processing the log file. |
182 | if [ -x /bin/mktemp ]; then | 225 | if [ -x /bin/mktemp ]; then |
183 | tempdiff=`/bin/mktemp /tmp/check_log.XXXXXXXXXX` | 226 | tempdiff=$(/bin/mktemp /tmp/check_log.XXXXXXXXXX) |
184 | else | 227 | else |
185 | tempdiff=`/bin/date '+%H%M%S'` | 228 | tempdiff=$(/bin/date '+%H%M%S') |
186 | tempdiff="/tmp/check_log.${tempdiff}" | 229 | tempdiff="/tmp/check_log.${tempdiff}" |
187 | touch $tempdiff | 230 | touch "$tempdiff" |
188 | chmod 600 $tempdiff | 231 | chmod 600 "$tempdiff" |
189 | fi | 232 | fi |
190 | 233 | ||
191 | diff $logfile $oldlog | grep -v "^>" > $tempdiff | 234 | diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff" |
235 | |||
236 | if [ $ALL ]; then | ||
237 | # Get the last matching entry in the diff file | ||
238 | entry=$($GREP "$query" "$tempdiff") | ||
192 | 239 | ||
193 | # Count the number of matching log entries we have | 240 | # Count the number of matching log entries we have |
194 | count=`grep -c "$query" $tempdiff` | 241 | count=$(echo "$entry" | wc -l) |
195 | 242 | ||
196 | # Get the last matching entry in the diff file | 243 | else |
197 | lastentry=`grep "$query" $tempdiff | tail -1` | 244 | # Count the number of matching log entries we have |
245 | count=$($GREP -c "$query" "$tempdiff") | ||
246 | |||
247 | # Get the last matching entry in the diff file | ||
248 | entry=$($GREP "$query" "$tempdiff" | tail -1) | ||
249 | fi | ||
198 | 250 | ||
199 | rm -f $tempdiff | 251 | rm -f "$tempdiff" |
200 | cat $logfile > $oldlog | 252 | cat "$logfile" > "$oldlog" |
201 | 253 | ||
202 | if [ "$count" = "0" ]; then # no matches, exit with no error | 254 | if [ "$count" = "0" ]; then # no matches, exit with no error |
203 | echo "Log check ok - 0 pattern matches found" | 255 | echo "Log check ok - 0 pattern matches found" |
204 | exitstatus=$STATE_OK | 256 | exitstatus=$STATE_OK |
205 | else # Print total matche count and the last entry we found | 257 | else # Print total matche count and the last entry we found |
206 | echo "($count) $lastentry" | 258 | echo "($count) $entry" |
207 | exitstatus=$STATE_CRITICAL | 259 | exitstatus=$STATE_CRITICAL |
208 | fi | 260 | fi |
209 | 261 | ||
210 | exit $exitstatus | 262 | exit "$exitstatus" |
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl index 1fc15ffc..c5486087 100755 --- a/plugins-scripts/check_mailq.pl +++ b/plugins-scripts/check_mailq.pl | |||
@@ -568,7 +568,9 @@ sub process_arguments(){ | |||
568 | "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number | 568 | "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 | 569 | "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number |
570 | "t=i" => \$opt_t, "timeout=i" => \$opt_t, | 570 | "t=i" => \$opt_t, "timeout=i" => \$opt_t, |
571 | "s" => \$opt_s, "sudo" => \$opt_s | 571 | "s" => \$opt_s, "sudo" => \$opt_s, |
572 | "W=i" => \$opt_W, # warning if above this number | ||
573 | "C=i" => \$opt_C, # critical if above this number | ||
572 | ); | 574 | ); |
573 | 575 | ||
574 | if ($opt_V) { | 576 | if ($opt_V) { |
@@ -662,8 +664,8 @@ sub print_help () { | |||
662 | print " Feedback/patches to support non-sendmail mailqueue welcome\n\n"; | 664 | print " Feedback/patches to support non-sendmail mailqueue welcome\n\n"; |
663 | print "-w (--warning) = Min. number of messages in queue to generate warning\n"; | 665 | print "-w (--warning) = Min. number of messages in queue to generate warning\n"; |
664 | print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n"; | 666 | print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n"; |
665 | print "-W (--Warning) = Min. number of messages for same domain in queue to generate warning\n"; | 667 | print "-W = Min. number of messages for same domain in queue to generate warning\n"; |
666 | print "-C (--Critical) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; | 668 | print "-C = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; |
667 | print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; | 669 | print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; |
668 | print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; | 670 | print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; |
669 | print "-s (--sudo) = Use sudo to call the mailq command\n"; | 671 | print "-s (--sudo) = Use sudo to call the mailq command\n"; |
diff --git a/plugins-scripts/check_uptime.pl b/plugins-scripts/check_uptime.pl new file mode 100755 index 00000000..4c9f22da --- /dev/null +++ b/plugins-scripts/check_uptime.pl | |||
@@ -0,0 +1,315 @@ | |||
1 | #!@PERL@ -w | ||
2 | |||
3 | # check_uptime - check uptime to see how long the system is running. | ||
4 | # | ||
5 | |||
6 | # License Information: | ||
7 | # This program is free software; you can redistribute it and/or modify | ||
8 | # it under the terms of the GNU General Public License as published by | ||
9 | # the Free Software Foundation; either version 2 of the License, or | ||
10 | # (at your option) any later version. | ||
11 | # | ||
12 | # This program is distributed in the hope that it will be useful, | ||
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | # GNU General Public License for more details. | ||
16 | # | ||
17 | # You should have received a copy of the GNU General Public License | ||
18 | # along with this program; if not, write to the Free Software | ||
19 | # Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | ||
20 | # USA | ||
21 | # | ||
22 | ############################################################################ | ||
23 | |||
24 | use POSIX; | ||
25 | use strict; | ||
26 | use Getopt::Long; | ||
27 | use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c | ||
28 | $opt_f $opt_s | ||
29 | $lower_warn_threshold $upper_warn_threshold | ||
30 | $lower_crit_threshold $upper_crit_threshold | ||
31 | $status $state $msg); | ||
32 | use FindBin; | ||
33 | use lib "$FindBin::Bin"; | ||
34 | use utils qw(%ERRORS &print_revision &support &usage ); | ||
35 | |||
36 | sub print_help (); | ||
37 | sub print_usage (); | ||
38 | sub process_arguments (); | ||
39 | |||
40 | $ENV{'PATH'}='@TRUSTED_PATH@'; | ||
41 | $ENV{'BASH_ENV'}=''; | ||
42 | $ENV{'ENV'}=''; | ||
43 | $PROGNAME = "check_uptime"; | ||
44 | $state = $ERRORS{'UNKNOWN'}; | ||
45 | |||
46 | my $uptime_file = "/proc/uptime"; | ||
47 | |||
48 | |||
49 | # Process arguments | ||
50 | |||
51 | Getopt::Long::Configure('bundling'); | ||
52 | $status = process_arguments(); | ||
53 | if ($status){ | ||
54 | print "ERROR: processing arguments\n"; | ||
55 | exit $ERRORS{"UNKNOWN"}; | ||
56 | } | ||
57 | |||
58 | |||
59 | # Get uptime info from file | ||
60 | |||
61 | if ( ! -r $uptime_file ) { | ||
62 | print "ERROR: file '$uptime_file' is not readable\n"; | ||
63 | exit $ERRORS{"UNKNOWN"}; | ||
64 | } | ||
65 | |||
66 | if ( ! open FILE, "<", $uptime_file ) { | ||
67 | print "ERROR: cannot read from file '$uptime_file'\n"; | ||
68 | exit $ERRORS{"UNKNOWN"}; | ||
69 | } | ||
70 | |||
71 | chomp( my $file_content = <FILE> ); | ||
72 | close FILE; | ||
73 | |||
74 | print "$uptime_file: $file_content\n" if $verbose; | ||
75 | |||
76 | # Get first digit value (without fraction) | ||
77 | my ( $uptime_seconds ) = $file_content =~ /^([\d]+)/; | ||
78 | |||
79 | # Bail out if value is not numeric | ||
80 | if ( $uptime_seconds !~ /^\d+$/ ) { | ||
81 | print "ERROR: no numeric value: $uptime_seconds\n"; | ||
82 | exit $ERRORS{"UNKNOWN"}; | ||
83 | } | ||
84 | |||
85 | |||
86 | # Do calculations for a "pretty" format (2 weeks, 5 days, ...) | ||
87 | |||
88 | my ( $secs, $mins, $hours, $days, $weeks ); | ||
89 | $secs = $uptime_seconds; | ||
90 | $mins = $hours = $days = $weeks = 0; | ||
91 | if ( $secs > 100 ) { | ||
92 | $mins = int( $secs / 60 ); | ||
93 | $secs -= $mins * 60; | ||
94 | } | ||
95 | if ( $mins > 100 ) { | ||
96 | $hours = int( $mins / 60 ); | ||
97 | $mins -= $hours * 60; | ||
98 | } | ||
99 | if ( $hours > 48 ) { | ||
100 | $days = int( $hours / 24 ); | ||
101 | $hours -= $days * 24; | ||
102 | } | ||
103 | if ( $days > 14 ) { | ||
104 | $weeks = int( $days / 7 ); | ||
105 | $days -= $weeks * 7; | ||
106 | } | ||
107 | |||
108 | my $pretty_uptime = ""; | ||
109 | $pretty_uptime .= sprintf( "%d week%s, ", $weeks, $weeks == 1 ? "" : "s" ) if $weeks; | ||
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; | ||
112 | $pretty_uptime .= sprintf( "%d minute%s, ", $mins, $mins == 1 ? "" : "s" ) if $mins; | ||
113 | # Replace last occurence of comma with "and" | ||
114 | $pretty_uptime =~ s/, $/ and /; | ||
115 | # Always print the seconds (though it may be 0 seconds) | ||
116 | $pretty_uptime .= sprintf( "%d second%s", $secs, $secs == 1 ? "" : "s" ); | ||
117 | |||
118 | |||
119 | # Default to catch errors in program | ||
120 | my $state_str = "UNKNOWN"; | ||
121 | |||
122 | # Check values | ||
123 | my $out_of_bounds_text = ""; | ||
124 | if ( $uptime_seconds > $upper_crit_threshold ) { | ||
125 | $state_str = "CRITICAL"; | ||
126 | $out_of_bounds_text = "upper crit"; | ||
127 | } elsif ( $uptime_seconds < $lower_crit_threshold ) { | ||
128 | $state_str = "CRITICAL"; | ||
129 | $out_of_bounds_text = "lower crit"; | ||
130 | } elsif ( $uptime_seconds > $upper_warn_threshold ) { | ||
131 | $state_str = "WARNING"; | ||
132 | $out_of_bounds_text = "upper warn"; | ||
133 | } elsif ( $uptime_seconds < $lower_warn_threshold ) { | ||
134 | $state_str = "WARNING"; | ||
135 | $out_of_bounds_text = "lower warn"; | ||
136 | } else { | ||
137 | $state_str = "OK"; | ||
138 | } | ||
139 | |||
140 | $msg = "$state_str: "; | ||
141 | |||
142 | $msg .= "uptime is $uptime_seconds seconds. "; | ||
143 | $msg .= "Exceeds $out_of_bounds_text threshold. " if $out_of_bounds_text; | ||
144 | $msg .= "Running for $pretty_uptime. " if $opt_f; | ||
145 | if ( $opt_s ) { | ||
146 | my $up_since = strftime( "%Y-%m-%d %H:%M:%S", localtime( time - $uptime_seconds ) ); | ||
147 | $msg .= "Running since $up_since. "; | ||
148 | } | ||
149 | |||
150 | $state = $ERRORS{$state_str}; | ||
151 | |||
152 | # Perfdata support | ||
153 | print "$msg|uptime=${uptime_seconds}s;$upper_warn_threshold;$upper_crit_threshold;0\n"; | ||
154 | exit $state; | ||
155 | |||
156 | |||
157 | ##################################### | ||
158 | #### subs | ||
159 | |||
160 | |||
161 | sub process_arguments(){ | ||
162 | GetOptions | ||
163 | ("V" => \$opt_V, "version" => \$opt_V, | ||
164 | "v" => \$opt_v, "verbose" => \$opt_v, | ||
165 | "h" => \$opt_h, "help" => \$opt_h, | ||
166 | "w=s" => \$opt_w, "warning=s" => \$opt_w, # warning if above this number | ||
167 | "c=s" => \$opt_c, "critical=s" => \$opt_c, # critical if above this number | ||
168 | "f" => \$opt_f, "for" => \$opt_f, # show "running for ..." | ||
169 | "s" => \$opt_s, "since" => \$opt_s, # show "running since ..." | ||
170 | ); | ||
171 | |||
172 | if ($opt_V) { | ||
173 | print_revision($PROGNAME,'@NP_VERSION@'); | ||
174 | exit $ERRORS{'UNKNOWN'}; | ||
175 | } | ||
176 | |||
177 | if ($opt_h) { | ||
178 | print_help(); | ||
179 | exit $ERRORS{'UNKNOWN'}; | ||
180 | } | ||
181 | |||
182 | if (defined $opt_v) { | ||
183 | $verbose = $opt_v; | ||
184 | } | ||
185 | |||
186 | unless ( defined $opt_w && defined $opt_c ) { | ||
187 | print_usage(); | ||
188 | exit $ERRORS{'UNKNOWN'}; | ||
189 | } | ||
190 | |||
191 | # Check if a range was supplied ("lowvalue:highvalue") for warning and critical | ||
192 | # Otherwise, set 0 as the lower threshold and the parameter value as upper threshold | ||
193 | # (the uptime should always be positive, so there should be no issue) | ||
194 | if ( $opt_w =~ /^(.+):(.+)$/ ) { | ||
195 | $lower_warn_threshold = $1; | ||
196 | $upper_warn_threshold = $2; | ||
197 | } else { | ||
198 | $lower_warn_threshold = 0; | ||
199 | $upper_warn_threshold = $opt_w; | ||
200 | } | ||
201 | if ( $opt_c =~ /^(.+):(.+)$/ ) { | ||
202 | $lower_crit_threshold = $1; | ||
203 | $upper_crit_threshold = $2; | ||
204 | } else { | ||
205 | $lower_crit_threshold = 0; | ||
206 | $upper_crit_threshold = $opt_c; | ||
207 | } | ||
208 | |||
209 | # Set as seconds (calculate if suffix present) | ||
210 | $lower_warn_threshold = calc_as_seconds( $lower_warn_threshold ); | ||
211 | $lower_crit_threshold = calc_as_seconds( $lower_crit_threshold ); | ||
212 | $upper_warn_threshold = calc_as_seconds( $upper_warn_threshold ); | ||
213 | $upper_crit_threshold = calc_as_seconds( $upper_crit_threshold ); | ||
214 | |||
215 | # Check for numeric value of warning parameter | ||
216 | if ( $lower_warn_threshold !~ /^\d+$/ ) { | ||
217 | print "Lower warning (-w) is not numeric\n"; | ||
218 | exit $ERRORS{'UNKNOWN'}; | ||
219 | } | ||
220 | if ( $upper_warn_threshold !~ /^\d+$/ ) { | ||
221 | print "Upper warning (-w) is not numeric\n"; | ||
222 | exit $ERRORS{'UNKNOWN'}; | ||
223 | } | ||
224 | # Check for numeric value of critical parameter | ||
225 | if ( $lower_crit_threshold !~ /^\d+$/ ) { | ||
226 | print "Lower critical (-c) is not numeric\n"; | ||
227 | exit $ERRORS{'UNKNOWN'}; | ||
228 | } | ||
229 | if ( $upper_crit_threshold !~ /^\d+$/ ) { | ||
230 | print "Upper critical (-c) is not numeric\n"; | ||
231 | exit $ERRORS{'UNKNOWN'}; | ||
232 | } | ||
233 | |||
234 | # Check boundaries | ||
235 | if ( $upper_warn_threshold >= $upper_crit_threshold ) { | ||
236 | print "Upper Warning (-w) cannot be greater than Critical (-c)!\n"; | ||
237 | exit $ERRORS{'UNKNOWN'}; | ||
238 | } | ||
239 | # No "<=" since both values are zero if no range (only upper threshold values) is given | ||
240 | if ( $lower_warn_threshold < $lower_crit_threshold ) { | ||
241 | print "Lower Warning (-w) cannot be less than Critical (-c)!\n"; | ||
242 | exit $ERRORS{'UNKNOWN'}; | ||
243 | } | ||
244 | |||
245 | return $ERRORS{'OK'}; | ||
246 | } | ||
247 | |||
248 | sub print_usage () { | ||
249 | print "Usage: $PROGNAME -w <warn> -c <crit> [-v]\n"; | ||
250 | } | ||
251 | |||
252 | sub print_help () { | ||
253 | print_revision($PROGNAME,'@NP_VERSION@'); | ||
254 | print "Copyright (c) 2002 Subhendu Ghosh/Carlos Canau/Benjamin Schmid\n"; | ||
255 | print "Copyright (c) 2018 Bernd Arnold\n"; | ||
256 | print "\n"; | ||
257 | print_usage(); | ||
258 | print "\n"; | ||
259 | print " Checks the uptime of the system using $uptime_file\n"; | ||
260 | print "\n"; | ||
261 | print "-w (--warning) = Min. number of uptime to generate warning\n"; | ||
262 | 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"; | ||
264 | print "-s (--since) = Show last boot in yyyy-mm-dd HH:MM:SS format (output from 'uptime -s')\n"; | ||
265 | print "-h (--help)\n"; | ||
266 | print "-V (--version)\n"; | ||
267 | print "-v (--verbose) = debugging output\n"; | ||
268 | print "\n\n"; | ||
269 | print "Note: -w and -c are required arguments.\n"; | ||
270 | print " You can suffix both values with s for seconds (default), m (minutes), h (hours), d (days) or w (weeks).\n"; | ||
271 | print "\n"; | ||
272 | print "Range support: You may specify a range for both warning and critical thresholds.\n"; | ||
273 | print " This works without additional Perl modules.\n"; | ||
274 | print "Example: ./check_uptime -w 10m:4w -c 1m:8w\n"; | ||
275 | print " Results in a critical state when uptime is below 60 seconds or higher than 8 weeks,\n"; | ||
276 | print " and in a warning state when uptime is below 10 minutes or above 4 weeks.\n"; | ||
277 | print "\n\n"; | ||
278 | support(); | ||
279 | } | ||
280 | |||
281 | sub calc_as_seconds () { | ||
282 | |||
283 | my $parameter = shift; | ||
284 | |||
285 | # Check if suffix is present | ||
286 | # Calculate parameter to seconds (to get an integer value finally) | ||
287 | # If no suffix is present, just return the value | ||
288 | |||
289 | # Possible suffixes: | ||
290 | # s = seconds | ||
291 | # m = minutes | ||
292 | # h = hours | ||
293 | # d = days | ||
294 | # w = weeks | ||
295 | my %factor = ( "s" => 1, | ||
296 | "m" => 60, | ||
297 | "h" => 60 * 60, | ||
298 | "d" => 60 * 60 * 24, | ||
299 | "w" => 60 * 60 * 24 * 7, | ||
300 | ); | ||
301 | |||
302 | if ( $parameter =~ /^(\d+)([a-z])$/ ) { | ||
303 | my $value = $1; | ||
304 | my $suffix = $2; | ||
305 | print "detected: value=$value, suffix=$suffix\n" if $verbose; | ||
306 | if ( ! defined $factor{$suffix} ) { | ||
307 | print "Error: wrong suffix ($suffix) for value '$parameter'"; | ||
308 | exit $ERRORS{'UNKNOWN'}; | ||
309 | } | ||
310 | $parameter = $value * $factor{$suffix}; | ||
311 | } | ||
312 | |||
313 | return $parameter; | ||
314 | |||
315 | } | ||
diff --git a/plugins-scripts/t/check_file_age.t b/plugins-scripts/t/check_file_age.t index ebf673f5..8b876708 100644 --- a/plugins-scripts/t/check_file_age.t +++ b/plugins-scripts/t/check_file_age.t | |||
@@ -20,105 +20,74 @@ my $temp_link = "/tmp/check_file_age.link.tmp"; | |||
20 | 20 | ||
21 | unlink $temp_file, $temp_link; | 21 | unlink $temp_file, $temp_link; |
22 | 22 | ||
23 | $result = NPTest->testCmd( | 23 | $result = NPTest->testCmd("./check_file_age"); |
24 | "./check_file_age" | ||
25 | ); | ||
26 | cmp_ok( $result->return_code, '==', 3, "Missing parameters" ); | 24 | cmp_ok( $result->return_code, '==', 3, "Missing parameters" ); |
27 | like ( $result->output, $unknownOutput, "Output for unknown correct" ); | 25 | like ( $result->output, $unknownOutput, "Output for unknown correct" ); |
28 | 26 | ||
29 | $result = NPTest->testCmd( | 27 | $result = NPTest->testCmd("./check_file_age -f $temp_file"); |
30 | "./check_file_age -f $temp_file" | ||
31 | ); | ||
32 | cmp_ok( $result->return_code, '==', 2, "File not exists" ); | 28 | cmp_ok( $result->return_code, '==', 2, "File not exists" ); |
33 | like ( $result->output, $criticalOutput, "Output for file missing correct" ); | 29 | like ( $result->output, $criticalOutput, "Output for file missing correct" ); |
34 | 30 | ||
35 | write_chars(100); | 31 | write_chars(100); |
36 | $result = NPTest->testCmd( | 32 | $result = NPTest->testCmd("./check_file_age -f $temp_file"); |
37 | "./check_file_age -f $temp_file" | ||
38 | ); | ||
39 | cmp_ok( $result->return_code, '==', 0, "File is new enough" ); | 33 | cmp_ok( $result->return_code, '==', 0, "File is new enough" ); |
40 | like ( $result->output, $successOutput, "Output for success correct" ); | 34 | like ( $result->output, $successOutput, "Output for success correct" ); |
41 | 35 | ||
42 | sleep 2; | 36 | sleep 2; |
43 | 37 | ||
44 | $result = NPTest->testCmd( | 38 | $result = NPTest->testCmd("./check_file_age -f $temp_file -w 1"); |
45 | "./check_file_age -f $temp_file -w 1" | ||
46 | ); | ||
47 | cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old" ); | 39 | cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old" ); |
48 | like ( $result->output, $warningOutput, "Output for warning correct" ); | 40 | like ( $result->output, $warningOutput, "Output for warning correct" ); |
49 | 41 | ||
50 | $result = NPTest->testCmd( | 42 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1"); |
51 | "./check_file_age -f $temp_file -w 0:1" | ||
52 | ); | ||
53 | cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old by range" ); | ||
54 | like ( $result->output, $warningOutput, "Output for warning by range correct" ); | ||
55 | |||
56 | $result = NPTest->testCmd( | ||
57 | "./check_file_age -f $temp_file -c 1" | ||
58 | ); | ||
59 | cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" ); | 43 | cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" ); |
60 | like ( $result->output, $criticalOutput, "Output for critical correct" ); | 44 | like ( $result->output, $criticalOutput, "Output for critical correct" ); |
61 | 45 | ||
62 | $result = NPTest->testCmd( | 46 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100"); |
63 | "./check_file_age -f $temp_file -c 0:1" | ||
64 | ); | ||
65 | cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old by range" ); | ||
66 | like ( $result->output, $criticalOutput, "Output for critical by range correct" ); | ||
67 | |||
68 | $result = NPTest->testCmd( | ||
69 | "./check_file_age -f $temp_file -c 1000 -W 100" | ||
70 | ); | ||
71 | cmp_ok( $result->return_code, '==', 0, "Checking file size" ); | 47 | cmp_ok( $result->return_code, '==', 0, "Checking file size" ); |
72 | 48 | ||
73 | $result = NPTest->testCmd( | 49 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100"); |
74 | "./check_file_age -f $temp_file -c 0:1000 -W 0:100" | ||
75 | ); | ||
76 | cmp_ok( $result->return_code, '==', 0, "Checking file size by range" ); | ||
77 | |||
78 | $result = NPTest->testCmd( | ||
79 | "./check_file_age -f $temp_file -c 1000 -W 100" | ||
80 | ); | ||
81 | like( $result->output, $performanceOutput, "Checking for performance Output" ); | 50 | like( $result->output, $performanceOutput, "Checking for performance Output" ); |
82 | 51 | ||
83 | $result = NPTest->testCmd( | 52 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100"); |
84 | "./check_file_age -f $temp_file -c 1000 -W 100" | ||
85 | ); | ||
86 | like( $result->output, $performanceOutput, "Checking for performance Output from range" ); | 53 | like( $result->output, $performanceOutput, "Checking for performance Output from range" ); |
87 | 54 | ||
88 | $result = NPTest->testCmd( | 55 | $result = NPTest->testCmd("./check_file_age -f /non/existent --ignore-missing"); |
89 | "./check_file_age -f /non/existent --ignore-missing" | ||
90 | ); | ||
91 | cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" ); | 56 | cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" ); |
92 | 57 | ||
93 | $result = NPTest->testCmd( | 58 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 101"); |
94 | "./check_file_age -f $temp_file -c 1000 -W 101" | ||
95 | ); | ||
96 | cmp_ok( $result->return_code, '==', 1, "One byte too short" ); | 59 | cmp_ok( $result->return_code, '==', 1, "One byte too short" ); |
97 | 60 | ||
98 | $result = NPTest->testCmd( | 61 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 101"); |
99 | "./check_file_age -f $temp_file -c 1000 -W 101:" | ||
100 | ); | ||
101 | cmp_ok( $result->return_code, '==', 1, "One byte too short by range" ); | ||
102 | |||
103 | $result = NPTest->testCmd( | ||
104 | "./check_file_age -f $temp_file -c 1000 -C 101" | ||
105 | ); | ||
106 | cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" ); | 62 | cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" ); |
107 | 63 | ||
108 | $result = NPTest->testCmd( | 64 | SKIP: { |
109 | "./check_file_age -f $temp_file -c 1000 -C 101:" | 65 | eval 'use Monitoring::Plugin::Range'; |
110 | ); | 66 | skip "Monitoring::Plugin::Range module require", 9 if $@; |
111 | cmp_ok( $result->return_code, '==', 2, "One byte too short by range - critical" ); | 67 | |
68 | $result = NPTest->testCmd("./check_file_age -f $temp_file -w 0:1"); | ||
69 | cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old by range" ); | ||
70 | like ( $result->output, $warningOutput, "Output for warning by range correct" ); | ||
71 | |||
72 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 0:1"); | ||
73 | cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old by range" ); | ||
74 | like ( $result->output, $criticalOutput, "Output for critical by range correct" ); | ||
75 | |||
76 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 0:1000 -W 0:100"); | ||
77 | cmp_ok( $result->return_code, '==', 0, "Checking file size by range" ); | ||
78 | |||
79 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 101:"); | ||
80 | cmp_ok( $result->return_code, '==', 1, "One byte too short by range" ); | ||
81 | |||
82 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 0:99"); | ||
83 | cmp_ok( $result->return_code, '==', 1, "One byte too long by range" ); | ||
112 | 84 | ||
113 | $result = NPTest->testCmd( | 85 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 101:"); |
114 | "./check_file_age -f $temp_file -c 1000 -W 0:99" | 86 | cmp_ok( $result->return_code, '==', 2, "One byte too short by range - critical" ); |
115 | ); | ||
116 | cmp_ok( $result->return_code, '==', 1, "One byte too long by range" ); | ||
117 | 87 | ||
118 | $result = NPTest->testCmd( | 88 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 0:99"); |
119 | "./check_file_age -f $temp_file -c 1000 -C 0:99" | 89 | cmp_ok( $result->return_code, '==', 2, "One byte too long by range - critical" ); |
120 | ); | 90 | }; |
121 | cmp_ok( $result->return_code, '==', 2, "One byte too long by range - critical" ); | ||
122 | 91 | ||
123 | symlink $temp_file, $temp_link or die "Cannot create symlink"; | 92 | symlink $temp_file, $temp_link or die "Cannot create symlink"; |
124 | $result = NPTest->testCmd("./check_file_age -f $temp_link -c 10"); | 93 | $result = NPTest->testCmd("./check_file_age -f $temp_link -c 10"); |
diff --git a/plugins-scripts/t/check_uptime.t b/plugins-scripts/t/check_uptime.t new file mode 100644 index 00000000..c395307c --- /dev/null +++ b/plugins-scripts/t/check_uptime.t | |||
@@ -0,0 +1,129 @@ | |||
1 | #!/usr/bin/perl -w -I .. | ||
2 | # | ||
3 | # check_uptime tests | ||
4 | # | ||
5 | # | ||
6 | |||
7 | use strict; | ||
8 | use Test::More tests => 40; | ||
9 | use NPTest; | ||
10 | |||
11 | my $result; | ||
12 | |||
13 | $result = NPTest->testCmd( | ||
14 | "./check_uptime" | ||
15 | ); | ||
16 | cmp_ok( $result->return_code, '==', 3, "Missing parameters" ); | ||
17 | like ( $result->output, '/^Usage: check_uptime -w/', "Output for missing parameters correct" ); | ||
18 | |||
19 | $result = NPTest->testCmd( | ||
20 | "./check_uptime --help" | ||
21 | ); | ||
22 | cmp_ok( $result->return_code, '==', 3, "Help output requested" ); | ||
23 | like ( $result->output, '/ABSOLUTELY NO WARRANTY/', "Output for help correct" ); | ||
24 | |||
25 | $result = NPTest->testCmd( | ||
26 | "./check_uptime -w 5 -c 2" | ||
27 | ); | ||
28 | cmp_ok( $result->return_code, '==', 3, "Warning greater than critical" ); | ||
29 | like ( $result->output, '/^Upper Warning .*cannot be greater than Critical/', "Output for warning greater than critical correct" ); | ||
30 | |||
31 | $result = NPTest->testCmd( | ||
32 | "./check_uptime -c 1000 -W 100 2>&1" | ||
33 | ); | ||
34 | like ( $result->output, '/^Unknown option: W/', "Output with wrong parameter is correct" ); | ||
35 | |||
36 | $result = NPTest->testCmd( | ||
37 | "./check_uptime -f -w 1 -c 2" | ||
38 | ); | ||
39 | cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" ); | ||
40 | like ( $result->output, '/Running for \d+/', "Output for the f parameter correct" ); | ||
41 | |||
42 | $result = NPTest->testCmd( | ||
43 | "./check_uptime -s -w 1 -c 2" | ||
44 | ); | ||
45 | cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" ); | ||
46 | like ( $result->output, '/Running since \d+/', "Output for the s parameter correct" ); | ||
47 | |||
48 | $result = NPTest->testCmd( | ||
49 | "./check_uptime -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+ seconds/', "Output for uptime higher than 2 seconds correct" ); | ||
53 | |||
54 | $result = NPTest->testCmd( | ||
55 | "./check_uptime -w 1 -c 9999w" | ||
56 | ); | ||
57 | 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" ); | ||
59 | |||
60 | $result = NPTest->testCmd( | ||
61 | "./check_uptime -w 9998w -c 9999w" | ||
62 | ); | ||
63 | 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" ); | ||
65 | like ( $result->output, '/\|uptime=[0-9]+s;6046790400;6047395200;/', "Checking for performance output" ); | ||
66 | |||
67 | $result = NPTest->testCmd( | ||
68 | "./check_uptime -w 111222d -c 222333d" | ||
69 | ); | ||
70 | 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" ); | ||
72 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); | ||
73 | |||
74 | # Same as before, hopefully uptime is higher than 2 seconds so no warning | ||
75 | $result = NPTest->testCmd( | ||
76 | "./check_uptime -w 2:111222d -c 1:222333d" | ||
77 | ); | ||
78 | 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" ); | ||
80 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); | ||
81 | |||
82 | # Same as before, now the low warning should trigger | ||
83 | $result = NPTest->testCmd( | ||
84 | "./check_uptime -w 111221d:111222d -c 1:222333d" | ||
85 | ); | ||
86 | 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" ); | ||
88 | like ( $result->output, '/Exceeds lower warn threshold/', "Exceeds text correct" ); | ||
89 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); | ||
90 | |||
91 | # Same as before, now the low critical should trigger | ||
92 | $result = NPTest->testCmd( | ||
93 | "./check_uptime -w 111221d:111222d -c 111220d:222333d" | ||
94 | ); | ||
95 | 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" ); | ||
97 | like ( $result->output, '/Exceeds lower crit threshold/', "Exceeds text correct" ); | ||
98 | like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); | ||
99 | |||
100 | |||
101 | # | ||
102 | # Range values using ":" without two parts ("a:b") is invalid | ||
103 | # Strings without two parts are always considered as upper threshold | ||
104 | # | ||
105 | |||
106 | $result = NPTest->testCmd( | ||
107 | "./check_uptime -w 2: -c 1:4" | ||
108 | ); | ||
109 | cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" ); | ||
110 | like ( $result->output, '/^Upper warning .* is not numeric/', "Output for wrong parameter format correct" ); | ||
111 | |||
112 | $result = NPTest->testCmd( | ||
113 | "./check_uptime -w 2:3 -c 1:" | ||
114 | ); | ||
115 | cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" ); | ||
116 | like ( $result->output, '/^Upper critical .* is not numeric/', "Output for wrong parameter format correct" ); | ||
117 | |||
118 | $result = NPTest->testCmd( | ||
119 | "./check_uptime -w :3 -c 1:4" | ||
120 | ); | ||
121 | cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" ); | ||
122 | like ( $result->output, '/^Upper warning .* is not numeric/', "Output for wrong parameter format correct" ); | ||
123 | |||
124 | $result = NPTest->testCmd( | ||
125 | "./check_uptime -w 2:3 -c :4" | ||
126 | ); | ||
127 | cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" ); | ||
128 | like ( $result->output, '/^Upper critical .* is not numeric/', "Output for wrong parameter format correct" ); | ||
129 | |||