summaryrefslogtreecommitdiffstats
path: root/plugins-scripts
diff options
context:
space:
mode:
authorLorenz <12514511+RincewindsHat@users.noreply.github.com>2023-03-10 11:33:25 +0100
committerGitHub <noreply@github.com>2023-03-10 11:33:25 +0100
commit5077120a251980b4fafed61b4aa8fa5730a85443 (patch)
tree8500b8f5dbe774b399cfdc79f5665ba88ef7f255 /plugins-scripts
parenta3de84594104ac87a91e200d569fb57edacca928 (diff)
parent269718094177fb8a7e3d3005d1310495009fe8c4 (diff)
downloadmonitoring-plugins-5077120a251980b4fafed61b4aa8fa5730a85443.tar.gz
Merge branch 'master' into master
Diffstat (limited to 'plugins-scripts')
-rw-r--r--[-rwxr-xr-x]plugins-scripts/check_disk_smb.pl21
-rwxr-xr-xplugins-scripts/check_file_age.pl2
-rwxr-xr-xplugins-scripts/check_ifoperstatus.pl2
-rwxr-xr-xplugins-scripts/check_ircd.pl4
-rwxr-xr-xplugins-scripts/check_log.sh168
-rwxr-xr-xplugins-scripts/check_mailq.pl46
-rwxr-xr-xplugins-scripts/check_oracle.sh240
-rwxr-xr-xplugins-scripts/check_sensors.sh34
-rwxr-xr-xplugins-scripts/check_uptime.pl17
-rw-r--r--plugins-scripts/t/check_log.t82
-rw-r--r--plugins-scripts/t/check_uptime.t22
11 files changed, 399 insertions, 239 deletions
diff --git a/plugins-scripts/check_disk_smb.pl b/plugins-scripts/check_disk_smb.pl
index 28c49e84..15d16340 100755..100644
--- a/plugins-scripts/check_disk_smb.pl
+++ b/plugins-scripts/check_disk_smb.pl
@@ -22,7 +22,7 @@ require 5.004;
22use POSIX qw(setsid); 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 $opt_C $opt_t $verbose);
26use vars qw($PROGNAME); 26use vars qw($PROGNAME);
27use FindBin; 27use FindBin;
28use lib "$FindBin::Bin"; 28use lib "$FindBin::Bin";
@@ -43,6 +43,7 @@ $ENV{'ENV'}='';
43Getopt::Long::Configure('bundling'); 43Getopt::Long::Configure('bundling');
44GetOptions 44GetOptions
45 ("v" => \$verbose, "verbose" => \$verbose, 45 ("v" => \$verbose, "verbose" => \$verbose,
46 "t=i" => \$opt_t, "timeout=i" => \$opt_t,
46 "P=s" => \$opt_P, "port=s" => \$opt_P, 47 "P=s" => \$opt_P, "port=s" => \$opt_P,
47 "V" => \$opt_V, "version" => \$opt_V, 48 "V" => \$opt_V, "version" => \$opt_V,
48 "h" => \$opt_h, "help" => \$opt_h, 49 "h" => \$opt_h, "help" => \$opt_h,
@@ -53,7 +54,8 @@ GetOptions
53 "s=s" => \$opt_s, "share=s" => \$opt_s, 54 "s=s" => \$opt_s, "share=s" => \$opt_s,
54 "W=s" => \$opt_W, "workgroup=s" => \$opt_W, 55 "W=s" => \$opt_W, "workgroup=s" => \$opt_W,
55 "H=s" => \$opt_H, "hostname=s" => \$opt_H, 56 "H=s" => \$opt_H, "hostname=s" => \$opt_H,
56 "a=s" => \$opt_a, "address=s" => \$opt_a); 57 "a=s" => \$opt_a, "address=s" => \$opt_a,
58 "C=s" => \$opt_C, "configfile=s" => \$opt_C);
57 59
58if ($opt_V) { 60if ($opt_V) {
59 print_revision($PROGNAME,'@NP_VERSION@'); #' 61 print_revision($PROGNAME,'@NP_VERSION@'); #'
@@ -91,6 +93,12 @@ my $warn = $1 if ($opt_w =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/);
91my $crit = $1 if ($opt_c =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/); 93my $crit = $1 if ($opt_c =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/);
92($crit) || usage("Invalid critical threshold: $opt_c\n"); 94($crit) || usage("Invalid critical threshold: $opt_c\n");
93 95
96($opt_C) || ($opt_C = shift @ARGV) || ($opt_C = "");
97my $configfile = $opt_C if ($opt_C);
98usage("Unable to read config file $configfile\n") if ($configfile) && (! -r $configfile);
99
100if ($opt_t && $opt_t =~ /^([0-9]+)$/) { $TIMEOUT = $1; }
101
94# Execute the given command line and return anything it writes to STDOUT and/or 102# Execute the given command line and return anything it writes to STDOUT and/or
95# STDERR. (This might be useful for other plugins, too, so it should possibly 103# STDERR. (This might be useful for other plugins, too, so it should possibly
96# be moved to utils.pm.) 104# be moved to utils.pm.)
@@ -193,6 +201,7 @@ my @cmd = (
193 defined($workgroup) ? ("-W", $workgroup) : (), 201 defined($workgroup) ? ("-W", $workgroup) : (),
194 defined($address) ? ("-I", $address) : (), 202 defined($address) ? ("-I", $address) : (),
195 defined($opt_P) ? ("-p", $opt_P) : (), 203 defined($opt_P) ? ("-p", $opt_P) : (),
204 defined($configfile) ? ("-s", $configfile) : (),
196 "-c", "du" 205 "-c", "du"
197); 206);
198 207
@@ -292,7 +301,8 @@ exit $ERRORS{$state};
292 301
293sub print_usage () { 302sub print_usage () {
294 print "Usage: $PROGNAME -H <host> -s <share> -u <user> -p <password> 303 print "Usage: $PROGNAME -H <host> -s <share> -u <user> -p <password>
295 -w <warn> -c <crit> [-W <workgroup>] [-P <port>] [-a <IP>]\n"; 304 -w <warn> -c <crit> [-W <workgroup>] [-P <port>] [-a <IP>] [-t timeout]
305 [-C <configfile>]\n";
296} 306}
297 307
298sub print_help () { 308sub print_help () {
@@ -318,11 +328,14 @@ Perl Check SMB Disk plugin for monitoring
318 Password to log in to server. (Defaults to an empty password) 328 Password to log in to server. (Defaults to an empty password)
319-w, --warning=INTEGER or INTEGER[kMG] 329-w, --warning=INTEGER or INTEGER[kMG]
320 Percent of used space at which a warning will be generated (Default: 85%) 330 Percent of used space at which a warning will be generated (Default: 85%)
321
322-c, --critical=INTEGER or INTEGER[kMG] 331-c, --critical=INTEGER or INTEGER[kMG]
323 Percent of used space at which a critical will be generated (Defaults: 95%) 332 Percent of used space at which a critical will be generated (Defaults: 95%)
333-t, --timeout=INTEGER
334 Seconds before connection times out (Default: 15)
324-P, --port=INTEGER 335-P, --port=INTEGER
325 Port to be used to connect to. Some Windows boxes use 139, others 445 (Defaults to smbclient default) 336 Port to be used to connect to. Some Windows boxes use 139, others 445 (Defaults to smbclient default)
337-C, --configfile=STRING
338 Path to configfile which should be used by smbclient (Defaults to smb.conf of your smb installation)
326 339
327 If thresholds are followed by either a k, M, or G then check to see if that 340 If thresholds are followed by either a k, M, or G then check to see if that
328 much disk space is available (kilobytes, Megabytes, Gigabytes) 341 much disk space is available (kilobytes, Megabytes, Gigabytes)
diff --git a/plugins-scripts/check_file_age.pl b/plugins-scripts/check_file_age.pl
index 01b854a6..26281ddd 100755
--- a/plugins-scripts/check_file_age.pl
+++ b/plugins-scripts/check_file_age.pl
@@ -147,7 +147,7 @@ sub print_help () {
147 print "\n"; 147 print "\n";
148 print " -i | --ignore-missing : return OK if the file does not exist\n"; 148 print " -i | --ignore-missing : return OK if the file does not exist\n";
149 print " <secs> File must be no more than this many seconds old (default: warn 240 secs, crit 600)\n"; 149 print " <secs> File must be no more than this many seconds old (default: warn 240 secs, crit 600)\n";
150 print " <size> File must be at least this many bytes long (default: crit 0 bytes)\n\n"; 150 print " <size> File must be at least this many bytes long (default: file size is ignored (0 bytes))\n\n";
151 print " Both <secs> and <size> can specify a range using the standard plugin syntax\n"; 151 print " Both <secs> and <size> can specify a range using the standard plugin syntax\n";
152 print " If any of the warning and critical arguments are in range syntax (not just bare numbers)\n"; 152 print " If any of the warning and critical arguments are in range syntax (not just bare numbers)\n";
153 print " then all warning and critical arguments will be interpreted as ranges.\n"; 153 print " then all warning and critical arguments will be interpreted as ranges.\n";
diff --git a/plugins-scripts/check_ifoperstatus.pl b/plugins-scripts/check_ifoperstatus.pl
index 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
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 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";
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 d28c8d0a..c623a8d6 100755
--- a/plugins-scripts/check_log.sh
+++ b/plugins-scripts/check_log.sh
@@ -1,8 +1,7 @@
1#!/bin/sh 1#!/bin/sh
2# 2#
3# Log file pattern detector plugin for monitoring 3# Log file pattern detector plugin for monitoring
4# Written by Ethan Galstad (nagios@nagios.org) 4# Written originally by Ethan Galstad (nagios@nagios.org)
5# Last Modified: 07-31-1999
6# 5#
7# Usage: ./check_log <log_file> <old_log_file> <pattern> 6# Usage: ./check_log <log_file> <old_log_file> <pattern>
8# 7#
@@ -19,7 +18,7 @@
19# On the first run of the plugin, it will return an OK state with a message 18# On the first run of the plugin, it will return an OK state with a message
20# of "Log check data initialized". On successive runs, it will return an OK 19# of "Log check data initialized". On successive runs, it will return an OK
21# state if *no* pattern matches have been found in the *difference* between the 20# state if *no* pattern matches have been found in the *difference* between the
22# log file and the older copy of the log file. If the plugin detects any 21# log file and the older copy of the log file. If the plugin detects any
23# pattern matches in the log diff, it will return a CRITICAL state and print 22# pattern matches in the log diff, it will return a CRITICAL state and print
24# out a message is the following format: "(x) last_match", where "x" is the 23# out a message is the following format: "(x) last_match", where "x" is the
25# total number of pattern matches found in the file and "last_match" is the 24# total number of pattern matches found in the file and "last_match" is the
@@ -44,6 +43,10 @@
44# check the same <log_file> for pattern matches. This is necessary 43# check the same <log_file> for pattern matches. This is necessary
45# because of the way the script operates. 44# because of the way the script operates.
46# 45#
46# 4. This plugin does NOT have an understanding of logrotation or similar
47# mechanisms. Therefore bad timing could lead to missing events
48#
49#
47# Examples: 50# Examples:
48# 51#
49# Check for login failures in the syslog... 52# Check for login failures in the syslog...
@@ -60,20 +63,26 @@
60 63
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 " --exclude: Exclude a pattern (-p or -e also applies here when used)"
80 echo " -p|--perl-regex : Use perl style regular expressions in the query"
81 echo " -e|--extended-regex : Use extended style regular expressions in the query (not necessary for GNU grep)"
73} 82}
74 83
75print_help() { 84print_help() {
76 print_revision $PROGNAME $REVISION 85 print_revision "$PROGNAME" "$REVISION"
77 echo "" 86 echo ""
78 print_usage 87 print_usage
79 echo "" 88 echo ""
@@ -87,81 +96,89 @@ print_help() {
87 96
88if [ $# -lt 1 ]; then 97if [ $# -lt 1 ]; then
89 print_usage 98 print_usage
90 exit $STATE_UNKNOWN 99 exit "$STATE_UNKNOWN"
91fi 100fi
92 101
93# Grab the command line arguments 102# Grab the command line arguments
94
95#logfile=$1
96#oldlog=$2
97#query=$3
98exitstatus=$STATE_WARNING #default 103exitstatus=$STATE_WARNING #default
99while test -n "$1"; do 104while test -n "$1"; do
100 case "$1" in 105 case "$1" in
101 --help) 106 -h | --help)
102 print_help 107 print_help
103 exit $STATE_OK 108 exit "$STATE_OK"
104 ;; 109 ;;
105 -h) 110 -V | --version)
106 print_help 111 print_revision "$PROGNAME" "$REVISION"
107 exit $STATE_OK 112 exit "$STATE_OK"
108 ;;
109 --version)
110 print_revision $PROGNAME $REVISION
111 exit $STATE_OK
112 ;;
113 -V)
114 print_revision $PROGNAME $REVISION
115 exit $STATE_OK
116 ;;
117 --filename)
118 logfile=$2
119 shift
120 ;; 113 ;;
121 -F) 114 -F | --filename)
122 logfile=$2 115 logfile=$2
123 shift 116 shift 2
124 ;; 117 ;;
125 --oldlog) 118 -O | --oldlog)
126 oldlog=$2 119 oldlog=$2
127 shift 120 shift 2
128 ;; 121 ;;
129 -O) 122 -q | --query)
130 oldlog=$2
131 shift
132 ;;
133 --query)
134 query=$2 123 query=$2
135 shift 124 shift 2
136 ;; 125 ;;
137 -q) 126 --exclude)
138 query=$2 127 exclude=$2
139 shift 128 shift 2
140 ;; 129 ;;
141 -x) 130 -x | --exitstatus)
142 exitstatus=$2 131 exitstatus=$2
132 shift 2
133 ;;
134 -e | --extended-regex)
135 ERE=1
143 shift 136 shift
144 ;; 137 ;;
145 --exitstatus) 138 -p | --perl-regex)
146 exitstatus=$2 139 PRE=1
140 shift
141 ;;
142 -a | --all)
143 ALL=1
147 shift 144 shift
148 ;; 145 ;;
149 *) 146 *)
150 echo "Unknown argument: $1" 147 echo "Unknown argument: $1"
151 print_usage 148 print_usage
152 exit $STATE_UNKNOWN 149 exit "$STATE_UNKNOWN"
153 ;; 150 ;;
154 esac 151 esac
155 shift
156done 152done
157 153
154# Parameter sanity check
155if [ $ERE ] && [ $PRE ] ; then
156 echo "Can not use extended and perl regex at the same time"
157 exit "$STATE_UNKNOWN"
158fi
159
160GREP="grep"
161
162if [ $ERE ]; then
163 GREP="grep -E"
164fi
165
166if [ $PRE ]; then
167 GREP="grep -P"
168fi
169
158# If the source log file doesn't exist, exit 170# If the source log file doesn't exist, exit
159 171
160if [ ! -e $logfile ]; then 172if [ ! -e "$logfile" ]; then
161 echo "Log check error: Log file $logfile does not exist!" 173 echo "Log check error: Log file $logfile does not exist!"
162 exit $STATE_UNKNOWN 174 exit "$STATE_UNKNOWN"
163elif [ ! -r $logfile ] ; then 175elif [ ! -r "$logfile" ] ; then
164 echo "Log check error: Log file $logfile is not readable!" 176 echo "Log check error: Log file $logfile is not readable!"
177 exit "$STATE_UNKNOWN"
178fi
179# If no oldlog was given this can not work properly, abort then
180if [ -z "$oldlog" ]; then
181 echo "Oldlog parameter is needed"
165 exit $STATE_UNKNOWN 182 exit $STATE_UNKNOWN
166fi 183fi
167 184
@@ -169,10 +186,10 @@ fi
169# we're running this test, so copy the original log file over to 186# we're running this test, so copy the original log file over to
170# the old diff file and exit 187# the old diff file and exit
171 188
172if [ ! -e $oldlog ]; then 189if [ ! -e "$oldlog" ]; then
173 cat $logfile > $oldlog 190 cat "$logfile" > "$oldlog"
174 echo "Log check data initialized..." 191 echo "Log check data initialized..."
175 exit $STATE_OK 192 exit "$STATE_OK"
176fi 193fi
177 194
178# The old log file exists, so compare it to the original log now 195# The old log file exists, so compare it to the original log now
@@ -180,31 +197,48 @@ fi
180# The temporary file that the script should use while 197# The temporary file that the script should use while
181# processing the log file. 198# processing the log file.
182if [ -x /bin/mktemp ]; then 199if [ -x /bin/mktemp ]; then
183 tempdiff=`/bin/mktemp /tmp/check_log.XXXXXXXXXX` 200
201 tempdiff=$(/bin/mktemp /tmp/check_log.XXXXXXXXXX)
184else 202else
185 tempdiff=`/bin/date '+%H%M%S'` 203 tempdiff=$(/bin/date '+%H%M%S')
186 tempdiff="/tmp/check_log.${tempdiff}" 204 tempdiff="/tmp/check_log.${tempdiff}"
187 touch $tempdiff 205 touch "$tempdiff"
188 chmod 600 $tempdiff 206 chmod 600 "$tempdiff"
189fi 207fi
190 208
191diff $logfile $oldlog | grep -v "^>" > $tempdiff 209diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff"
210
192 211
193# Count the number of matching log entries we have 212if [ $ALL ]; then
194count=`grep -c "$query" $tempdiff` 213 # Get all matching entries in the diff file
214 if [ -n "$exclude" ]; then
215 entry=$($GREP "$query" "$tempdiff" | $GREP -v "$exclude")
216 count=$($GREP "$query" "$tempdiff" | $GREP -vc "$exclude")
217 else
218 entry=$($GREP "$query" "$tempdiff")
219 count=$($GREP -c "$query" "$tempdiff")
220 fi
195 221
196# Get the last matching entry in the diff file 222else
197lastentry=`grep "$query" $tempdiff | tail -1` 223 # Get the last matching entry in the diff file
224 if [ -n "$exclude" ]; then
225 entry=$($GREP "$query" "$tempdiff" | $GREP -v "$exclude" | tail -1)
226 count=$($GREP "$query" "$tempdiff" | $GREP -vc "$exclude")
227 else
228 entry=$($GREP "$query" "$tempdiff" | tail -1)
229 count=$($GREP -c "$query" "$tempdiff")
230 fi
231fi
198 232
199rm -f $tempdiff 233rm -f "$tempdiff"
200cat $logfile > $oldlog 234cat "$logfile" > "$oldlog"
201 235
202if [ "$count" = "0" ]; then # no matches, exit with no error 236if [ "$count" = "0" ]; then # no matches, exit with no error
203 echo "Log check ok - 0 pattern matches found" 237 echo "Log check ok - 0 pattern matches found"
204 exitstatus=$STATE_OK 238 exitstatus=$STATE_OK
205else # Print total matche count and the last entry we found 239else # Print total match count and the last entry we found
206 echo "($count) $lastentry" 240 echo "($count) $entry"
207 exitstatus=$STATE_CRITICAL 241 exitstatus=$STATE_CRITICAL
208fi 242fi
209 243
210exit $exitstatus 244exit "$exitstatus"
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl
index 32f498d3..27073d3c 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
@@ -531,9 +537,9 @@ elsif ( $mailq eq "nullmailer" ) {
531 } 537 }
532 538
533 while (<MAILQ>) { 539 while (<MAILQ>) {
534 #2006-06-22 16:00:00 282 bytes 540 #2022-08-25 01:30:40 502 bytes from <user@example.com>
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 (/^\d{4}-\d{2}-\d{2}\s+\d{2}\:\d{2}\:\d{2}\s+\d+\sbytes/) {
537 $msg_q++ ; 543 $msg_q++ ;
538 } 544 }
539 } 545 }
@@ -561,14 +567,17 @@ exit $state;
561 567
562sub process_arguments(){ 568sub process_arguments(){
563 GetOptions 569 GetOptions
564 ("V" => \$opt_V, "version" => \$opt_V, 570 ("V" => \$opt_V, "version" => \$opt_V,
565 "v" => \$opt_v, "verbose" => \$opt_v, 571 "v" => \$opt_v, "verbose" => \$opt_v,
566 "h" => \$opt_h, "help" => \$opt_h, 572 "h" => \$opt_h, "help" => \$opt_h,
567 "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail) 573 "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail)
568 "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number 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
576 "W=i" => \$opt_W, "warning-domain=i" => \$opt_W, # Warning if above this number
577 "C=i" => \$opt_C, "critical-domain=i" => \$opt_C, # Critical if above this number
570 "t=i" => \$opt_t, "timeout=i" => \$opt_t, 578 "t=i" => \$opt_t, "timeout=i" => \$opt_t,
571 "s" => \$opt_s, "sudo" => \$opt_s 579 "s" => \$opt_s, "sudo" => \$opt_s,
580 "d:s" => \$opt_d, "configdir:s" => \$opt_d,
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,14 +671,15 @@ 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 (--warning-domain) = 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 (--critical-domain) = 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";
673 print "\n\n"; 683 print "\n\n";
674 print "Note: -w and -c are required arguments. -W and -C are optional.\n"; 684 print "Note: -w and -c are required arguments. -W and -C are optional.\n";
675 print " -W and -C are applied to domains listed on the queues - both FROM and TO. (sendmail)\n"; 685 print " -W and -C are applied to domains listed on the queues - both FROM and TO. (sendmail)\n";
diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh
index 96078aca..b14ec50e 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 f7428301..921e7b36 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}" | grep -E ALARM > /dev/null; then
53 text="SENSOR CRITICAL - Sensor alarm detected!" 53 text="SENSOR CRITICAL - Sensor alarm detected!"
54 exit=$STATE_CRITICAL 54 exit=$STATE_CRITICAL
55 elif echo ${sensordata} | egrep FAULT > /dev/null \ 55 elif echo "${sensordata}" | grep -E FAULT > /dev/null \
56 && test "$1" != "-i" -a "$1" != "--ignore-fault"; then 56 && test "$1" != "-i" -a "$1" != "--ignore-fault"; then
57 text="SENSOR UNKNOWN - Sensor reported fault" 57 text="SENSOR UNKNOWN - Sensor reported fault"
58 exit=$STATE_UNKNOWN 58 exit=$STATE_UNKNOWN
@@ -63,8 +63,8 @@ case "$1" in
63 63
64 echo "$text" 64 echo "$text"
65 if test "$1" = "-v" -o "$1" = "--verbose"; then 65 if test "$1" = "-v" -o "$1" = "--verbose"; then
66 echo ${sensordata} 66 echo "${sensordata}"
67 fi 67 fi
68 exit $exit 68 exit "$exit"
69 ;; 69 ;;
70esac 70esac
diff --git a/plugins-scripts/check_uptime.pl b/plugins-scripts/check_uptime.pl
index 4c9f22da..f9542872 100755
--- a/plugins-scripts/check_uptime.pl
+++ b/plugins-scripts/check_uptime.pl
@@ -25,7 +25,7 @@ use POSIX;
25use strict; 25use strict;
26use Getopt::Long; 26use Getopt::Long;
27use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c 27use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c
28 $opt_f $opt_s 28 $opt_f $opt_s $opt_d
29 $lower_warn_threshold $upper_warn_threshold 29 $lower_warn_threshold $upper_warn_threshold
30 $lower_crit_threshold $upper_crit_threshold 30 $lower_crit_threshold $upper_crit_threshold
31 $status $state $msg); 31 $status $state $msg);
@@ -137,9 +137,20 @@ if ( $uptime_seconds > $upper_crit_threshold ) {
137 $state_str = "OK"; 137 $state_str = "OK";
138} 138}
139 139
140# Prepare uptime value (seconds or days)
141my $uptime_text = "";
142my $uptime_unit = "";
143if ( $opt_d ) {
144 $uptime_text = floor($uptime_seconds / 60 / 60 / 24);
145 $uptime_unit = "days";
146} else {
147 $uptime_text = $uptime_seconds;
148 $uptime_unit = "seconds";
149}
150
140$msg = "$state_str: "; 151$msg = "$state_str: ";
141 152
142$msg .= "uptime is $uptime_seconds seconds. "; 153$msg .= "Uptime is $uptime_text $uptime_unit. ";
143$msg .= "Exceeds $out_of_bounds_text threshold. " if $out_of_bounds_text; 154$msg .= "Exceeds $out_of_bounds_text threshold. " if $out_of_bounds_text;
144$msg .= "Running for $pretty_uptime. " if $opt_f; 155$msg .= "Running for $pretty_uptime. " if $opt_f;
145if ( $opt_s ) { 156if ( $opt_s ) {
@@ -167,6 +178,7 @@ sub process_arguments(){
167 "c=s" => \$opt_c, "critical=s" => \$opt_c, # critical if above this number 178 "c=s" => \$opt_c, "critical=s" => \$opt_c, # critical if above this number
168 "f" => \$opt_f, "for" => \$opt_f, # show "running for ..." 179 "f" => \$opt_f, "for" => \$opt_f, # show "running for ..."
169 "s" => \$opt_s, "since" => \$opt_s, # show "running since ..." 180 "s" => \$opt_s, "since" => \$opt_s, # show "running since ..."
181 "d" => \$opt_d, "days" => \$opt_d, # report uptime in days
170 ); 182 );
171 183
172 if ($opt_V) { 184 if ($opt_V) {
@@ -262,6 +274,7 @@ sub print_help () {
262 print "-c (--critical) = Min. number of uptime to generate critical alert ( w < c )\n"; 274 print "-c (--critical) = Min. number of uptime to generate critical alert ( w < c )\n";
263 print "-f (--for) = Show uptime in a pretty format (Running for x weeks, x days, ...)\n"; 275 print "-f (--for) = Show uptime in a pretty format (Running for x weeks, x days, ...)\n";
264 print "-s (--since) = Show last boot in yyyy-mm-dd HH:MM:SS format (output from 'uptime -s')\n"; 276 print "-s (--since) = Show last boot in yyyy-mm-dd HH:MM:SS format (output from 'uptime -s')\n";
277 print "-d (--days) = Show uptime in days\n";
265 print "-h (--help)\n"; 278 print "-h (--help)\n";
266 print "-V (--version)\n"; 279 print "-V (--version)\n";
267 print "-v (--verbose) = debugging output\n"; 280 print "-v (--verbose) = debugging output\n";
diff --git a/plugins-scripts/t/check_log.t b/plugins-scripts/t/check_log.t
new file mode 100644
index 00000000..b66e0fd8
--- /dev/null
+++ b/plugins-scripts/t/check_log.t
@@ -0,0 +1,82 @@
1#!/usr/bin/perl -w -I ..
2#
3# check_log tests
4#
5#
6
7use strict;
8use Test::More;
9use NPTest;
10
11my $tests = 18;
12plan tests => $tests;
13
14my $firstTimeOutput ='/^Log check data initialized/';
15my $okOutput = '/^Log check ok - 0 pattern matches found/';
16my $criticalOutput = '/^\(\d+\) < /';
17my $multilineOutput = '/\(3\) <.*\n.*\n.*$/';
18my $unknownOutput = '/^Usage: /';
19my $unknownArgOutput = '/^Unknown argument: /';
20my $bothRegexOutput = '/^Can not use extended and perl regex/';
21
22my $result;
23my $temp_file = "/tmp/check_log.tmp";
24my $oldlog = "/tmp/oldlog.tmp";
25
26open(FH, '>', $temp_file) or die $!;
27close(FH);
28
29$result = NPTest->testCmd("./check_log");
30cmp_ok( $result->return_code, '==', 3, "Missing parameters" );
31like ( $result->output, $unknownOutput, "Output for unknown correct" );
32
33$result = NPTest->testCmd("./check_log -f");
34cmp_ok( $result->return_code, '==', 3, "Wrong parameters" );
35like ( $result->output, $unknownArgOutput, "Output for unknown correct" );
36
37$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Simple match' -e -p");
38cmp_ok( $result->return_code, '==', 3, "Both regex parameters" );
39like ( $result->output, $bothRegexOutput, "Output for unknown correct" );
40
41$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Simple match'");
42cmp_ok( $result->return_code, '==', 0, "First time executing" );
43like ( $result->output, $firstTimeOutput, "Output for first time executing correct" );
44
45open(FH, '>>', $temp_file) or die $!;
46print FH "This is some text, that should not match\n";
47close(FH);
48
49$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'No match'");
50cmp_ok( $result->return_code, '==', 0, "No match" );
51like ( $result->output, $okOutput, "Output for no match correct" );
52
53open(FH, '>>', $temp_file) or die $!;
54print FH "This text should match\n";
55close(FH);
56
57$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'should match'");
58cmp_ok( $result->return_code, '==', 2, "Pattern match" );
59like ( $result->output, $criticalOutput, "Output for match correct" );
60
61open(FH, '>>', $temp_file) or die $!;
62print FH "This text should not match, because it is excluded\n";
63close(FH);
64
65$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'match' --exclude 'because'");
66cmp_ok( $result->return_code, '==', 0, "Exclude a pattern" );
67like ( $result->output, $okOutput, "Output for no match correct" );
68
69open(FH, '>>', $temp_file) or die $!;
70print FH "Trying\nwith\nmultiline\nignore me\n";
71close(FH);
72
73$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Trying\\|with\\|multiline\\|ignore' --exclude 'me' --all");
74cmp_ok( $result->return_code, '==', 2, "Multiline pattern match with --all" );
75like ( $result->output, $multilineOutput, "Output for multiline match correct" );
76
77$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'match' -a");
78cmp_ok( $result->return_code, '==', 0, "Non matching --all" );
79like ( $result->output, $okOutput, "Output for no match correct" );
80
81unlink($oldlog);
82unlink($temp_file);
diff --git a/plugins-scripts/t/check_uptime.t b/plugins-scripts/t/check_uptime.t
index c395307c..6e81db3c 100644
--- a/plugins-scripts/t/check_uptime.t
+++ b/plugins-scripts/t/check_uptime.t
@@ -5,7 +5,7 @@
5# 5#
6 6
7use strict; 7use strict;
8use Test::More tests => 40; 8use Test::More tests => 42;
9use NPTest; 9use NPTest;
10 10
11my $result; 11my $result;
@@ -46,29 +46,35 @@ cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
46like ( $result->output, '/Running since \d+/', "Output for the s parameter correct" ); 46like ( $result->output, '/Running since \d+/', "Output for the s parameter correct" );
47 47
48$result = NPTest->testCmd( 48$result = NPTest->testCmd(
49 "./check_uptime -d -w 1 -c 2"
50 );
51cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" );
52like ( $result->output, '/CRITICAL: Uptime is \d+ days/', "Output for the d parameter correct" );
53
54$result = NPTest->testCmd(
49 "./check_uptime -w 1 -c 2" 55 "./check_uptime -w 1 -c 2"
50 ); 56 );
51cmp_ok( $result->return_code, '==', 2, "Uptime higher than 2 seconds" ); 57cmp_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" ); 58like ( $result->output, '/^CRITICAL: Uptime is \d+ seconds/', "Output for uptime higher than 2 seconds correct" );
53 59
54$result = NPTest->testCmd( 60$result = NPTest->testCmd(
55 "./check_uptime -w 1 -c 9999w" 61 "./check_uptime -w 1 -c 9999w"
56 ); 62 );
57cmp_ok( $result->return_code, '==', 1, "Uptime lower than 9999 weeks" ); 63cmp_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" ); 64like ( $result->output, '/^WARNING: Uptime is \d+ seconds/', "Output for uptime lower than 9999 weeks correct" );
59 65
60$result = NPTest->testCmd( 66$result = NPTest->testCmd(
61 "./check_uptime -w 9998w -c 9999w" 67 "./check_uptime -w 9998w -c 9999w"
62 ); 68 );
63cmp_ok( $result->return_code, '==', 0, "Uptime lower than 9998 weeks" ); 69cmp_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" ); 70like ( $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" ); 71like ( $result->output, '/\|uptime=[0-9]+s;6046790400;6047395200;/', "Checking for performance output" );
66 72
67$result = NPTest->testCmd( 73$result = NPTest->testCmd(
68 "./check_uptime -w 111222d -c 222333d" 74 "./check_uptime -w 111222d -c 222333d"
69 ); 75 );
70cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days" ); 76cmp_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" ); 77like ( $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" ); 78like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" );
73 79
74# Same as before, hopefully uptime is higher than 2 seconds so no warning 80# Same as before, hopefully uptime is higher than 2 seconds so no warning
@@ -76,7 +82,7 @@ $result = NPTest->testCmd(
76 "./check_uptime -w 2:111222d -c 1:222333d" 82 "./check_uptime -w 2:111222d -c 1:222333d"
77 ); 83 );
78cmp_ok( $result->return_code, '==', 0, "Uptime lower than 111222 days, and higher 2 seconds" ); 84cmp_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" ); 85like ( $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" ); 86like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" );
81 87
82# Same as before, now the low warning should trigger 88# Same as before, now the low warning should trigger
@@ -84,7 +90,7 @@ $result = NPTest->testCmd(
84 "./check_uptime -w 111221d:111222d -c 1:222333d" 90 "./check_uptime -w 111221d:111222d -c 1:222333d"
85 ); 91 );
86cmp_ok( $result->return_code, '==', 1, "Uptime lower than 111221 days raises warning" ); 92cmp_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" ); 93like ( $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" ); 94like ( $result->output, '/Exceeds lower warn threshold/', "Exceeds text correct" );
89like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); 95like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" );
90 96
@@ -93,7 +99,7 @@ $result = NPTest->testCmd(
93 "./check_uptime -w 111221d:111222d -c 111220d:222333d" 99 "./check_uptime -w 111221d:111222d -c 111220d:222333d"
94 ); 100 );
95cmp_ok( $result->return_code, '==', 2, "Uptime lower than 111220 days raises critical" ); 101cmp_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" ); 102like ( $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" ); 103like ( $result->output, '/Exceeds lower crit threshold/', "Exceeds text correct" );
98like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" ); 104like ( $result->output, '/\|uptime=[0-9]+s;9609580800;19209571200;/', "Checking for performance output" );
99 105