summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--NEWS23
-rw-r--r--THANKS.in5
-rw-r--r--configure.in9
-rw-r--r--contrib/check_linux_raid.pl20
-rw-r--r--contrib/check_nmap.py7
-rw-r--r--gl/Makefile.am8
-rw-r--r--gl/fsusage.c13
-rw-r--r--gl/m4/fcntl-o.m48
-rw-r--r--gl/m4/fsusage.m428
-rw-r--r--gl/m4/gnulib-comp.m42
-rw-r--r--gl/m4/lib-link.m44
-rw-r--r--gl/m4/malloc.m431
-rw-r--r--gl/m4/stdlib_h.m412
-rw-r--r--gl/stdlib.in.h29
-rw-r--r--gl/str-two-way.h59
-rw-r--r--gl/string.in.h38
-rw-r--r--lib/tests/test_utils.c14
-rwxr-xr-xplugins-scripts/check_sensors.sh33
-rw-r--r--plugins/check_apt.c10
-rw-r--r--plugins/check_fping.c78
-rw-r--r--plugins/check_http.c148
-rw-r--r--plugins/check_mysql.c154
-rw-r--r--plugins/check_nt.c16
-rw-r--r--plugins/check_ntp_peer.c32
-rw-r--r--plugins/check_pgsql.c236
-rw-r--r--plugins/check_procs.c76
-rw-r--r--plugins/check_smtp.c26
-rw-r--r--plugins/check_snmp.c41
-rw-r--r--plugins/t/check_apt.t4
-rw-r--r--plugins/t/check_http.t32
-rw-r--r--plugins/t/check_procs.t6
-rwxr-xr-xplugins/tests/check_http.t13
33 files changed, 973 insertions, 243 deletions
diff --git a/.gitignore b/.gitignore
index bda7b276..4dca502c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -191,6 +191,7 @@ NP-VERSION-FILE
191/plugins/.libs 191/plugins/.libs
192/plugins/Makefile 192/plugins/Makefile
193/plugins/Makefile.in 193/plugins/Makefile.in
194/plugins/libnpcommon.a
194/plugins/negate 195/plugins/negate
195/plugins/stamp-h* 196/plugins/stamp-h*
196/plugins/urlize 197/plugins/urlize
diff --git a/NEWS b/NEWS
index 3285b3d5..d916283f 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ This file documents the major additions and syntax changes between releases.
4 ENHANCEMENTS 4 ENHANCEMENTS
5 New check_dbi plugin for checking an (SQL) database using DBI 5 New check_dbi plugin for checking an (SQL) database using DBI
6 Let OpenSSL load its configuration file (see the OPENSSL_config(3) man page) 6 Let OpenSSL load its configuration file (see the OPENSSL_config(3) man page)
7 Add performance data to check_apt
7 Add performance data to check_procs 8 Add performance data to check_procs
8 Added -4/-6 options to check_dig (Ville Mattila) 9 Added -4/-6 options to check_dig (Ville Mattila)
9 New check_oracle --connect option to perform real login 10 New check_oracle --connect option to perform real login
@@ -11,6 +12,22 @@ This file documents the major additions and syntax changes between releases.
11 New check_disk -N/--include-type option to limit the filesystem types to check 12 New check_disk -N/--include-type option to limit the filesystem types to check
12 Allow for building the plugins in parallel 13 Allow for building the plugins in parallel
13 Add --without-{dbi,ldap,radius} options to ./configure 14 Add --without-{dbi,ldap,radius} options to ./configure
15 Made Verbose output of check_sensors compliant (Gabriele Tozzi)
16 New switch -E/--extended-perfdata for check_http to print additional performance data (Sebastian Nohn)
17 New check_http -d option to specify a string to expect within the response headers
18 Add support for executing queries to check_pgsql
19 Let check_pgsql accept a UNIX socket directory as hostname
20 New check_pgsql -o option to specify additional connection parameters
21 New check_fping -S option to specify the source IP address
22 New check_fping -I option to specify the interface to bind to
23 Let check_fping support IPv6
24 New check_procs -k option to ignore kernel threads (on Linux)
25 Let check_procs use /proc/<PID>/exe (if available) instead of getpid(2), unless -T is specified
26 Let check_mysql support SSL
27 Let check_mysql add perfromance metrics for all checks
28 New check_mysql -f option to specify a client options file
29 New check_mysql -g option to specify a client options group
30 New check_snmp --offset option to allow for adding/substracting an offset value to sensor data
14 31
15 FIXES 32 FIXES
16 Change the MAIL FROM command generated by check_smtp to be RFC compliant 33 Change the MAIL FROM command generated by check_smtp to be RFC compliant
@@ -18,6 +35,12 @@ This file documents the major additions and syntax changes between releases.
18 Fix check_snmp reversed threshold ranges (backward-compatibility) 35 Fix check_snmp reversed threshold ranges (backward-compatibility)
19 Fix check_snmp memory violation when using more than 8 oids (Robin Sonefors) 36 Fix check_snmp memory violation when using more than 8 oids (Robin Sonefors)
20 Fix check_apt security regular expression (Alex Bradley) 37 Fix check_apt security regular expression (Alex Bradley)
38 Fix check_http handling extra header (-k) containing semicolons (Richard Leitner)
39 Fix check_apt handling unknown exit codes from apt-get (Richard Leitner)
40 Fix deprecated imports of check_nmap.py (Fabio Rueda)
41
42 WARNINGS
43 check_http behaviour of -k/--header changed since it does not seperate multiple headers by semicolons anymore. Use multiple -k switches instead.
21 44
221.4.16 27th June 2012 451.4.16 27th June 2012
23 ENHANCEMENTS 46 ENHANCEMENTS
diff --git a/THANKS.in b/THANKS.in
index fdebd656..54315afa 100644
--- a/THANKS.in
+++ b/THANKS.in
@@ -280,3 +280,8 @@ Alex Bradley
280Brian De Wolf 280Brian De Wolf
281Richard Leitner 281Richard Leitner
282Diego Elio Pettenò 282Diego Elio Pettenò
283Vaclav Ovsik
284Roman Fiedler
285Fabio Rueda
286Gabriele Tozzi
287Sebastian Nohn
diff --git a/configure.in b/configure.in
index 25c0c9cd..43fe4ade 100644
--- a/configure.in
+++ b/configure.in
@@ -1378,13 +1378,22 @@ then
1378fi 1378fi
1379 1379
1380AC_PATH_PROG(PATH_TO_FPING,fping) 1380AC_PATH_PROG(PATH_TO_FPING,fping)
1381AC_PATH_PROG(PATH_TO_FPING6,fping6)
1382
1381AC_ARG_WITH(fping_command, 1383AC_ARG_WITH(fping_command,
1382 ACX_HELP_STRING([--with-fping-command=PATH], 1384 ACX_HELP_STRING([--with-fping-command=PATH],
1383 [Path to fping command]), PATH_TO_FPING=$withval) 1385 [Path to fping command]), PATH_TO_FPING=$withval)
1386AC_ARG_WITH(fping6_command,
1387 ACX_HELP_STRING([--with-fping6-command=PATH],
1388 [Path to fping6 command]), PATH_TO_FPING6=$withval)
1389
1384if test -n "$PATH_TO_FPING" 1390if test -n "$PATH_TO_FPING"
1385then 1391then
1386 AC_DEFINE_UNQUOTED(PATH_TO_FPING,"$PATH_TO_FPING",[path to fping]) 1392 AC_DEFINE_UNQUOTED(PATH_TO_FPING,"$PATH_TO_FPING",[path to fping])
1387 EXTRAS="$EXTRAS check_fping" 1393 EXTRAS="$EXTRAS check_fping"
1394 if test x"$with_ipv6" != xno && test -n "$PATH_TO_FPING6"; then
1395 AC_DEFINE_UNQUOTED(PATH_TO_FPING6,"$PATH_TO_FPING6",[path to fping6])
1396 fi
1388else 1397else
1389 AC_MSG_WARN([Get fping from http://www.fping.com in order to make check_fping plugin]) 1398 AC_MSG_WARN([Get fping from http://www.fping.com in order to make check_fping plugin])
1390fi 1399fi
diff --git a/contrib/check_linux_raid.pl b/contrib/check_linux_raid.pl
index c24b0cd2..6650a42b 100644
--- a/contrib/check_linux_raid.pl
+++ b/contrib/check_linux_raid.pl
@@ -28,8 +28,8 @@ use utils qw(%ERRORS);
28 28
29# die with an error if we're not on Linux 29# die with an error if we're not on Linux
30if ($^O ne 'linux') { 30if ($^O ne 'linux') {
31 print "This plugin only applicable on Linux.\n"; 31 print "This plugin only applicable on Linux.\n";
32 exit $ERRORS{'UNKNOWN'}; 32 exit $ERRORS{'UNKNOWN'};
33} 33}
34 34
35sub max_state($$){ 35sub max_state($$){
@@ -50,6 +50,7 @@ my $code = "UNKNOWN";
50my $msg = ""; 50my $msg = "";
51my %status; 51my %status;
52my %recovery; 52my %recovery;
53my %resyncing;
53my %finish; 54my %finish;
54my %active; 55my %active;
55my %devices; 56my %devices;
@@ -65,6 +66,10 @@ while(defined $nextdev){
65 $recovery{$device} = $1; 66 $recovery{$device} = $1;
66 ($finish{$device}) = /finish=(.*?min)/; 67 ($finish{$device}) = /finish=(.*?min)/;
67 $device=undef; 68 $device=undef;
69 } elsif (/resync =\s+(.*?)\s/) {
70 $resyncing{$device} = $1;
71 ($finish{$device}) = /finish=(.*?min)/;
72 $device=undef;
68 } elsif (/^\s*$/) { 73 } elsif (/^\s*$/) {
69 $device=undef; 74 $device=undef;
70 } 75 }
@@ -95,8 +100,14 @@ foreach my $k (sort keys %devices){
95 $code = max_state($code, "CRITICAL"); 100 $code = max_state($code, "CRITICAL");
96 } 101 }
97 } elsif ($status{$k} =~ /U+/) { 102 } elsif ($status{$k} =~ /U+/) {
98 $msg .= sprintf " %s status=%s.", $devices{$k}, $status{$k}; 103 if (defined $resyncing{$k}) {
99 $code = max_state($code, "OK"); 104 $msg .= sprintf " %s status=%s, resync=%s, finish=%s.",
105 $devices{$k}, $status{$k}, $resyncing{$k}, $finish{$k};
106 $code = max_state($code, "WARNING");
107 } else {
108 $msg .= sprintf " %s status=%s.", $devices{$k}, $status{$k};
109 $code = max_state($code, "OK");
110 }
100 } else { 111 } else {
101 if ($active{$k}) { 112 if ($active{$k}) {
102 $msg .= sprintf " %s active with no status information.", 113 $msg .= sprintf " %s active with no status information.",
@@ -112,4 +123,3 @@ foreach my $k (sort keys %devices){
112 123
113print $code, $msg, "\n"; 124print $code, $msg, "\n";
114exit ($ERRORS{$code}); 125exit ($ERRORS{$code});
115
diff --git a/contrib/check_nmap.py b/contrib/check_nmap.py
index 07f6d7fa..481a62bf 100644
--- a/contrib/check_nmap.py
+++ b/contrib/check_nmap.py
@@ -43,7 +43,7 @@ _version_ = '1.21'
43# 0.20 2000-07-10 jaclu Initial release 43# 0.20 2000-07-10 jaclu Initial release
44 44
45 45
46import sys, os, string, whrandom 46import sys, os, string, random
47 47
48import tempfile 48import tempfile
49from getopt import getopt 49from getopt import getopt
@@ -207,8 +207,7 @@ class CheckNmap:
207 # _if_ two processes in deed get the same tmp-file 207 # _if_ two processes in deed get the same tmp-file
208 # the only result is a normal error message to nagios 208 # the only result is a normal error message to nagios
209 # 209 #
210 r=whrandom.whrandom() 210 self.tmp_file=tempfile.mktemp('.%s') % random.randint(0,100000)
211 self.tmp_file=tempfile.mktemp('.%s')%r.randint(0,100000)
212 if self.debug: 211 if self.debug:
213 print 'Tmpfile is: %s'%self.tmp_file 212 print 'Tmpfile is: %s'%self.tmp_file
214 # 213 #
@@ -388,7 +387,7 @@ Version: %s""" % _version_
388 387
389def doc_syntax(): 388def doc_syntax():
390 print """ 389 print """
391Usage: check_ports [-v|--debug] [-H|--host host] [-V|--version] [-h|--help] 390Usage: check_nmap.py [-v|--debug] [-H|--host host] [-V|--version] [-h|--help]
392 [-o|--optional port1,port2,port3 ...] [-r|--range range] 391 [-o|--optional port1,port2,port3 ...] [-r|--range range]
393 [-p|--port port1,port2,port3 ...] [-t|--timeout timeout]""" 392 [-p|--port port1,port2,port3 ...] [-t|--timeout timeout]"""
394 393
diff --git a/gl/Makefile.am b/gl/Makefile.am
index e9e23026..edc7db15 100644
--- a/gl/Makefile.am
+++ b/gl/Makefile.am
@@ -1182,6 +1182,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1182 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 1182 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1183 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1183 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1184 -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \ 1184 -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \
1185 -e 's|@''GNULIB__EXIT''@|$(GNULIB__EXIT)|g' \
1185 -e 's|@''GNULIB_ATOLL''@|$(GNULIB_ATOLL)|g' \ 1186 -e 's|@''GNULIB_ATOLL''@|$(GNULIB_ATOLL)|g' \
1186 -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \ 1187 -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \
1187 -e 's|@''GNULIB_CANONICALIZE_FILE_NAME''@|$(GNULIB_CANONICALIZE_FILE_NAME)|g' \ 1188 -e 's|@''GNULIB_CANONICALIZE_FILE_NAME''@|$(GNULIB_CANONICALIZE_FILE_NAME)|g' \
@@ -1206,13 +1207,12 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1206 -e 's|@''GNULIB_STRTOULL''@|$(GNULIB_STRTOULL)|g' \ 1207 -e 's|@''GNULIB_STRTOULL''@|$(GNULIB_STRTOULL)|g' \
1207 -e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \ 1208 -e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \
1208 -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \ 1209 -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \
1210 -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \
1209 -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \ 1211 -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
1210 -e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \
1211 -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \ 1212 -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \
1212 -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \ 1213 -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \
1213 -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \ 1214 -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
1214 -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \ 1215 -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \
1215 -e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \
1216 -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \ 1216 -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
1217 -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \ 1217 -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \
1218 -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \ 1218 -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \
@@ -1221,7 +1221,6 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1221 -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \ 1221 -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \
1222 -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \ 1222 -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \
1223 -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \ 1223 -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \
1224 -e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \
1225 -e 's|@''HAVE_REALPATH''@|$(HAVE_REALPATH)|g' \ 1224 -e 's|@''HAVE_REALPATH''@|$(HAVE_REALPATH)|g' \
1226 -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \ 1225 -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \
1227 -e 's|@''HAVE_SETENV''@|$(HAVE_SETENV)|g' \ 1226 -e 's|@''HAVE_SETENV''@|$(HAVE_SETENV)|g' \
@@ -1232,9 +1231,12 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1232 -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \ 1231 -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \
1233 -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \ 1232 -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \
1234 -e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \ 1233 -e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \
1234 -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \
1235 -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \ 1235 -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \
1236 -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
1236 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ 1237 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
1237 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \ 1238 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
1239 -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \
1238 -e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \ 1240 -e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \
1239 -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \ 1241 -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \
1240 -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \ 1242 -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \
diff --git a/gl/fsusage.c b/gl/fsusage.c
index 10db467d..17102aad 100644
--- a/gl/fsusage.c
+++ b/gl/fsusage.c
@@ -94,7 +94,7 @@
94int 94int
95get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) 95get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
96{ 96{
97#if defined STAT_STATVFS /* POSIX */ 97#if defined STAT_STATVFS /* POSIX, except glibc/Linux */
98 98
99 struct statvfs fsd; 99 struct statvfs fsd;
100 100
@@ -156,7 +156,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
156 : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1)); 156 : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1));
157 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode); 157 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode);
158 158
159#elif defined STAT_STATFS3_OSF1 159#elif defined STAT_STATFS3_OSF1 /* OSF/1 */
160 160
161 struct statfs fsd; 161 struct statfs fsd;
162 162
@@ -165,7 +165,9 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
165 165
166 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); 166 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize);
167 167
168#elif defined STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */ 168#elif defined STAT_STATFS2_BSIZE /* glibc/Linux, 4.3BSD, SunOS 4, \
169 MacOS X < 10.4, FreeBSD < 5.0, \
170 NetBSD < 3.0, OpenBSD < 4.4 */
169 171
170 struct statfs fsd; 172 struct statfs fsd;
171 173
@@ -189,7 +191,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
189 } 191 }
190# endif /* STATFS_TRUNCATES_BLOCK_COUNTS */ 192# endif /* STATFS_TRUNCATES_BLOCK_COUNTS */
191 193
192#elif defined STAT_STATFS2_FSIZE /* 4.4BSD */ 194#elif defined STAT_STATFS2_FSIZE /* 4.4BSD and older NetBSD */
193 195
194 struct statfs fsd; 196 struct statfs fsd;
195 197
@@ -198,7 +200,8 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
198 200
199 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); 201 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize);
200 202
201#elif defined STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */ 203#elif defined STAT_STATFS4 /* SVR3, Dynix, old Irix, old AIX, \
204 Dolphin */
202 205
203# if !_AIX && !defined _SEQUENT_ && !defined DOLPHIN 206# if !_AIX && !defined _SEQUENT_ && !defined DOLPHIN
204# define f_bavail f_bfree 207# define f_bavail f_bfree
diff --git a/gl/m4/fcntl-o.m4 b/gl/m4/fcntl-o.m4
index d416a61c..1adacc8a 100644
--- a/gl/m4/fcntl-o.m4
+++ b/gl/m4/fcntl-o.m4
@@ -1,4 +1,4 @@
1# fcntl-o.m4 serial 1 1# fcntl-o.m4 serial 2
2dnl Copyright (C) 2006, 2009-2010 Free Software Foundation, Inc. 2dnl Copyright (C) 2006, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
@@ -12,7 +12,11 @@ dnl Written by Paul Eggert.
12AC_DEFUN([gl_FCNTL_O_FLAGS], 12AC_DEFUN([gl_FCNTL_O_FLAGS],
13[ 13[
14 dnl Persuade glibc <fcntl.h> to define O_NOATIME and O_NOFOLLOW. 14 dnl Persuade glibc <fcntl.h> to define O_NOATIME and O_NOFOLLOW.
15 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) 15 dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes
16 dnl AC_GNU_SOURCE.
17 m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],
18 [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])],
19 [AC_REQUIRE([AC_GNU_SOURCE])])
16 AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h], 20 AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h],
17 [AC_RUN_IFELSE( 21 [AC_RUN_IFELSE(
18 [AC_LANG_PROGRAM( 22 [AC_LANG_PROGRAM(
diff --git a/gl/m4/fsusage.m4 b/gl/m4/fsusage.m4
index 216b9dd8..68684c27 100644
--- a/gl/m4/fsusage.m4
+++ b/gl/m4/fsusage.m4
@@ -1,4 +1,4 @@
1# serial 25 1# serial 26
2# Obtaining file system usage information. 2# Obtaining file system usage information.
3 3
4# Copyright (C) 1997-1998, 2000-2001, 2003-2010 Free Software Foundation, Inc. 4# Copyright (C) 1997-1998, 2000-2001, 2003-2010 Free Software Foundation, Inc.
@@ -44,7 +44,8 @@ ac_fsusage_space=no
44# systems. That system is reported to work fine with STAT_STATFS4 which 44# systems. That system is reported to work fine with STAT_STATFS4 which
45# is what it gets when this test fails. 45# is what it gets when this test fails.
46if test $ac_fsusage_space = no; then 46if test $ac_fsusage_space = no; then
47 # SVR4 47 # glibc/{Hurd,kFreeBSD}, MacOS X >= 10.4, FreeBSD >= 5.0, NetBSD >= 3.0,
48 # OpenBSD >= 4.4, AIX, HP-UX, IRIX, Solaris, Cygwin, Interix, BeOS.
48 AC_CACHE_CHECK([for statvfs function (SVR4)], [fu_cv_sys_stat_statvfs], 49 AC_CACHE_CHECK([for statvfs function (SVR4)], [fu_cv_sys_stat_statvfs],
49 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h> 50 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
50#if defined __GLIBC__ && defined __linux__ 51#if defined __GLIBC__ && defined __linux__
@@ -97,8 +98,13 @@ if test $ac_fsusage_space = no; then
97fi 98fi
98 99
99if test $ac_fsusage_space = no; then 100if test $ac_fsusage_space = no; then
100# AIX 101 # glibc/Linux, MacOS X < 10.4, FreeBSD < 5.0, NetBSD < 3.0, OpenBSD < 4.4.
101 AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl 102 # (glibc/{Hurd,kFreeBSD}, MacOS X >= 10.4, FreeBSD >= 5.0, NetBSD >= 3.0,
103 # OpenBSD >= 4.4, AIX, HP-UX, OSF/1, Cygwin already handled above.)
104 # (On IRIX you need to include <sys/statfs.h>, not only <sys/mount.h> and
105 # <sys/vfs.h>.)
106 # (On Solaris, statfs has 4 arguments.)
107 AC_MSG_CHECKING([for two-argument statfs with statfs.f_bsize dnl
102member (AIX, 4.3BSD)]) 108member (AIX, 4.3BSD)])
103 AC_CACHE_VAL([fu_cv_sys_stat_statfs2_bsize], 109 AC_CACHE_VAL([fu_cv_sys_stat_statfs2_bsize],
104 [AC_RUN_IFELSE([AC_LANG_SOURCE([[ 110 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
@@ -131,7 +137,8 @@ member (AIX, 4.3BSD)])
131fi 137fi
132 138
133if test $ac_fsusage_space = no; then 139if test $ac_fsusage_space = no; then
134# SVR3 140 # SVR3
141 # (Solaris already handled above.)
135 AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)]) 142 AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
136 AC_CACHE_VAL([fu_cv_sys_stat_statfs4], 143 AC_CACHE_VAL([fu_cv_sys_stat_statfs4],
137 [AC_RUN_IFELSE([AC_LANG_SOURCE([[ 144 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
@@ -150,13 +157,17 @@ if test $ac_fsusage_space = no; then
150 if test $fu_cv_sys_stat_statfs4 = yes; then 157 if test $fu_cv_sys_stat_statfs4 = yes; then
151 ac_fsusage_space=yes 158 ac_fsusage_space=yes
152 AC_DEFINE([STAT_STATFS4], [1], 159 AC_DEFINE([STAT_STATFS4], [1],
153 [ Define if statfs takes 4 args. (SVR3, Dynix, Irix, Dolphin)]) 160 [ Define if statfs takes 4 args. (SVR3, Dynix, old Irix, old AIX, Dolphin)])
154 fi 161 fi
155fi 162fi
156 163
157if test $ac_fsusage_space = no; then 164if test $ac_fsusage_space = no; then
158# 4.4BSD and NetBSD 165 # 4.4BSD and older NetBSD
159 AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl 166 # (OSF/1 already handled above.)
167 # (On AIX, you need to include <sys/statfs.h>, not only <sys/mount.h>.)
168 # (On Solaris, statfs has 4 arguments and 'struct statfs' is not declared in
169 # <sys/mount.h>.)
170 AC_MSG_CHECKING([for two-argument statfs with statfs.f_fsize dnl
160member (4.4BSD and NetBSD)]) 171member (4.4BSD and NetBSD)])
161 AC_CACHE_VAL([fu_cv_sys_stat_statfs2_fsize], 172 AC_CACHE_VAL([fu_cv_sys_stat_statfs2_fsize],
162 [AC_RUN_IFELSE([AC_LANG_SOURCE([[ 173 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
@@ -223,6 +234,7 @@ fi
223 234
224if test $ac_fsusage_space = no; then 235if test $ac_fsusage_space = no; then
225 # SVR2 236 # SVR2
237 # (AIX, HP-UX, OSF/1 already handled above.)
226 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <sys/filsys.h> 238 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <sys/filsys.h>
227 ]])], 239 ]])],
228 [AC_DEFINE([STAT_READ_FILSYS], [1], 240 [AC_DEFINE([STAT_READ_FILSYS], [1],
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4
index fc3f3538..b5e6b438 100644
--- a/gl/m4/gnulib-comp.m4
+++ b/gl/m4/gnulib-comp.m4
@@ -254,7 +254,7 @@ AC_DEFUN([gl_INIT],
254 # Code from module locale: 254 # Code from module locale:
255 gl_LOCALE_H 255 gl_LOCALE_H
256 # Code from module malloc: 256 # Code from module malloc:
257 AC_FUNC_MALLOC 257 gl_FUNC_MALLOC_GNU
258 AC_DEFINE([GNULIB_MALLOC_GNU], 1, [Define to indicate the 'malloc' module.]) 258 AC_DEFINE([GNULIB_MALLOC_GNU], 1, [Define to indicate the 'malloc' module.])
259 # Code from module malloc-posix: 259 # Code from module malloc-posix:
260 gl_FUNC_MALLOC_POSIX 260 gl_FUNC_MALLOC_POSIX
diff --git a/gl/m4/lib-link.m4 b/gl/m4/lib-link.m4
index 59b367df..9f3be3a2 100644
--- a/gl/m4/lib-link.m4
+++ b/gl/m4/lib-link.m4
@@ -1,4 +1,4 @@
1# lib-link.m4 serial 23 (gettext-0.18.2) 1# lib-link.m4 serial 24 (gettext-0.18.2)
2dnl Copyright (C) 2001-2010 Free Software Foundation, Inc. 2dnl Copyright (C) 2001-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
@@ -165,7 +165,7 @@ AC_DEFUN([AC_LIB_FROMPACKAGE],
165 pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-], 165 pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-],
166 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) 166 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
167 define([acl_libsinpackage_]PACKUP, 167 define([acl_libsinpackage_]PACKUP,
168 m4_ifdef([acl_libsinpackage_]PACKUP, [acl_libsinpackage_]PACKUP[[, ]],)[lib$1]) 168 m4_ifdef([acl_libsinpackage_]PACKUP, [m4_defn([acl_libsinpackage_]PACKUP)[, ]],)[lib$1])
169 popdef([PACKUP]) 169 popdef([PACKUP])
170 popdef([PACK]) 170 popdef([PACK])
171]) 171])
diff --git a/gl/m4/malloc.m4 b/gl/m4/malloc.m4
index 910ac922..fe5befc2 100644
--- a/gl/m4/malloc.m4
+++ b/gl/m4/malloc.m4
@@ -1,25 +1,40 @@
1# malloc.m4 serial 9 1# malloc.m4 serial 10
2dnl Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. 2dnl Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
6 6
7# gl_FUNC_MALLOC_GNU
8# ------------------
9# Test whether 'malloc (0)' is handled like in GNU libc, and replace malloc if
10# it is not.
11AC_DEFUN([gl_FUNC_MALLOC_GNU],
12[
13 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
14 dnl _AC_FUNC_MALLOC_IF is defined in Autoconf.
15 _AC_FUNC_MALLOC_IF(
16 [AC_DEFINE([HAVE_MALLOC], [1],
17 [Define to 1 if your system has a GNU libc compatible 'malloc'
18 function, and to 0 otherwise.])],
19 [AC_DEFINE([HAVE_MALLOC], [0])
20 gl_REPLACE_MALLOC
21 ])
22])
23
7# gl_FUNC_MALLOC_POSIX 24# gl_FUNC_MALLOC_POSIX
8# -------------------- 25# --------------------
9# Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it 26# Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it
10# fails), and replace malloc if it is not. 27# fails), and replace malloc if it is not.
11AC_DEFUN([gl_FUNC_MALLOC_POSIX], 28AC_DEFUN([gl_FUNC_MALLOC_POSIX],
12[ 29[
30 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
13 AC_REQUIRE([gl_CHECK_MALLOC_POSIX]) 31 AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
14 if test $gl_cv_func_malloc_posix = yes; then 32 if test $gl_cv_func_malloc_posix = yes; then
15 HAVE_MALLOC_POSIX=1
16 AC_DEFINE([HAVE_MALLOC_POSIX], [1], 33 AC_DEFINE([HAVE_MALLOC_POSIX], [1],
17 [Define if the 'malloc' function is POSIX compliant.]) 34 [Define if the 'malloc' function is POSIX compliant.])
18 else 35 else
19 AC_LIBOBJ([malloc]) 36 gl_REPLACE_MALLOC
20 HAVE_MALLOC_POSIX=0
21 fi 37 fi
22 AC_SUBST([HAVE_MALLOC_POSIX])
23]) 38])
24 39
25# Test whether malloc, realloc, calloc are POSIX compliant, 40# Test whether malloc, realloc, calloc are POSIX compliant,
@@ -39,3 +54,9 @@ AC_DEFUN([gl_CHECK_MALLOC_POSIX],
39 ], [gl_cv_func_malloc_posix=yes], [gl_cv_func_malloc_posix=no]) 54 ], [gl_cv_func_malloc_posix=yes], [gl_cv_func_malloc_posix=no])
40 ]) 55 ])
41]) 56])
57
58AC_DEFUN([gl_REPLACE_MALLOC],
59[
60 AC_LIBOBJ([malloc])
61 REPLACE_MALLOC=1
62])
diff --git a/gl/m4/stdlib_h.m4 b/gl/m4/stdlib_h.m4
index dd84796d..fc150197 100644
--- a/gl/m4/stdlib_h.m4
+++ b/gl/m4/stdlib_h.m4
@@ -1,4 +1,4 @@
1# stdlib_h.m4 serial 28 1# stdlib_h.m4 serial 30
2dnl Copyright (C) 2007-2010 Free Software Foundation, Inc. 2dnl Copyright (C) 2007-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
@@ -33,7 +33,7 @@ AC_DEFUN([gl_STDLIB_H],
33#if HAVE_RANDOM_H 33#if HAVE_RANDOM_H
34# include <random.h> 34# include <random.h>
35#endif 35#endif
36 ]], [atoll canonicalize_file_name getloadavg getsubopt grantpt mkdtemp 36 ]], [_Exit atoll canonicalize_file_name getloadavg getsubopt grantpt mkdtemp
37 mkostemp mkostemps mkstemp mkstemps ptsname random_r initstat_r srandom_r 37 mkostemp mkostemps mkstemp mkstemps ptsname random_r initstat_r srandom_r
38 setstate_r realpath rpmatch setenv strtod strtoll strtoull unlockpt 38 setstate_r realpath rpmatch setenv strtod strtoll strtoull unlockpt
39 unsetenv]) 39 unsetenv])
@@ -50,6 +50,7 @@ AC_DEFUN([gl_STDLIB_MODULE_INDICATOR],
50 50
51AC_DEFUN([gl_STDLIB_H_DEFAULTS], 51AC_DEFUN([gl_STDLIB_H_DEFAULTS],
52[ 52[
53 GNULIB__EXIT=0; AC_SUBST([GNULIB__EXIT])
53 GNULIB_ATOLL=0; AC_SUBST([GNULIB_ATOLL]) 54 GNULIB_ATOLL=0; AC_SUBST([GNULIB_ATOLL])
54 GNULIB_CALLOC_POSIX=0; AC_SUBST([GNULIB_CALLOC_POSIX]) 55 GNULIB_CALLOC_POSIX=0; AC_SUBST([GNULIB_CALLOC_POSIX])
55 GNULIB_CANONICALIZE_FILE_NAME=0; AC_SUBST([GNULIB_CANONICALIZE_FILE_NAME]) 56 GNULIB_CANONICALIZE_FILE_NAME=0; AC_SUBST([GNULIB_CANONICALIZE_FILE_NAME])
@@ -75,13 +76,12 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
75 GNULIB_UNLOCKPT=0; AC_SUBST([GNULIB_UNLOCKPT]) 76 GNULIB_UNLOCKPT=0; AC_SUBST([GNULIB_UNLOCKPT])
76 GNULIB_UNSETENV=0; AC_SUBST([GNULIB_UNSETENV]) 77 GNULIB_UNSETENV=0; AC_SUBST([GNULIB_UNSETENV])
77 dnl Assume proper GNU behavior unless another module says otherwise. 78 dnl Assume proper GNU behavior unless another module says otherwise.
79 HAVE__EXIT=1; AC_SUBST([HAVE__EXIT])
78 HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL]) 80 HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL])
79 HAVE_CALLOC_POSIX=1; AC_SUBST([HAVE_CALLOC_POSIX])
80 HAVE_CANONICALIZE_FILE_NAME=1; AC_SUBST([HAVE_CANONICALIZE_FILE_NAME]) 81 HAVE_CANONICALIZE_FILE_NAME=1; AC_SUBST([HAVE_CANONICALIZE_FILE_NAME])
81 HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG]) 82 HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG])
82 HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT]) 83 HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT])
83 HAVE_GRANTPT=1; AC_SUBST([HAVE_GRANTPT]) 84 HAVE_GRANTPT=1; AC_SUBST([HAVE_GRANTPT])
84 HAVE_MALLOC_POSIX=1; AC_SUBST([HAVE_MALLOC_POSIX])
85 HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP]) 85 HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP])
86 HAVE_MKOSTEMP=1; AC_SUBST([HAVE_MKOSTEMP]) 86 HAVE_MKOSTEMP=1; AC_SUBST([HAVE_MKOSTEMP])
87 HAVE_MKOSTEMPS=1; AC_SUBST([HAVE_MKOSTEMPS]) 87 HAVE_MKOSTEMPS=1; AC_SUBST([HAVE_MKOSTEMPS])
@@ -89,7 +89,6 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
89 HAVE_MKSTEMPS=1; AC_SUBST([HAVE_MKSTEMPS]) 89 HAVE_MKSTEMPS=1; AC_SUBST([HAVE_MKSTEMPS])
90 HAVE_PTSNAME=1; AC_SUBST([HAVE_PTSNAME]) 90 HAVE_PTSNAME=1; AC_SUBST([HAVE_PTSNAME])
91 HAVE_RANDOM_R=1; AC_SUBST([HAVE_RANDOM_R]) 91 HAVE_RANDOM_R=1; AC_SUBST([HAVE_RANDOM_R])
92 HAVE_REALLOC_POSIX=1; AC_SUBST([HAVE_REALLOC_POSIX])
93 HAVE_REALPATH=1; AC_SUBST([HAVE_REALPATH]) 92 HAVE_REALPATH=1; AC_SUBST([HAVE_REALPATH])
94 HAVE_RPMATCH=1; AC_SUBST([HAVE_RPMATCH]) 93 HAVE_RPMATCH=1; AC_SUBST([HAVE_RPMATCH])
95 HAVE_SETENV=1; AC_SUBST([HAVE_SETENV]) 94 HAVE_SETENV=1; AC_SUBST([HAVE_SETENV])
@@ -100,9 +99,12 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
100 HAVE_SYS_LOADAVG_H=0; AC_SUBST([HAVE_SYS_LOADAVG_H]) 99 HAVE_SYS_LOADAVG_H=0; AC_SUBST([HAVE_SYS_LOADAVG_H])
101 HAVE_UNLOCKPT=1; AC_SUBST([HAVE_UNLOCKPT]) 100 HAVE_UNLOCKPT=1; AC_SUBST([HAVE_UNLOCKPT])
102 HAVE_UNSETENV=1; AC_SUBST([HAVE_UNSETENV]) 101 HAVE_UNSETENV=1; AC_SUBST([HAVE_UNSETENV])
102 REPLACE_CALLOC=0; AC_SUBST([REPLACE_CALLOC])
103 REPLACE_CANONICALIZE_FILE_NAME=0; AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME]) 103 REPLACE_CANONICALIZE_FILE_NAME=0; AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME])
104 REPLACE_MALLOC=0; AC_SUBST([REPLACE_MALLOC])
104 REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP]) 105 REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP])
105 REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV]) 106 REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV])
107 REPLACE_REALLOC=0; AC_SUBST([REPLACE_REALLOC])
106 REPLACE_REALPATH=0; AC_SUBST([REPLACE_REALPATH]) 108 REPLACE_REALPATH=0; AC_SUBST([REPLACE_REALPATH])
107 REPLACE_SETENV=0; AC_SUBST([REPLACE_SETENV]) 109 REPLACE_SETENV=0; AC_SUBST([REPLACE_SETENV])
108 REPLACE_STRTOD=0; AC_SUBST([REPLACE_STRTOD]) 110 REPLACE_STRTOD=0; AC_SUBST([REPLACE_STRTOD])
diff --git a/gl/stdlib.in.h b/gl/stdlib.in.h
index d74c2518..d4ac4690 100644
--- a/gl/stdlib.in.h
+++ b/gl/stdlib.in.h
@@ -74,6 +74,12 @@ struct random_data
74# include <unistd.h> 74# include <unistd.h>
75#endif 75#endif
76 76
77#ifndef __attribute__
78# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
79# define __attribute__(Spec) /* empty */
80# endif
81#endif
82
77/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 83/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
78 84
79/* The definition of _GL_ARG_NONNULL is copied here. */ 85/* The definition of _GL_ARG_NONNULL is copied here. */
@@ -95,6 +101,23 @@ struct random_data
95#endif 101#endif
96 102
97 103
104#if @GNULIB__EXIT@
105/* Terminate the current process with the given return code, without running
106 the 'atexit' handlers. */
107# if !@HAVE__EXIT@
108_GL_FUNCDECL_SYS (_Exit, void, (int status) __attribute__ ((__noreturn__)));
109# endif
110_GL_CXXALIAS_SYS (_Exit, void, (int status));
111_GL_CXXALIASWARN (_Exit);
112#elif defined GNULIB_POSIXCHECK
113# undef _Exit
114# if HAVE_RAW_DECL__EXIT
115_GL_WARN_ON_USE (_Exit, "_Exit is unportable - "
116 "use gnulib module _Exit for portability");
117# endif
118#endif
119
120
98#if @GNULIB_ATOLL@ 121#if @GNULIB_ATOLL@
99/* Parse a signed decimal integer. 122/* Parse a signed decimal integer.
100 Returns the value of the integer. Errors are not detected. */ 123 Returns the value of the integer. Errors are not detected. */
@@ -112,7 +135,7 @@ _GL_WARN_ON_USE (atoll, "atoll is unportable - "
112#endif 135#endif
113 136
114#if @GNULIB_CALLOC_POSIX@ 137#if @GNULIB_CALLOC_POSIX@
115# if !@HAVE_CALLOC_POSIX@ 138# if @REPLACE_CALLOC@
116# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 139# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
117# undef calloc 140# undef calloc
118# define calloc rpl_calloc 141# define calloc rpl_calloc
@@ -218,7 +241,7 @@ _GL_WARN_ON_USE (ptsname, "grantpt is not portable - "
218#endif 241#endif
219 242
220#if @GNULIB_MALLOC_POSIX@ 243#if @GNULIB_MALLOC_POSIX@
221# if !@HAVE_MALLOC_POSIX@ 244# if @REPLACE_MALLOC@
222# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 245# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
223# undef malloc 246# undef malloc
224# define malloc rpl_malloc 247# define malloc rpl_malloc
@@ -477,7 +500,7 @@ _GL_WARN_ON_USE (setstate_r, "setstate_r is unportable - "
477 500
478 501
479#if @GNULIB_REALLOC_POSIX@ 502#if @GNULIB_REALLOC_POSIX@
480# if !@HAVE_REALLOC_POSIX@ 503# if @REPLACE_REALLOC@
481# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 504# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
482# undef realloc 505# undef realloc
483# define realloc rpl_realloc 506# define realloc rpl_realloc
diff --git a/gl/str-two-way.h b/gl/str-two-way.h
index c08f60ef..4d555f92 100644
--- a/gl/str-two-way.h
+++ b/gl/str-two-way.h
@@ -95,26 +95,37 @@
95 A critical factorization has the property that the local period 95 A critical factorization has the property that the local period
96 equals the global period. All strings have at least one critical 96 equals the global period. All strings have at least one critical
97 factorization with the left half smaller than the global period. 97 factorization with the left half smaller than the global period.
98 And while some strings have more than one critical factorization,
99 it is provable that with an ordered alphabet, at least one of the
100 critical factorizations corresponds to a maximal suffix.
98 101
99 Given an ordered alphabet, a critical factorization can be computed 102 Given an ordered alphabet, a critical factorization can be computed
100 in linear time, with 2 * NEEDLE_LEN comparisons, by computing the 103 in linear time, with 2 * NEEDLE_LEN comparisons, by computing the
101 larger of two ordered maximal suffixes. The ordered maximal 104 shorter of two ordered maximal suffixes. The ordered maximal
102 suffixes are determined by lexicographic comparison of 105 suffixes are determined by lexicographic comparison while tracking
103 periodicity. */ 106 periodicity. */
104static size_t 107static size_t
105critical_factorization (const unsigned char *needle, size_t needle_len, 108critical_factorization (const unsigned char *needle, size_t needle_len,
106 size_t *period) 109 size_t *period)
107{ 110{
108 /* Index of last byte of left half, or SIZE_MAX. */ 111 /* Index of last byte of left half. */
109 size_t max_suffix, max_suffix_rev; 112 size_t max_suffix, max_suffix_rev;
110 size_t j; /* Index into NEEDLE for current candidate suffix. */ 113 size_t j; /* Index into NEEDLE for current candidate suffix. */
111 size_t k; /* Offset into current period. */ 114 size_t k; /* Offset into current period. */
112 size_t p; /* Intermediate period. */ 115 size_t p; /* Intermediate period. */
113 unsigned char a, b; /* Current comparison bytes. */ 116 unsigned char a, b; /* Current comparison bytes. */
114 117
118 /* Special case NEEDLE_LEN of 1 or 2 (all callers already filtered
119 out 0-length needles. */
120 if (needle_len < 3)
121 {
122 *period = 1;
123 return needle_len - 1;
124 }
125
115 /* Invariants: 126 /* Invariants:
116 0 <= j < NEEDLE_LEN - 1 127 1 <= j < NEEDLE_LEN - 1
117 -1 <= max_suffix{,_rev} < j (treating SIZE_MAX as if it were signed) 128 0 <= max_suffix{,_rev} < j
118 min(max_suffix, max_suffix_rev) < global period of NEEDLE 129 min(max_suffix, max_suffix_rev) < global period of NEEDLE
119 1 <= p <= global period of NEEDLE 130 1 <= p <= global period of NEEDLE
120 p == global period of the substring NEEDLE[max_suffix{,_rev}+1...j] 131 p == global period of the substring NEEDLE[max_suffix{,_rev}+1...j]
@@ -122,9 +133,8 @@ critical_factorization (const unsigned char *needle, size_t needle_len,
122 */ 133 */
123 134
124 /* Perform lexicographic search. */ 135 /* Perform lexicographic search. */
125 max_suffix = SIZE_MAX; 136 max_suffix = 0;
126 j = 0; 137 j = k = p = 1;
127 k = p = 1;
128 while (j + k < needle_len) 138 while (j + k < needle_len)
129 { 139 {
130 a = CANON_ELEMENT (needle[j + k]); 140 a = CANON_ELEMENT (needle[j + k]);
@@ -157,9 +167,8 @@ critical_factorization (const unsigned char *needle, size_t needle_len,
157 *period = p; 167 *period = p;
158 168
159 /* Perform reverse lexicographic search. */ 169 /* Perform reverse lexicographic search. */
160 max_suffix_rev = SIZE_MAX; 170 max_suffix_rev = 0;
161 j = 0; 171 j = k = p = 1;
162 k = p = 1;
163 while (j + k < needle_len) 172 while (j + k < needle_len)
164 { 173 {
165 a = CANON_ELEMENT (needle[j + k]); 174 a = CANON_ELEMENT (needle[j + k]);
@@ -190,8 +199,20 @@ critical_factorization (const unsigned char *needle, size_t needle_len,
190 } 199 }
191 } 200 }
192 201
193 /* Choose the longer suffix. Return the first byte of the right 202 /* Choose the shorter suffix. Return the index of the first byte of
194 half, rather than the last byte of the left half. */ 203 the right half, rather than the last byte of the left half.
204
205 For some examples, 'banana' has two critical factorizations, both
206 exposed by the two lexicographic extreme suffixes of 'anana' and
207 'nana', where both suffixes have a period of 2. On the other
208 hand, with 'aab' and 'bba', both strings have a single critical
209 factorization of the last byte, with the suffix having a period
210 of 1. While the maximal lexicographic suffix of 'aab' is 'b',
211 the maximal lexicographic suffix of 'bba' is 'ba', which is not a
212 critical factorization. Conversely, the maximal reverse
213 lexicographic suffix of 'a' works for 'bba', but not 'ab' for
214 'aab'. The shorter suffix of the two will always be a critical
215 factorization. */
195 if (max_suffix_rev + 1 < max_suffix + 1) 216 if (max_suffix_rev + 1 < max_suffix + 1)
196 return max_suffix + 1; 217 return max_suffix + 1;
197 *period = p; 218 *period = p;
@@ -226,9 +247,9 @@ two_way_short_needle (const unsigned char *haystack, size_t haystack_len,
226 first. */ 247 first. */
227 if (CMP_FUNC (needle, needle + period, suffix) == 0) 248 if (CMP_FUNC (needle, needle + period, suffix) == 0)
228 { 249 {
229 /* Entire needle is periodic; a mismatch can only advance by the 250 /* Entire needle is periodic; a mismatch in the left half can
230 period, so use memory to avoid rescanning known occurrences 251 only advance by the period, so use memory to avoid rescanning
231 of the period. */ 252 known occurrences of the period in the right half. */
232 size_t memory = 0; 253 size_t memory = 0;
233 j = 0; 254 j = 0;
234 while (AVAILABLE (haystack, haystack_len, j, needle_len)) 255 while (AVAILABLE (haystack, haystack_len, j, needle_len))
@@ -330,9 +351,9 @@ two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
330 first. */ 351 first. */
331 if (CMP_FUNC (needle, needle + period, suffix) == 0) 352 if (CMP_FUNC (needle, needle + period, suffix) == 0)
332 { 353 {
333 /* Entire needle is periodic; a mismatch can only advance by the 354 /* Entire needle is periodic; a mismatch in the left half can
334 period, so use memory to avoid rescanning known occurrences 355 only advance by the period, so use memory to avoid rescanning
335 of the period. */ 356 known occurrences of the period in the right half. */
336 size_t memory = 0; 357 size_t memory = 0;
337 size_t shift; 358 size_t shift;
338 j = 0; 359 j = 0;
diff --git a/gl/string.in.h b/gl/string.in.h
index 13c0f095..f64fce30 100644
--- a/gl/string.in.h
+++ b/gl/string.in.h
@@ -41,10 +41,12 @@
41# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) 41# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
42# define __attribute__(Spec) /* empty */ 42# define __attribute__(Spec) /* empty */
43# endif 43# endif
44#endif
44/* The attribute __pure__ was added in gcc 2.96. */ 45/* The attribute __pure__ was added in gcc 2.96. */
45# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96) 46#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
46# define __pure__ /* empty */ 47# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
47# endif 48#else
49# define _GL_ATTRIBUTE_PURE /* empty */
48#endif 50#endif
49 51
50 52
@@ -62,13 +64,13 @@
62# define memchr rpl_memchr 64# define memchr rpl_memchr
63# endif 65# endif
64_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n) 66_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
65 __attribute__ ((__pure__)) 67 _GL_ATTRIBUTE_PURE
66 _GL_ARG_NONNULL ((1))); 68 _GL_ARG_NONNULL ((1)));
67_GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n)); 69_GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
68# else 70# else
69# if ! @HAVE_MEMCHR@ 71# if ! @HAVE_MEMCHR@
70_GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n) 72_GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n)
71 __attribute__ ((__pure__)) 73 _GL_ATTRIBUTE_PURE
72 _GL_ARG_NONNULL ((1))); 74 _GL_ARG_NONNULL ((1)));
73# endif 75# endif
74 /* On some systems, this function is defined as an overloaded function: 76 /* On some systems, this function is defined as an overloaded function:
@@ -102,7 +104,8 @@ _GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - "
102_GL_FUNCDECL_RPL (memmem, void *, 104_GL_FUNCDECL_RPL (memmem, void *,
103 (void const *__haystack, size_t __haystack_len, 105 (void const *__haystack, size_t __haystack_len,
104 void const *__needle, size_t __needle_len) 106 void const *__needle, size_t __needle_len)
105 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3))); 107 _GL_ATTRIBUTE_PURE
108 _GL_ARG_NONNULL ((1, 3)));
106_GL_CXXALIAS_RPL (memmem, void *, 109_GL_CXXALIAS_RPL (memmem, void *,
107 (void const *__haystack, size_t __haystack_len, 110 (void const *__haystack, size_t __haystack_len,
108 void const *__needle, size_t __needle_len)); 111 void const *__needle, size_t __needle_len));
@@ -111,7 +114,8 @@ _GL_CXXALIAS_RPL (memmem, void *,
111_GL_FUNCDECL_SYS (memmem, void *, 114_GL_FUNCDECL_SYS (memmem, void *,
112 (void const *__haystack, size_t __haystack_len, 115 (void const *__haystack, size_t __haystack_len,
113 void const *__needle, size_t __needle_len) 116 void const *__needle, size_t __needle_len)
114 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3))); 117 _GL_ATTRIBUTE_PURE
118 _GL_ARG_NONNULL ((1, 3)));
115# endif 119# endif
116_GL_CXXALIAS_SYS (memmem, void *, 120_GL_CXXALIAS_SYS (memmem, void *,
117 (void const *__haystack, size_t __haystack_len, 121 (void const *__haystack, size_t __haystack_len,
@@ -152,7 +156,7 @@ _GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
152#if @GNULIB_MEMRCHR@ 156#if @GNULIB_MEMRCHR@
153# if ! @HAVE_DECL_MEMRCHR@ 157# if ! @HAVE_DECL_MEMRCHR@
154_GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t) 158_GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t)
155 __attribute__ ((__pure__)) 159 _GL_ATTRIBUTE_PURE
156 _GL_ARG_NONNULL ((1))); 160 _GL_ARG_NONNULL ((1)));
157# endif 161# endif
158 /* On some systems, this function is defined as an overloaded function: 162 /* On some systems, this function is defined as an overloaded function:
@@ -182,7 +186,7 @@ _GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
182#if @GNULIB_RAWMEMCHR@ 186#if @GNULIB_RAWMEMCHR@
183# if ! @HAVE_RAWMEMCHR@ 187# if ! @HAVE_RAWMEMCHR@
184_GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in) 188_GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in)
185 __attribute__ ((__pure__)) 189 _GL_ATTRIBUTE_PURE
186 _GL_ARG_NONNULL ((1))); 190 _GL_ARG_NONNULL ((1)));
187# endif 191# endif
188 /* On some systems, this function is defined as an overloaded function: 192 /* On some systems, this function is defined as an overloaded function:
@@ -272,7 +276,7 @@ _GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings "
272#if @GNULIB_STRCHRNUL@ 276#if @GNULIB_STRCHRNUL@
273# if ! @HAVE_STRCHRNUL@ 277# if ! @HAVE_STRCHRNUL@
274_GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in) 278_GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
275 __attribute__ ((__pure__)) 279 _GL_ATTRIBUTE_PURE
276 _GL_ARG_NONNULL ((1))); 280 _GL_ARG_NONNULL ((1)));
277# endif 281# endif
278 /* On some systems, this function is defined as an overloaded function: 282 /* On some systems, this function is defined as an overloaded function:
@@ -378,13 +382,13 @@ _GL_WARN_ON_USE (strndup, "strndup is unportable - "
378# define strnlen rpl_strnlen 382# define strnlen rpl_strnlen
379# endif 383# endif
380_GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen) 384_GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)
381 __attribute__ ((__pure__)) 385 _GL_ATTRIBUTE_PURE
382 _GL_ARG_NONNULL ((1))); 386 _GL_ARG_NONNULL ((1)));
383_GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)); 387_GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen));
384# else 388# else
385# if ! @HAVE_DECL_STRNLEN@ 389# if ! @HAVE_DECL_STRNLEN@
386_GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen) 390_GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)
387 __attribute__ ((__pure__)) 391 _GL_ATTRIBUTE_PURE
388 _GL_ARG_NONNULL ((1))); 392 _GL_ARG_NONNULL ((1)));
389# endif 393# endif
390_GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)); 394_GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen));
@@ -414,7 +418,7 @@ _GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
414#if @GNULIB_STRPBRK@ 418#if @GNULIB_STRPBRK@
415# if ! @HAVE_STRPBRK@ 419# if ! @HAVE_STRPBRK@
416_GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept) 420_GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
417 __attribute__ ((__pure__)) 421 _GL_ATTRIBUTE_PURE
418 _GL_ARG_NONNULL ((1, 2))); 422 _GL_ARG_NONNULL ((1, 2)));
419# endif 423# endif
420 /* On some systems, this function is defined as an overloaded function: 424 /* On some systems, this function is defined as an overloaded function:
@@ -514,7 +518,7 @@ _GL_WARN_ON_USE (strsep, "strsep is unportable - "
514# define strstr rpl_strstr 518# define strstr rpl_strstr
515# endif 519# endif
516_GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle) 520_GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
517 __attribute__ ((__pure__)) 521 _GL_ATTRIBUTE_PURE
518 _GL_ARG_NONNULL ((1, 2))); 522 _GL_ARG_NONNULL ((1, 2)));
519_GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle)); 523_GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
520# else 524# else
@@ -556,14 +560,16 @@ _GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot "
556# endif 560# endif
557_GL_FUNCDECL_RPL (strcasestr, char *, 561_GL_FUNCDECL_RPL (strcasestr, char *,
558 (const char *haystack, const char *needle) 562 (const char *haystack, const char *needle)
559 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2))); 563 _GL_ATTRIBUTE_PURE
564 _GL_ARG_NONNULL ((1, 2)));
560_GL_CXXALIAS_RPL (strcasestr, char *, 565_GL_CXXALIAS_RPL (strcasestr, char *,
561 (const char *haystack, const char *needle)); 566 (const char *haystack, const char *needle));
562# else 567# else
563# if ! @HAVE_STRCASESTR@ 568# if ! @HAVE_STRCASESTR@
564_GL_FUNCDECL_SYS (strcasestr, char *, 569_GL_FUNCDECL_SYS (strcasestr, char *,
565 (const char *haystack, const char *needle) 570 (const char *haystack, const char *needle)
566 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2))); 571 _GL_ATTRIBUTE_PURE
572 _GL_ARG_NONNULL ((1, 2)));
567# endif 573# endif
568 /* On some systems, this function is defined as an overloaded function: 574 /* On some systems, this function is defined as an overloaded function:
569 extern "C++" { const char * strcasestr (const char *, const char *); } 575 extern "C++" { const char * strcasestr (const char *, const char *); }
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c
index d4a08005..79e1110a 100644
--- a/lib/tests/test_utils.c
+++ b/lib/tests/test_utils.c
@@ -38,7 +38,7 @@ main (int argc, char **argv)
38 state_data *temp_state_data; 38 state_data *temp_state_data;
39 time_t current_time; 39 time_t current_time;
40 40
41 plan_tests(141); 41 plan_tests(150);
42 42
43 ok( this_nagios_plugin==NULL, "nagios_plugin not initialised"); 43 ok( this_nagios_plugin==NULL, "nagios_plugin not initialised");
44 44
@@ -132,6 +132,18 @@ main (int argc, char **argv)
132 ok( check_range(0, range) == TRUE, "0 - alert"); 132 ok( check_range(0, range) == TRUE, "0 - alert");
133 free(range); 133 free(range);
134 134
135 range = parse_range_string("@1:1");
136 ok( range != NULL, "'@1:1' is a valid range");
137 ok( range->start == 1, "Start correct");
138 ok( range->start_infinity == FALSE, "Not using negative infinity");
139 ok( range->end == 1, "End correct");
140 ok( range->end_infinity == FALSE, "Not using infinity");
141 ok( range->alert_on == INSIDE, "Will alert on inside of this range" );
142 ok( check_range(0.5, range) == FALSE, "0.5 - no alert");
143 ok( check_range(1, range) == TRUE, "1 - alert");
144 ok( check_range(5.2, range) == FALSE, "5.2 - no alert");
145 free(range);
146
135 range = parse_range_string("1:1"); 147 range = parse_range_string("1:1");
136 ok( range != NULL, "'1:1' is a valid range"); 148 ok( range != NULL, "'1:1' is a valid range");
137 ok( range->start == 1, "Start correct"); 149 ok( range->start == 1, "Start correct");
diff --git a/plugins-scripts/check_sensors.sh b/plugins-scripts/check_sensors.sh
index ffaa9748..874e1049 100755
--- a/plugins-scripts/check_sensors.sh
+++ b/plugins-scripts/check_sensors.sh
@@ -44,25 +44,28 @@ case "$1" in
44 *) 44 *)
45 sensordata=`sensors 2>&1` 45 sensordata=`sensors 2>&1`
46 status=$? 46 status=$?
47 if test "$1" = "-v" -o "$1" = "--verbose"; then
48 echo ${sensordata}
49 fi
50 if test ${status} -eq 127; then 47 if test ${status} -eq 127; then
51 echo "SENSORS UNKNOWN - command not found (did you install lmsensors?)" 48 text="SENSORS UNKNOWN - command not found (did you install lmsensors?)"
52 exit $STATE_UNKNOWN 49 exit=$STATE_UNKNOWN
53 elif test ${status} -ne 0; then 50 elif test ${status} -ne 0; then
54 echo "WARNING - sensors returned state $status" 51 text="WARNING - sensors returned state $status"
55 exit $STATE_WARNING 52 exit=$STATE_WARNING
56 fi 53 elif echo ${sensordata} | egrep ALARM > /dev/null; then
57 if echo ${sensordata} | egrep ALARM > /dev/null; then 54 text="SENSOR CRITICAL - Sensor alarm detected!"
58 echo SENSOR CRITICAL - Sensor alarm detected! 55 exit=$STATE_CRITICAL
59 exit $STATE_CRITICAL
60 elif echo ${sensordata} | egrep FAULT > /dev/null \ 56 elif echo ${sensordata} | egrep FAULT > /dev/null \
61 && test "$1" != "-i" -a "$1" != "--ignore-fault"; then 57 && test "$1" != "-i" -a "$1" != "--ignore-fault"; then
62 echo SENSOR UNKNOWN - Sensor reported fault 58 text="SENSOR UNKNOWN - Sensor reported fault"
63 exit $STATE_UNKNOWN 59 exit=$STATE_UNKNOWN
60 else
61 text="SENSORS OK"
62 exit=$STATE_OK
64 fi 63 fi
65 echo sensor ok 64
66 exit $STATE_OK 65 echo "$text"
66 if test "$1" = "-v" -o "$1" = "--verbose"; then
67 echo ${sensordata}
68 fi
69 exit $exit
67 ;; 70 ;;
68esac 71esac
diff --git a/plugins/check_apt.c b/plugins/check_apt.c
index 7ec2d55a..daeb7578 100644
--- a/plugins/check_apt.c
+++ b/plugins/check_apt.c
@@ -112,11 +112,11 @@ int main (int argc, char **argv) {
112 result = max_state(result, STATE_CRITICAL); 112 result = max_state(result, STATE_CRITICAL);
113 } else if(packages_available > 0){ 113 } else if(packages_available > 0){
114 result = max_state(result, STATE_WARNING); 114 result = max_state(result, STATE_WARNING);
115 } else { 115 } else if(result > STATE_UNKNOWN){
116 result = max_state(result, STATE_OK); 116 result = STATE_UNKNOWN;
117 } 117 }
118 118
119 printf(_("APT %s: %d packages available for %s (%d critical updates). %s%s%s%s\n"), 119 printf(_("APT %s: %d packages available for %s (%d critical updates). %s%s%s%s|available_upgrades=%d;;;0 critical_updates=%d;;;0\n"),
120 state_text(result), 120 state_text(result),
121 packages_available, 121 packages_available,
122 (upgrade==DIST_UPGRADE)?"dist-upgrade":"upgrade", 122 (upgrade==DIST_UPGRADE)?"dist-upgrade":"upgrade",
@@ -124,7 +124,9 @@ int main (int argc, char **argv) {
124 (stderr_warning)?" warnings detected":"", 124 (stderr_warning)?" warnings detected":"",
125 (stderr_warning && exec_warning)?",":"", 125 (stderr_warning && exec_warning)?",":"",
126 (exec_warning)?" errors detected":"", 126 (exec_warning)?" errors detected":"",
127 (stderr_warning||exec_warning)?". run with -v for information.":"" 127 (stderr_warning||exec_warning)?". run with -v for information.":"",
128 packages_available,
129 sec_count
128 ); 130 );
129 131
130 return result; 132 return result;
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index 675a547c..c7cce97d 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -52,6 +52,8 @@ void print_help (void);
52void print_usage (void); 52void print_usage (void);
53 53
54char *server_name = NULL; 54char *server_name = NULL;
55char *sourceip = NULL;
56char *sourceif = NULL;
55int packet_size = PACKET_SIZE; 57int packet_size = PACKET_SIZE;
56int packet_count = PACKET_COUNT; 58int packet_count = PACKET_COUNT;
57int target_timeout = 0; 59int target_timeout = 0;
@@ -72,6 +74,8 @@ main (int argc, char **argv)
72/* normaly should be int result = STATE_UNKNOWN; */ 74/* normaly should be int result = STATE_UNKNOWN; */
73 75
74 int status = STATE_UNKNOWN; 76 int status = STATE_UNKNOWN;
77 int result = 0;
78 char *fping_prog = NULL;
75 char *server = NULL; 79 char *server = NULL;
76 char *command_line = NULL; 80 char *command_line = NULL;
77 char *input_buffer = NULL; 81 char *input_buffer = NULL;
@@ -95,8 +99,21 @@ main (int argc, char **argv)
95 xasprintf(&option_string, "%s-t %d ", option_string, target_timeout); 99 xasprintf(&option_string, "%s-t %d ", option_string, target_timeout);
96 if (packet_interval) 100 if (packet_interval)
97 xasprintf(&option_string, "%s-p %d ", option_string, packet_interval); 101 xasprintf(&option_string, "%s-p %d ", option_string, packet_interval);
98 102 if (sourceip)
99 xasprintf (&command_line, "%s %s-b %d -c %d %s", PATH_TO_FPING, 103 xasprintf(&option_string, "%s-S %s ", option_string, sourceip);
104 if (sourceif)
105 xasprintf(&option_string, "%s-I %s ", option_string, sourceif);
106
107#ifdef PATH_TO_FPING6
108 if (address_family == AF_INET6)
109 fping_prog = strdup(PATH_TO_FPING6);
110 else
111 fping_prog = strdup(PATH_TO_FPING);
112#else
113 fping_prog = strdup(PATH_TO_FPING);
114#endif
115
116 xasprintf (&command_line, "%s %s-b %d -c %d %s", fping_prog,
100 option_string, packet_size, packet_count, server); 117 option_string, packet_size, packet_count, server);
101 118
102 if (verbose) 119 if (verbose)
@@ -130,10 +147,24 @@ main (int argc, char **argv)
130 (void) fclose (child_stderr); 147 (void) fclose (child_stderr);
131 148
132 /* close the pipe */ 149 /* close the pipe */
133 if (spclose (child_process)) 150 if (result = spclose (child_process))
134 /* need to use max_state not max */ 151 /* need to use max_state not max */
135 status = max_state (status, STATE_WARNING); 152 status = max_state (status, STATE_WARNING);
136 153
154 if (result > 1 ) {
155 status = max_state (status, STATE_UNKNOWN);
156 if (result == 2) {
157 die (STATE_UNKNOWN, _("FPING UNKNOWN - IP address not found\n"));
158 }
159 if (result == 3) {
160 die (STATE_UNKNOWN, _("FPING UNKNOWN - invalid commandline argument\n"));
161 }
162 if (result == 4) {
163 die (STATE_UNKNOWN, _("FPING UNKNOWN - failed system call\n"));
164 }
165
166 }
167
137 printf ("FPING %s - %s\n", state_text (status), server_name); 168 printf ("FPING %s - %s\n", state_text (status), server_name);
138 169
139 return status; 170 return status;
@@ -159,6 +190,10 @@ textscan (char *buf)
159 "host"); 190 "host");
160 191
161 } 192 }
193 else if (strstr (buf, "Operation not permitted") || strstr (buf, "No such device") ) {
194 die (STATE_UNKNOWN, _("FPING UNKNOWN - %s parameter error\n"),
195 "host");
196 }
162 else if (strstr (buf, "is down")) { 197 else if (strstr (buf, "is down")) {
163 die (STATE_CRITICAL, _("FPING CRITICAL - %s is down\n"), server_name); 198 die (STATE_CRITICAL, _("FPING CRITICAL - %s is down\n"), server_name);
164 199
@@ -232,6 +267,8 @@ process_arguments (int argc, char **argv)
232 int option = 0; 267 int option = 0;
233 static struct option longopts[] = { 268 static struct option longopts[] = {
234 {"hostname", required_argument, 0, 'H'}, 269 {"hostname", required_argument, 0, 'H'},
270 {"sourceip", required_argument, 0, 'S'},
271 {"sourceif", required_argument, 0, 'I'},
235 {"critical", required_argument, 0, 'c'}, 272 {"critical", required_argument, 0, 'c'},
236 {"warning", required_argument, 0, 'w'}, 273 {"warning", required_argument, 0, 'w'},
237 {"bytes", required_argument, 0, 'b'}, 274 {"bytes", required_argument, 0, 'b'},
@@ -241,6 +278,8 @@ process_arguments (int argc, char **argv)
241 {"verbose", no_argument, 0, 'v'}, 278 {"verbose", no_argument, 0, 'v'},
242 {"version", no_argument, 0, 'V'}, 279 {"version", no_argument, 0, 'V'},
243 {"help", no_argument, 0, 'h'}, 280 {"help", no_argument, 0, 'h'},
281 {"use-ipv4", no_argument, 0, '4'},
282 {"use-ipv6", no_argument, 0, '6'},
244 {0, 0, 0, 0} 283 {0, 0, 0, 0}
245 }; 284 };
246 285
@@ -258,7 +297,7 @@ process_arguments (int argc, char **argv)
258 } 297 }
259 298
260 while (1) { 299 while (1) {
261 c = getopt_long (argc, argv, "+hVvH:c:w:b:n:T:i:", longopts, &option); 300 c = getopt_long (argc, argv, "+hVvH:S:c:w:b:n:T:i:I:46", longopts, &option);
262 301
263 if (c == -1 || c == EOF || c == 1) 302 if (c == -1 || c == EOF || c == 1)
264 break; 303 break;
@@ -281,6 +320,24 @@ process_arguments (int argc, char **argv)
281 } 320 }
282 server_name = strscpy (server_name, optarg); 321 server_name = strscpy (server_name, optarg);
283 break; 322 break;
323 case 'S': /* sourceip */
324 if (is_host (optarg) == FALSE) {
325 usage2 (_("Invalid hostname/address"), optarg);
326 }
327 sourceip = strscpy (sourceip, optarg);
328 break;
329 case 'I': /* sourceip */
330 sourceif = strscpy (sourceif, optarg);
331 case '4': /* IPv4 only */
332 address_family = AF_INET;
333 break;
334 case '6': /* IPv6 only */
335#ifdef USE_IPV6
336 address_family = AF_INET6;
337#else
338 usage (_("IPv6 support not available\n"));
339#endif
340 break;
284 case 'c': 341 case 'c':
285 get_threshold (optarg, rv); 342 get_threshold (optarg, rv);
286 if (rv[RTA]) { 343 if (rv[RTA]) {
@@ -402,6 +459,8 @@ print_help (void)
402 printf (UT_HELP_VRSN); 459 printf (UT_HELP_VRSN);
403 printf (UT_EXTRA_OPTS); 460 printf (UT_EXTRA_OPTS);
404 461
462 printf (UT_IPv46);
463
405 printf (" %s\n", "-H, --hostname=HOST"); 464 printf (" %s\n", "-H, --hostname=HOST");
406 printf (" %s\n", _("name or IP Address of host to ping (IP Address bypasses name lookup, reducing system load)")); 465 printf (" %s\n", _("name or IP Address of host to ping (IP Address bypasses name lookup, reducing system load)"));
407 printf (" %s\n", "-w, --warning=THRESHOLD"); 466 printf (" %s\n", "-w, --warning=THRESHOLD");
@@ -413,15 +472,22 @@ print_help (void)
413 printf (" %s\n", "-n, --number=INTEGER"); 472 printf (" %s\n", "-n, --number=INTEGER");
414 printf (" %s (default: %d)\n", _("number of ICMP packets to send"),PACKET_COUNT); 473 printf (" %s (default: %d)\n", _("number of ICMP packets to send"),PACKET_COUNT);
415 printf (" %s\n", "-T, --target-timeout=INTEGER"); 474 printf (" %s\n", "-T, --target-timeout=INTEGER");
416 printf (" %s (default: fping's default for -t)\n", _("Target timeout (ms)"),PACKET_COUNT); 475 printf (" %s (default: fping's default for -t)\n", _("Target timeout (ms)"));
417 printf (" %s\n", "-i, --interval=INTEGER"); 476 printf (" %s\n", "-i, --interval=INTEGER");
418 printf (" %s (default: fping's default for -p)\n", _("Interval (ms) between sending packets"),PACKET_COUNT); 477 printf (" %s (default: fping's default for -p)\n", _("Interval (ms) between sending packets"));
478 printf (" %s\n", "-S, --sourceip=HOST");
479 printf (" %s\n", _("name or IP Address of sourceip"));
480 printf (" %s\n", "-I, --sourceif=IF");
481 printf (" %s\n", _("source interface name"));
419 printf (UT_VERBOSE); 482 printf (UT_VERBOSE);
420 printf ("\n"); 483 printf ("\n");
421 printf (" %s\n", _("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)")); 484 printf (" %s\n", _("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)"));
422 printf (" %s\n", _("which triggers a WARNING or CRITICAL state, and <pl> is the percentage of")); 485 printf (" %s\n", _("which triggers a WARNING or CRITICAL state, and <pl> is the percentage of"));
423 printf (" %s\n", _("packet loss to trigger an alarm state.")); 486 printf (" %s\n", _("packet loss to trigger an alarm state."));
424 487
488 printf ("\n");
489 printf (" %s\n", _("IPv4 is used by default. Specify -6 to use IPv6."));
490
425 printf (UT_SUPPORT); 491 printf (UT_SUPPORT);
426} 492}
427 493
diff --git a/plugins/check_http.c b/plugins/check_http.c
index ddaca337..46c0c135 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -1,40 +1,40 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Nagios check_http plugin 3* Nagios check_http plugin
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 1999-2008 Nagios Plugins Development Team 6* Copyright (c) 1999-2013 Nagios Plugins Development Team
7* 7*
8* Description: 8* Description:
9* 9*
10* This file contains the check_http plugin 10* This file contains the check_http plugin
11* 11*
12* This plugin tests the HTTP service on the specified host. It can test 12* This plugin tests the HTTP service on the specified host. It can test
13* normal (http) and secure (https) servers, follow redirects, search for 13* normal (http) and secure (https) servers, follow redirects, search for
14* strings and regular expressions, check connection times, and report on 14* strings and regular expressions, check connection times, and report on
15* certificate expiration times. 15* certificate expiration times.
16* 16*
17* 17*
18* This program is free software: you can redistribute it and/or modify 18* This program is free software: you can redistribute it and/or modify
19* it under the terms of the GNU General Public License as published by 19* it under the terms of the GNU General Public License as published by
20* the Free Software Foundation, either version 3 of the License, or 20* the Free Software Foundation, either version 3 of the License, or
21* (at your option) any later version. 21* (at your option) any later version.
22* 22*
23* This program is distributed in the hope that it will be useful, 23* This program is distributed in the hope that it will be useful,
24* but WITHOUT ANY WARRANTY; without even the implied warranty of 24* but WITHOUT ANY WARRANTY; without even the implied warranty of
25* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26* GNU General Public License for more details. 26* GNU General Public License for more details.
27* 27*
28* You should have received a copy of the GNU General Public License 28* You should have received a copy of the GNU General Public License
29* along with this program. If not, see <http://www.gnu.org/licenses/>. 29* along with this program. If not, see <http://www.gnu.org/licenses/>.
30* 30*
31* 31*
32*****************************************************************************/ 32*****************************************************************************/
33 33
34/* splint -I. -I../../plugins -I../../lib/ -I/usr/kerberos/include/ ../../plugins/check_http.c */ 34/* splint -I. -I../../plugins -I../../lib/ -I/usr/kerberos/include/ ../../plugins/check_http.c */
35 35
36const char *progname = "check_http"; 36const char *progname = "check_http";
37const char *copyright = "1999-2011"; 37const char *copyright = "1999-2013";
38const char *email = "nagiosplug-devel@lists.sourceforge.net"; 38const char *email = "nagiosplug-devel@lists.sourceforge.net";
39 39
40#include "common.h" 40#include "common.h"
@@ -43,7 +43,6 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
43#include "base64.h" 43#include "base64.h"
44#include <ctype.h> 44#include <ctype.h>
45 45
46#define INPUT_DELIMITER ";"
47#define STICKY_NONE 0 46#define STICKY_NONE 0
48#define STICKY_HOST 1 47#define STICKY_HOST 1
49#define STICKY_PORT 2 48#define STICKY_PORT 2
@@ -85,6 +84,7 @@ int errcode;
85int invert_regex = 0; 84int invert_regex = 0;
86 85
87struct timeval tv; 86struct timeval tv;
87struct timeval tv_temp;
88 88
89#define HTTP_URL "/" 89#define HTTP_URL "/"
90#define CRLF "\r\n" 90#define CRLF "\r\n"
@@ -100,7 +100,9 @@ char *user_agent;
100int server_url_length; 100int server_url_length;
101int server_expect_yn = 0; 101int server_expect_yn = 0;
102char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT; 102char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT;
103char header_expect[MAX_INPUT_BUFFER] = "";
103char string_expect[MAX_INPUT_BUFFER] = ""; 104char string_expect[MAX_INPUT_BUFFER] = "";
105char output_header_search[30] = "";
104char output_string_search[30] = ""; 106char output_string_search[30] = "";
105char *warning_thresholds = NULL; 107char *warning_thresholds = NULL;
106char *critical_thresholds = NULL; 108char *critical_thresholds = NULL;
@@ -115,6 +117,7 @@ int followsticky = STICKY_NONE;
115int use_ssl = FALSE; 117int use_ssl = FALSE;
116int use_sni = FALSE; 118int use_sni = FALSE;
117int verbose = FALSE; 119int verbose = FALSE;
120int show_extended_perfdata = FALSE;
118int sd; 121int sd;
119int min_page_len = 0; 122int min_page_len = 0;
120int max_page_len = 0; 123int max_page_len = 0;
@@ -133,6 +136,11 @@ void redir (char *pos, char *status_line);
133int server_type_check(const char *type); 136int server_type_check(const char *type);
134int server_port_check(int ssl_flag); 137int server_port_check(int ssl_flag);
135char *perfd_time (double microsec); 138char *perfd_time (double microsec);
139char *perfd_time_connect (double microsec);
140char *perfd_time_ssl (double microsec);
141char *perfd_time_firstbyte (double microsec);
142char *perfd_time_headers (double microsec);
143char *perfd_time_transfer (double microsec);
136char *perfd_size (int page_len); 144char *perfd_size (int page_len);
137void print_help (void); 145void print_help (void);
138void print_usage (void); 146void print_usage (void);
@@ -208,6 +216,7 @@ process_arguments (int argc, char **argv)
208 {"port", required_argument, 0, 'p'}, 216 {"port", required_argument, 0, 'p'},
209 {"authorization", required_argument, 0, 'a'}, 217 {"authorization", required_argument, 0, 'a'},
210 {"proxy_authorization", required_argument, 0, 'b'}, 218 {"proxy_authorization", required_argument, 0, 'b'},
219 {"header-string", required_argument, 0, 'd'},
211 {"string", required_argument, 0, 's'}, 220 {"string", required_argument, 0, 's'},
212 {"expect", required_argument, 0, 'e'}, 221 {"expect", required_argument, 0, 'e'},
213 {"regex", required_argument, 0, 'r'}, 222 {"regex", required_argument, 0, 'r'},
@@ -216,7 +225,7 @@ process_arguments (int argc, char **argv)
216 {"linespan", no_argument, 0, 'l'}, 225 {"linespan", no_argument, 0, 'l'},
217 {"onredirect", required_argument, 0, 'f'}, 226 {"onredirect", required_argument, 0, 'f'},
218 {"certificate", required_argument, 0, 'C'}, 227 {"certificate", required_argument, 0, 'C'},
219 {"client-cert", required_argument, 0, 'E'}, 228 {"client-cert", required_argument, 0, 'J'},
220 {"private-key", required_argument, 0, 'K'}, 229 {"private-key", required_argument, 0, 'K'},
221 {"useragent", required_argument, 0, 'A'}, 230 {"useragent", required_argument, 0, 'A'},
222 {"header", required_argument, 0, 'k'}, 231 {"header", required_argument, 0, 'k'},
@@ -227,6 +236,7 @@ process_arguments (int argc, char **argv)
227 {"invert-regex", no_argument, NULL, INVERT_REGEX}, 236 {"invert-regex", no_argument, NULL, INVERT_REGEX},
228 {"use-ipv4", no_argument, 0, '4'}, 237 {"use-ipv4", no_argument, 0, '4'},
229 {"use-ipv6", no_argument, 0, '6'}, 238 {"use-ipv6", no_argument, 0, '6'},
239 {"extended-perfdata", no_argument, 0, 'E'},
230 {0, 0, 0, 0} 240 {0, 0, 0, 0}
231 }; 241 };
232 242
@@ -247,7 +257,7 @@ process_arguments (int argc, char **argv)
247 } 257 }
248 258
249 while (1) { 259 while (1) {
250 c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:e:p:s:R:r:u:f:C:E:K:nlLS::m:M:N", longopts, &option); 260 c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:nlLS::m:M:N:E", longopts, &option);
251 if (c == -1 || c == EOF) 261 if (c == -1 || c == EOF)
252 break; 262 break;
253 263
@@ -314,7 +324,7 @@ process_arguments (int argc, char **argv)
314 check_cert = TRUE; 324 check_cert = TRUE;
315 goto enable_ssl; 325 goto enable_ssl;
316#endif 326#endif
317 case 'E': /* use client certificate */ 327 case 'J': /* use client certificate */
318#ifdef HAVE_SSL 328#ifdef HAVE_SSL
319 test_file(optarg); 329 test_file(optarg);
320 client_cert = optarg; 330 client_cert = optarg;
@@ -340,7 +350,7 @@ process_arguments (int argc, char **argv)
340 if (specify_port == FALSE) 350 if (specify_port == FALSE)
341 server_port = HTTPS_PORT; 351 server_port = HTTPS_PORT;
342#else 352#else
343 /* -C -E and -K fall through to here without SSL */ 353 /* -C -J and -K fall through to here without SSL */
344 usage4 (_("Invalid option - SSL is not available")); 354 usage4 (_("Invalid option - SSL is not available"));
345#endif 355#endif
346 break; 356 break;
@@ -410,6 +420,10 @@ process_arguments (int argc, char **argv)
410 free(http_method); 420 free(http_method);
411 http_method = strdup (optarg); 421 http_method = strdup (optarg);
412 break; 422 break;
423 case 'd': /* string or substring */
424 strncpy (header_expect, optarg, MAX_INPUT_BUFFER - 1);
425 header_expect[MAX_INPUT_BUFFER - 1] = 0;
426 break;
413 case 's': /* string or substring */ 427 case 's': /* string or substring */
414 strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1); 428 strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1);
415 string_expect[MAX_INPUT_BUFFER - 1] = 0; 429 string_expect[MAX_INPUT_BUFFER - 1] = 0;
@@ -496,6 +510,9 @@ process_arguments (int argc, char **argv)
496 } 510 }
497 } 511 }
498 break; 512 break;
513 case 'E': /* show extended perfdata */
514 show_extended_perfdata = TRUE;
515 break;
499 } 516 }
500 } 517 }
501 518
@@ -840,17 +857,33 @@ check_http (void)
840 char *pos; 857 char *pos;
841 long microsec; 858 long microsec;
842 double elapsed_time; 859 double elapsed_time;
860 long microsec_connect;
861 double elapsed_time_connect;
862 long microsec_ssl;
863 double elapsed_time_ssl;
864 long microsec_firstbyte;
865 double elapsed_time_firstbyte;
866 long microsec_headers;
867 double elapsed_time_headers;
868 long microsec_transfer;
869 double elapsed_time_transfer;
843 int page_len = 0; 870 int page_len = 0;
844 int result = STATE_OK; 871 int result = STATE_OK;
845 872
846 /* try to connect to the host at the given port number */ 873 /* try to connect to the host at the given port number */
874 gettimeofday (&tv_temp, NULL);
847 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) 875 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK)
848 die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n")); 876 die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n"));
877 microsec_connect = deltime (tv_temp);
849#ifdef HAVE_SSL 878#ifdef HAVE_SSL
879 elapsed_time_connect = (double)microsec_connect / 1.0e6;
850 if (use_ssl == TRUE) { 880 if (use_ssl == TRUE) {
881 gettimeofday (&tv_temp, NULL);
851 result = np_net_ssl_init_with_hostname_version_and_certificate(sd, (use_sni ? host_name : NULL), ssl_version, client_cert, client_privkey); 882 result = np_net_ssl_init_with_hostname_version_and_certificate(sd, (use_sni ? host_name : NULL), ssl_version, client_cert, client_privkey);
852 if (result != STATE_OK) 883 if (result != STATE_OK)
853 return result; 884 return result;
885 microsec_ssl = deltime (tv_temp);
886 elapsed_time_ssl = (double)microsec_ssl / 1.0e6;
854 if (check_cert == TRUE) { 887 if (check_cert == TRUE) {
855 result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); 888 result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit);
856 np_net_ssl_cleanup(); 889 np_net_ssl_cleanup();
@@ -882,8 +915,7 @@ check_http (void)
882 /* optionally send any other header tag */ 915 /* optionally send any other header tag */
883 if (http_opt_headers_count) { 916 if (http_opt_headers_count) {
884 for (i = 0; i < http_opt_headers_count ; i++) { 917 for (i = 0; i < http_opt_headers_count ; i++) {
885 for ((pos = strtok(http_opt_headers[i], INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER))) 918 xasprintf (&buf, "%s%s\r\n", buf, http_opt_headers[i]);
886 xasprintf (&buf, "%s%s\r\n", buf, pos);
887 } 919 }
888 /* This cannot be free'd here because a redirection will then try to access this and segfault */ 920 /* This cannot be free'd here because a redirection will then try to access this and segfault */
889 /* Covered in a testcase in tests/check_http.t */ 921 /* Covered in a testcase in tests/check_http.t */
@@ -919,11 +951,19 @@ check_http (void)
919 } 951 }
920 952
921 if (verbose) printf ("%s\n", buf); 953 if (verbose) printf ("%s\n", buf);
954 gettimeofday (&tv_temp, NULL);
922 my_send (buf, strlen (buf)); 955 my_send (buf, strlen (buf));
956 microsec_headers = deltime (tv_temp);
957 elapsed_time_headers = (double)microsec_headers / 1.0e6;
923 958
924 /* fetch the page */ 959 /* fetch the page */
925 full_page = strdup(""); 960 full_page = strdup("");
961 gettimeofday (&tv_temp, NULL);
926 while ((i = my_recv (buffer, MAX_INPUT_BUFFER-1)) > 0) { 962 while ((i = my_recv (buffer, MAX_INPUT_BUFFER-1)) > 0) {
963 if ((i >= 1) && (elapsed_time_firstbyte <= 0.000001)) {
964 microsec_firstbyte = deltime (tv_temp);
965 elapsed_time_firstbyte = (double)microsec_firstbyte / 1.0e6;
966 }
927 buffer[i] = '\0'; 967 buffer[i] = '\0';
928 xasprintf (&full_page_new, "%s%s", full_page, buffer); 968 xasprintf (&full_page_new, "%s%s", full_page, buffer);
929 free (full_page); 969 free (full_page);
@@ -935,6 +975,8 @@ check_http (void)
935 break; 975 break;
936 } 976 }
937 } 977 }
978 microsec_transfer = deltime (tv_temp);
979 elapsed_time_transfer = (double)microsec_transfer / 1.0e6;
938 980
939 if (i < 0 && errno != ECONNRESET) { 981 if (i < 0 && errno != ECONNRESET) {
940#ifdef HAVE_SSL 982#ifdef HAVE_SSL
@@ -1078,6 +1120,17 @@ check_http (void)
1078 } 1120 }
1079 1121
1080 /* Page and Header content checks go here */ 1122 /* Page and Header content checks go here */
1123 if (strlen (header_expect)) {
1124 if (!strstr (header, header_expect)) {
1125 strncpy(&output_header_search[0],header_expect,sizeof(output_header_search));
1126 if(output_header_search[sizeof(output_header_search)-1]!='\0') {
1127 bcopy("...",&output_header_search[sizeof(output_header_search)-4],4);
1128 }
1129 xasprintf (&msg, _("%sheader '%s' not found on '%s://%s:%d%s', "), msg, output_header_search, use_ssl ? "https" : "http", host_name ? host_name : server_address, server_port, server_url);
1130 result = STATE_CRITICAL;
1131 }
1132 }
1133
1081 1134
1082 if (strlen (string_expect)) { 1135 if (strlen (string_expect)) {
1083 if (!strstr (page, string_expect)) { 1136 if (!strstr (page, string_expect)) {
@@ -1136,11 +1189,25 @@ check_http (void)
1136 msg[strlen(msg)-3] = '\0'; 1189 msg[strlen(msg)-3] = '\0';
1137 1190
1138 /* check elapsed time */ 1191 /* check elapsed time */
1139 xasprintf (&msg, 1192 if (show_extended_perfdata)
1140 _("%s - %d bytes in %.3f second response time %s|%s %s"), 1193 xasprintf (&msg,
1141 msg, page_len, elapsed_time, 1194 _("%s - %d bytes in %.3f second response time %s|%s %s %s %s %s %s %s"),
1142 (display_html ? "</A>" : ""), 1195 msg, page_len, elapsed_time,
1143 perfd_time (elapsed_time), perfd_size (page_len)); 1196 (display_html ? "</A>" : ""),
1197 perfd_time (elapsed_time),
1198 perfd_size (page_len),
1199 perfd_time_connect (elapsed_time_connect),
1200 use_ssl == TRUE ? perfd_time_ssl (elapsed_time_ssl) : "",
1201 perfd_time_headers (elapsed_time_headers),
1202 perfd_time_firstbyte (elapsed_time_firstbyte),
1203 perfd_time_transfer (elapsed_time_transfer));
1204 else
1205 xasprintf (&msg,
1206 _("%s - %d bytes in %.3f second response time %s|%s %s"),
1207 msg, page_len, elapsed_time,
1208 (display_html ? "</A>" : ""),
1209 perfd_time (elapsed_time),
1210 perfd_size (page_len));
1144 1211
1145 result = max_state_alt(get_status(elapsed_time, thlds), result); 1212 result = max_state_alt(get_status(elapsed_time, thlds), result);
1146 1213
@@ -1329,7 +1396,30 @@ char *perfd_time (double elapsed_time)
1329 TRUE, 0, FALSE, 0); 1396 TRUE, 0, FALSE, 0);
1330} 1397}
1331 1398
1399char *perfd_time_connect (double elapsed_time_connect)
1400{
1401 return fperfdata ("time_connect", elapsed_time_connect, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0);
1402}
1403
1404char *perfd_time_ssl (double elapsed_time_ssl)
1405{
1406 return fperfdata ("time_ssl", elapsed_time_ssl, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0);
1407}
1408
1409char *perfd_time_headers (double elapsed_time_headers)
1410{
1411 return fperfdata ("time_headers", elapsed_time_headers, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0);
1412}
1413
1414char *perfd_time_firstbyte (double elapsed_time_firstbyte)
1415{
1416 return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0);
1417}
1332 1418
1419char *perfd_time_transfer (double elapsed_time_transfer)
1420{
1421 return fperfdata ("time_transfer", elapsed_time_transfer, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0);
1422}
1333 1423
1334char *perfd_size (int page_len) 1424char *perfd_size (int page_len)
1335{ 1425{
@@ -1383,7 +1473,7 @@ print_help (void)
1383 printf (" %s\n", "-C, --certificate=INTEGER[,INTEGER]"); 1473 printf (" %s\n", "-C, --certificate=INTEGER[,INTEGER]");
1384 printf (" %s\n", _("Minimum number of days a certificate has to be valid. Port defaults to 443")); 1474 printf (" %s\n", _("Minimum number of days a certificate has to be valid. Port defaults to 443"));
1385 printf (" %s\n", _("(when this option is used the URL is not checked.)")); 1475 printf (" %s\n", _("(when this option is used the URL is not checked.)"));
1386 printf (" %s\n", "-E, --client-cert=FILE"); 1476 printf (" %s\n", "-J, --client-cert=FILE");
1387 printf (" %s\n", _("Name of file that contains the client certificate (PEM format)")); 1477 printf (" %s\n", _("Name of file that contains the client certificate (PEM format)"));
1388 printf (" %s\n", _("to be used in establishing the SSL session")); 1478 printf (" %s\n", _("to be used in establishing the SSL session"));
1389 printf (" %s\n", "-K, --private-key=FILE"); 1479 printf (" %s\n", "-K, --private-key=FILE");
@@ -1396,6 +1486,8 @@ print_help (void)
1396 printf (" %s", _("the first (status) line of the server response (default: ")); 1486 printf (" %s", _("the first (status) line of the server response (default: "));
1397 printf ("%s)\n", HTTP_EXPECT); 1487 printf ("%s)\n", HTTP_EXPECT);
1398 printf (" %s\n", _("If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)")); 1488 printf (" %s\n", _("If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)"));
1489 printf (" %s\n", "-d, --header-string=STRING");
1490 printf (" %s\n", _("String to expect in the response headers"));
1399 printf (" %s\n", "-s, --string=STRING"); 1491 printf (" %s\n", "-s, --string=STRING");
1400 printf (" %s\n", _("String to expect in the content")); 1492 printf (" %s\n", _("String to expect in the content"));
1401 printf (" %s\n", "-u, --url=PATH"); 1493 printf (" %s\n", "-u, --url=PATH");
@@ -1495,10 +1587,10 @@ print_usage (void)
1495{ 1587{
1496 printf ("%s\n", _("Usage:")); 1588 printf ("%s\n", _("Usage:"));
1497 printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname); 1589 printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname);
1498 printf (" [-E <client certificate file>] [-K <private key>]\n"); 1590 printf (" [-J <client certificate file>] [-K <private key>]\n");
1499 printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-a auth]\n"); 1591 printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-a auth]\n");
1500 printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n"); 1592 printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n");
1501 printf (" [-e <expect>] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); 1593 printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n");
1502 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); 1594 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n");
1503 printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n"); 1595 printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n");
1504 printf (" [-T <content-type>] [-j method]\n"); 1596 printf (" [-T <content-type>] [-j method]\n");
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 51579c2a..db670e2d 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -49,10 +49,44 @@ char *db_host = NULL;
49char *db_socket = NULL; 49char *db_socket = NULL;
50char *db_pass = NULL; 50char *db_pass = NULL;
51char *db = NULL; 51char *db = NULL;
52char *ca_cert = NULL;
53char *ca_dir = NULL;
54char *cert = NULL;
55char *key = NULL;
56char *ciphers = NULL;
57bool ssl = false;
58char *opt_file = NULL;
59char *opt_group = NULL;
52unsigned int db_port = MYSQL_PORT; 60unsigned int db_port = MYSQL_PORT;
53int check_slave = 0, warn_sec = 0, crit_sec = 0; 61int check_slave = 0, warn_sec = 0, crit_sec = 0;
54int verbose = 0; 62int verbose = 0;
55 63
64static double warning_time = 0;
65static double critical_time = 0;
66
67#define LENGTH_METRIC_UNIT 6
68static const char *metric_unit[LENGTH_METRIC_UNIT] = {
69 "Open_files",
70 "Open_tables",
71 "Qcache_free_memory",
72 "Qcache_queries_in_cache",
73 "Threads_connected",
74 "Threads_running"
75};
76
77#define LENGTH_METRIC_COUNTER 9
78static const char *metric_counter[LENGTH_METRIC_COUNTER] = {
79 "Connections",
80 "Qcache_hits",
81 "Qcache_inserts",
82 "Qcache_lowmem_prunes",
83 "Qcache_not_cached",
84 "Queries",
85 "Questions",
86 "Table_locks_waited",
87 "Uptime"
88};
89
56thresholds *my_threshold = NULL; 90thresholds *my_threshold = NULL;
57 91
58int process_arguments (int, char **); 92int process_arguments (int, char **);
@@ -73,6 +107,9 @@ main (int argc, char **argv)
73 char *result = NULL; 107 char *result = NULL;
74 char *error = NULL; 108 char *error = NULL;
75 char slaveresult[SLAVERESULTSIZE]; 109 char slaveresult[SLAVERESULTSIZE];
110 char* perf;
111
112 perf = strdup ("");
76 113
77 setlocale (LC_ALL, ""); 114 setlocale (LC_ALL, "");
78 bindtextdomain (PACKAGE, LOCALEDIR); 115 bindtextdomain (PACKAGE, LOCALEDIR);
@@ -86,9 +123,17 @@ main (int argc, char **argv)
86 123
87 /* initialize mysql */ 124 /* initialize mysql */
88 mysql_init (&mysql); 125 mysql_init (&mysql);
126
127 if (opt_file != NULL)
128 mysql_options(&mysql,MYSQL_READ_DEFAULT_FILE,opt_file);
89 129
90 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client"); 130 if (opt_group != NULL)
131 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,opt_group);
132 else
133 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client");
91 134
135 if (ssl)
136 mysql_ssl_set(&mysql,key,cert,ca_cert,ca_dir,ciphers);
92 /* establish a connection to the server and error checking */ 137 /* establish a connection to the server and error checking */
93 if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) { 138 if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) {
94 if (mysql_errno (&mysql) == CR_UNKNOWN_HOST) 139 if (mysql_errno (&mysql) == CR_UNKNOWN_HOST)
@@ -118,6 +163,37 @@ main (int argc, char **argv)
118 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql)); 163 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
119 } 164 }
120 165
166 /* try to fetch some perf data */
167 if (mysql_query (&mysql, "show global status") == 0) {
168 if ( (res = mysql_store_result (&mysql)) == NULL) {
169 error = strdup(mysql_error(&mysql));
170 mysql_close (&mysql);
171 die (STATE_CRITICAL, _("status store_result error: %s\n"), error);
172 }
173
174 while ( (row = mysql_fetch_row (res)) != NULL) {
175 int i;
176
177 for(i = 0; i < LENGTH_METRIC_UNIT; i++) {
178 if (strcmp(row[0], metric_unit[i]) == 0) {
179 xasprintf(&perf, "%s%s ", perf, perfdata(metric_unit[i],
180 atol(row[1]), "", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0));
181 continue;
182 }
183 }
184 for(i = 0; i < LENGTH_METRIC_COUNTER; i++) {
185 if (strcmp(row[0], metric_counter[i]) == 0) {
186 xasprintf(&perf, "%s%s ", perf, perfdata(metric_counter[i],
187 atol(row[1]), "c", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0));
188 continue;
189 }
190 }
191 }
192 /* remove trailing space */
193 if (strlen(perf) > 0)
194 perf[strlen(perf) - 1] = '\0';
195 }
196
121 if(check_slave) { 197 if(check_slave) {
122 /* check the slave status */ 198 /* check the slave status */
123 if (mysql_query (&mysql, "show slave status") != 0) { 199 if (mysql_query (&mysql, "show slave status") != 0) {
@@ -210,11 +286,17 @@ main (int argc, char **argv)
210 286
211 status = get_status(value, my_threshold); 287 status = get_status(value, my_threshold);
212 288
289 xasprintf (&perf, "%s %s", perf, fperfdata ("seconds behind master", value, "s",
290 TRUE, (double) warning_time,
291 TRUE, (double) critical_time,
292 FALSE, 0,
293 FALSE, 0));
294
213 if (status == STATE_WARNING) { 295 if (status == STATE_WARNING) {
214 printf("SLOW_SLAVE %s: %s\n", _("WARNING"), slaveresult); 296 printf("SLOW_SLAVE %s: %s|%s\n", _("WARNING"), slaveresult, perf);
215 exit(STATE_WARNING); 297 exit(STATE_WARNING);
216 } else if (status == STATE_CRITICAL) { 298 } else if (status == STATE_CRITICAL) {
217 printf("SLOW_SLAVE %s: %s\n", _("CRITICAL"), slaveresult); 299 printf("SLOW_SLAVE %s: %s|%s\n", _("CRITICAL"), slaveresult, perf);
218 exit(STATE_CRITICAL); 300 exit(STATE_CRITICAL);
219 } 301 }
220 } 302 }
@@ -229,9 +311,9 @@ main (int argc, char **argv)
229 311
230 /* print out the result of stats */ 312 /* print out the result of stats */
231 if (check_slave) { 313 if (check_slave) {
232 printf ("%s %s\n", result, slaveresult); 314 printf ("%s %s|%s\n", result, slaveresult, perf);
233 } else { 315 } else {
234 printf ("%s\n", result); 316 printf ("%s|%s\n", result, perf);
235 } 317 }
236 318
237 return STATE_OK; 319 return STATE_OK;
@@ -253,6 +335,8 @@ process_arguments (int argc, char **argv)
253 {"database", required_argument, 0, 'd'}, 335 {"database", required_argument, 0, 'd'},
254 {"username", required_argument, 0, 'u'}, 336 {"username", required_argument, 0, 'u'},
255 {"password", required_argument, 0, 'p'}, 337 {"password", required_argument, 0, 'p'},
338 {"file", required_argument, 0, 'f'},
339 {"group", required_argument, 0, 'g'},
256 {"port", required_argument, 0, 'P'}, 340 {"port", required_argument, 0, 'P'},
257 {"critical", required_argument, 0, 'c'}, 341 {"critical", required_argument, 0, 'c'},
258 {"warning", required_argument, 0, 'w'}, 342 {"warning", required_argument, 0, 'w'},
@@ -260,6 +344,12 @@ process_arguments (int argc, char **argv)
260 {"verbose", no_argument, 0, 'v'}, 344 {"verbose", no_argument, 0, 'v'},
261 {"version", no_argument, 0, 'V'}, 345 {"version", no_argument, 0, 'V'},
262 {"help", no_argument, 0, 'h'}, 346 {"help", no_argument, 0, 'h'},
347 {"ssl", no_argument, 0, 'l'},
348 {"ca-cert", optional_argument, 0, 'C'},
349 {"key", required_argument,0,'k'},
350 {"cert", required_argument,0,'a'},
351 {"ca-dir", required_argument, 0, 'D'},
352 {"ciphers", required_argument, 0, 'L'},
263 {0, 0, 0, 0} 353 {0, 0, 0, 0}
264 }; 354 };
265 355
@@ -267,7 +357,7 @@ process_arguments (int argc, char **argv)
267 return ERROR; 357 return ERROR;
268 358
269 while (1) { 359 while (1) {
270 c = getopt_long (argc, argv, "hvVSP:p:u:d:H:s:c:w:", longopts, &option); 360 c = getopt_long (argc, argv, "hlvVSP:p:u:d:H:s:c:w:a:k:C:D:L:f:g:", longopts, &option);
271 361
272 if (c == -1 || c == EOF) 362 if (c == -1 || c == EOF)
273 break; 363 break;
@@ -287,6 +377,24 @@ process_arguments (int argc, char **argv)
287 case 'd': /* database */ 377 case 'd': /* database */
288 db = optarg; 378 db = optarg;
289 break; 379 break;
380 case 'l':
381 ssl = true;
382 break;
383 case 'C':
384 ca_cert = optarg;
385 break;
386 case 'a':
387 cert = optarg;
388 break;
389 case 'k':
390 key = optarg;
391 break;
392 case 'D':
393 ca_dir = optarg;
394 break;
395 case 'L':
396 ciphers = optarg;
397 break;
290 case 'u': /* username */ 398 case 'u': /* username */
291 db_user = optarg; 399 db_user = optarg;
292 break; 400 break;
@@ -299,6 +407,12 @@ process_arguments (int argc, char **argv)
299 optarg++; 407 optarg++;
300 } 408 }
301 break; 409 break;
410 case 'f': /* client options file */
411 opt_file = optarg;
412 break;
413 case 'g': /* client options group */
414 opt_group = optarg;
415 break;
302 case 'P': /* critical time threshold */ 416 case 'P': /* critical time threshold */
303 db_port = atoi (optarg); 417 db_port = atoi (optarg);
304 break; 418 break;
@@ -307,9 +421,11 @@ process_arguments (int argc, char **argv)
307 break; 421 break;
308 case 'w': 422 case 'w':
309 warning = optarg; 423 warning = optarg;
424 warning_time = strtod (warning, NULL);
310 break; 425 break;
311 case 'c': 426 case 'c':
312 critical = optarg; 427 critical = optarg;
428 critical_time = strtod (critical, NULL);
313 break; 429 break;
314 case 'V': /* version */ 430 case 'V': /* version */
315 print_revision (progname, NP_VERSION); 431 print_revision (progname, NP_VERSION);
@@ -360,6 +476,12 @@ validate_arguments (void)
360 if (db_user == NULL) 476 if (db_user == NULL)
361 db_user = strdup(""); 477 db_user = strdup("");
362 478
479 if (opt_file == NULL)
480 opt_file = strdup("");
481
482 if (opt_group == NULL)
483 opt_group = strdup("");
484
363 if (db_host == NULL) 485 if (db_host == NULL)
364 db_host = strdup(""); 486 db_host = strdup("");
365 487
@@ -395,6 +517,10 @@ print_help (void)
395 517
396 printf (" %s\n", "-d, --database=STRING"); 518 printf (" %s\n", "-d, --database=STRING");
397 printf (" %s\n", _("Check database with indicated name")); 519 printf (" %s\n", _("Check database with indicated name"));
520 printf (" %s\n", "-f, --file=STRING");
521 printf (" %s\n", _("Read from the specified client options file"));
522 printf (" %s\n", "-g, --group=STRING");
523 printf (" %s\n", _("Use a client options group"));
398 printf (" %s\n", "-u, --username=STRING"); 524 printf (" %s\n", "-u, --username=STRING");
399 printf (" %s\n", _("Connect using the indicated username")); 525 printf (" %s\n", _("Connect using the indicated username"));
400 printf (" %s\n", "-p, --password=STRING"); 526 printf (" %s\n", "-p, --password=STRING");
@@ -409,6 +535,19 @@ print_help (void)
409 printf (" %s\n", "-c, --critical"); 535 printf (" %s\n", "-c, --critical");
410 printf (" %s\n", _("Exit with CRITICAL status if slave server is more then INTEGER seconds")); 536 printf (" %s\n", _("Exit with CRITICAL status if slave server is more then INTEGER seconds"));
411 printf (" %s\n", _("behind master")); 537 printf (" %s\n", _("behind master"));
538 printf (" %s\n", "-l, --ssl");
539 printf (" %s\n", _("Use ssl encryptation"));
540 printf (" %s\n", "-C, --ca-cert=STRING");
541 printf (" %s\n", _("Path to CA signing the cert"));
542 printf (" %s\n", "-a, --cert=STRING");
543 printf (" %s\n", _("Path to SSL certificate"));
544 printf (" %s\n", "-k, --key=STRING");
545 printf (" %s\n", _("Path to private SSL key"));
546 printf (" %s\n", "-D, --ca-dir=STRING");
547 printf (" %s\n", _("Path to CA directory"));
548 printf (" %s\n", "-L, --ciphers=STRING");
549 printf (" %s\n", _("List of valid SSL ciphers"));
550
412 551
413 printf ("\n"); 552 printf ("\n");
414 printf (" %s\n", _("There are no required arguments. By default, the local database is checked")); 553 printf (" %s\n", _("There are no required arguments. By default, the local database is checked"));
@@ -429,5 +568,6 @@ print_usage (void)
429{ 568{
430 printf ("%s\n", _("Usage:")); 569 printf ("%s\n", _("Usage:"));
431 printf (" %s [-d database] [-H host] [-P port] [-s socket]\n",progname); 570 printf (" %s [-d database] [-H host] [-P port] [-s socket]\n",progname);
432 printf (" [-u user] [-p password] [-S]\n"); 571 printf (" [-u user] [-p password] [-S] [-l] [-a cert] [-k key]\n");
572 printf (" [-C ca-cert] [-D ca-dir] [-L ciphers] [-f optfile] [-g group]\n");
433} 573}
diff --git a/plugins/check_nt.c b/plugins/check_nt.c
index 89c4d8d3..52bbd1c5 100644
--- a/plugins/check_nt.c
+++ b/plugins/check_nt.c
@@ -94,6 +94,7 @@ int main(int argc, char **argv){
94 char *description=NULL,*counter_unit = NULL; 94 char *description=NULL,*counter_unit = NULL;
95 char *minval = NULL, *maxval = NULL, *errcvt = NULL; 95 char *minval = NULL, *maxval = NULL, *errcvt = NULL;
96 char *fds=NULL, *tds=NULL; 96 char *fds=NULL, *tds=NULL;
97 char *numstr;
97 98
98 double total_disk_space=0; 99 double total_disk_space=0;
99 double free_disk_space=0; 100 double free_disk_space=0;
@@ -265,7 +266,10 @@ int main(int argc, char **argv){
265 xasprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6, 266 xasprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6,
266 (show_all==TRUE) ? "ShowAll" : "ShowFail",value_list); 267 (show_all==TRUE) ? "ShowAll" : "ShowFail",value_list);
267 fetch_data (server_address, server_port, send_buffer); 268 fetch_data (server_address, server_port, send_buffer);
268 return_code=atoi(strtok(recv_buffer,"&")); 269 numstr = strtok(recv_buffer,"&");
270 if (numstr == NULL)
271 die(STATE_UNKNOWN, _("could not fetch information from server\n"));
272 return_code=atoi(numstr);
269 temp_string=strtok(NULL,"&"); 273 temp_string=strtok(NULL,"&");
270 output_message = strdup (temp_string); 274 output_message = strdup (temp_string);
271 } 275 }
@@ -275,8 +279,14 @@ int main(int argc, char **argv){
275 279
276 xasprintf(&send_buffer,"%s&7", req_password); 280 xasprintf(&send_buffer,"%s&7", req_password);
277 fetch_data (server_address, server_port, send_buffer); 281 fetch_data (server_address, server_port, send_buffer);
278 mem_commitLimit=atof(strtok(recv_buffer,"&")); 282 numstr = strtok(recv_buffer,"&");
279 mem_commitByte=atof(strtok(NULL,"&")); 283 if (numstr == NULL)
284 die(STATE_UNKNOWN, _("could not fetch information from server\n"));
285 mem_commitLimit=atof(numstr);
286 numstr = strtok(NULL,"&");
287 if (numstr == NULL)
288 die(STATE_UNKNOWN, _("could not fetch information from server\n"));
289 mem_commitByte=atof(numstr);
280 percent_used_space = (mem_commitByte / mem_commitLimit) * 100; 290 percent_used_space = (mem_commitByte / mem_commitLimit) * 100;
281 warning_used_space = ((float)warning_value / 100) * mem_commitLimit; 291 warning_used_space = ((float)warning_value / 100) * mem_commitLimit;
282 critical_used_space = ((float)critical_value / 100) * mem_commitLimit; 292 critical_used_space = ((float)critical_value / 100) * mem_commitLimit;
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c
index b59c056d..76152e17 100644
--- a/plugins/check_ntp_peer.c
+++ b/plugins/check_ntp_peer.c
@@ -241,15 +241,19 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji
241 DBG(printf("sending READSTAT request")); 241 DBG(printf("sending READSTAT request"));
242 write(conn, &req, SIZEOF_NTPCM(req)); 242 write(conn, &req, SIZEOF_NTPCM(req));
243 DBG(print_ntp_control_message(&req)); 243 DBG(print_ntp_control_message(&req));
244 /* Attempt to read the largest size packet possible */ 244
245 req.count=htons(MAX_CM_SIZE); 245 do {
246 DBG(printf("recieving READSTAT response")) 246 /* Attempt to read the largest size packet possible */
247 if(read(conn, &req, SIZEOF_NTPCM(req)) == -1) 247 req.count=htons(MAX_CM_SIZE);
248 die(STATE_CRITICAL, "NTP CRITICAL: No response from NTP server\n"); 248 DBG(printf("recieving READSTAT response"))
249 DBG(print_ntp_control_message(&req)); 249 if(read(conn, &req, SIZEOF_NTPCM(req)) == -1)
250 /* discard obviously invalid packets */ 250 die(STATE_CRITICAL, "NTP CRITICAL: No response from NTP server\n");
251 if (ntohs(req.count) > MAX_CM_SIZE) 251 DBG(print_ntp_control_message(&req));
252 die(STATE_CRITICAL, "NTP CRITICAL: Invalid packet received from NTP server\n"); 252 /* discard obviously invalid packets */
253 if (ntohs(req.count) > MAX_CM_SIZE)
254 die(STATE_CRITICAL, "NTP CRITICAL: Invalid packet received from NTP server\n");
255 } while (!(req.op&OP_READSTAT && ntohs(req.seq) == 1));
256
253 if (LI(req.flags) == LI_ALARM) li_alarm = 1; 257 if (LI(req.flags) == LI_ALARM) li_alarm = 1;
254 /* Each peer identifier is 4 bytes in the data section, which 258 /* Each peer identifier is 4 bytes in the data section, which
255 * we represent as a ntp_assoc_status_pair datatype. 259 * we represent as a ntp_assoc_status_pair datatype.
@@ -312,10 +316,12 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji
312 write(conn, &req, SIZEOF_NTPCM(req)); 316 write(conn, &req, SIZEOF_NTPCM(req));
313 DBG(print_ntp_control_message(&req)); 317 DBG(print_ntp_control_message(&req));
314 318
315 req.count = htons(MAX_CM_SIZE); 319 do {
316 DBG(printf("receiving READVAR response...\n")); 320 req.count = htons(MAX_CM_SIZE);
317 read(conn, &req, SIZEOF_NTPCM(req)); 321 DBG(printf("receiving READVAR response...\n"));
318 DBG(print_ntp_control_message(&req)); 322 read(conn, &req, SIZEOF_NTPCM(req));
323 DBG(print_ntp_control_message(&req));
324 } while (!(req.op&OP_READVAR && ntohs(req.seq) == 2));
319 325
320 if(!(req.op&REM_ERROR)) 326 if(!(req.op&REM_ERROR))
321 xasprintf(&data, "%s%s", data, req.data); 327 xasprintf(&data, "%s%s", data, req.data);
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c
index 8b0769f1..8d60701f 100644
--- a/plugins/check_pgsql.c
+++ b/plugins/check_pgsql.c
@@ -3,7 +3,7 @@
3* Nagios check_pgsql plugin 3* Nagios check_pgsql plugin
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 1999-2007 Nagios Plugins Development Team 6* Copyright (c) 1999-2011 Nagios Plugins Development Team
7* 7*
8* Description: 8* Description:
9* 9*
@@ -29,7 +29,7 @@
29*****************************************************************************/ 29*****************************************************************************/
30 30
31const char *progname = "check_pgsql"; 31const char *progname = "check_pgsql";
32const char *copyright = "1999-2007"; 32const char *copyright = "1999-2011";
33const char *email = "nagiosplug-devel@lists.sourceforge.net"; 33const char *email = "nagiosplug-devel@lists.sourceforge.net";
34 34
35#include "common.h" 35#include "common.h"
@@ -42,6 +42,20 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
42#define DEFAULT_DB "template1" 42#define DEFAULT_DB "template1"
43#define DEFAULT_HOST "127.0.0.1" 43#define DEFAULT_HOST "127.0.0.1"
44 44
45/* return the PSQL server version as a 3-tuple */
46#define PSQL_SERVER_VERSION3(server_version) \
47 (server_version) / 10000, \
48 (server_version) / 100 - (int)((server_version) / 10000) * 100, \
49 (server_version) - (int)((server_version) / 100) * 100
50/* return true if the given host is a UNIX domain socket */
51#define PSQL_IS_UNIX_DOMAIN_SOCKET(host) \
52 ((NULL == (host)) || ('\0' == *(host)) || ('/' == *(host)))
53/* return a 3-tuple identifying a host/port independent of the socket type */
54#define PSQL_SOCKET3(host, port) \
55 ((NULL == (host)) || ('\0' == *(host))) ? DEFAULT_PGSOCKET_DIR : host, \
56 PSQL_IS_UNIX_DOMAIN_SOCKET (host) ? "/.s.PGSQL." : ":", \
57 port
58
45enum { 59enum {
46 DEFAULT_PORT = 5432, 60 DEFAULT_PORT = 5432,
47 DEFAULT_WARN = 2, 61 DEFAULT_WARN = 2,
@@ -56,6 +70,7 @@ void print_usage (void);
56void print_help (void); 70void print_help (void);
57int is_pg_dbname (char *); 71int is_pg_dbname (char *);
58int is_pg_logname (char *); 72int is_pg_logname (char *);
73int do_query (PGconn *, char *);
59 74
60char *pghost = NULL; /* host name of the backend server */ 75char *pghost = NULL; /* host name of the backend server */
61char *pgport = NULL; /* port of the backend server */ 76char *pgport = NULL; /* port of the backend server */
@@ -65,14 +80,15 @@ char *pgtty = NULL;
65char dbName[NAMEDATALEN] = DEFAULT_DB; 80char dbName[NAMEDATALEN] = DEFAULT_DB;
66char *pguser = NULL; 81char *pguser = NULL;
67char *pgpasswd = NULL; 82char *pgpasswd = NULL;
83char *pgparams = NULL;
68double twarn = (double)DEFAULT_WARN; 84double twarn = (double)DEFAULT_WARN;
69double tcrit = (double)DEFAULT_CRIT; 85double tcrit = (double)DEFAULT_CRIT;
86char *pgquery = NULL;
87char *query_warning = NULL;
88char *query_critical = NULL;
89thresholds *qthresholds = NULL;
70int verbose = 0; 90int verbose = 0;
71 91
72PGconn *conn;
73/*PGresult *res;*/
74
75
76/****************************************************************************** 92/******************************************************************************
77 93
78The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@ 94The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@
@@ -115,10 +131,6 @@ Please note that all tags must be lowercase to use the DocBook XML DTD.
115<sect2> 131<sect2>
116<title>Future Enhancements</title> 132<title>Future Enhancements</title>
117<para>ToDo List</para> 133<para>ToDo List</para>
118<itemizedlist>
119<listitem>Add option to get password from a secured file rather than the command line</listitem>
120<listitem>Add option to specify the query to execute</listitem>
121</itemizedlist>
122</sect2> 134</sect2>
123 135
124 136
@@ -132,8 +144,14 @@ Please note that all tags must be lowercase to use the DocBook XML DTD.
132int 144int
133main (int argc, char **argv) 145main (int argc, char **argv)
134{ 146{
135 int elapsed_time; 147 PGconn *conn;
148 char *conninfo = NULL;
149
150 struct timeval start_timeval;
151 struct timeval end_timeval;
152 double elapsed_time;
136 int status = STATE_UNKNOWN; 153 int status = STATE_UNKNOWN;
154 int query_status = STATE_UNKNOWN;
137 155
138 /* begin, by setting the parameters for a backend connection if the 156 /* begin, by setting the parameters for a backend connection if the
139 * parameters are null, then the system will try to use reasonable 157 * parameters are null, then the system will try to use reasonable
@@ -161,20 +179,41 @@ main (int argc, char **argv)
161 } 179 }
162 alarm (timeout_interval); 180 alarm (timeout_interval);
163 181
164 if (verbose) 182 if (pgparams)
165 printf("Connecting to database:\n DB: %s\n User: %s\n Host: %s\n Port: %d\n", dbName, 183 asprintf (&conninfo, "%s ", pgparams);
166 (pguser != NULL) ? pguser : "unspecified", 184
167 (pghost != NULL) ? pghost : "unspecified", 185 asprintf (&conninfo, "%sdbname = '%s'", conninfo ? conninfo : "", dbName);
168 (pgport != NULL) ? atoi(pgport) : DEFAULT_PORT); 186 if (pghost)
187 asprintf (&conninfo, "%s host = '%s'", conninfo, pghost);
188 if (pgport)
189 asprintf (&conninfo, "%s port = '%s'", conninfo, pgport);
190 if (pgoptions)
191 asprintf (&conninfo, "%s options = '%s'", conninfo, pgoptions);
192 /* if (pgtty) -- ignored by PQconnectdb */
193 if (pguser)
194 asprintf (&conninfo, "%s user = '%s'", conninfo, pguser);
195
196 if (verbose) /* do not include password (see right below) in output */
197 printf ("Connecting to PostgreSQL using conninfo: %s%s\n", conninfo,
198 pgpasswd ? " password = <hidden>" : "");
199
200 if (pgpasswd)
201 asprintf (&conninfo, "%s password = '%s'", conninfo, pgpasswd);
169 202
170 /* make a connection to the database */ 203 /* make a connection to the database */
171 time (&start_time); 204 gettimeofday (&start_timeval, NULL);
172 conn = 205 conn = PQconnectdb (conninfo);
173 PQsetdbLogin (pghost, pgport, pgoptions, pgtty, dbName, pguser, pgpasswd); 206 gettimeofday (&end_timeval, NULL);
174 time (&end_time); 207
175 elapsed_time = (int) (end_time - start_time); 208 while (start_timeval.tv_usec > end_timeval.tv_usec) {
209 --end_timeval.tv_sec;
210 end_timeval.tv_usec += 1000000;
211 }
212 elapsed_time = (double)(end_timeval.tv_sec - start_timeval.tv_sec)
213 + (double)(end_timeval.tv_usec - start_timeval.tv_usec) / 1000000.0;
214
176 if (verbose) 215 if (verbose)
177 printf("Time elapsed: %d\n", elapsed_time); 216 printf("Time elapsed: %f\n", elapsed_time);
178 217
179 /* check to see that the backend connection was successfully made */ 218 /* check to see that the backend connection was successfully made */
180 if (verbose) 219 if (verbose)
@@ -194,14 +233,32 @@ main (int argc, char **argv)
194 else { 233 else {
195 status = STATE_OK; 234 status = STATE_OK;
196 } 235 }
236
237 if (verbose) {
238 char *server_host = PQhost (conn);
239 int server_version = PQserverVersion (conn);
240
241 printf ("Successfully connected to database %s (user %s) "
242 "at server %s%s%s (server version: %d.%d.%d, "
243 "protocol version: %d, pid: %d)\n",
244 PQdb (conn), PQuser (conn),
245 PSQL_SOCKET3 (server_host, PQport (conn)),
246 PSQL_SERVER_VERSION3 (server_version),
247 PQprotocolVersion (conn), PQbackendPID (conn));
248 }
249
250 printf (_(" %s - database %s (%f sec.)|%s\n"),
251 state_text(status), dbName, elapsed_time,
252 fperfdata("time", elapsed_time, "s",
253 !!(twarn > 0.0), twarn, !!(tcrit > 0.0), tcrit, TRUE, 0, FALSE,0));
254
255 if (pgquery)
256 query_status = do_query (conn, pgquery);
257
197 if (verbose) 258 if (verbose)
198 printf("Closing connection\n"); 259 printf("Closing connection\n");
199 PQfinish (conn); 260 PQfinish (conn);
200 printf (_(" %s - database %s (%d sec.)|%s\n"), 261 return (query_status > status) ? query_status : status;
201 state_text(status), dbName, elapsed_time,
202 fperfdata("time", elapsed_time, "s",
203 (int)twarn, twarn, (int)tcrit, tcrit, TRUE, 0, FALSE,0));
204 return status;
205} 262}
206 263
207 264
@@ -225,12 +282,16 @@ process_arguments (int argc, char **argv)
225 {"authorization", required_argument, 0, 'a'}, 282 {"authorization", required_argument, 0, 'a'},
226 {"port", required_argument, 0, 'P'}, 283 {"port", required_argument, 0, 'P'},
227 {"database", required_argument, 0, 'd'}, 284 {"database", required_argument, 0, 'd'},
285 {"option", required_argument, 0, 'o'},
286 {"query", required_argument, 0, 'q'},
287 {"query_critical", required_argument, 0, 'C'},
288 {"query_warning", required_argument, 0, 'W'},
228 {"verbose", no_argument, 0, 'v'}, 289 {"verbose", no_argument, 0, 'v'},
229 {0, 0, 0, 0} 290 {0, 0, 0, 0}
230 }; 291 };
231 292
232 while (1) { 293 while (1) {
233 c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:v", 294 c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:o:q:C:W:v",
234 longopts, &option); 295 longopts, &option);
235 296
236 if (c == EOF) 297 if (c == EOF)
@@ -263,8 +324,14 @@ process_arguments (int argc, char **argv)
263 else 324 else
264 twarn = strtod (optarg, NULL); 325 twarn = strtod (optarg, NULL);
265 break; 326 break;
327 case 'C': /* critical query threshold */
328 query_critical = optarg;
329 break;
330 case 'W': /* warning query threshold */
331 query_warning = optarg;
332 break;
266 case 'H': /* host */ 333 case 'H': /* host */
267 if (!is_host (optarg)) 334 if ((*optarg != '/') && (!is_host (optarg)))
268 usage2 (_("Invalid hostname/address"), optarg); 335 usage2 (_("Invalid hostname/address"), optarg);
269 else 336 else
270 pghost = optarg; 337 pghost = optarg;
@@ -291,12 +358,23 @@ process_arguments (int argc, char **argv)
291 case 'a': 358 case 'a':
292 pgpasswd = optarg; 359 pgpasswd = optarg;
293 break; 360 break;
361 case 'o':
362 if (pgparams)
363 asprintf (&pgparams, "%s %s", pgparams, optarg);
364 else
365 asprintf (&pgparams, "%s", optarg);
366 break;
367 case 'q':
368 pgquery = optarg;
369 break;
294 case 'v': 370 case 'v':
295 verbose++; 371 verbose++;
296 break; 372 break;
297 } 373 }
298 } 374 }
299 375
376 set_thresholds (&qthresholds, query_warning, query_critical);
377
300 return validate_arguments (); 378 return validate_arguments ();
301} 379}
302 380
@@ -434,8 +512,6 @@ print_help (void)
434 512
435 printf (UT_HOST_PORT, 'P', myport); 513 printf (UT_HOST_PORT, 'P', myport);
436 514
437 printf (UT_IPv46);
438
439 printf (" %s\n", "-d, --database=STRING"); 515 printf (" %s\n", "-d, --database=STRING");
440 printf (" %s", _("Database to check ")); 516 printf (" %s", _("Database to check "));
441 printf (_("(default: %s)"), DEFAULT_DB); 517 printf (_("(default: %s)"), DEFAULT_DB);
@@ -443,11 +519,20 @@ print_help (void)
443 printf (" %s\n", _("Login name of user")); 519 printf (" %s\n", _("Login name of user"));
444 printf (" %s\n", "-p, --password = STRING"); 520 printf (" %s\n", "-p, --password = STRING");
445 printf (" %s\n", _("Password (BIG SECURITY ISSUE)")); 521 printf (" %s\n", _("Password (BIG SECURITY ISSUE)"));
522 printf (" %s\n", "-o, --option = STRING");
523 printf (" %s\n", _("Connection parameters (keyword = value), see below"));
446 524
447 printf (UT_WARN_CRIT); 525 printf (UT_WARN_CRIT);
448 526
449 printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 527 printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
450 528
529 printf (" %s\n", "-q, --query=STRING");
530 printf (" %s\n", _("SQL query to run. Only first column in first row will be read"));
531 printf (" %s\n", "-W, --query-warning=RANGE");
532 printf (" %s\n", _("SQL query value to result in warning status (double)"));
533 printf (" %s\n", "-C, --query-critical=RANGE");
534 printf (" %s\n", _("SQL query value to result in critical status (double)"));
535
451 printf (UT_VERBOSE); 536 printf (UT_VERBOSE);
452 537
453 printf ("\n"); 538 printf ("\n");
@@ -458,6 +543,22 @@ print_help (void)
458 printf (" %s\n", _("connects to the template1 database, which is present in every functioning")); 543 printf (" %s\n", _("connects to the template1 database, which is present in every functioning"));
459 printf (" %s\n\n", _("PostgreSQL DBMS.")); 544 printf (" %s\n\n", _("PostgreSQL DBMS."));
460 545
546 printf (" %s\n", _("If a query is specified using the -q option, it will be executed after"));
547 printf (" %s\n", _("connecting to the server. The result from the query has to be numeric."));
548 printf (" %s\n", _("Multiple SQL commands, separated by semicolon, are allowed but the result "));
549 printf (" %s\n", _("of the last command is taken into account only. The value of the first"));
550 printf (" %s\n\n", _("column in the first row is used as the check result."));
551
552 printf (" %s\n", _("See the chapter \"Monitoring Database Activity\" of the PostgreSQL manual"));
553 printf (" %s\n\n", _("for details about how to access internal statistics of the database server."));
554
555 printf (" %s\n", _("For a list of available connection parameters which may be used with the -o"));
556 printf (" %s\n", _("command line option, see the documentation for PQconnectdb() in the chapter"));
557 printf (" %s\n", _("\"libpq - C Library\" of the PostgreSQL manual. For example, this may be"));
558 printf (" %s\n", _("used to specify a service name in pg_service.conf to be used for additional"));
559 printf (" %s\n", _("connection parameters: -o 'service=<name>' or to specify the SSL mode:"));
560 printf (" %s\n\n", _("-o 'sslmode=require'."));
561
461 printf (" %s\n", _("The plugin will connect to a local postmaster if no host is specified. To")); 562 printf (" %s\n", _("The plugin will connect to a local postmaster if no host is specified. To"));
462 printf (" %s\n", _("connect to a remote host, be sure that the remote postmaster accepts TCP/IP")); 563 printf (" %s\n", _("connect to a remote host, be sure that the remote postmaster accepts TCP/IP"));
463 printf (" %s\n\n", _("connections (start the postmaster with the -i option).")); 564 printf (" %s\n\n", _("connections (start the postmaster with the -i option)."));
@@ -475,6 +576,75 @@ void
475print_usage (void) 576print_usage (void)
476{ 577{
477 printf ("%s\n", _("Usage:")); 578 printf ("%s\n", _("Usage:"));
478 printf ("%s [-H <host>] [-4|-6] [-P <port>] [-c <critical time>] [-w <warning time>]\n", progname); 579 printf ("%s [-H <host>] [-P <port>] [-c <critical time>] [-w <warning time>]\n", progname);
479 printf (" [-t <timeout>] [-d <database>] [-l <logname>] [-p <password>]\n"); 580 printf (" [-t <timeout>] [-d <database>] [-l <logname>] [-p <password>]\n"
581 "[-q <query>] [-C <critical query range>] [-W <warning query range>]\n");
480} 582}
583
584int
585do_query (PGconn *conn, char *query)
586{
587 PGresult *res;
588
589 char *val_str;
590 double value;
591
592 char *endptr = NULL;
593
594 int my_status = STATE_UNKNOWN;
595
596 if (verbose)
597 printf ("Executing SQL query \"%s\".\n", query);
598 res = PQexec (conn, query);
599
600 if (PGRES_TUPLES_OK != PQresultStatus (res)) {
601 printf (_("QUERY %s - %s: %s.\n"), _("CRITICAL"), _("Error with query"),
602 PQerrorMessage (conn));
603 return STATE_CRITICAL;
604 }
605
606 if (PQntuples (res) < 1) {
607 printf ("QUERY %s - %s.\n", _("WARNING"), _("No rows returned"));
608 return STATE_WARNING;
609 }
610
611 if (PQnfields (res) < 1) {
612 printf ("QUERY %s - %s.\n", _("WARNING"), _("No columns returned"));
613 return STATE_WARNING;
614 }
615
616 val_str = PQgetvalue (res, 0, 0);
617 if (! val_str) {
618 printf ("QUERY %s - %s.\n", _("CRITICAL"), _("No data returned"));
619 return STATE_CRITICAL;
620 }
621
622 value = strtod (val_str, &endptr);
623 if (verbose)
624 printf ("Query result: %f\n", value);
625
626 if (endptr == val_str) {
627 printf ("QUERY %s - %s: %s\n", _("CRITICAL"), _("Is not a numeric"), val_str);
628 return STATE_CRITICAL;
629 }
630 else if ((endptr != NULL) && (*endptr != '\0')) {
631 if (verbose)
632 printf ("Garbage after value: %s.\n", endptr);
633 }
634
635 my_status = get_status (value, qthresholds);
636 printf ("QUERY %s - ",
637 (my_status == STATE_OK)
638 ? _("OK")
639 : (my_status == STATE_WARNING)
640 ? _("WARNING")
641 : (my_status == STATE_CRITICAL)
642 ? _("CRITICAL")
643 : _("UNKNOWN"));
644 printf (_("'%s' returned %f"), query, value);
645 printf ("|query=%f;%s;%s;;\n", value,
646 query_warning ? query_warning : "",
647 query_critical ? query_critical : "");
648 return my_status;
649}
650
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 6acedc70..d09bd8b6 100644
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
@@ -42,6 +42,11 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
42#include "regex.h" 42#include "regex.h"
43 43
44#include <pwd.h> 44#include <pwd.h>
45#include <errno.h>
46
47#ifdef HAVE_SYS_STAT_H
48#include <sys/stat.h>
49#endif
45 50
46int process_arguments (int, char **); 51int process_arguments (int, char **);
47int validate_arguments (void); 52int validate_arguments (void);
@@ -65,6 +70,10 @@ int options = 0; /* bitmask of filter criteria to test against */
65#define PCPU 256 70#define PCPU 256
66#define ELAPSED 512 71#define ELAPSED 512
67#define EREG_ARGS 1024 72#define EREG_ARGS 1024
73
74#define KTHREAD_PARENT "kthreadd" /* the parent process of kernel threads:
75 ppid of procs are compared to pid of this proc*/
76
68/* Different metrics */ 77/* Different metrics */
69char *metric_name; 78char *metric_name;
70enum metric { 79enum metric {
@@ -90,9 +99,21 @@ regex_t re_args;
90char *fmt; 99char *fmt;
91char *fails; 100char *fails;
92char tmp[MAX_INPUT_BUFFER]; 101char tmp[MAX_INPUT_BUFFER];
102int kthread_filter = 0;
103int usepid = 0; /* whether to test for pid or /proc/pid/exe */
93 104
94FILE *ps_input = NULL; 105FILE *ps_input = NULL;
95 106
107static int
108stat_exe (const pid_t pid, struct stat *buf) {
109 char *path;
110 int ret;
111 xasprintf(&path, "/proc/%d/exe", pid);
112 ret = stat(path, buf);
113 free(path);
114 return ret;
115}
116
96 117
97int 118int
98main (int argc, char **argv) 119main (int argc, char **argv)
@@ -102,9 +123,13 @@ main (int argc, char **argv)
102 char *procprog; 123 char *procprog;
103 124
104 pid_t mypid = 0; 125 pid_t mypid = 0;
126 struct stat statbuf;
127 dev_t mydev = 0;
128 ino_t myino = 0;
105 int procuid = 0; 129 int procuid = 0;
106 pid_t procpid = 0; 130 pid_t procpid = 0;
107 pid_t procppid = 0; 131 pid_t procppid = 0;
132 pid_t kthread_ppid = 0;
108 int procvsz = 0; 133 int procvsz = 0;
109 int procrss = 0; 134 int procrss = 0;
110 int procseconds = 0; 135 int procseconds = 0;
@@ -125,6 +150,7 @@ main (int argc, char **argv)
125 int crit = 0; /* number of processes in crit state */ 150 int crit = 0; /* number of processes in crit state */
126 int i = 0, j = 0; 151 int i = 0, j = 0;
127 int result = STATE_UNKNOWN; 152 int result = STATE_UNKNOWN;
153 int ret;
128 output chld_out, chld_err; 154 output chld_out, chld_err;
129 155
130 setlocale (LC_ALL, ""); 156 setlocale (LC_ALL, "");
@@ -144,8 +170,16 @@ main (int argc, char **argv)
144 if (process_arguments (argc, argv) == ERROR) 170 if (process_arguments (argc, argv) == ERROR)
145 usage4 (_("Could not parse arguments")); 171 usage4 (_("Could not parse arguments"));
146 172
147 /* get our pid */ 173 /* find ourself */
148 mypid = getpid(); 174 mypid = getpid();
175 if (usepid || stat_exe(mypid, &statbuf) == -1) {
176 /* usepid might have been set by -T */
177 usepid = 1;
178 } else {
179 usepid = 0;
180 mydev = statbuf.st_dev;
181 myino = statbuf.st_ino;
182 }
149 183
150 /* Set signal handling and alarm timeout */ 184 /* Set signal handling and alarm timeout */
151 if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) { 185 if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) {
@@ -200,7 +234,28 @@ main (int argc, char **argv)
200 procetime, procprog, procargs); 234 procetime, procprog, procargs);
201 235
202 /* Ignore self */ 236 /* Ignore self */
203 if (mypid == procpid) continue; 237 if ((usepid && mypid == procpid) ||
238 (!usepid && ((ret = stat_exe(procpid, &statbuf) != -1) && statbuf.st_dev == mydev && statbuf.st_ino == myino) ||
239 (ret == -1 && errno == ENOENT))) {
240 if (verbose >= 3)
241 printf("not considering - is myself or gone\n");
242 continue;
243 }
244
245 /* filter kernel threads (childs of KTHREAD_PARENT)*/
246 /* TODO adapt for other OSes than GNU/Linux
247 sorry for not doing that, but I've no other OSes to test :-( */
248 if (kthread_filter == 1) {
249 /* get pid KTHREAD_PARENT */
250 if (kthread_ppid == 0 && !strcmp(procprog, KTHREAD_PARENT) )
251 kthread_ppid = procpid;
252
253 if (kthread_ppid == procppid) {
254 if (verbose >= 2)
255 printf ("Ignore kernel thread: pid=%d ppid=%d prog=%s args=%s\n", procpid, procppid, procprog, procargs);
256 continue;
257 }
258 }
204 259
205 if ((options & STAT) && (strstr (statopts, procstat))) 260 if ((options & STAT) && (strstr (statopts, procstat)))
206 resultsum |= STAT; 261 resultsum |= STAT;
@@ -344,6 +399,8 @@ process_arguments (int argc, char **argv)
344 {"verbose", no_argument, 0, 'v'}, 399 {"verbose", no_argument, 0, 'v'},
345 {"ereg-argument-array", required_argument, 0, CHAR_MAX+1}, 400 {"ereg-argument-array", required_argument, 0, CHAR_MAX+1},
346 {"input-file", required_argument, 0, CHAR_MAX+2}, 401 {"input-file", required_argument, 0, CHAR_MAX+2},
402 {"no-kthreads", required_argument, 0, 'k'},
403 {"traditional-filter", no_argument, 0, 'T'},
347 {0, 0, 0, 0} 404 {0, 0, 0, 0}
348 }; 405 };
349 406
@@ -352,7 +409,7 @@ process_arguments (int argc, char **argv)
352 strcpy (argv[c], "-t"); 409 strcpy (argv[c], "-t");
353 410
354 while (1) { 411 while (1) {
355 c = getopt_long (argc, argv, "Vvht:c:w:p:s:u:C:a:z:r:m:P:", 412 c = getopt_long (argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:T",
356 longopts, &option); 413 longopts, &option);
357 414
358 if (c == -1 || c == EOF) 415 if (c == -1 || c == EOF)
@@ -496,9 +553,15 @@ process_arguments (int argc, char **argv)
496 } 553 }
497 554
498 usage4 (_("Metric must be one of PROCS, VSZ, RSS, CPU, ELAPSED!")); 555 usage4 (_("Metric must be one of PROCS, VSZ, RSS, CPU, ELAPSED!"));
556 case 'k': /* linux kernel thread filter */
557 kthread_filter = 1;
558 break;
499 case 'v': /* command */ 559 case 'v': /* command */
500 verbose++; 560 verbose++;
501 break; 561 break;
562 case 'T':
563 usepid = 1;
564 break;
502 case CHAR_MAX+2: 565 case CHAR_MAX+2:
503 input_filename = optarg; 566 input_filename = optarg;
504 break; 567 break;
@@ -649,6 +712,9 @@ print_help (void)
649 printf (" %s\n", "-v, --verbose"); 712 printf (" %s\n", "-v, --verbose");
650 printf (" %s\n", _("Extra information. Up to 3 verbosity levels")); 713 printf (" %s\n", _("Extra information. Up to 3 verbosity levels"));
651 714
715 printf (" %s\n", "-T, --traditional");
716 printf (" %s\n", _("Filter own process the traditional way by PID instead of /proc/pid/exe"));
717
652 printf ("\n"); 718 printf ("\n");
653 printf ("%s\n", "Filters:"); 719 printf ("%s\n", "Filters:");
654 printf (" %s\n", "-s, --state=STATUSFLAGS"); 720 printf (" %s\n", "-s, --state=STATUSFLAGS");
@@ -671,6 +737,8 @@ print_help (void)
671 printf (" %s\n", _("Only scan for processes with args that contain the regex STRING.")); 737 printf (" %s\n", _("Only scan for processes with args that contain the regex STRING."));
672 printf (" %s\n", "-C, --command=COMMAND"); 738 printf (" %s\n", "-C, --command=COMMAND");
673 printf (" %s\n", _("Only scan for exact matches of COMMAND (without path).")); 739 printf (" %s\n", _("Only scan for exact matches of COMMAND (without path)."));
740 printf (" %s\n", "-k, --no-kthreads");
741 printf (" %s\n", _("Only scan for non kernel threads (works on Linux only)."));
674 742
675 printf(_("\n\ 743 printf(_("\n\
676RANGEs are specified 'min:max' or 'min:' or ':max' (or 'max'). If\n\ 744RANGEs are specified 'min:max' or 'min:' or ':max' (or 'max'). If\n\
@@ -705,5 +773,5 @@ print_usage (void)
705 printf ("%s\n", _("Usage:")); 773 printf ("%s\n", _("Usage:"));
706 printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n", progname); 774 printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n", progname);
707 printf (" [-u user] [-r rss] [-z vsz] [-P %%cpu] [-a argument-array]\n"); 775 printf (" [-u user] [-r rss] [-z vsz] [-P %%cpu] [-a argument-array]\n");
708 printf (" [-C command] [-t timeout] [-v]\n"); 776 printf (" [-C command] [-k] [-t timeout] [-v]\n");
709} 777}
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index 79fa4824..d477a51e 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -99,9 +99,9 @@ char **responses = NULL;
99char *authtype = NULL; 99char *authtype = NULL;
100char *authuser = NULL; 100char *authuser = NULL;
101char *authpass = NULL; 101char *authpass = NULL;
102int warning_time = 0; 102double warning_time = 0;
103int check_warning_time = FALSE; 103int check_warning_time = FALSE;
104int critical_time = 0; 104double critical_time = 0;
105int check_critical_time = FALSE; 105int check_critical_time = FALSE;
106int verbose = 0; 106int verbose = 0;
107int use_ssl = FALSE; 107int use_ssl = FALSE;
@@ -417,9 +417,9 @@ main (int argc, char **argv)
417 elapsed_time = (double)microsec / 1.0e6; 417 elapsed_time = (double)microsec / 1.0e6;
418 418
419 if (result == STATE_OK) { 419 if (result == STATE_OK) {
420 if (check_critical_time && elapsed_time > (double) critical_time) 420 if (check_critical_time && elapsed_time > critical_time)
421 result = STATE_CRITICAL; 421 result = STATE_CRITICAL;
422 else if (check_warning_time && elapsed_time > (double) warning_time) 422 else if (check_warning_time && elapsed_time > warning_time)
423 result = STATE_WARNING; 423 result = STATE_WARNING;
424 } 424 }
425 425
@@ -552,21 +552,19 @@ process_arguments (int argc, char **argv)
552 nresponses++; 552 nresponses++;
553 break; 553 break;
554 case 'c': /* critical time threshold */ 554 case 'c': /* critical time threshold */
555 if (is_intnonneg (optarg)) { 555 if (!is_nonnegative (optarg))
556 critical_time = atoi (optarg); 556 usage4 (_("Critical time must be a positive"));
557 check_critical_time = TRUE;
558 }
559 else { 557 else {
560 usage4 (_("Critical time must be a positive integer")); 558 critical_time = strtod (optarg, NULL);
559 check_critical_time = TRUE;
561 } 560 }
562 break; 561 break;
563 case 'w': /* warning time threshold */ 562 case 'w': /* warning time threshold */
564 if (is_intnonneg (optarg)) { 563 if (!is_nonnegative (optarg))
565 warning_time = atoi (optarg); 564 usage4 (_("Warning time must be a positive"));
566 check_warning_time = TRUE;
567 }
568 else { 565 else {
569 usage4 (_("Warning time must be a positive integer")); 566 warning_time = strtod (optarg, NULL);
567 check_warning_time = TRUE;
570 } 568 }
571 break; 569 break;
572 case 'v': /* verbose */ 570 case 'v': /* verbose */
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 7c5d0ec5..7c3bc4b9 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -63,6 +63,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
63#define L_CALCULATE_RATE CHAR_MAX+1 63#define L_CALCULATE_RATE CHAR_MAX+1
64#define L_RATE_MULTIPLIER CHAR_MAX+2 64#define L_RATE_MULTIPLIER CHAR_MAX+2
65#define L_INVERT_SEARCH CHAR_MAX+3 65#define L_INVERT_SEARCH CHAR_MAX+3
66#define L_OFFSET CHAR_MAX+4
66 67
67/* Gobble to string - stop incrementing c when c[0] match one of the 68/* Gobble to string - stop incrementing c when c[0] match one of the
68 * characters in s */ 69 * characters in s */
@@ -138,6 +139,7 @@ char *output_delim;
138char *miblist = NULL; 139char *miblist = NULL;
139int needmibs = FALSE; 140int needmibs = FALSE;
140int calculate_rate = 0; 141int calculate_rate = 0;
142double offset = 0.0;
141int rate_multiplier = 1; 143int rate_multiplier = 1;
142state_data *previous_state; 144state_data *previous_state;
143double previous_value[MAX_OIDS]; 145double previous_value[MAX_OIDS];
@@ -274,35 +276,36 @@ main (int argc, char **argv)
274 snmpcmd = strdup (PATH_TO_SNMPGET); 276 snmpcmd = strdup (PATH_TO_SNMPGET);
275 } 277 }
276 278
277 /* 9 arguments to pass before authpriv options + 1 for host and numoids. Add one for terminating NULL */ 279 /* 10 arguments to pass before authpriv options + 1 for host and numoids. Add one for terminating NULL */
278 command_line = calloc (9 + numauthpriv + 1 + numoids + 1, sizeof (char *)); 280 command_line = calloc (10 + numauthpriv + 1 + numoids + 1, sizeof (char *));
279 command_line[0] = snmpcmd; 281 command_line[0] = snmpcmd;
280 command_line[1] = strdup ("-t"); 282 command_line[1] = strdup ("-Le");
281 xasprintf (&command_line[2], "%d", timeout_interval); 283 command_line[2] = strdup ("-t");
282 command_line[3] = strdup ("-r"); 284 xasprintf (&command_line[3], "%d", timeout_interval);
283 xasprintf (&command_line[4], "%d", retries); 285 command_line[4] = strdup ("-r");
284 command_line[5] = strdup ("-m"); 286 xasprintf (&command_line[5], "%d", retries);
285 command_line[6] = strdup (miblist); 287 command_line[6] = strdup ("-m");
286 command_line[7] = "-v"; 288 command_line[7] = strdup (miblist);
287 command_line[8] = strdup (proto); 289 command_line[8] = "-v";
290 command_line[9] = strdup (proto);
288 291
289 for (i = 0; i < numauthpriv; i++) { 292 for (i = 0; i < numauthpriv; i++) {
290 command_line[9 + i] = authpriv[i]; 293 command_line[10 + i] = authpriv[i];
291 } 294 }
292 295
293 xasprintf (&command_line[9 + numauthpriv], "%s:%s", server_address, port); 296 xasprintf (&command_line[10 + numauthpriv], "%s:%s", server_address, port);
294 297
295 /* This is just for display purposes, so it can remain a string */ 298 /* This is just for display purposes, so it can remain a string */
296 xasprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s", 299 xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s:%s",
297 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]", 300 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]",
298 server_address, port); 301 server_address, port);
299 302
300 for (i = 0; i < numoids; i++) { 303 for (i = 0; i < numoids; i++) {
301 command_line[9 + numauthpriv + 1 + i] = oids[i]; 304 command_line[10 + numauthpriv + 1 + i] = oids[i];
302 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); 305 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
303 } 306 }
304 307
305 command_line[9 + numauthpriv + 1 + numoids] = NULL; 308 command_line[10 + numauthpriv + 1 + numoids] = NULL;
306 309
307 if (verbose) 310 if (verbose)
308 printf ("%s\n", cl_hidden_auth); 311 printf ("%s\n", cl_hidden_auth);
@@ -429,7 +432,7 @@ main (int argc, char **argv)
429 ptr = strpbrk (show, "0123456789"); 432 ptr = strpbrk (show, "0123456789");
430 if (ptr == NULL) 433 if (ptr == NULL)
431 die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); 434 die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show);
432 response_value[i] = strtod (ptr, NULL); 435 response_value[i] = strtod (ptr, NULL) + offset;
433 436
434 if(calculate_rate) { 437 if(calculate_rate) {
435 if (previous_state!=NULL) { 438 if (previous_state!=NULL) {
@@ -618,6 +621,7 @@ process_arguments (int argc, char **argv)
618 {"next", no_argument, 0, 'n'}, 621 {"next", no_argument, 0, 'n'},
619 {"rate", no_argument, 0, L_CALCULATE_RATE}, 622 {"rate", no_argument, 0, L_CALCULATE_RATE},
620 {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER}, 623 {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER},
624 {"offset", required_argument, 0, L_OFFSET},
621 {"invert-search", no_argument, 0, L_INVERT_SEARCH}, 625 {"invert-search", no_argument, 0, L_INVERT_SEARCH},
622 {"perf-oids", no_argument, 0, 'O'}, 626 {"perf-oids", no_argument, 0, 'O'},
623 {0, 0, 0, 0} 627 {0, 0, 0, 0}
@@ -832,6 +836,9 @@ process_arguments (int argc, char **argv)
832 if(!is_integer(optarg)||((rate_multiplier=atoi(optarg))<=0)) 836 if(!is_integer(optarg)||((rate_multiplier=atoi(optarg))<=0))
833 usage2(_("Rate multiplier must be a positive integer"),optarg); 837 usage2(_("Rate multiplier must be a positive integer"),optarg);
834 break; 838 break;
839 case L_OFFSET:
840 offset=strtod(optarg,NULL);
841 break;
835 case L_INVERT_SEARCH: 842 case L_INVERT_SEARCH:
836 invert_search=1; 843 invert_search=1;
837 break; 844 break;
@@ -1080,6 +1087,8 @@ print_help (void)
1080 printf (" %s\n", _("Enable rate calculation. See 'Rate Calculation' below")); 1087 printf (" %s\n", _("Enable rate calculation. See 'Rate Calculation' below"));
1081 printf (" %s\n", "--rate-multiplier"); 1088 printf (" %s\n", "--rate-multiplier");
1082 printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute")); 1089 printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute"));
1090 printf (" %s\n", "--offset=OFFSET");
1091 printf (" %s\n", _("Add/substract the specified OFFSET to numeric sensor data"));
1083 1092
1084 /* Tests Against Strings */ 1093 /* Tests Against Strings */
1085 printf (" %s\n", "-s, --string=STRING"); 1094 printf (" %s\n", "-s, --string=STRING");
diff --git a/plugins/t/check_apt.t b/plugins/t/check_apt.t
index 71230979..9ba0ff8e 100644
--- a/plugins/t/check_apt.t
+++ b/plugins/t/check_apt.t
@@ -18,8 +18,8 @@ sub make_result_regexp {
18 } else { 18 } else {
19 $status = "CRITICAL"; 19 $status = "CRITICAL";
20 } 20 }
21 return sprintf('/^APT %s: %d packages available for upgrade \(%d critical updates\).\s*$/', 21 return sprintf('/^APT %s: %d packages available for upgrade \(%d critical updates\)\. |available_upgrades=%d;;;0 critical_updates=%d;;;0$/',
22 $status, $warning, $critical); 22 $status, $warning, $critical, $warning, $critical);
23} 23}
24 24
25if (-x "./check_apt") { 25if (-x "./check_apt") {
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index 0a25c775..9948c539 100644
--- a/plugins/t/check_http.t
+++ b/plugins/t/check_http.t
@@ -8,22 +8,22 @@ use strict;
8use Test::More; 8use Test::More;
9use NPTest; 9use NPTest;
10 10
11plan tests => 28; 11plan tests => 30;
12 12
13my $successOutput = '/OK.*HTTP.*second/'; 13my $successOutput = '/OK.*HTTP.*second/';
14 14
15my $res; 15my $res;
16 16
17my $host_tcp_http = getTestParameter( "NP_HOST_TCP_HTTP", 17my $host_tcp_http = getTestParameter( "NP_HOST_TCP_HTTP",
18 "A host providing the HTTP Service (a web server)", 18 "A host providing the HTTP Service (a web server)",
19 "localhost" ); 19 "localhost" );
20 20
21my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", 21my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
22 "The hostname of system not responsive to network requests", 22 "The hostname of system not responsive to network requests",
23 "10.0.0.1" ); 23 "10.0.0.1" );
24 24
25my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", 25my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
26 "An invalid (not known to DNS) hostname", 26 "An invalid (not known to DNS) hostname",
27 "nosuchhost"); 27 "nosuchhost");
28 28
29my $internet_access = getTestParameter( "NP_INTERNET_ACCESS", 29my $internet_access = getTestParameter( "NP_INTERNET_ACCESS",
@@ -32,8 +32,8 @@ my $internet_access = getTestParameter( "NP_INTERNET_ACCESS",
32 32
33my $host_tcp_http2; 33my $host_tcp_http2;
34if ($internet_access eq "no") { 34if ($internet_access eq "no") {
35 $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2", 35 $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2",
36 "A host providing an index page containing the string 'nagios'", 36 "A host providing an index page containing the string 'nagios'",
37 "www.nagios.com" ); 37 "www.nagios.com" );
38} 38}
39 39
@@ -45,14 +45,9 @@ cmp_ok( $res->return_code, '==', 0, "Webserver $host_tcp_http responded" );
45like( $res->output, $successOutput, "Output OK" ); 45like( $res->output, $successOutput, "Output OK" );
46 46
47$res = NPTest->testCmd( 47$res = NPTest->testCmd(
48 "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there;fred:here'" 48 "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there' -k 'carl:frown'"
49 ); 49 );
50like( $res->output, '/bob:there\r\nfred:here\r\n/', "Got headers, delimited with ';'" ); 50like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" );
51
52$res = NPTest->testCmd(
53 "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there;fred:here' -k 'carl:frown'"
54 );
55like( $res->output, '/bob:there\r\nfred:here\r\ncarl:frown\r\n/', "Got headers with multiple -k options" );
56 51
57$res = NPTest->testCmd( 52$res = NPTest->testCmd(
58 "./check_http $host_nonresponsive -wt 1 -ct 2" 53 "./check_http $host_nonresponsive -wt 1 -ct 2"
@@ -123,6 +118,10 @@ SKIP: {
123 $res = NPTest->testCmd( "./check_http www.verisign.com -C 1" ); 118 $res = NPTest->testCmd( "./check_http www.verisign.com -C 1" );
124 cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works"); 119 cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works");
125 120
121 $res = NPTest->testCmd( "./check_http --ssl www.verisign.com -E" );
122 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
123 like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' );
124
126 $res = NPTest->testCmd( 125 $res = NPTest->testCmd(
127 "./check_http --ssl www.e-paycobalt.com" 126 "./check_http --ssl www.e-paycobalt.com"
128 ); 127 );
@@ -131,4 +130,7 @@ SKIP: {
131 130
132 $res = NPTest->testCmd( "./check_http -H www.mozilla.com -u /firefox -f follow" ); 131 $res = NPTest->testCmd( "./check_http -H www.mozilla.com -u /firefox -f follow" );
133 is( $res->return_code, 0, "Redirection based on location is okay"); 132 is( $res->return_code, 0, "Redirection based on location is okay");
133
134 $res = NPTest->testCmd( "./check_http -H www.mozilla.com --extended-perfdata" );
135 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
134} 136}
diff --git a/plugins/t/check_procs.t b/plugins/t/check_procs.t
index 30f02488..a1a28836 100644
--- a/plugins/t/check_procs.t
+++ b/plugins/t/check_procs.t
@@ -20,7 +20,7 @@ my $result;
20 20
21$result = NPTest->testCmd( "./check_procs -w 100000 -c 100000" ); 21$result = NPTest->testCmd( "./check_procs -w 100000 -c 100000" );
22is( $result->return_code, 0, "Checking less than 10000 processes" ); 22is( $result->return_code, 0, "Checking less than 10000 processes" );
23like( $result->output, '/^PROCS OK: [0-9]+ process(es)?$/', "Output correct" ); 23like( $result->output, '/^PROCS OK: [0-9]+ process(es)? | procs=[0-9]+;100000;100000;0;$/', "Output correct" );
24 24
25$result = NPTest->testCmd( "./check_procs -w 100000 -c 100000 -s Z" ); 25$result = NPTest->testCmd( "./check_procs -w 100000 -c 100000 -s Z" );
26is( $result->return_code, 0, "Checking less than 100000 zombie processes" ); 26is( $result->return_code, 0, "Checking less than 100000 zombie processes" );
@@ -28,11 +28,11 @@ like( $result->output, '/^PROCS OK: [0-9]+ process(es)? with /', "Output correct
28 28
29$result = NPTest->testCmd( "./check_procs -w 0 -c 100000" ); 29$result = NPTest->testCmd( "./check_procs -w 0 -c 100000" );
30is( $result->return_code, 1, "Checking warning if processes > 0" ); 30is( $result->return_code, 1, "Checking warning if processes > 0" );
31like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)?$/', "Output correct" ); 31like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)? | procs=[0-9]+;0;100000;0;$/', "Output correct" );
32 32
33$result = NPTest->testCmd( "./check_procs -w 0 -c 0" ); 33$result = NPTest->testCmd( "./check_procs -w 0 -c 0" );
34is( $result->return_code, 2, "Checking critical if processes > 0" ); 34is( $result->return_code, 2, "Checking critical if processes > 0" );
35like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)?$/', "Output correct" ); 35like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)? | procs=[0-9]+;0;0;0;$/', "Output correct" );
36 36
37$result = NPTest->testCmd( "./check_procs -w 0 -c 0 -s S" ); 37$result = NPTest->testCmd( "./check_procs -w 0 -c 0 -s S" );
38is( $result->return_code, 2, "Checking critical if sleeping processes" ); 38is( $result->return_code, 2, "Checking critical if sleeping processes" );
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index 9f97abdc..c3085e13 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -17,7 +17,7 @@ use Test::More;
17use NPTest; 17use NPTest;
18use FindBin qw($Bin); 18use FindBin qw($Bin);
19 19
20my $common_tests = 66; 20my $common_tests = 70;
21my $ssl_only_tests = 8; 21my $ssl_only_tests = 8;
22# Check that all dependent modules are available 22# Check that all dependent modules are available
23eval { 23eval {
@@ -151,6 +151,10 @@ sub run_server {
151 unshift @persist, $c; 151 unshift @persist, $c;
152 delete($persist[1000]); 152 delete($persist[1000]);
153 next MAINLOOP; 153 next MAINLOOP;
154 } elsif ($r->url->path eq "/header_check") {
155 $c->send_basic_header;
156 $c->send_header('foo');
157 $c->send_crlf;
154 } else { 158 } else {
155 $c->send_error(HTTP::Status->RC_FORBIDDEN); 159 $c->send_error(HTTP::Status->RC_FORBIDDEN);
156 } 160 }
@@ -223,6 +227,13 @@ sub run_common_tests {
223 is( $result->return_code, 2, "Missing string check"); 227 is( $result->return_code, 2, "Missing string check");
224 like( $result->output, qr%HTTP CRITICAL: HTTP/1\.1 200 OK - string 'NonRootWithOver30charsAndM...' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location"); 228 like( $result->output, qr%HTTP CRITICAL: HTTP/1\.1 200 OK - string 'NonRootWithOver30charsAndM...' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location");
225 229
230 $result = NPTest->testCmd( "$command -u /header_check -d foo" );
231 is( $result->return_code, 0, "header_check search for string");
232 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 96 bytes in [\d\.]+ second/', "Output correct" );
233
234 $result = NPTest->testCmd( "$command -u /header_check -d bar" );
235 is( $result->return_code, 2, "Missing header string check");
236 like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - header 'bar' not found on 'https?://127\.0\.0\.1:\d+/header_check'%, "Shows search string and location");
226 237
227 my $cmd; 238 my $cmd;
228 $cmd = "$command -u /slow"; 239 $cmd = "$command -u /slow";