summaryrefslogtreecommitdiffstats
path: root/plugins-scripts
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts')
-rw-r--r--plugins-scripts/Makefile.am2
-rwxr-xr-xplugins-scripts/check_disk_smb.pl7
-rwxr-xr-xplugins-scripts/check_file_age.pl61
-rwxr-xr-xplugins-scripts/check_ifoperstatus.pl2
-rwxr-xr-xplugins-scripts/check_ircd.pl4
-rwxr-xr-xplugins-scripts/check_log.sh149
-rwxr-xr-xplugins-scripts/check_mailq.pl34
-rwxr-xr-xplugins-scripts/check_oracle.sh240
-rwxr-xr-xplugins-scripts/check_sensors.sh34
-rwxr-xr-xplugins-scripts/check_uptime.pl315
-rw-r--r--plugins-scripts/t/check_file_age.t75
-rw-r--r--plugins-scripts/t/check_uptime.t129
-rw-r--r--plugins-scripts/t/utils.t1
13 files changed, 813 insertions, 240 deletions
diff --git a/plugins-scripts/Makefile.am b/plugins-scripts/Makefile.am
index ea65aed..088a445 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/
16libexec_SCRIPTS = check_breeze check_disk_smb check_flexlm check_ircd \ 16libexec_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
21EXTRA_DIST=check_breeze.pl check_disk_smb.pl check_flexlm.pl check_ircd.pl \ 22EXTRA_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
26EDIT = sed \ 28EDIT = sed \
diff --git a/plugins-scripts/check_disk_smb.pl b/plugins-scripts/check_disk_smb.pl
index 9899226..28c49e8 100755
--- a/plugins-scripts/check_disk_smb.pl
+++ b/plugins-scripts/check_disk_smb.pl
@@ -19,7 +19,7 @@
19# 19#
20 20
21require 5.004; 21require 5.004;
22use POSIX; 22use POSIX qw(setsid);
23use strict; 23use strict;
24use Getopt::Long; 24use Getopt::Long;
25use 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); 25use 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);
@@ -28,6 +28,9 @@ use FindBin;
28use lib "$FindBin::Bin"; 28use lib "$FindBin::Bin";
29use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); 29use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
30 30
31# make us session leader which makes all childs exit if we do
32setsid;
33
31sub print_help (); 34sub print_help ();
32sub print_usage (); 35sub print_usage ();
33 36
@@ -175,6 +178,8 @@ my @lines = undef;
175# Just in case of problems, let's not hang the monitoring system 178# Just in case of problems, let's not hang the monitoring system
176$SIG{'ALRM'} = sub { 179$SIG{'ALRM'} = sub {
177 print "No Answer from Client\n"; 180 print "No Answer from Client\n";
181 $SIG{'INT'} = 'IGNORE';
182 kill(-2, $$);
178 exit $ERRORS{"UNKNOWN"}; 183 exit $ERRORS{"UNKNOWN"};
179}; 184};
180alarm($TIMEOUT); 185alarm($TIMEOUT);
diff --git a/plugins-scripts/check_file_age.pl b/plugins-scripts/check_file_age.pl
index 56b8e97..26281dd 100755
--- a/plugins-scripts/check_file_age.pl
+++ b/plugins-scripts/check_file_age.pl
@@ -43,8 +43,6 @@ $ENV{'ENV'}='';
43 43
44$opt_w = 240; 44$opt_w = 240;
45$opt_c = 600; 45$opt_c = 600;
46$opt_W = 0;
47$opt_C = 0;
48$opt_f = ""; 46$opt_f = "";
49 47
50Getopt::Long::Configure('bundling'); 48Getopt::Long::Configure('bundling');
@@ -53,10 +51,10 @@ GetOptions(
53 "h" => \$opt_h, "help" => \$opt_h, 51 "h" => \$opt_h, "help" => \$opt_h,
54 "i" => \$opt_i, "ignore-missing" => \$opt_i, 52 "i" => \$opt_i, "ignore-missing" => \$opt_i,
55 "f=s" => \$opt_f, "file" => \$opt_f, 53 "f=s" => \$opt_f, "file" => \$opt_f,
56 "w=f" => \$opt_w, "warning-age=f" => \$opt_w, 54 "w=s" => \$opt_w, "warning-age=s" => \$opt_w,
57 "W=f" => \$opt_W, "warning-size=f" => \$opt_W, 55 "W=s" => \$opt_W, "warning-size=s" => \$opt_W,
58 "c=f" => \$opt_c, "critical-age=f" => \$opt_c, 56 "c=s" => \$opt_c, "critical-age=s" => \$opt_c,
59 "C=f" => \$opt_C, "critical-size=f" => \$opt_C); 57 "C=s" => \$opt_C, "critical-size=s" => \$opt_C);
60 58
61if ($opt_V) { 59if ($opt_V) {
62 print_revision($PROGNAME, '@NP_VERSION@'); 60 print_revision($PROGNAME, '@NP_VERSION@');
@@ -91,18 +89,47 @@ unless (-e $opt_f) {
91$st = File::stat::stat($opt_f); 89$st = File::stat::stat($opt_f);
92$age = time - $st->mtime; 90$age = time - $st->mtime;
93$size = $st->size; 91$size = $st->size;
94$perfdata = "age=${age}s;${opt_w};${opt_c} size=${size}B;${opt_W};${opt_C};0";
95
96 92
97$result = 'OK'; 93$result = 'OK';
98 94
99if (($opt_c and $age > $opt_c) or ($opt_C and $size < $opt_C)) { 95if ($opt_c !~ m/^\d+$/ or ($opt_C and $opt_C !~ m/^\d+$/)
100 $result = 'CRITICAL'; 96 or $opt_w !~ m/^\d+$/ or ($opt_W and $opt_W !~ m/^\d+$/)) {
97 # range has been specified so use M::P::R to process
98 require Monitoring::Plugin::Range;
99 # use permissive range defaults for size when none specified
100 $opt_W = "0:" unless ($opt_W);
101 $opt_C = "0:" unless ($opt_C);
102
103 if (Monitoring::Plugin::Range->parse_range_string($opt_c)
104 ->check_range($age) == 1) { # 1 means it raises an alert because it's OUTSIDE the range
105 $result = 'CRITICAL';
106 }
107 elsif (Monitoring::Plugin::Range->parse_range_string($opt_C)
108 ->check_range($size) == 1) {
109 $result = 'CRITICAL';
110 }
111 elsif (Monitoring::Plugin::Range->parse_range_string($opt_w)
112 ->check_range($age) == 1) {
113 $result = 'WARNING';
114 }
115 elsif (Monitoring::Plugin::Range->parse_range_string($opt_W)
116 ->check_range($size) == 1) {
117 $result = 'WARNING';
118 }
101} 119}
102elsif (($opt_w and $age > $opt_w) or ($opt_W and $size < $opt_W)) { 120else {
103 $result = 'WARNING'; 121 # use permissive defaults for size when none specified
122 $opt_W = 0 unless ($opt_W);
123 $opt_C = 0 unless ($opt_C);
124 if ($age > $opt_c or $size < $opt_C) {
125 $result = 'CRITICAL';
126 }
127 elsif ($age > $opt_w or $size < $opt_W) {
128 $result = 'WARNING';
129 }
104} 130}
105 131
132$perfdata = "age=${age}s;${opt_w};${opt_c} size=${size}B;${opt_W};${opt_C};0";
106print "FILE_AGE $result: $opt_f is $age seconds old and $size bytes | $perfdata\n"; 133print "FILE_AGE $result: $opt_f is $age seconds old and $size bytes | $perfdata\n";
107exit $ERRORS{$result}; 134exit $ERRORS{$result};
108 135
@@ -120,7 +147,15 @@ sub print_help () {
120 print "\n"; 147 print "\n";
121 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";
122 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";
123 print " <size> File must be at least this many bytes long (default: crit 0 bytes)\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";
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";
154 print " To use range processing the perl module Monitoring::Plugin must be installed\n";
155 print " For range syntax see https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT\n";
156 print " It is strongly recommended when using range syntax that all four of -w, -W, -c and -C are specified\n";
157 print " otherwise it is unlikely that the size test will be doing what is desired\n";
124 print "\n"; 158 print "\n";
125 support(); 159 support();
126} 160}
161
diff --git a/plugins-scripts/check_ifoperstatus.pl b/plugins-scripts/check_ifoperstatus.pl
index 9ede163..c190ce9 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
126if (defined $ifdescr || defined $iftype) { 126if (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 22d21c2..d869ae7 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";
72my $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
74my $NICK="ircd" . $$ % 10000;
73my $USER_INFO="monitor localhost localhost : "; 75my $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 d28c8d0..fdb5741 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#
@@ -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,25 @@
60 63
61PATH="@TRUSTED_PATH@" 64PATH="@TRUSTED_PATH@"
62export PATH 65export PATH
63PROGNAME=`basename $0` 66PROGNAME=$(basename "$0")
64PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` 67PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,')
65REVISION="@NP_VERSION@" 68REVISION="@NP_VERSION@"
66 69
67. $PROGPATH/utils.sh 70. "$PROGPATH"/utils.sh
68 71
69print_usage() { 72print_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 " -p|--perl-regex : Use perl style regular expressions in the query"
80 echo " -e|--extended-regex : Use extended style regular expressions in the query (not necessary for GNU grep)"
73} 81}
74 82
75print_help() { 83print_help() {
76 print_revision $PROGNAME $REVISION 84 print_revision "$PROGNAME" "$REVISION"
77 echo "" 85 echo ""
78 print_usage 86 print_usage
79 echo "" 87 echo ""
@@ -87,7 +95,7 @@ print_help() {
87 95
88if [ $# -lt 1 ]; then 96if [ $# -lt 1 ]; then
89 print_usage 97 print_usage
90 exit $STATE_UNKNOWN 98 exit "$STATE_UNKNOWN"
91fi 99fi
92 100
93# Grab the command line arguments 101# Grab the command line arguments
@@ -100,79 +108,123 @@ while test -n "$1"; do
100 case "$1" in 108 case "$1" in
101 --help) 109 --help)
102 print_help 110 print_help
103 exit $STATE_OK 111 exit "$STATE_OK"
104 ;; 112 ;;
105 -h) 113 -h)
106 print_help 114 print_help
107 exit $STATE_OK 115 exit "$STATE_OK"
108 ;; 116 ;;
109 --version) 117 --version)
110 print_revision $PROGNAME $REVISION 118 print_revision "$PROGNAME" "$REVISION"
111 exit $STATE_OK 119 exit "$STATE_OK"
112 ;; 120 ;;
113 -V) 121 -V)
114 print_revision $PROGNAME $REVISION 122 print_revision "$PROGNAME" "$REVISION"
115 exit $STATE_OK 123 exit "$STATE_OK"
116 ;; 124 ;;
117 --filename) 125 --filename)
118 logfile=$2 126 logfile=$2
119 shift 127 shift 2
120 ;; 128 ;;
121 -F) 129 -F)
122 logfile=$2 130 logfile=$2
123 shift 131 shift 2
124 ;; 132 ;;
125 --oldlog) 133 --oldlog)
126 oldlog=$2 134 oldlog=$2
127 shift 135 shift 2
128 ;; 136 ;;
129 -O) 137 -O)
130 oldlog=$2 138 oldlog=$2
131 shift 139 shift 2
132 ;; 140 ;;
133 --query) 141 --query)
134 query=$2 142 query=$2
135 shift 143 shift 2
136 ;; 144 ;;
137 -q) 145 -q)
138 query=$2 146 query=$2
139 shift 147 shift 2
140 ;; 148 ;;
141 -x) 149 -x)
142 exitstatus=$2 150 exitstatus=$2
143 shift 151 shift 2
144 ;; 152 ;;
145 --exitstatus) 153 --exitstatus)
146 exitstatus=$2 154 exitstatus=$2
155 shift 2
156 ;;
157 --extended-regex)
158 ERE=1
159 shift
160 ;;
161 -e)
162 ERE=1
163 shift
164 ;;
165 --perl-regex)
166 PRE=1
167 shift
168 ;;
169 -p)
170 PRE=1
171 shift
172 ;;
173 --all)
174 ALL=1
175 shift
176 ;;
177 -a)
178 ALL=1
147 shift 179 shift
148 ;; 180 ;;
149 *) 181 *)
150 echo "Unknown argument: $1" 182 echo "Unknown argument: $1"
151 print_usage 183 print_usage
152 exit $STATE_UNKNOWN 184 exit "$STATE_UNKNOWN"
153 ;; 185 ;;
154 esac 186 esac
155 shift
156done 187done
157 188
189# Parameter sanity check
190if [ $ERE ] && [ $PRE ] ; then
191 echo "Can not use extended and perl regex at the same time"
192 exit "$STATE_UNKNOWN"
193fi
194
195GREP="grep"
196
197if [ $ERE ]; then
198 GREP="grep -E"
199fi
200
201if [ $PRE ]; then
202 GREP="grep -P"
203fi
204
158# If the source log file doesn't exist, exit 205# If the source log file doesn't exist, exit
159 206
160if [ ! -e $logfile ]; then 207if [ ! -e "$logfile" ]; then
161 echo "Log check error: Log file $logfile does not exist!" 208 echo "Log check error: Log file $logfile does not exist!"
162 exit $STATE_UNKNOWN 209 exit "$STATE_UNKNOWN"
163elif [ ! -r $logfile ] ; then 210elif [ ! -r "$logfile" ] ; then
164 echo "Log check error: Log file $logfile is not readable!" 211 echo "Log check error: Log file $logfile is not readable!"
165 exit $STATE_UNKNOWN 212 exit "$STATE_UNKNOWN"
213fi
214# If no oldlog was given this can not work properly, abort then
215if [ -z "$oldlog" ]; then
216 echo "Oldlog parameter is needed"
217 exit $STATE_UNKNOWN
166fi 218fi
167 219
168# If the old log file doesn't exist, this must be the first time 220# 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 221# we're running this test, so copy the original log file over to
170# the old diff file and exit 222# the old diff file and exit
171 223
172if [ ! -e $oldlog ]; then 224if [ ! -e "$oldlog" ]; then
173 cat $logfile > $oldlog 225 cat "$logfile" > "$oldlog"
174 echo "Log check data initialized..." 226 echo "Log check data initialized..."
175 exit $STATE_OK 227 exit "$STATE_OK"
176fi 228fi
177 229
178# The old log file exists, so compare it to the original log now 230# The old log file exists, so compare it to the original log now
@@ -180,31 +232,42 @@ fi
180# The temporary file that the script should use while 232# The temporary file that the script should use while
181# processing the log file. 233# processing the log file.
182if [ -x /bin/mktemp ]; then 234if [ -x /bin/mktemp ]; then
183 tempdiff=`/bin/mktemp /tmp/check_log.XXXXXXXXXX` 235
236 tempdiff=$(/bin/mktemp /tmp/check_log.XXXXXXXXXX)
184else 237else
185 tempdiff=`/bin/date '+%H%M%S'` 238 tempdiff=$(/bin/date '+%H%M%S')
186 tempdiff="/tmp/check_log.${tempdiff}" 239 tempdiff="/tmp/check_log.${tempdiff}"
187 touch $tempdiff 240 touch "$tempdiff"
188 chmod 600 $tempdiff 241 chmod 600 "$tempdiff"
189fi 242fi
190 243
191diff $logfile $oldlog | grep -v "^>" > $tempdiff 244diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff"
245
192 246
193# Count the number of matching log entries we have 247if [ $ALL ]; then
194count=`grep -c "$query" $tempdiff` 248 # Get the last matching entry in the diff file
249 entry=$($GREP "$query" "$tempdiff")
195 250
196# Get the last matching entry in the diff file 251 # Count the number of matching log entries we have
197lastentry=`grep "$query" $tempdiff | tail -1` 252 count=$(echo "$entry" | wc -l)
253
254else
255 # Count the number of matching log entries we have
256 count=$($GREP -c "$query" "$tempdiff")
257
258 # Get the last matching entry in the diff file
259 entry=$($GREP "$query" "$tempdiff" | tail -1)
260fi
198 261
199rm -f $tempdiff 262rm -f "$tempdiff"
200cat $logfile > $oldlog 263cat "$logfile" > "$oldlog"
201 264
202if [ "$count" = "0" ]; then # no matches, exit with no error 265if [ "$count" = "0" ]; then # no matches, exit with no error
203 echo "Log check ok - 0 pattern matches found" 266 echo "Log check ok - 0 pattern matches found"
204 exitstatus=$STATE_OK 267 exitstatus=$STATE_OK
205else # Print total matche count and the last entry we found 268else # Print total match count and the last entry we found
206 echo "($count) $lastentry" 269 echo "($count) $entry"
207 exitstatus=$STATE_CRITICAL 270 exitstatus=$STATE_CRITICAL
208fi 271fi
209 272
210exit $exitstatus 273exit "$exitstatus"
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl
index 32f498d..3914f4a 100755
--- a/plugins-scripts/check_mailq.pl
+++ b/plugins-scripts/check_mailq.pl
@@ -28,9 +28,9 @@
28use POSIX; 28use POSIX;
29use strict; 29use strict;
30use Getopt::Long; 30use Getopt::Long;
31use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t $opt_s 31use 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);
34use FindBin; 34use FindBin;
35use lib "$FindBin::Bin"; 35use lib "$FindBin::Bin";
36use utils qw(%ERRORS &print_revision &support &usage ); 36use 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
53Getopt::Long::Configure('bundling'); 55Getopt::Long::Configure('bundling');
@@ -68,6 +70,10 @@ if ($opt_s) {
68 $sudo = ""; 70 $sudo = "";
69} 71}
70 72
73if ($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"};
@@ -309,8 +315,8 @@ elsif ( $mailq eq "postfix" ) {
309 315
310 ## open mailq 316 ## open mailq
311 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 317 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
312 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { 318 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ$mailq_args | " ) ) {
313 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 319 print "ERROR: could not open $utils::PATH_TO_MAILQ$mailq_args \n";
314 exit $ERRORS{'UNKNOWN'}; 320 exit $ERRORS{'UNKNOWN'};
315 } 321 }
316 }elsif( defined $utils::PATH_TO_MAILQ){ 322 }elsif( defined $utils::PATH_TO_MAILQ){
@@ -330,7 +336,7 @@ elsif ( $mailq eq "postfix" ) {
330 close MAILQ; 336 close MAILQ;
331 337
332 if ( $? ) { 338 if ( $? ) {
333 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/; 339 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ$mailq_args",$/;
334 exit $ERRORS{CRITICAL}; 340 exit $ERRORS{CRITICAL};
335 } 341 }
336 342
@@ -343,7 +349,7 @@ elsif ( $mailq eq "postfix" ) {
343 }elsif ($lines[0]=~/Mail queue is empty/) { 349 }elsif ($lines[0]=~/Mail queue is empty/) {
344 $msg_q = 0; 350 $msg_q = 0;
345 }else{ 351 }else{
346 print "Couldn't match $utils::PATH_TO_MAILQ output\n"; 352 print "Couldn't match $utils::PATH_TO_MAILQ$mailq_args output\n";
347 exit $ERRORS{'UNKNOWN'}; 353 exit $ERRORS{'UNKNOWN'};
348 } 354 }
349 355
@@ -533,7 +539,7 @@ elsif ( $mailq eq "nullmailer" ) {
533 while (<MAILQ>) { 539 while (<MAILQ>) {
534 #2006-06-22 16:00:00 282 bytes 540 #2006-06-22 16:00:00 282 bytes
535 541
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$/) { 542 if (/^[1-9][0-9]*-[01][0-9]-[0-3][0-9]\s[0-2][0-9]\:[0-5][0-9]\:[0-5][0-9]\s+[0-9]+\sbytes/) {
537 $msg_q++ ; 543 $msg_q++ ;
538 } 544 }
539 } 545 }
@@ -568,7 +574,10 @@ sub process_arguments(){
568 "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number 574 "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 575 "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number
570 "t=i" => \$opt_t, "timeout=i" => \$opt_t, 576 "t=i" => \$opt_t, "timeout=i" => \$opt_t,
571 "s" => \$opt_s, "sudo" => \$opt_s 577 "s" => \$opt_s, "sudo" => \$opt_s,
578 "d:s" => \$opt_d, "configdir:s" => \$opt_d,
579 "W=i" => \$opt_W, # warning if above this number
580 "C=i" => \$opt_C, # critical if above this number
572 ); 581 );
573 582
574 if ($opt_V) { 583 if ($opt_V) {
@@ -649,7 +658,7 @@ sub process_arguments(){
649} 658}
650 659
651sub print_usage () { 660sub print_usage () {
652 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-v]\n"; 661 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-d <CONFIGDIR>] [-v]\n";
653} 662}
654 663
655sub print_help () { 664sub print_help () {
@@ -662,11 +671,12 @@ sub print_help () {
662 print " Feedback/patches to support non-sendmail mailqueue welcome\n\n"; 671 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"; 672 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"; 673 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"; 674 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"; 675 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"; 676 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n";
668 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; 677 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n";
669 print "-s (--sudo) = Use sudo to call the mailq command\n"; 678 print "-s (--sudo) = Use sudo to call the mailq command\n";
679 print "-d (--configdir) = Config file or directory\n";
670 print "-h (--help)\n"; 680 print "-h (--help)\n";
671 print "-V (--version)\n"; 681 print "-V (--version)\n";
672 print "-v (--verbose) = debugging output\n"; 682 print "-v (--verbose) = debugging output\n";
diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh
index 96078ac..b14ec50 100755
--- a/plugins-scripts/check_oracle.sh
+++ b/plugins-scripts/check_oracle.sh
@@ -8,11 +8,11 @@
8 8
9PATH="@TRUSTED_PATH@" 9PATH="@TRUSTED_PATH@"
10export PATH 10export PATH
11PROGNAME=`basename $0` 11PROGNAME=$(basename "$0")
12PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` 12PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,')
13REVISION="@NP_VERSION@" 13REVISION="@NP_VERSION@"
14 14
15. $PROGPATH/utils.sh 15. "$PROGPATH"/utils.sh
16 16
17 17
18print_usage() { 18print_usage() {
@@ -29,7 +29,7 @@ print_usage() {
29} 29}
30 30
31print_help() { 31print_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 ""
@@ -87,47 +87,47 @@ esac
87case "$cmd" in 87case "$cmd" in
88--help) 88--help)
89 print_help 89 print_help
90 exit $STATE_OK 90 exit "$STATE_OK"
91 ;; 91 ;;
92-h) 92-h)
93 print_help 93 print_help
94 exit $STATE_OK 94 exit "$STATE_OK"
95 ;; 95 ;;
96--version) 96--version)
97 print_revision $PROGNAME $REVISION 97 print_revision "$PROGNAME" "$REVISION"
98 exit $STATE_OK 98 exit "$STATE_OK"
99 ;; 99 ;;
100-V) 100-V)
101 print_revision $PROGNAME $REVISION 101 print_revision "$PROGNAME" "$REVISION"
102 exit $STATE_OK 102 exit "$STATE_OK"
103 ;; 103 ;;
104esac 104esac
105 105
106# Hunt down a reasonable ORACLE_HOME 106# Hunt down a reasonable ORACLE_HOME
107if [ -z "$ORACLE_HOME" ] ; then 107if [ -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
122fi 122fi
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
126if [ "$cmd" != "--db" ]; then 126if [ "$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
131fi 131fi
132PATH=$PATH:$ORACLE_HOME/bin 132PATH=$PATH:$ORACLE_HOME/bin
133LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib 133LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
@@ -135,81 +135,81 @@ export ORACLE_HOME PATH LD_LIBRARY_PATH
135 135
136case "$cmd" in 136case "$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
213set pagesize 0 213set pagesize 0
214set numf '9999999.99' 214set numf '9999999.99'
215select (1-(pr.value/(dbg.value+cg.value)))*100 215select (1-(pr.value/(dbg.value+cg.value)))*100
@@ -219,48 +219,48 @@ and dbg.name='db block gets'
219and cg.name='consistent gets'; 219and cg.name='consistent gets';
220EOF` 220EOF`
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
231set pagesize 0 231set pagesize 0
232set numf '9999999.99' 232set numf '9999999.99'
233select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100 233select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100
234from v\\$librarycache lc; 234from v\\$librarycache lc;
235EOF` 235EOF`
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
264set pagesize 0 264set pagesize 0
265set numf '9999999.99' 265set numf '9999999.99'
266select NVL(b.free,0.0),a.total,100 - trunc(NVL(b.free,0.0)/a.total * 1000) / 10 prc 266select 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
273ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${5}'; 273ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${5}';
274EOF` 274EOF`
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"
304esac 304esac
diff --git a/plugins-scripts/check_sensors.sh b/plugins-scripts/check_sensors.sh
index f742830..ab4e726 100755
--- a/plugins-scripts/check_sensors.sh
+++ b/plugins-scripts/check_sensors.sh
@@ -2,57 +2,57 @@
2 2
3PATH="@TRUSTED_PATH@" 3PATH="@TRUSTED_PATH@"
4export PATH 4export PATH
5PROGNAME=`basename $0` 5PROGNAME=$(basename "$0")
6PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` 6PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,')
7REVISION="@NP_VERSION@" 7REVISION="@NP_VERSION@"
8 8
9. $PROGPATH/utils.sh 9. "$PROGPATH"/utils.sh
10 10
11print_usage() { 11print_usage() {
12 echo "Usage: $PROGNAME" [--ignore-fault] 12 echo "Usage: $PROGNAME" [--ignore-fault]
13} 13}
14 14
15print_help() { 15print_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
26case "$1" in 26case "$1" in
27 --help) 27 --help)
28 print_help 28 print_help
29 exit $STATE_OK 29 exit "$STATE_OK"
30 ;; 30 ;;
31 -h) 31 -h)
32 print_help 32 print_help
33 exit $STATE_OK 33 exit "$STATE_OK"
34 ;; 34 ;;
35 --version) 35 --version)
36 print_revision $PROGNAME $REVISION 36 print_revision "$PROGNAME" "$REVISION"
37 exit $STATE_OK 37 exit "$STATE_OK"
38 ;; 38 ;;
39 -V) 39 -V)
40 print_revision $PROGNAME $REVISION 40 print_revision "$PROGNAME" "$REVISION"
41 exit $STATE_OK 41 exit "$STATE_OK"
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}" | egrep 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}" | egrep 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 ;;
70esac 70esac
diff --git a/plugins-scripts/check_uptime.pl b/plugins-scripts/check_uptime.pl
new file mode 100755
index 0000000..4c9f22d
--- /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
24use POSIX;
25use strict;
26use Getopt::Long;
27use 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);
32use FindBin;
33use lib "$FindBin::Bin";
34use utils qw(%ERRORS &print_revision &support &usage );
35
36sub print_help ();
37sub print_usage ();
38sub process_arguments ();
39
40$ENV{'PATH'}='@TRUSTED_PATH@';
41$ENV{'BASH_ENV'}='';
42$ENV{'ENV'}='';
43$PROGNAME = "check_uptime";
44$state = $ERRORS{'UNKNOWN'};
45
46my $uptime_file = "/proc/uptime";
47
48
49# Process arguments
50
51Getopt::Long::Configure('bundling');
52$status = process_arguments();
53if ($status){
54 print "ERROR: processing arguments\n";
55 exit $ERRORS{"UNKNOWN"};
56}
57
58
59# Get uptime info from file
60
61if ( ! -r $uptime_file ) {
62 print "ERROR: file '$uptime_file' is not readable\n";
63 exit $ERRORS{"UNKNOWN"};
64}
65
66if ( ! open FILE, "<", $uptime_file ) {
67 print "ERROR: cannot read from file '$uptime_file'\n";
68 exit $ERRORS{"UNKNOWN"};
69}
70
71chomp( my $file_content = <FILE> );
72close FILE;
73
74print "$uptime_file: $file_content\n" if $verbose;
75
76# Get first digit value (without fraction)
77my ( $uptime_seconds ) = $file_content =~ /^([\d]+)/;
78
79# Bail out if value is not numeric
80if ( $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
88my ( $secs, $mins, $hours, $days, $weeks );
89$secs = $uptime_seconds;
90$mins = $hours = $days = $weeks = 0;
91if ( $secs > 100 ) {
92 $mins = int( $secs / 60 );
93 $secs -= $mins * 60;
94}
95if ( $mins > 100 ) {
96 $hours = int( $mins / 60 );
97 $mins -= $hours * 60;
98}
99if ( $hours > 48 ) {
100 $days = int( $hours / 24 );
101 $hours -= $days * 24;
102}
103if ( $days > 14 ) {
104 $weeks = int( $days / 7 );
105 $days -= $weeks * 7;
106}
107
108my $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
120my $state_str = "UNKNOWN";
121
122# Check values
123my $out_of_bounds_text = "";
124if ( $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;
145if ( $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
153print "$msg|uptime=${uptime_seconds}s;$upper_warn_threshold;$upper_crit_threshold;0\n";
154exit $state;
155
156
157#####################################
158#### subs
159
160
161sub 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
248sub print_usage () {
249 print "Usage: $PROGNAME -w <warn> -c <crit> [-v]\n";
250}
251
252sub 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
281sub 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 50a2e69..8b87670 100644
--- a/plugins-scripts/t/check_file_age.t
+++ b/plugins-scripts/t/check_file_age.t
@@ -5,14 +5,14 @@
5# 5#
6 6
7use strict; 7use strict;
8use Test::More tests => 17; 8use Test::More tests => 27;
9use NPTest; 9use NPTest;
10 10
11my $successOutput = '/^FILE_AGE OK: /'; 11my $successOutput = '/^FILE_AGE OK: /';
12my $warningOutput = '/^FILE_AGE WARNING: /'; 12my $warningOutput = '/^FILE_AGE WARNING: /';
13my $criticalOutput = '/^FILE_AGE CRITICAL: /'; 13my $criticalOutput = '/^FILE_AGE CRITICAL: /';
14my $unknownOutput = '/^FILE_AGE UNKNOWN: /'; 14my $unknownOutput = '/^FILE_AGE UNKNOWN: /';
15my $performanceOutput = '/ \| age=[0-9]+s;[0-9]+;[0-9]+ size=[0-9]+B;[0-9]+;[0-9]+;0$/'; 15my $performanceOutput = '/ \| age=[0-9]+s;[0-9:]+;[0-9:]+ size=[0-9]+B;[0-9:]+;[0-9:]+;0$/';
16 16
17my $result; 17my $result;
18my $temp_file = "/tmp/check_file_age.tmp"; 18my $temp_file = "/tmp/check_file_age.tmp";
@@ -20,64 +20,75 @@ my $temp_link = "/tmp/check_file_age.link.tmp";
20 20
21unlink $temp_file, $temp_link; 21unlink $temp_file, $temp_link;
22 22
23$result = NPTest->testCmd( 23$result = NPTest->testCmd("./check_file_age");
24 "./check_file_age"
25 );
26cmp_ok( $result->return_code, '==', 3, "Missing parameters" ); 24cmp_ok( $result->return_code, '==', 3, "Missing parameters" );
27like ( $result->output, $unknownOutput, "Output for unknown correct" ); 25like ( $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 );
32cmp_ok( $result->return_code, '==', 2, "File not exists" ); 28cmp_ok( $result->return_code, '==', 2, "File not exists" );
33like ( $result->output, $criticalOutput, "Output for file missing correct" ); 29like ( $result->output, $criticalOutput, "Output for file missing correct" );
34 30
35write_chars(100); 31write_chars(100);
36$result = NPTest->testCmd( 32$result = NPTest->testCmd("./check_file_age -f $temp_file");
37 "./check_file_age -f $temp_file"
38 );
39cmp_ok( $result->return_code, '==', 0, "File is new enough" ); 33cmp_ok( $result->return_code, '==', 0, "File is new enough" );
40like ( $result->output, $successOutput, "Output for success correct" ); 34like ( $result->output, $successOutput, "Output for success correct" );
41 35
42sleep 2; 36sleep 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 );
47cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old" ); 39cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old" );
48like ( $result->output, $warningOutput, "Output for warning correct" ); 40like ( $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 -c 1"
52 );
53cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" ); 43cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" );
54like ( $result->output, $criticalOutput, "Output for critical correct" ); 44like ( $result->output, $criticalOutput, "Output for critical correct" );
55 45
56$result = NPTest->testCmd( 46$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100");
57 "./check_file_age -f $temp_file -c 1000 -W 100"
58 );
59cmp_ok( $result->return_code, '==', 0, "Checking file size" ); 47cmp_ok( $result->return_code, '==', 0, "Checking file size" );
60 48
61$result = NPTest->testCmd( 49$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100");
62 "./check_file_age -f $temp_file -c 1000 -W 100"
63 );
64like( $result->output, $performanceOutput, "Checking for performance Output" ); 50like( $result->output, $performanceOutput, "Checking for performance Output" );
65 51
66$result = NPTest->testCmd( 52$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100");
67 "./check_file_age -f /non/existent --ignore-missing" 53like( $result->output, $performanceOutput, "Checking for performance Output from range" );
68 ); 54
55$result = NPTest->testCmd("./check_file_age -f /non/existent --ignore-missing");
69cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" ); 56cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" );
70 57
71$result = NPTest->testCmd( 58$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 101");
72 "./check_file_age -f $temp_file -c 1000 -W 101"
73 );
74cmp_ok( $result->return_code, '==', 1, "One byte too short" ); 59cmp_ok( $result->return_code, '==', 1, "One byte too short" );
75 60
76$result = NPTest->testCmd( 61$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 101");
77 "./check_file_age -f $temp_file -c 1000 -C 101"
78 );
79cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" ); 62cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" );
80 63
64SKIP: {
65 eval 'use Monitoring::Plugin::Range';
66 skip "Monitoring::Plugin::Range module require", 9 if $@;
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" );
84
85 $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 101:");
86 cmp_ok( $result->return_code, '==', 2, "One byte too short by range - critical" );
87
88 $result = NPTest->testCmd("./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" );
90};
91
81symlink $temp_file, $temp_link or die "Cannot create symlink"; 92symlink $temp_file, $temp_link or die "Cannot create symlink";
82$result = NPTest->testCmd("./check_file_age -f $temp_link -c 10"); 93$result = NPTest->testCmd("./check_file_age -f $temp_link -c 10");
83cmp_ok( $result->return_code, '==', 0, "Works for symlinks" ); 94cmp_ok( $result->return_code, '==', 0, "Works for symlinks" );
diff --git a/plugins-scripts/t/check_uptime.t b/plugins-scripts/t/check_uptime.t
new file mode 100644
index 0000000..c395307
--- /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
7use strict;
8use Test::More tests => 40;
9use NPTest;
10
11my $result;
12
13$result = NPTest->testCmd(
14 "./check_uptime"
15 );
16cmp_ok( $result->return_code, '==', 3, "Missing parameters" );
17like ( $result->output, '/^Usage: check_uptime -w/', "Output for missing parameters correct" );
18
19$result = NPTest->testCmd(
20 "./check_uptime --help"
21 );
22cmp_ok( $result->return_code, '==', 3, "Help output requested" );
23like ( $result->output, '/ABSOLUTELY NO WARRANTY/', "Output for help correct" );
24
25$result = NPTest->testCmd(
26 "./check_uptime -w 5 -c 2"
27 );
28cmp_ok( $result->return_code, '==', 3, "Warning greater than critical" );
29like ( $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 );
34like ( $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 );
39cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
40like ( $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 );
45cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
46like ( $result->output, '/Running since \d+/', "Output for the s parameter correct" );
47
48$result = NPTest->testCmd(
49 "./check_uptime -w 1 -c 2"
50 );
51cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
52like ( $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 );
57cmp_ok( $result->return_code, '==', 1, "Uptime lower than 9999 weeks" );
58like ( $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 );
63cmp_ok( $result->return_code, '==', 0, "Uptime lower than 9998 weeks" );
64like ( $result->output, '/^OK: uptime is \d+ seconds/', "Output for uptime lower than 9998 weeks correct" );
65like ( $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 );
70cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days" );
71like ( $result->output, '/^OK: uptime is \d+ seconds/', "Output for uptime lower than 111222 days correct" );
72like ( $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 );
78cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days, and higher 2 seconds" );
79like ( $result->output, '/^OK: uptime is \d+ seconds/', "Output for uptime lower than 111222 days, and higher 2 seconds correct" );
80like ( $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 );
86cmp_ok( $result->return_code, '==', 1, "Uptime lower than 111221 days raises warning" );
87like ( $result->output, '/^WARNING: uptime is \d+ seconds/', "Output for uptime lower than 111221 days correct" );
88like ( $result->output, '/Exceeds lower warn threshold/', "Exceeds text correct" );
89like ( $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 );
95cmp_ok( $result->return_code, '==', 2, "Uptime lower than 111220 days raises critical" );
96like ( $result->output, '/^CRITICAL: uptime is \d+ seconds/', "Output for uptime lower than 111220 days correct" );
97like ( $result->output, '/Exceeds lower crit threshold/', "Exceeds text correct" );
98like ( $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 );
109cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" );
110like ( $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 );
115cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" );
116like ( $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 );
121cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" );
122like ( $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 );
127cmp_ok( $result->return_code, '==', 3, "Wrong parameter format raises unknown" );
128like ( $result->output, '/^Upper critical .* is not numeric/', "Output for wrong parameter format correct" );
129
diff --git a/plugins-scripts/t/utils.t b/plugins-scripts/t/utils.t
index 9c2c569..5c23179 100644
--- a/plugins-scripts/t/utils.t
+++ b/plugins-scripts/t/utils.t
@@ -10,6 +10,7 @@ use strict;
10use Test::More; 10use Test::More;
11use NPTest; 11use NPTest;
12 12
13use lib ".";
13use lib ".."; 14use lib "..";
14use utils; 15use utils;
15 16