summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--ChangeLog4
-rw-r--r--NEWS21
-rw-r--r--REQUIREMENTS5
-rw-r--r--THANKS.in10
-rw-r--r--configure.in91
-rw-r--r--contrib/check_linux_raid.pl2
-rw-r--r--contrib/check_nmap.py7
-rw-r--r--doc/developer-guidelines.sgml8
-rw-r--r--doc/makefile2
-rw-r--r--lib/tests/test_utils.c14
-rw-r--r--lib/utils_base.c16
-rwxr-xr-xplugins-scripts/check_oracle.sh15
-rwxr-xr-xplugins-scripts/check_sensors.sh33
-rw-r--r--plugins-scripts/utils.sh.in11
-rw-r--r--plugins/Makefile.am95
-rw-r--r--plugins/check_apt.c68
-rw-r--r--plugins/check_dig.c21
-rw-r--r--plugins/check_disk.c20
-rw-r--r--plugins/check_dns.c2
-rw-r--r--plugins/check_http.c151
-rw-r--r--plugins/check_ldap.c5
-rw-r--r--plugins/check_mysql.c11
-rw-r--r--plugins/check_nagios.c16
-rw-r--r--plugins/check_nt.c16
-rw-r--r--plugins/check_ntp.c9
-rw-r--r--plugins/check_ntp_peer.c41
-rw-r--r--plugins/check_ntp_time.c9
-rw-r--r--plugins/check_pgsql.c2
-rw-r--r--plugins/check_procs.c114
-rw-r--r--plugins/check_smtp.c28
-rw-r--r--plugins/check_snmp.c49
-rw-r--r--plugins/check_ssh.c2
-rw-r--r--plugins/check_tcp.c27
-rw-r--r--plugins/common.h1
-rw-r--r--plugins/runcmd.c2
-rw-r--r--plugins/runcmd.h2
-rw-r--r--plugins/t/check_apt.t90
-rw-r--r--plugins/t/check_apt_input/debian14
-rw-r--r--plugins/t/check_apt_input/debian237
-rw-r--r--plugins/t/check_apt_input/debian342
-rw-r--r--plugins/t/check_apt_input/ubuntu114
-rw-r--r--plugins/t/check_apt_input/ubuntu254
-rw-r--r--plugins/t/check_dig.t22
-rw-r--r--plugins/t/check_http.t32
-rw-r--r--plugins/t/check_procs.t6
-rw-r--r--plugins/t/check_tcp.t4
-rwxr-xr-xplugins/tests/check_http.t20
-rwxr-xr-xtools/np_build_from_sf11
-rwxr-xr-xtools/sfwebcron34
-rwxr-xr-xtools/snapshot69
-rwxr-xr-xtools/update_man_pages34
52 files changed, 893 insertions, 513 deletions
diff --git a/.gitignore b/.gitignore
index 52ca6aa4..4dca502c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,6 +37,8 @@ NP-VERSION-FILE
37 37
38# /doc/ 38# /doc/
39/doc/developer-guidelines.html 39/doc/developer-guidelines.html
40/doc/developer-guidelines.html.last
41/doc/jade-out.fot
40 42
41# /tap/ 43# /tap/
42/tap/.deps 44/tap/.deps
@@ -189,6 +191,7 @@ NP-VERSION-FILE
189/plugins/.libs 191/plugins/.libs
190/plugins/Makefile 192/plugins/Makefile
191/plugins/Makefile.in 193/plugins/Makefile.in
194/plugins/libnpcommon.a
192/plugins/negate 195/plugins/negate
193/plugins/stamp-h* 196/plugins/stamp-h*
194/plugins/urlize 197/plugins/urlize
diff --git a/ChangeLog b/ChangeLog
index 050d42bf..acc35759 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
12013-01-23 Robin Sonefors <robin.sonefors@op5.com>
2
3 * plugins/check_snmp.c: fix memory allocation if using >= 8 oids
4
12012-06-27 Holger Weiss <holger@zedat.fu-berlin.de> 52012-06-27 Holger Weiss <holger@zedat.fu-berlin.de>
2 6
3 * plugins/check_tcp.c: check_tcp: Print performance data even with 7 * plugins/check_tcp.c: check_tcp: Print performance data even with
diff --git a/NEWS b/NEWS
index e1367d14..849341f9 100644
--- a/NEWS
+++ b/NEWS
@@ -3,9 +3,30 @@ This file documents the major additions and syntax changes between releases.
3... 3...
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)
7 Add performance data to check_apt
8 Add performance data to check_procs
9 Added -4/-6 options to check_dig (Ville Mattila)
10 New check_oracle --connect option to perform real login
11 New check_nagios -t option to override the default timeout
12 New check_disk -N/--include-type option to limit the filesystem types to check
13 Allow for building the plugins in parallel
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)
6 17
7 FIXES 18 FIXES
8 Change the MAIL FROM command generated by check_smtp to be RFC compliant 19 Change the MAIL FROM command generated by check_smtp to be RFC compliant
20 Fix compilation of check_http without SSL support
21 Fix check_snmp reversed threshold ranges (backward-compatibility)
22 Fix check_snmp memory violation when using more than 8 oids (Robin Sonefors)
23 Fix check_apt security regular expression (Alex Bradley)
24 Fix check_http handling extra header (-k) containing semicolons (Richard Leitner)
25 Fix check_apt handling unknown exit codes from apt-get (Richard Leitner)
26 Fix deprecated imports of check_nmap.py (Fabio Rueda)
27
28 WARNINGS
29 check_http behaviour of -k/--header changed since it does not seperate multiple headers by semicolons anymore. Use multiple -k switches instead.
9 30
101.4.16 27th June 2012 311.4.16 27th June 2012
11 ENHANCEMENTS 32 ENHANCEMENTS
diff --git a/REQUIREMENTS b/REQUIREMENTS
index 9f2eec0f..1f673e98 100644
--- a/REQUIREMENTS
+++ b/REQUIREMENTS
@@ -36,10 +36,9 @@ check_ldap:
36 36
37check_mysql, check_mysql_query: 37check_mysql, check_mysql_query:
38 - Requires the MySQL libraries available from 38 - Requires the MySQL libraries available from
39 http://www.mysql.org/ 39 http://dev.mysql.com/downloads/
40 Lib: libmysql, libmysqlclient 40 Lib: libmysql, libmysqlclient
41 Redhat Powertools Source: mysql-3.20.32a-3.i386.rpm, mysql-devel-3.20.32a-3.i386.rpm (these seem to be broken, however) 41 Redhat Source (RHEL6, YUM): mysql-devel, mysql-libs
42 RPMS from www.mysql.org work better
43 Must have mysql_config in PATH or specified with --with-mysql=DIR for DIR/bin/mysql_config 42 Must have mysql_config in PATH or specified with --with-mysql=DIR for DIR/bin/mysql_config
44 43
45check_pqsql: 44check_pqsql:
diff --git a/THANKS.in b/THANKS.in
index 51935119..54315afa 100644
--- a/THANKS.in
+++ b/THANKS.in
@@ -275,3 +275,13 @@ Tobias Brox
275William Leibzon 275William Leibzon
276Jochen Bern 276Jochen Bern
277Anders Kaseorg 277Anders Kaseorg
278Robin Sonefors
279Alex Bradley
280Brian De Wolf
281Richard Leitner
282Diego Elio Pettenò
283Vaclav Ovsik
284Roman Fiedler
285Fabio Rueda
286Gabriele Tozzi
287Sebastian Nohn
diff --git a/configure.in b/configure.in
index 1d4ed006..25c0c9cd 100644
--- a/configure.in
+++ b/configure.in
@@ -255,55 +255,66 @@ fi
255LIBS="$_SAVEDLIBS" 255LIBS="$_SAVEDLIBS"
256CPPFLAGS="$_SAVEDCPPFLAGS" 256CPPFLAGS="$_SAVEDCPPFLAGS"
257 257
258AC_ARG_WITH([dbi], [AS_HELP_STRING([--without-dbi], [Skips the dbi plugin])])
258dnl Check for DBI libraries 259dnl Check for DBI libraries
259_SAVEDLIBS="$LIBS" 260AS_IF([test "x$with_dbi" != "xno"], [
260AC_CHECK_LIB(dbi,dbi_initialize) 261 _SAVEDLIBS="$LIBS"
261if test "$ac_cv_lib_dbi_dbi_initialize" = "yes"; then 262 AC_CHECK_LIB(dbi,dbi_initialize)
262 EXTRAS="$EXTRAS check_dbi" 263 if test "$ac_cv_lib_dbi_dbi_initialize" = "yes"; then
263 DBILIBS="-ldbi" 264 EXTRAS="$EXTRAS check_dbi"
264 AC_SUBST(DBILIBS) 265 DBILIBS="-ldbi"
265else 266 AC_SUBST(DBILIBS)
266 AC_MSG_WARN([Skipping dbi plugin]) 267 else
267 AC_MSG_WARN([install DBI libs to compile this plugin (see REQUIREMENTS).]) 268 AC_MSG_WARN([Skipping dbi plugin])
268fi 269 AC_MSG_WARN([install DBI libs to compile this plugin (see REQUIREMENTS).])
269LIBS="$_SAVEDLIBS" 270 fi
271 LIBS="$_SAVEDLIBS"
272])
273
274AC_ARG_WITH([radius], [AS_HELP_STRING([--without-radius], [Skips the radius plugin])])
270 275
271dnl Check for radius libraries 276dnl Check for radius libraries
272_SAVEDLIBS="$LIBS" 277AS_IF([test "x$with_radius" != "xno"], [
273AC_CHECK_LIB(radiusclient,rc_read_config) 278 _SAVEDLIBS="$LIBS"
274if test "$ac_cv_lib_radiusclient_rc_read_config" = "yes"; then 279 AC_CHECK_LIB(radiusclient,rc_read_config)
275 EXTRAS="$EXTRAS check_radius" 280 if test "$ac_cv_lib_radiusclient_rc_read_config" = "yes"; then
276 RADIUSLIBS="-lradiusclient"
277 AC_SUBST(RADIUSLIBS)
278else
279 AC_CHECK_LIB(radiusclient-ng,rc_read_config)
280 if test "$ac_cv_lib_radiusclient_ng_rc_read_config" = "yes"; then
281 EXTRAS="$EXTRAS check_radius" 281 EXTRAS="$EXTRAS check_radius"
282 RADIUSLIBS="-lradiusclient-ng" 282 RADIUSLIBS="-lradiusclient"
283 AC_SUBST(RADIUSLIBS) 283 AC_SUBST(RADIUSLIBS)
284 else 284 else
285 AC_MSG_WARN([Skipping radius plugin]) 285 AC_CHECK_LIB(radiusclient-ng,rc_read_config)
286 AC_MSG_WARN([install radius libs to compile this plugin (see REQUIREMENTS).]) 286 if test "$ac_cv_lib_radiusclient_ng_rc_read_config" = "yes"; then
287 EXTRAS="$EXTRAS check_radius"
288 RADIUSLIBS="-lradiusclient-ng"
289 AC_SUBST(RADIUSLIBS)
290 else
291 AC_MSG_WARN([Skipping radius plugin])
292 AC_MSG_WARN([install radius libs to compile this plugin (see REQUIREMENTS).])
293 fi
287 fi 294 fi
288fi 295 LIBS="$_SAVEDLIBS"
289LIBS="$_SAVEDLIBS" 296])
297
298AC_ARG_WITH([ldap], [AS_HELP_STRING([--without-ldap], [Skips the LDAP plugin])])
290 299
291dnl Check for LDAP libraries 300dnl Check for LDAP libraries
292_SAVEDLIBS="$LIBS" 301AS_IF([test "x$with_ldap" != "xno"], [
293AC_CHECK_LIB(ldap,main,,,-llber) 302 _SAVEDLIBS="$LIBS"
294if test "$ac_cv_lib_ldap_main" = "yes"; then 303 AC_CHECK_LIB(ldap,main,,,-llber)
295 LDAPLIBS="-lldap -llber"\ 304 if test "$ac_cv_lib_ldap_main" = "yes"; then
296 LDAPINCLUDE="-I/usr/include/ldap" 305 LDAPLIBS="-lldap -llber"\
297 AC_SUBST(LDAPLIBS) 306 LDAPINCLUDE="-I/usr/include/ldap"
298 AC_SUBST(LDAPINCLUDE) 307 AC_SUBST(LDAPLIBS)
299 AC_CHECK_FUNCS(ldap_set_option) 308 AC_SUBST(LDAPINCLUDE)
300 EXTRAS="$EXTRAS check_ldap" 309 AC_CHECK_FUNCS(ldap_set_option)
301 AC_CHECK_FUNCS(ldap_init ldap_set_option ldap_get_option ldap_start_tls_s) 310 EXTRAS="$EXTRAS check_ldap"
302else 311 AC_CHECK_FUNCS(ldap_init ldap_set_option ldap_get_option ldap_start_tls_s)
303 AC_MSG_WARN([Skipping LDAP plugin]) 312 else
304 AC_MSG_WARN([install LDAP libs to compile this plugin (see REQUIREMENTS).]) 313 AC_MSG_WARN([Skipping LDAP plugin])
305fi 314 AC_MSG_WARN([install LDAP libs to compile this plugin (see REQUIREMENTS).])
306LIBS="$_SAVEDLIBS" 315 fi
316 LIBS="$_SAVEDLIBS"
317])
307 318
308dnl Check for headers used by check_ide_smart 319dnl Check for headers used by check_ide_smart
309AC_CHECK_HEADER(linux/hdreg.h, FOUNDINCLUDE=yes, FOUNDINCLUDE=no) 320AC_CHECK_HEADER(linux/hdreg.h, FOUNDINCLUDE=yes, FOUNDINCLUDE=no)
diff --git a/contrib/check_linux_raid.pl b/contrib/check_linux_raid.pl
index 77e75f6d..c24b0cd2 100644
--- a/contrib/check_linux_raid.pl
+++ b/contrib/check_linux_raid.pl
@@ -61,7 +61,7 @@ while(defined $nextdev){
61 if (defined $device) { 61 if (defined $device) {
62 if (/(\[[_U]+\])/) { 62 if (/(\[[_U]+\])/) {
63 $status{$device} = $1; 63 $status{$device} = $1;
64 } elsif (/recovery = (.*?)\s/) { 64 } elsif (/recovery =\s+(.*?)\s/) {
65 $recovery{$device} = $1; 65 $recovery{$device} = $1;
66 ($finish{$device}) = /finish=(.*?min)/; 66 ($finish{$device}) = /finish=(.*?min)/;
67 $device=undef; 67 $device=undef;
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/doc/developer-guidelines.sgml b/doc/developer-guidelines.sgml
index 1ce78ff4..e7754f4e 100644
--- a/doc/developer-guidelines.sgml
+++ b/doc/developer-guidelines.sgml
@@ -303,15 +303,15 @@
303 </row> 303 </row>
304 <row> 304 <row>
305 <entry>check_stuff -w~:0 -c10</entry> 305 <entry>check_stuff -w~:0 -c10</entry>
306 <entry>Critical if "stuff" is above 10; Warn if "stuff" is above zero</entry> 306 <entry>Critical if "stuff" is above 10; Warn if "stuff" is above zero (will be critical if "stuff" is less than 0)</entry>
307 </row> 307 </row>
308 <row> 308 <row>
309 <entry>check_stuff -c5:6</entry> 309 <entry>check_stuff -c5:6</entry>
310 <entry>The only noncritical range is 5:6</entry> 310 <entry>Critical if "stuff" is less than 5 or more than 6</entry>
311 </row> 311 </row>
312 <row> 312 <row>
313 <entry>check_stuff -c10:20</entry> 313 <entry>check_stuff -c@10:20</entry>
314 <entry>Critical if "stuff" is less than 10 or over 20</entry> 314 <entry>OK if stuff is less than 10 or higher than 20, otherwise critical </entry>
315 </row> 315 </row>
316 </tbody> 316 </tbody>
317 </tgroup> 317 </tgroup>
diff --git a/doc/makefile b/doc/makefile
index b1b56c18..89caf9ed 100644
--- a/doc/makefile
+++ b/doc/makefile
@@ -8,4 +8,4 @@ developer-guidelines.html: developer-guidelines.sgml
8 fi 8 fi
9 9
10clean: 10clean:
11 rm -f developer-guidelines.html 11 rm -f developer-guidelines.html developer-guidelines.html.last jade-out.fot
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/lib/utils_base.c b/lib/utils_base.c
index 1f705d97..c93e9c3c 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -35,7 +35,7 @@ nagios_plugin *this_nagios_plugin=NULL;
35 35
36void np_init( char *plugin_name, int argc, char **argv ) { 36void np_init( char *plugin_name, int argc, char **argv ) {
37 if (this_nagios_plugin==NULL) { 37 if (this_nagios_plugin==NULL) {
38 this_nagios_plugin = malloc(sizeof(nagios_plugin)); 38 this_nagios_plugin = calloc(1, sizeof(nagios_plugin));
39 if (this_nagios_plugin==NULL) { 39 if (this_nagios_plugin==NULL) {
40 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), 40 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
41 strerror(errno)); 41 strerror(errno));
@@ -108,7 +108,7 @@ range
108 double end; 108 double end;
109 char *end_str; 109 char *end_str;
110 110
111 temp_range = (range *) malloc(sizeof(range)); 111 temp_range = (range *) calloc(1, sizeof(range));
112 112
113 /* Set defaults */ 113 /* Set defaults */
114 temp_range->start = 0; 114 temp_range->start = 0;
@@ -154,7 +154,7 @@ _set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_st
154{ 154{
155 thresholds *temp_thresholds = NULL; 155 thresholds *temp_thresholds = NULL;
156 156
157 if ((temp_thresholds = malloc(sizeof(thresholds))) == NULL) 157 if ((temp_thresholds = calloc(1, sizeof(thresholds))) == NULL)
158 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), 158 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
159 strerror(errno)); 159 strerror(errno));
160 160
@@ -335,13 +335,13 @@ char *np_extract_value(const char *varlist, const char *name, char sep) {
335 if (tmp = index(varlist, sep)) { 335 if (tmp = index(varlist, sep)) {
336 /* Value is delimited by a comma */ 336 /* Value is delimited by a comma */
337 if (tmp-varlist == 0) continue; 337 if (tmp-varlist == 0) continue;
338 value = (char *)malloc(tmp-varlist+1); 338 value = (char *)calloc(1, tmp-varlist+1);
339 strncpy(value, varlist, tmp-varlist); 339 strncpy(value, varlist, tmp-varlist);
340 value[tmp-varlist] = '\0'; 340 value[tmp-varlist] = '\0';
341 } else { 341 } else {
342 /* Value is delimited by a \0 */ 342 /* Value is delimited by a \0 */
343 if (strlen(varlist) == 0) continue; 343 if (strlen(varlist) == 0) continue;
344 value = (char *)malloc(strlen(varlist) + 1); 344 value = (char *)calloc(1, strlen(varlist) + 1);
345 strncpy(value, varlist, strlen(varlist)); 345 strncpy(value, varlist, strlen(varlist));
346 value[strlen(varlist)] = '\0'; 346 value[strlen(varlist)] = '\0';
347 } 347 }
@@ -431,7 +431,7 @@ void np_enable_state(char *keyname, int expected_data_version) {
431 if(this_nagios_plugin==NULL) 431 if(this_nagios_plugin==NULL)
432 die(STATE_UNKNOWN, _("This requires np_init to be called")); 432 die(STATE_UNKNOWN, _("This requires np_init to be called"));
433 433
434 this_state = (state_key *) malloc(sizeof(state_key)); 434 this_state = (state_key *) calloc(1, sizeof(state_key));
435 if(this_state==NULL) 435 if(this_state==NULL)
436 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), 436 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
437 strerror(errno)); 437 strerror(errno));
@@ -482,7 +482,7 @@ state_data *np_state_read() {
482 statefile = fopen( this_nagios_plugin->state->_filename, "r" ); 482 statefile = fopen( this_nagios_plugin->state->_filename, "r" );
483 if(statefile!=NULL) { 483 if(statefile!=NULL) {
484 484
485 this_state_data = (state_data *) malloc(sizeof(state_data)); 485 this_state_data = (state_data *) calloc(1, sizeof(state_data));
486 if(this_state_data==NULL) 486 if(this_state_data==NULL)
487 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), 487 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
488 strerror(errno)); 488 strerror(errno));
@@ -517,7 +517,7 @@ int _np_state_read_file(FILE *f) {
517 time(&current_time); 517 time(&current_time);
518 518
519 /* Note: This introduces a limit of 1024 bytes in the string data */ 519 /* Note: This introduces a limit of 1024 bytes in the string data */
520 line = (char *) malloc(1024); 520 line = (char *) calloc(1, 1024);
521 if(line==NULL) 521 if(line==NULL)
522 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), 522 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
523 strerror(errno)); 523 strerror(errno));
diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh
index 664795eb..2a8ab21d 100755
--- a/plugins-scripts/check_oracle.sh
+++ b/plugins-scripts/check_oracle.sh
@@ -18,6 +18,7 @@ print_usage() {
18 echo " $PROGNAME --tns <Oracle Sid or Hostname/IP address>" 18 echo " $PROGNAME --tns <Oracle Sid or Hostname/IP address>"
19 echo " $PROGNAME --db <ORACLE_SID>" 19 echo " $PROGNAME --db <ORACLE_SID>"
20 echo " $PROGNAME --login <ORACLE_SID>" 20 echo " $PROGNAME --login <ORACLE_SID>"
21 echo " $PROGNAME --connect <ORACLE_SID>"
21 echo " $PROGNAME --cache <ORACLE_SID> <USER> <PASS> <CRITICAL> <WARNING>" 22 echo " $PROGNAME --cache <ORACLE_SID> <USER> <PASS> <CRITICAL> <WARNING>"
22 echo " $PROGNAME --tablespace <ORACLE_SID> <USER> <PASS> <TABLESPACE> <CRITICAL> <WARNING>" 23 echo " $PROGNAME --tablespace <ORACLE_SID> <USER> <PASS> <TABLESPACE> <CRITICAL> <WARNING>"
23 echo " $PROGNAME --oranames <Hostname>" 24 echo " $PROGNAME --oranames <Hostname>"
@@ -39,6 +40,8 @@ print_help() {
39 echo " filesystem for sgadefORACLE_SID.dbf" 40 echo " filesystem for sgadefORACLE_SID.dbf"
40 echo "--login SID" 41 echo "--login SID"
41 echo " Attempt a dummy login and alert if not ORA-01017: invalid username/password" 42 echo " Attempt a dummy login and alert if not ORA-01017: invalid username/password"
43 echo "--connect SID"
44 echo " Attempt a login and alert if an ORA- error is returned"
42 echo "--cache" 45 echo "--cache"
43 echo " Check local database for library and buffer cache hit ratios" 46 echo " Check local database for library and buffer cache hit ratios"
44 echo " ---> Requires Oracle user/password and SID specified." 47 echo " ---> Requires Oracle user/password and SID specified."
@@ -187,6 +190,18 @@ case "$cmd" in
187 exit $STATE_CRITICAL 190 exit $STATE_CRITICAL
188 fi 191 fi
189 ;; 192 ;;
193--connect)
194 connectchk=`sqlplus $2 < /dev/null`
195 connectchk2=` echo $connectchk | grep -c ORA-`
196 if [ ${connectchk2} -eq 0 ] ; then
197 echo "OK - login successful"
198 exit $STATE_OK
199 else
200 connectchk3=` echo "$connectchk" | grep "ORA-" | head -1`
201 echo "CRITICAL - $connectchk3"
202 exit $STATE_CRITICAL
203 fi
204 ;;
190--cache) 205--cache)
191 if [ ${5} -gt ${6} ] ; then 206 if [ ${5} -gt ${6} ] ; then
192 echo "UNKNOWN - Warning level is less then Crit" 207 echo "UNKNOWN - Warning level is less then Crit"
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-scripts/utils.sh.in b/plugins-scripts/utils.sh.in
index 5fae6adb..4a07df89 100644
--- a/plugins-scripts/utils.sh.in
+++ b/plugins-scripts/utils.sh.in
@@ -23,7 +23,16 @@ support() {
23 23
24# 24#
25# check_range takes a value and a range string, returning successfully if an 25# check_range takes a value and a range string, returning successfully if an
26# alert should be raised based on the range. 26# alert should be raised based on the range. Range values are inclusive.
27# Values may be integers or floats.
28#
29# Example usage:
30#
31# Generating an exit code of 1:
32# check_range 5 2:8
33#
34# Generating an exit code of 0:
35# check_range 1 2:8
27# 36#
28check_range() { 37check_range() {
29 local v range yes no err decimal start end cmp match 38 local v range yes no err decimal start end cmp match
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 0eb0255b..64969dbf 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -39,15 +39,19 @@ EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \
39 check_nagios check_by_ssh check_dns check_nt check_ide_smart \ 39 check_nagios check_by_ssh check_dns check_nt check_ide_smart \
40 check_procs check_mysql_query check_apt check_dbi 40 check_procs check_mysql_query check_apt check_dbi
41 41
42EXTRA_DIST = t tests utils.c netutils.c sslutils.c popen.c utils.h netutils.h \ 42EXTRA_DIST = t tests
43 popen.h common.h runcmd.c runcmd.h
44 43
45PLUGINHDRS = common.h 44PLUGINHDRS = common.h
46 45
47BASEOBJS = utils.o ../lib/libnagiosplug.a ../gl/libgnu.a 46noinst_LIBRARIES = libnpcommon.a
48NETOBJS = netutils.o $(BASEOBJS) $(EXTRA_NETOBJS) 47
49SSLOBJS = sslutils.o 48libnpcommon_a_SOURCES = utils.c netutils.c sslutils.c runcmd.c \
49 popen.c utils.h netutils.h popen.h common.h runcmd.c runcmd.h
50
51BASEOBJS = libnpcommon.a ../lib/libnagiosplug.a ../gl/libgnu.a
52NETOBJS = $(BASEOBJS) $(EXTRA_NETOBLS)
50NETLIBS = $(NETOBJS) $(SOCKETLIBS) 53NETLIBS = $(NETOBJS) $(SOCKETLIBS)
54SSLOBJS = $(BASEOBJS) $(NETLIBS) $(SSLLIBS)
51 55
52TESTS_ENVIRONMENT = perl -I $(top_builddir) -I $(top_srcdir) 56TESTS_ENVIRONMENT = perl -I $(top_builddir) -I $(top_srcdir)
53 57
@@ -62,19 +66,19 @@ test-debug:
62############################################################################## 66##############################################################################
63# the actual targets 67# the actual targets
64 68
65check_apt_LDADD = $(BASEOBJS) runcmd.o 69check_apt_LDADD = $(BASEOBJS)
66check_cluster_LDADD = $(BASEOBJS) 70check_cluster_LDADD = $(BASEOBJS)
67check_dbi_LDADD = $(NETLIBS) $(DBILIBS) 71check_dbi_LDADD = $(NETLIBS) $(DBILIBS)
68check_dig_LDADD = $(NETLIBS) runcmd.o 72check_dig_LDADD = $(NETLIBS)
69check_disk_LDADD = $(BASEOBJS) popen.o 73check_disk_LDADD = $(BASEOBJS)
70check_dns_LDADD = $(NETLIBS) runcmd.o 74check_dns_LDADD = $(NETLIBS)
71check_dummy_LDADD = $(BASEOBJS) 75check_dummy_LDADD = $(BASEOBJS)
72check_fping_LDADD = $(NETLIBS) popen.o 76check_fping_LDADD = $(NETLIBS)
73check_game_LDADD = $(BASEOBJS) runcmd.o 77check_game_LDADD = $(BASEOBJS)
74check_http_LDADD = $(SSLOBJS) $(NETLIBS) $(SSLLIBS) 78check_http_LDADD = $(SSLOBJS)
75check_hpjd_LDADD = $(NETLIBS) popen.o 79check_hpjd_LDADD = $(NETLIBS)
76check_ldap_LDADD = $(NETLIBS) $(LDAPLIBS) 80check_ldap_LDADD = $(NETLIBS) $(LDAPLIBS)
77check_load_LDADD = $(BASEOBJS) popen.o 81check_load_LDADD = $(BASEOBJS)
78check_mrtg_LDADD = $(BASEOBJS) 82check_mrtg_LDADD = $(BASEOBJS)
79check_mrtgtraf_LDADD = $(BASEOBJS) 83check_mrtgtraf_LDADD = $(BASEOBJS)
80check_mysql_CFLAGS = $(MYSQLCFLAGS) -DNP_VERSION='"$(NP_VERSION)"' 84check_mysql_CFLAGS = $(MYSQLCFLAGS) -DNP_VERSION='"$(NP_VERSION)"'
@@ -83,22 +87,22 @@ check_mysql_LDADD = $(NETLIBS) $(MYSQLLIBS)
83check_mysql_query_CFLAGS = $(MYSQLCFLAGS) -DNP_VERSION='"$(NP_VERSION)"' 87check_mysql_query_CFLAGS = $(MYSQLCFLAGS) -DNP_VERSION='"$(NP_VERSION)"'
84check_mysql_query_CPPFLAGS = $(MYSQLINCLUDE) 88check_mysql_query_CPPFLAGS = $(MYSQLINCLUDE)
85check_mysql_query_LDADD = $(NETLIBS) $(MYSQLLIBS) 89check_mysql_query_LDADD = $(NETLIBS) $(MYSQLLIBS)
86check_nagios_LDADD = $(BASEOBJS) runcmd.o 90check_nagios_LDADD = $(BASEOBJS)
87check_nt_LDADD = $(NETLIBS) 91check_nt_LDADD = $(NETLIBS)
88check_ntp_LDADD = $(NETLIBS) $(MATHLIBS) 92check_ntp_LDADD = $(NETLIBS) $(MATHLIBS)
89check_ntp_peer_LDADD = $(NETLIBS) $(MATHLIBS) 93check_ntp_peer_LDADD = $(NETLIBS) $(MATHLIBS)
90check_nwstat_LDADD = $(NETLIBS) 94check_nwstat_LDADD = $(NETLIBS)
91check_overcr_LDADD = $(NETLIBS) 95check_overcr_LDADD = $(NETLIBS)
92check_pgsql_LDADD = $(NETLIBS) $(PGLIBS) 96check_pgsql_LDADD = $(NETLIBS) $(PGLIBS)
93check_ping_LDADD = $(NETLIBS) popen.o 97check_ping_LDADD = $(NETLIBS)
94check_procs_LDADD = $(BASEOBJS) 98check_procs_LDADD = $(BASEOBJS)
95check_radius_LDADD = $(NETLIBS) $(RADIUSLIBS) 99check_radius_LDADD = $(NETLIBS) $(RADIUSLIBS)
96check_real_LDADD = $(NETLIBS) 100check_real_LDADD = $(NETLIBS)
97check_snmp_LDADD = $(BASEOBJS) 101check_snmp_LDADD = $(BASEOBJS)
98check_smtp_LDADD = $(SSLOBJS) $(NETLIBS) $(SSLLIBS) 102check_smtp_LDADD = $(SSLOBJS)
99check_ssh_LDADD = $(NETLIBS) 103check_ssh_LDADD = $(NETLIBS)
100check_swap_LDADD = $(MATHLIBS) $(BASEOBJS) popen.o 104check_swap_LDADD = $(MATHLIBS) $(BASEOBJS)
101check_tcp_LDADD = $(SSLOBJS) $(NETLIBS) $(SSLLIBS) 105check_tcp_LDADD = $(SSLOBJS)
102check_time_LDADD = $(NETLIBS) 106check_time_LDADD = $(NETLIBS)
103check_ntp_time_LDADD = $(NETLIBS) $(MATHLIBS) 107check_ntp_time_LDADD = $(NETLIBS) $(MATHLIBS)
104check_ups_LDADD = $(NETLIBS) 108check_ups_LDADD = $(NETLIBS)
@@ -106,62 +110,11 @@ check_users_LDADD = $(BASEOBJS)
106check_by_ssh_LDADD = $(NETLIBS) 110check_by_ssh_LDADD = $(NETLIBS)
107check_ide_smart_LDADD = $(BASEOBJS) 111check_ide_smart_LDADD = $(BASEOBJS)
108negate_LDADD = $(BASEOBJS) 112negate_LDADD = $(BASEOBJS)
109urlize_LDADD = $(BASEOBJS) popen.o 113urlize_LDADD = $(BASEOBJS)
110
111check_apt_DEPENDENCIES = check_apt.c $(BASEOBJS) runcmd.o $(DEPLIBS)
112check_cluster_DEPENDENCIES = check_cluster.c $(BASEOBJS) $(DEPLIBS)
113check_dbi_DEPENDENCIES = check_dbi.c $(NETOBJS) $(DEPLIBS)
114check_dig_DEPENDENCIES = check_dig.c $(NETOBJS) runcmd.o $(DEPLIBS)
115check_disk_DEPENDENCIES = check_disk.c $(BASEOBJS) popen.o $(DEPLIBS)
116check_dns_DEPENDENCIES = check_dns.c $(NETOBJS) runcmd.o $(DEPLIBS)
117check_dummy_DEPENDENCIES = check_dummy.c $(DEPLIBS)
118check_fping_DEPENDENCIES = check_fping.c $(NETOBJS) popen.o $(DEPLIBS)
119check_game_DEPENDENCIES = check_game.c $(DEPLIBS) runcmd.o
120check_http_DEPENDENCIES = check_http.c $(SSLOBJS) $(NETOBJS) $(DEPLIBS)
121check_hpjd_DEPENDENCIES = check_hpjd.c $(NETOBJS) popen.o $(DEPLIBS)
122check_ide_smart_DEPENDENCIES = check_ide_smart.c $(BASEOBJS) $(DEPLIBS)
123check_ldap_DEPENDENCIES = check_ldap.c $(NETOBJS) $(DEPLIBS)
124check_load_DEPENDENCIES = check_load.c $(BASEOBJS) popen.o $(DEPLIBS)
125check_mrtg_DEPENDENCIES = check_mrtg.c $(DEPLIBS)
126check_mrtgtraf_DEPENDENCIES = check_mrtgtraf.c $(DEPLIBS)
127check_mysql_DEPENDENCIES = check_mysql.c $(NETOBJS) $(DEPLIBS)
128check_mysql_query_DEPENDENCIES = check_mysql_query.c $(NETOBJS) $(DEPLIBS)
129check_nagios_DEPENDENCIES = check_nagios.c $(BASEOBJS) runcmd.o $(DEPLIBS)
130check_nt_DEPENDENCIES = check_nt.c $(NETOBJS) $(DEPLIBS)
131check_ntp_DEPENDENCIES = check_ntp.c $(NETOBJS) $(DEPLIBS)
132check_ntp_peer_DEPENDENCIES = check_ntp_peer.c $(NETOBJS) $(DEPLIBS)
133check_nwstat_DEPENDENCIES = check_nwstat.c $(NETOBJS) $(DEPLIBS)
134check_overcr_DEPENDENCIES = check_overcr.c $(NETOBJS) $(DEPLIBS)
135check_pgsql_DEPENDENCIES = check_pgsql.c $(NETOBJS) $(DEPLIBS)
136check_ping_DEPENDENCIES = check_ping.c $(NETOBJS) popen.o $(DEPLIBS)
137check_procs_DEPENDENCIES = check_procs.c $(BASEOBJS) popen.o $(DEPLIBS)
138check_radius_DEPENDENCIES = check_radius.c $(NETOBJS) $(DEPLIBS)
139check_real_DEPENDENCIES = check_real.c $(NETOBJS) $(DEPLIBS)
140check_snmp_DEPENDENCIES = check_snmp.c $(BASEOBJS) $(DEPLIBS)
141check_smtp_DEPENDENCIES = check_smtp.c $(SSLOBJS) $(NETOBJS) $(DEPLIBS)
142check_ssh_DEPENDENCIES = check_ssh.c $(NETOBJS) $(DEPLIBS)
143check_swap_DEPENDENCIES = check_swap.c $(BASEOBJS) popen.o $(DEPLIBS)
144check_tcp_DEPENDENCIES = check_tcp.c $(SSLOBJS) $(NETOBJS) $(DEPLIBS)
145check_time_DEPENDENCIES = check_time.c $(NETOBJS) $(DEPLIBS)
146check_ntp_time_DEPENDENCIES = check_ntp_time.c $(NETOBJS) $(DEPLIBS)
147check_ups_DEPENDENCIES = check_ups.c $(NETOBJS) $(DEPLIBS)
148check_users_DEPENDENCIES = check_users.c $(BASEOBJS) popen.o $(DEPLIBS)
149check_by_ssh_DEPENDENCIES = check_by_ssh.c $(NETOBJS) $(DEPLIBS)
150negate_DEPENDENCIES = negate.c $(BASEOBJS) $(DEPLIBS)
151urlize_DEPENDENCIES = urlize.c $(BASEOBJS) popen.o $(DEPLIBS)
152 114
153############################################################################## 115##############################################################################
154# secondary dependencies 116# secondary dependencies
155 117
156popen.o: popen.c popen.h $(PLUGINHDRS)
157
158runcmd.o: runcmd.c runcmd.h $(PLUGINHDRS)
159
160utils.o: utils.c utils.h $(PLUGINHDRS)
161
162netutils.o: netutils.c netutils.h $(PLUGINHDRS)
163sslutils.o: sslutils.c netutils.h $(PLUGINHDRS)
164
165all-local: $(check_tcp_programs) 118all-local: $(check_tcp_programs)
166 119
167$(check_tcp_programs): check_tcp 120$(check_tcp_programs): check_tcp
diff --git a/plugins/check_apt.c b/plugins/check_apt.c
index 7efa596b..daeb7578 100644
--- a/plugins/check_apt.c
+++ b/plugins/check_apt.c
@@ -41,6 +41,8 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
41/* some constants */ 41/* some constants */
42typedef enum { UPGRADE, DIST_UPGRADE, NO_UPGRADE } upgrade_type; 42typedef enum { UPGRADE, DIST_UPGRADE, NO_UPGRADE } upgrade_type;
43 43
44/* Character for hidden input file option (for testing). */
45#define INPUT_FILE_OPT CHAR_MAX+1
44/* the default opts can be overridden via the cmdline */ 46/* the default opts can be overridden via the cmdline */
45#define UPGRADE_DEFAULT_OPTS "-o 'Debug::NoLocking=true' -s -qq" 47#define UPGRADE_DEFAULT_OPTS "-o 'Debug::NoLocking=true' -s -qq"
46#define UPDATE_DEFAULT_OPTS "-q" 48#define UPDATE_DEFAULT_OPTS "-q"
@@ -49,8 +51,10 @@ typedef enum { UPGRADE, DIST_UPGRADE, NO_UPGRADE } upgrade_type;
49#ifndef PATH_TO_APTGET 51#ifndef PATH_TO_APTGET
50# define PATH_TO_APTGET "/usr/bin/apt-get" 52# define PATH_TO_APTGET "/usr/bin/apt-get"
51#endif /* PATH_TO_APTGET */ 53#endif /* PATH_TO_APTGET */
54/* String found at the beginning of the apt output lines we're interested in */
55#define PKGINST_PREFIX "Inst "
52/* the RE that catches security updates */ 56/* the RE that catches security updates */
53#define SECURITY_RE "^[^\\(]*\\([^ ]* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)" 57#define SECURITY_RE "^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)"
54 58
55/* some standard functions */ 59/* some standard functions */
56int process_arguments(int, char **); 60int process_arguments(int, char **);
@@ -75,6 +79,7 @@ static char *update_opts = NULL; /* options to override defaults for update */
75static char *do_include = NULL; /* regexp to only include certain packages */ 79static char *do_include = NULL; /* regexp to only include certain packages */
76static char *do_exclude = NULL; /* regexp to only exclude certain packages */ 80static char *do_exclude = NULL; /* regexp to only exclude certain packages */
77static char *do_critical = NULL; /* regexp specifying critical packages */ 81static char *do_critical = NULL; /* regexp specifying critical packages */
82static char *input_filename = NULL; /* input filename for testing */
78 83
79/* other global variables */ 84/* other global variables */
80static int stderr_warning = 0; /* if a cmd issued output on stderr */ 85static int stderr_warning = 0; /* if a cmd issued output on stderr */
@@ -107,11 +112,11 @@ int main (int argc, char **argv) {
107 result = max_state(result, STATE_CRITICAL); 112 result = max_state(result, STATE_CRITICAL);
108 } else if(packages_available > 0){ 113 } else if(packages_available > 0){
109 result = max_state(result, STATE_WARNING); 114 result = max_state(result, STATE_WARNING);
110 } else { 115 } else if(result > STATE_UNKNOWN){
111 result = max_state(result, STATE_OK); 116 result = STATE_UNKNOWN;
112 } 117 }
113 118
114 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"),
115 state_text(result), 120 state_text(result),
116 packages_available, 121 packages_available,
117 (upgrade==DIST_UPGRADE)?"dist-upgrade":"upgrade", 122 (upgrade==DIST_UPGRADE)?"dist-upgrade":"upgrade",
@@ -119,7 +124,9 @@ int main (int argc, char **argv) {
119 (stderr_warning)?" warnings detected":"", 124 (stderr_warning)?" warnings detected":"",
120 (stderr_warning && exec_warning)?",":"", 125 (stderr_warning && exec_warning)?",":"",
121 (exec_warning)?" errors detected":"", 126 (exec_warning)?" errors detected":"",
122 (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
123 ); 130 );
124 131
125 return result; 132 return result;
@@ -141,6 +148,7 @@ int process_arguments (int argc, char **argv) {
141 {"include", required_argument, 0, 'i'}, 148 {"include", required_argument, 0, 'i'},
142 {"exclude", required_argument, 0, 'e'}, 149 {"exclude", required_argument, 0, 'e'},
143 {"critical", required_argument, 0, 'c'}, 150 {"critical", required_argument, 0, 'c'},
151 {"input-file", required_argument, 0, INPUT_FILE_OPT},
144 {0, 0, 0, 0} 152 {0, 0, 0, 0}
145 }; 153 };
146 154
@@ -195,6 +203,9 @@ int process_arguments (int argc, char **argv) {
195 case 'c': 203 case 'c':
196 do_critical=add_to_regexp(do_critical, optarg); 204 do_critical=add_to_regexp(do_critical, optarg);
197 break; 205 break;
206 case INPUT_FILE_OPT:
207 input_filename = optarg;
208 break;
198 default: 209 default:
199 /* print short usage statement if args not parsable */ 210 /* print short usage statement if args not parsable */
200 usage5(); 211 usage5();
@@ -211,22 +222,18 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
211 struct output chld_out, chld_err; 222 struct output chld_out, chld_err;
212 regex_t ireg, ereg, sreg; 223 regex_t ireg, ereg, sreg;
213 char *cmdline=NULL, rerrbuf[64]; 224 char *cmdline=NULL, rerrbuf[64];
214 const char *include_ptr=NULL, *crit_ptr=NULL;
215 225
216 if(upgrade==NO_UPGRADE) return STATE_OK; 226 if(upgrade==NO_UPGRADE) return STATE_OK;
217 227
218 /* compile the regexps */ 228 /* compile the regexps */
219 if(do_include!=NULL) include_ptr=do_include; 229 if (do_include != NULL) {
220 else include_ptr="^Inst"; 230 regres=regcomp(&ireg, do_include, REG_EXTENDED);
221 if(do_critical!=NULL) crit_ptr=do_critical; 231 if (regres!=0) {
222 else crit_ptr=SECURITY_RE; 232 regerror(regres, &ireg, rerrbuf, 64);
223 233 die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), progname, rerrbuf);
224 regres=regcomp(&ireg, include_ptr, REG_EXTENDED); 234 }
225 if(regres!=0) {
226 regerror(regres, &ireg, rerrbuf, 64);
227 die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), progname, rerrbuf);
228 } 235 }
229 236
230 if(do_exclude!=NULL){ 237 if(do_exclude!=NULL){
231 regres=regcomp(&ereg, do_exclude, REG_EXTENDED); 238 regres=regcomp(&ereg, do_exclude, REG_EXTENDED);
232 if(regres!=0) { 239 if(regres!=0) {
@@ -235,6 +242,8 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
235 progname, rerrbuf); 242 progname, rerrbuf);
236 } 243 }
237 } 244 }
245
246 const char *crit_ptr = (do_critical != NULL) ? do_critical : SECURITY_RE;
238 regres=regcomp(&sreg, crit_ptr, REG_EXTENDED); 247 regres=regcomp(&sreg, crit_ptr, REG_EXTENDED);
239 if(regres!=0) { 248 if(regres!=0) {
240 regerror(regres, &ereg, rerrbuf, 64); 249 regerror(regres, &ereg, rerrbuf, 64);
@@ -243,8 +252,14 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
243 } 252 }
244 253
245 cmdline=construct_cmdline(upgrade, upgrade_opts); 254 cmdline=construct_cmdline(upgrade, upgrade_opts);
246 /* run the upgrade */ 255 if (input_filename != NULL) {
247 result = np_runcmd(cmdline, &chld_out, &chld_err, 0); 256 /* read input from a file for testing */
257 result = cmd_file_read(input_filename, &chld_out, 0);
258 } else {
259 /* run the upgrade */
260 result = np_runcmd(cmdline, &chld_out, &chld_err, 0);
261 }
262
248 /* apt-get upgrade only changes exit status if there is an 263 /* apt-get upgrade only changes exit status if there is an
249 * internal error when run in dry-run mode. therefore we will 264 * internal error when run in dry-run mode. therefore we will
250 * treat such an error as UNKNOWN */ 265 * treat such an error as UNKNOWN */
@@ -269,7 +284,8 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
269 printf("%s\n", chld_out.line[i]); 284 printf("%s\n", chld_out.line[i]);
270 } 285 }
271 /* if it is a package we care about */ 286 /* if it is a package we care about */
272 if(regexec(&ireg, chld_out.line[i], 0, NULL, 0)==0){ 287 if (strncmp(PKGINST_PREFIX, chld_out.line[i], strlen(PKGINST_PREFIX)) == 0 &&
288 (do_include == NULL || regexec(&ireg, chld_out.line[i], 0, NULL, 0) == 0)) {
273 /* if we're not excluding, or it's not in the 289 /* if we're not excluding, or it's not in the
274 * list of stuff to exclude */ 290 * list of stuff to exclude */
275 if(do_exclude==NULL || 291 if(do_exclude==NULL ||
@@ -289,7 +305,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
289 *secpkgcount=spc; 305 *secpkgcount=spc;
290 306
291 /* If we get anything on stderr, at least set warning */ 307 /* If we get anything on stderr, at least set warning */
292 if(chld_err.buflen){ 308 if (input_filename == NULL && chld_err.buflen) {
293 stderr_warning=1; 309 stderr_warning=1;
294 result = max_state(result, STATE_WARNING); 310 result = max_state(result, STATE_WARNING);
295 if(verbose){ 311 if(verbose){
@@ -298,7 +314,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
298 } 314 }
299 } 315 }
300 } 316 }
301 regfree(&ireg); 317 if (do_include != NULL) regfree(&ireg);
302 regfree(&sreg); 318 regfree(&sreg);
303 if(do_exclude!=NULL) regfree(&ereg); 319 if(do_exclude!=NULL) regfree(&ereg);
304 free(cmdline); 320 free(cmdline);
@@ -348,15 +364,15 @@ char* add_to_regexp(char *expr, const char *next){
348 char *re=NULL; 364 char *re=NULL;
349 365
350 if(expr==NULL){ 366 if(expr==NULL){
351 re=malloc(sizeof(char)*(strlen("^Inst () ")+strlen(next)+1)); 367 re=malloc(sizeof(char)*(strlen("()")+strlen(next)+1));
352 if(!re) die(STATE_UNKNOWN, "malloc failed!\n"); 368 if(!re) die(STATE_UNKNOWN, "malloc failed!\n");
353 sprintf(re, "^Inst (%s) ", next); 369 sprintf(re, "(%s)", next);
354 } else { 370 } else {
355 /* resize it, adding an extra char for the new '|' separator */ 371 /* resize it, adding an extra char for the new '|' separator */
356 re=realloc(expr, sizeof(char)*strlen(expr)+1+strlen(next)+1); 372 re=realloc(expr, sizeof(char)*(strlen(expr)+1+strlen(next)+1));
357 if(!re) die(STATE_UNKNOWN, "realloc failed!\n"); 373 if(!re) die(STATE_UNKNOWN, "realloc failed!\n");
358 /* append it starting at ')' in the old re */ 374 /* append it starting at ')' in the old re */
359 sprintf((char*)(re+strlen(re)-2), "|%s) ", next); 375 sprintf((char*)(re+strlen(re)-1), "|%s)", next);
360 } 376 }
361 377
362 return re; 378 return re;
@@ -430,7 +446,7 @@ print_help (void)
430 printf (" %s\n", _("Do not run the upgrade. Probably not useful (without -u at least).")); 446 printf (" %s\n", _("Do not run the upgrade. Probably not useful (without -u at least)."));
431 printf (" %s\n", "-i, --include=REGEXP"); 447 printf (" %s\n", "-i, --include=REGEXP");
432 printf (" %s\n", _("Include only packages matching REGEXP. Can be specified multiple times")); 448 printf (" %s\n", _("Include only packages matching REGEXP. Can be specified multiple times"));
433 printf (" %s\n", _("the values will be combined together. Any patches matching this list")); 449 printf (" %s\n", _("the values will be combined together. Any packages matching this list"));
434 printf (" %s\n", _("cause the plugin to return WARNING status. Others will be ignored.")); 450 printf (" %s\n", _("cause the plugin to return WARNING status. Others will be ignored."));
435 printf (" %s\n", _("Default is to include all packages.")); 451 printf (" %s\n", _("Default is to include all packages."));
436 printf (" %s\n", "-e, --exclude=REGEXP"); 452 printf (" %s\n", "-e, --exclude=REGEXP");
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index 893e0a14..c113d87b 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -54,6 +54,7 @@ char *record_type = "A";
54char *expected_address = NULL; 54char *expected_address = NULL;
55char *dns_server = NULL; 55char *dns_server = NULL;
56char *dig_args = ""; 56char *dig_args = "";
57char *query_transport = "";
57int verbose = FALSE; 58int verbose = FALSE;
58int server_port = DEFAULT_PORT; 59int server_port = DEFAULT_PORT;
59double warning_interval = UNDEFINED; 60double warning_interval = UNDEFINED;
@@ -77,7 +78,7 @@ main (int argc, char **argv)
77 textdomain (PACKAGE); 78 textdomain (PACKAGE);
78 79
79 /* Set signal handling and alarm */ 80 /* Set signal handling and alarm */
80 if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) 81 if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR)
81 usage_va(_("Cannot catch SIGALRM")); 82 usage_va(_("Cannot catch SIGALRM"));
82 83
83 /* Parse extra opts if any */ 84 /* Parse extra opts if any */
@@ -87,8 +88,8 @@ main (int argc, char **argv)
87 usage_va(_("Could not parse arguments")); 88 usage_va(_("Could not parse arguments"));
88 89
89 /* get the command to run */ 90 /* get the command to run */
90 xasprintf (&command_line, "%s @%s -p %d %s -t %s %s", 91 xasprintf (&command_line, "%s @%s -p %d %s -t %s %s %s",
91 PATH_TO_DIG, dns_server, server_port, query_address, record_type, dig_args); 92 PATH_TO_DIG, dns_server, server_port, query_address, record_type, dig_args, query_transport);
92 93
93 alarm (timeout_interval); 94 alarm (timeout_interval);
94 gettimeofday (&tv, NULL); 95 gettimeofday (&tv, NULL);
@@ -199,6 +200,8 @@ process_arguments (int argc, char **argv)
199 {"record_type", required_argument, 0, 'T'}, 200 {"record_type", required_argument, 0, 'T'},
200 {"expected_address", required_argument, 0, 'a'}, 201 {"expected_address", required_argument, 0, 'a'},
201 {"port", required_argument, 0, 'p'}, 202 {"port", required_argument, 0, 'p'},
203 {"use-ipv4", no_argument, 0, '4'},
204 {"use-ipv6", no_argument, 0, '6'},
202 {0, 0, 0, 0} 205 {0, 0, 0, 0}
203 }; 206 };
204 207
@@ -206,7 +209,7 @@ process_arguments (int argc, char **argv)
206 return ERROR; 209 return ERROR;
207 210
208 while (1) { 211 while (1) {
209 c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:p:a:A:", longopts, &option); 212 c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:p:a:A:46", longopts, &option);
210 213
211 if (c == -1 || c == EOF) 214 if (c == -1 || c == EOF)
212 break; 215 break;
@@ -269,6 +272,12 @@ process_arguments (int argc, char **argv)
269 case 'a': 272 case 'a':
270 expected_address = optarg; 273 expected_address = optarg;
271 break; 274 break;
275 case '4':
276 query_transport = "-4";
277 break;
278 case '6':
279 query_transport = "-6";
280 break;
272 default: /* usage5 */ 281 default: /* usage5 */
273 usage5(); 282 usage5();
274 } 283 }
@@ -325,6 +334,10 @@ print_help (void)
325 334
326 printf (UT_HOST_PORT, 'p', myport); 335 printf (UT_HOST_PORT, 'p', myport);
327 336
337 printf (" %s\n","-4, --use-ipv4");
338 printf (" %s\n",_("Force dig to only use IPv4 query transport"));
339 printf (" %s\n","-6, --use-ipv6");
340 printf (" %s\n",_("Force dig to only use IPv6 query transport"));
328 printf (" %s\n","-l, --query_address=STRING"); 341 printf (" %s\n","-l, --query_address=STRING");
329 printf (" %s\n",_("Machine name to lookup")); 342 printf (" %s\n",_("Machine name to lookup"));
330 printf (" %s\n","-T, --record_type=STRING"); 343 printf (" %s\n","-T, --record_type=STRING");
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index f8e913e1..4ea03935 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -91,9 +91,12 @@ static int stat_remote_fs = 0;
91 91
92/* Linked list of filesystem types to omit. 92/* Linked list of filesystem types to omit.
93 If the list is empty, don't exclude any types. */ 93 If the list is empty, don't exclude any types. */
94
95static struct name_list *fs_exclude_list; 94static struct name_list *fs_exclude_list;
96 95
96/* Linked list of filesystem types to check.
97 If the list is empty, include all types. */
98static struct name_list *fs_include_list;
99
97static struct name_list *dp_exclude_list; 100static struct name_list *dp_exclude_list;
98 101
99static struct parameter_list *path_select_list = NULL; 102static struct parameter_list *path_select_list = NULL;
@@ -255,6 +258,9 @@ main (int argc, char **argv)
255 (np_find_name (dp_exclude_list, me->me_devname) || 258 (np_find_name (dp_exclude_list, me->me_devname) ||
256 np_find_name (dp_exclude_list, me->me_mountdir))) { 259 np_find_name (dp_exclude_list, me->me_mountdir))) {
257 continue; 260 continue;
261 /* Skip not included fstypes */
262 } else if (fs_include_list && !np_find_name (fs_include_list, me->me_type)) {
263 continue;
258 } 264 }
259 265
260 stat_path(path); 266 stat_path(path);
@@ -419,6 +425,7 @@ process_arguments (int argc, char **argv)
419 {"partition", required_argument, 0, 'p'}, 425 {"partition", required_argument, 0, 'p'},
420 {"exclude_device", required_argument, 0, 'x'}, 426 {"exclude_device", required_argument, 0, 'x'},
421 {"exclude-type", required_argument, 0, 'X'}, 427 {"exclude-type", required_argument, 0, 'X'},
428 {"include-type", required_argument, 0, 'N'},
422 {"group", required_argument, 0, 'g'}, 429 {"group", required_argument, 0, 'g'},
423 {"eregi-path", required_argument, 0, 'R'}, 430 {"eregi-path", required_argument, 0, 'R'},
424 {"eregi-partition", required_argument, 0, 'R'}, 431 {"eregi-partition", required_argument, 0, 'R'},
@@ -452,7 +459,7 @@ process_arguments (int argc, char **argv)
452 strcpy (argv[c], "-t"); 459 strcpy (argv[c], "-t");
453 460
454 while (1) { 461 while (1) {
455 c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklLg:R:r:i:I:MEA", longopts, &option); 462 c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:N:mklLg:R:r:i:I:MEA", longopts, &option);
456 463
457 if (c == -1 || c == EOF) 464 if (c == -1 || c == EOF)
458 break; 465 break;
@@ -591,6 +598,9 @@ process_arguments (int argc, char **argv)
591 case 'X': /* exclude file system type */ 598 case 'X': /* exclude file system type */
592 np_add_name(&fs_exclude_list, optarg); 599 np_add_name(&fs_exclude_list, optarg);
593 break; 600 break;
601 case 'N': /* include file system type */
602 np_add_name(&fs_include_list, optarg);
603 break;
594 case 'v': /* verbose */ 604 case 'v': /* verbose */
595 verbose++; 605 verbose++;
596 break; 606 break;
@@ -856,7 +866,7 @@ print_help (void)
856 printf (" %s\n", "-c, --critical=INTEGER"); 866 printf (" %s\n", "-c, --critical=INTEGER");
857 printf (" %s\n", _("Exit with CRITICAL status if less than INTEGER units of disk are free")); 867 printf (" %s\n", _("Exit with CRITICAL status if less than INTEGER units of disk are free"));
858 printf (" %s\n", "-c, --critical=PERCENT%"); 868 printf (" %s\n", "-c, --critical=PERCENT%");
859 printf (" %s\n", _("Exit with CRITCAL status if less than PERCENT of disk space is free")); 869 printf (" %s\n", _("Exit with CRITICAL status if less than PERCENT of disk space is free"));
860 printf (" %s\n", "-W, --iwarning=PERCENT%"); 870 printf (" %s\n", "-W, --iwarning=PERCENT%");
861 printf (" %s\n", _("Exit with WARNING status if less than PERCENT of inode space is free")); 871 printf (" %s\n", _("Exit with WARNING status if less than PERCENT of inode space is free"));
862 printf (" %s\n", "-K, --icritical=PERCENT%"); 872 printf (" %s\n", "-K, --icritical=PERCENT%");
@@ -900,6 +910,8 @@ print_help (void)
900 printf (UT_VERBOSE); 910 printf (UT_VERBOSE);
901 printf (" %s\n", "-X, --exclude-type=TYPE"); 911 printf (" %s\n", "-X, --exclude-type=TYPE");
902 printf (" %s\n", _("Ignore all filesystems of indicated type (may be repeated)")); 912 printf (" %s\n", _("Ignore all filesystems of indicated type (may be repeated)"));
913 printf (" %s\n", "-N, --include-type=TYPE");
914 printf (" %s\n", _("Check only filesystems of indicated type (may be repeated)"));
903 915
904 printf ("\n"); 916 printf ("\n");
905 printf ("%s\n", _("Examples:")); 917 printf ("%s\n", _("Examples:"));
@@ -922,7 +934,7 @@ print_usage (void)
922 printf ("%s\n", _("Usage:")); 934 printf ("%s\n", _("Usage:"));
923 printf (" %s -w limit -c limit [-W limit] [-K limit] {-p path | -x device}\n", progname); 935 printf (" %s -w limit -c limit [-W limit] [-K limit] {-p path | -x device}\n", progname);
924 printf ("[-C] [-E] [-e] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n"); 936 printf ("[-C] [-E] [-e] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n");
925 printf ("[-t timeout] [-u unit] [-v] [-X type]\n"); 937 printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type]\n");
926} 938}
927 939
928void 940void
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 91af730b..ac6cfc38 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -91,7 +91,7 @@ main (int argc, char **argv)
91 textdomain (PACKAGE); 91 textdomain (PACKAGE);
92 92
93 /* Set signal handling and alarm */ 93 /* Set signal handling and alarm */
94 if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { 94 if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) {
95 usage_va(_("Cannot catch SIGALRM")); 95 usage_va(_("Cannot catch SIGALRM"));
96 } 96 }
97 97
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 77a235e4..6db38e8c 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"
@@ -115,6 +115,7 @@ int followsticky = STICKY_NONE;
115int use_ssl = FALSE; 115int use_ssl = FALSE;
116int use_sni = FALSE; 116int use_sni = FALSE;
117int verbose = FALSE; 117int verbose = FALSE;
118int show_extended_perfdata = FALSE;
118int sd; 119int sd;
119int min_page_len = 0; 120int min_page_len = 0;
120int max_page_len = 0; 121int max_page_len = 0;
@@ -131,6 +132,11 @@ void redir (char *pos, char *status_line);
131int server_type_check(const char *type); 132int server_type_check(const char *type);
132int server_port_check(int ssl_flag); 133int server_port_check(int ssl_flag);
133char *perfd_time (double microsec); 134char *perfd_time (double microsec);
135char *perfd_time_connect (double microsec);
136char *perfd_time_ssl (double microsec);
137char *perfd_time_firstbyte (double microsec);
138char *perfd_time_headers (double microsec);
139char *perfd_time_transfer (double microsec);
134char *perfd_size (int page_len); 140char *perfd_size (int page_len);
135void print_help (void); 141void print_help (void);
136void print_usage (void); 142void print_usage (void);
@@ -216,6 +222,7 @@ process_arguments (int argc, char **argv)
216 {"invert-regex", no_argument, NULL, INVERT_REGEX}, 222 {"invert-regex", no_argument, NULL, INVERT_REGEX},
217 {"use-ipv4", no_argument, 0, '4'}, 223 {"use-ipv4", no_argument, 0, '4'},
218 {"use-ipv6", no_argument, 0, '6'}, 224 {"use-ipv6", no_argument, 0, '6'},
225 {"extended-perfdata", no_argument, 0, 'E'},
219 {0, 0, 0, 0} 226 {0, 0, 0, 0}
220 }; 227 };
221 228
@@ -236,7 +243,7 @@ process_arguments (int argc, char **argv)
236 } 243 }
237 244
238 while (1) { 245 while (1) {
239 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:nlLS::m:M:N", longopts, &option); 246 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:nlLS::m:M:N:E", longopts, &option);
240 if (c == -1 || c == EOF) 247 if (c == -1 || c == EOF)
241 break; 248 break;
242 249
@@ -284,18 +291,18 @@ process_arguments (int argc, char **argv)
284 case 'C': /* Check SSL cert validity */ 291 case 'C': /* Check SSL cert validity */
285#ifdef HAVE_SSL 292#ifdef HAVE_SSL
286 if ((temp=strchr(optarg,','))!=NULL) { 293 if ((temp=strchr(optarg,','))!=NULL) {
287 *temp='\0'; 294 *temp='\0';
288 if (!is_intnonneg (temp)) 295 if (!is_intnonneg (optarg))
289 usage2 (_("Invalid certificate expiration period"), optarg); 296 usage2 (_("Invalid certificate expiration period"), optarg);
290 days_till_exp_warn = atoi(optarg); 297 days_till_exp_warn = atoi(optarg);
291 *temp=','; 298 *temp=',';
292 temp++; 299 temp++;
293 if (!is_intnonneg (temp)) 300 if (!is_intnonneg (temp))
294 usage2 (_("Invalid certificate expiration period"), temp); 301 usage2 (_("Invalid certificate expiration period"), temp);
295 days_till_exp_crit = atoi (temp); 302 days_till_exp_crit = atoi (temp);
296 } 303 }
297 else { 304 else {
298 days_till_exp_crit=0; 305 days_till_exp_crit=0;
299 if (!is_intnonneg (optarg)) 306 if (!is_intnonneg (optarg))
300 usage2 (_("Invalid certificate expiration period"), optarg); 307 usage2 (_("Invalid certificate expiration period"), optarg);
301 days_till_exp_warn = atoi (optarg); 308 days_till_exp_warn = atoi (optarg);
@@ -304,9 +311,7 @@ process_arguments (int argc, char **argv)
304 /* Fall through to -S option */ 311 /* Fall through to -S option */
305#endif 312#endif
306 case 'S': /* use SSL */ 313 case 'S': /* use SSL */
307#ifndef HAVE_SSL 314#ifdef HAVE_SSL
308 usage4 (_("Invalid option - SSL is not available"));
309#endif
310 use_ssl = TRUE; 315 use_ssl = TRUE;
311 if (optarg == NULL || c != 'S') 316 if (optarg == NULL || c != 'S')
312 ssl_version = 0; 317 ssl_version = 0;
@@ -317,6 +322,9 @@ process_arguments (int argc, char **argv)
317 } 322 }
318 if (specify_port == FALSE) 323 if (specify_port == FALSE)
319 server_port = HTTPS_PORT; 324 server_port = HTTPS_PORT;
325#else
326 usage4 (_("Invalid option - SSL is not available"));
327#endif
320 break; 328 break;
321 case SNI_OPTION: 329 case SNI_OPTION:
322 use_sni = TRUE; 330 use_sni = TRUE;
@@ -470,6 +478,9 @@ process_arguments (int argc, char **argv)
470 } 478 }
471 } 479 }
472 break; 480 break;
481 case 'E': /* show extended perfdata */
482 show_extended_perfdata = TRUE;
483 break;
473 } 484 }
474 } 485 }
475 486
@@ -811,17 +822,33 @@ check_http (void)
811 char *pos; 822 char *pos;
812 long microsec; 823 long microsec;
813 double elapsed_time; 824 double elapsed_time;
825 long microsec_connect;
826 double elapsed_time_connect;
827 long microsec_ssl;
828 double elapsed_time_ssl;
829 long microsec_firstbyte;
830 double elapsed_time_firstbyte;
831 long microsec_headers;
832 double elapsed_time_headers;
833 long microsec_transfer;
834 double elapsed_time_transfer;
814 int page_len = 0; 835 int page_len = 0;
815 int result = STATE_OK; 836 int result = STATE_OK;
816 837
817 /* try to connect to the host at the given port number */ 838 /* try to connect to the host at the given port number */
839 gettimeofday (&tv_temp, NULL);
818 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) 840 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK)
819 die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n")); 841 die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n"));
842 microsec_connect = deltime (tv_temp);
820#ifdef HAVE_SSL 843#ifdef HAVE_SSL
844 elapsed_time_connect = (double)microsec_connect / 1.0e6;
821 if (use_ssl == TRUE) { 845 if (use_ssl == TRUE) {
846 gettimeofday (&tv_temp, NULL);
822 result = np_net_ssl_init_with_hostname_and_version(sd, (use_sni ? host_name : NULL), ssl_version); 847 result = np_net_ssl_init_with_hostname_and_version(sd, (use_sni ? host_name : NULL), ssl_version);
823 if (result != STATE_OK) 848 if (result != STATE_OK)
824 return result; 849 return result;
850 microsec_ssl = deltime (tv_temp);
851 elapsed_time_ssl = (double)microsec_ssl / 1.0e6;
825 if (check_cert == TRUE) { 852 if (check_cert == TRUE) {
826 result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); 853 result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit);
827 np_net_ssl_cleanup(); 854 np_net_ssl_cleanup();
@@ -853,8 +880,7 @@ check_http (void)
853 /* optionally send any other header tag */ 880 /* optionally send any other header tag */
854 if (http_opt_headers_count) { 881 if (http_opt_headers_count) {
855 for (i = 0; i < http_opt_headers_count ; i++) { 882 for (i = 0; i < http_opt_headers_count ; i++) {
856 for ((pos = strtok(http_opt_headers[i], INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER))) 883 xasprintf (&buf, "%s%s\r\n", buf, http_opt_headers[i]);
857 xasprintf (&buf, "%s%s\r\n", buf, pos);
858 } 884 }
859 /* This cannot be free'd here because a redirection will then try to access this and segfault */ 885 /* This cannot be free'd here because a redirection will then try to access this and segfault */
860 /* Covered in a testcase in tests/check_http.t */ 886 /* Covered in a testcase in tests/check_http.t */
@@ -890,11 +916,19 @@ check_http (void)
890 } 916 }
891 917
892 if (verbose) printf ("%s\n", buf); 918 if (verbose) printf ("%s\n", buf);
919 gettimeofday (&tv_temp, NULL);
893 my_send (buf, strlen (buf)); 920 my_send (buf, strlen (buf));
921 microsec_headers = deltime (tv_temp);
922 elapsed_time_headers = (double)microsec_headers / 1.0e6;
894 923
895 /* fetch the page */ 924 /* fetch the page */
896 full_page = strdup(""); 925 full_page = strdup("");
926 gettimeofday (&tv_temp, NULL);
897 while ((i = my_recv (buffer, MAX_INPUT_BUFFER-1)) > 0) { 927 while ((i = my_recv (buffer, MAX_INPUT_BUFFER-1)) > 0) {
928 if ((i >= 1) && (elapsed_time_firstbyte <= 0.000001)) {
929 microsec_firstbyte = deltime (tv_temp);
930 elapsed_time_firstbyte = (double)microsec_firstbyte / 1.0e6;
931 }
898 buffer[i] = '\0'; 932 buffer[i] = '\0';
899 xasprintf (&full_page_new, "%s%s", full_page, buffer); 933 xasprintf (&full_page_new, "%s%s", full_page, buffer);
900 free (full_page); 934 free (full_page);
@@ -906,6 +940,8 @@ check_http (void)
906 break; 940 break;
907 } 941 }
908 } 942 }
943 microsec_transfer = deltime (tv_temp);
944 elapsed_time_transfer = (double)microsec_transfer / 1.0e6;
909 945
910 if (i < 0 && errno != ECONNRESET) { 946 if (i < 0 && errno != ECONNRESET) {
911#ifdef HAVE_SSL 947#ifdef HAVE_SSL
@@ -1107,11 +1143,25 @@ check_http (void)
1107 msg[strlen(msg)-3] = '\0'; 1143 msg[strlen(msg)-3] = '\0';
1108 1144
1109 /* check elapsed time */ 1145 /* check elapsed time */
1110 xasprintf (&msg, 1146 if (show_extended_perfdata)
1111 _("%s - %d bytes in %.3f second response time %s|%s %s"), 1147 xasprintf (&msg,
1112 msg, page_len, elapsed_time, 1148 _("%s - %d bytes in %.3f second response time %s|%s %s %s %s %s %s %s"),
1113 (display_html ? "</A>" : ""), 1149 msg, page_len, elapsed_time,
1114 perfd_time (elapsed_time), perfd_size (page_len)); 1150 (display_html ? "</A>" : ""),
1151 perfd_time (elapsed_time),
1152 perfd_size (page_len),
1153 perfd_time_connect (elapsed_time_connect),
1154 use_ssl == TRUE ? perfd_time_ssl (elapsed_time_ssl) : "",
1155 perfd_time_headers (elapsed_time_headers),
1156 perfd_time_firstbyte (elapsed_time_firstbyte),
1157 perfd_time_transfer (elapsed_time_transfer));
1158 else
1159 xasprintf (&msg,
1160 _("%s - %d bytes in %.3f second response time %s|%s %s"),
1161 msg, page_len, elapsed_time,
1162 (display_html ? "</A>" : ""),
1163 perfd_time (elapsed_time),
1164 perfd_size (page_len));
1115 1165
1116 result = max_state_alt(get_status(elapsed_time, thlds), result); 1166 result = max_state_alt(get_status(elapsed_time, thlds), result);
1117 1167
@@ -1300,7 +1350,30 @@ char *perfd_time (double elapsed_time)
1300 TRUE, 0, FALSE, 0); 1350 TRUE, 0, FALSE, 0);
1301} 1351}
1302 1352
1353char *perfd_time_connect (double elapsed_time_connect)
1354{
1355 return fperfdata ("time_connect", elapsed_time_connect, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0);
1356}
1357
1358char *perfd_time_ssl (double elapsed_time_ssl)
1359{
1360 return fperfdata ("time_ssl", elapsed_time_ssl, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0);
1361}
1362
1363char *perfd_time_headers (double elapsed_time_headers)
1364{
1365 return fperfdata ("time_headers", elapsed_time_headers, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0);
1366}
1303 1367
1368char *perfd_time_firstbyte (double elapsed_time_firstbyte)
1369{
1370 return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0);
1371}
1372
1373char *perfd_time_transfer (double elapsed_time_transfer)
1374{
1375 return fperfdata ("time_transfer", elapsed_time_transfer, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0);
1376}
1304 1377
1305char *perfd_size (int page_len) 1378char *perfd_size (int page_len)
1306{ 1379{
@@ -1351,7 +1424,7 @@ print_help (void)
1351 printf (" %s\n", _("auto-negotiation (1 = TLSv1, 2 = SSLv2, 3 = SSLv3).")); 1424 printf (" %s\n", _("auto-negotiation (1 = TLSv1, 2 = SSLv2, 3 = SSLv3)."));
1352 printf (" %s\n", "--sni"); 1425 printf (" %s\n", "--sni");
1353 printf (" %s\n", _("Enable SSL/TLS hostname extension support (SNI)")); 1426 printf (" %s\n", _("Enable SSL/TLS hostname extension support (SNI)"));
1354 printf (" %s\n", "-C, --certificate=INTEGER"); 1427 printf (" %s\n", "-C, --certificate=INTEGER[,INTEGER]");
1355 printf (" %s\n", _("Minimum number of days a certificate has to be valid. Port defaults to 443")); 1428 printf (" %s\n", _("Minimum number of days a certificate has to be valid. Port defaults to 443"));
1356 printf (" %s\n", _("(when this option is used the URL is not checked.)\n")); 1429 printf (" %s\n", _("(when this option is used the URL is not checked.)\n"));
1357#endif 1430#endif
@@ -1433,14 +1506,14 @@ print_help (void)
1433 printf (" %s\n", _("When the 'www.verisign.com' server returns its content within 5 seconds,")); 1506 printf (" %s\n", _("When the 'www.verisign.com' server returns its content within 5 seconds,"));
1434 printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds")); 1507 printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds"));
1435 printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,")); 1508 printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,"));
1436 printf (" %s\n\n", _("a STATE_CRITICAL will be returned.")); 1509 printf (" %s\n", _("a STATE_CRITICAL will be returned."));
1437 1510 printf ("\n");
1438 printf (" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 14"); 1511 printf (" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 14");
1439 printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 14 days,")); 1512 printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 14 days,"));
1440 printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than")); 1513 printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than"));
1441 printf (" %s\n", _("14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when")); 1514 printf (" %s\n", _("14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when"));
1442 printf (" %s\n", _("the certificate is expired.")); 1515 printf (" %s\n", _("the certificate is expired."));
1443 1516 printf ("\n");
1444 printf (" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 30,14"); 1517 printf (" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 30,14");
1445 printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 30 days,")); 1518 printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 30 days,"));
1446 printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than")); 1519 printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than"));
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c
index 65db8517..b05aca9a 100644
--- a/plugins/check_ldap.c
+++ b/plugins/check_ldap.c
@@ -445,11 +445,6 @@ print_help (void)
445 printf (UT_SUPPORT); 445 printf (UT_SUPPORT);
446} 446}
447 447
448/* todo
449* add option -4 and -6 to the long manual
450*
451*/
452
453void 448void
454print_usage (void) 449print_usage (void)
455{ 450{
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 4fbdc2b9..51579c2a 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -5,7 +5,7 @@
5* License: GPL 5* License: GPL
6* Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at) 6* Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)
7* Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net) 7* Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net)
8* Copyright (c) 1999-2009 Nagios Plugins Development Team 8* Copyright (c) 1999-2011 Nagios Plugins Development Team
9* 9*
10* Description: 10* Description:
11* 11*
@@ -31,7 +31,7 @@
31*****************************************************************************/ 31*****************************************************************************/
32 32
33const char *progname = "check_mysql"; 33const char *progname = "check_mysql";
34const char *copyright = "1999-2007"; 34const char *copyright = "1999-2011";
35const char *email = "nagiosplug-devel@lists.sourceforge.net"; 35const char *email = "nagiosplug-devel@lists.sourceforge.net";
36 36
37#define SLAVERESULTSIZE 70 37#define SLAVERESULTSIZE 70
@@ -157,7 +157,7 @@ main (int argc, char **argv)
157 } 157 }
158 158
159 } else { 159 } else {
160 /* mysql 4.x.x */ 160 /* mysql 4.x.x and mysql 5.x.x */
161 int slave_io_field = -1 , slave_sql_field = -1, seconds_behind_field = -1, i, num_fields; 161 int slave_io_field = -1 , slave_sql_field = -1, seconds_behind_field = -1, i, num_fields;
162 MYSQL_FIELD* fields; 162 MYSQL_FIELD* fields;
163 163
@@ -178,13 +178,17 @@ main (int argc, char **argv)
178 } 178 }
179 } 179 }
180 180
181 /* Check if slave status is available */
181 if ((slave_io_field < 0) || (slave_sql_field < 0) || (num_fields == 0)) { 182 if ((slave_io_field < 0) || (slave_sql_field < 0) || (num_fields == 0)) {
182 mysql_free_result (res); 183 mysql_free_result (res);
183 mysql_close (&mysql); 184 mysql_close (&mysql);
184 die (STATE_CRITICAL, "Slave status unavailable\n"); 185 die (STATE_CRITICAL, "Slave status unavailable\n");
185 } 186 }
186 187
188 /* Save slave status in slaveresult */
187 snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s Seconds Behind Master: %s", row[slave_io_field], row[slave_sql_field], seconds_behind_field!=-1?row[seconds_behind_field]:"Unknown"); 189 snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s Seconds Behind Master: %s", row[slave_io_field], row[slave_sql_field], seconds_behind_field!=-1?row[seconds_behind_field]:"Unknown");
190
191 /* Raise critical error if SQL THREAD or IO THREAD are stopped */
188 if (strcmp (row[slave_io_field], "Yes") != 0 || strcmp (row[slave_sql_field], "Yes") != 0) { 192 if (strcmp (row[slave_io_field], "Yes") != 0 || strcmp (row[slave_sql_field], "Yes") != 0) {
189 mysql_free_result (res); 193 mysql_free_result (res);
190 mysql_close (&mysql); 194 mysql_close (&mysql);
@@ -199,6 +203,7 @@ main (int argc, char **argv)
199 } 203 }
200 } 204 }
201 205
206 /* Check Seconds Behind against threshold */
202 if ((seconds_behind_field != -1) && (strcmp (row[seconds_behind_field], "NULL") != 0)) { 207 if ((seconds_behind_field != -1) && (strcmp (row[seconds_behind_field], "NULL") != 0)) {
203 double value = atof(row[seconds_behind_field]); 208 double value = atof(row[seconds_behind_field]);
204 int status; 209 int status;
diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c
index c8cdbc02..4fd6342d 100644
--- a/plugins/check_nagios.c
+++ b/plugins/check_nagios.c
@@ -205,6 +205,7 @@ process_arguments (int argc, char **argv)
205 {"filename", required_argument, 0, 'F'}, 205 {"filename", required_argument, 0, 'F'},
206 {"expires", required_argument, 0, 'e'}, 206 {"expires", required_argument, 0, 'e'},
207 {"command", required_argument, 0, 'C'}, 207 {"command", required_argument, 0, 'C'},
208 {"timeout", optional_argument, 0, 't'},
208 {"version", no_argument, 0, 'V'}, 209 {"version", no_argument, 0, 'V'},
209 {"help", no_argument, 0, 'h'}, 210 {"help", no_argument, 0, 'h'},
210 {"verbose", no_argument, 0, 'v'}, 211 {"verbose", no_argument, 0, 'v'},
@@ -226,7 +227,7 @@ process_arguments (int argc, char **argv)
226 } 227 }
227 228
228 while (1) { 229 while (1) {
229 c = getopt_long (argc, argv, "+hVvF:C:e:", longopts, &option); 230 c = getopt_long (argc, argv, "+hVvF:C:e:t:", longopts, &option);
230 231
231 if (c == -1 || c == EOF || c == 1) 232 if (c == -1 || c == EOF || c == 1)
232 break; 233 break;
@@ -251,6 +252,13 @@ process_arguments (int argc, char **argv)
251 die (STATE_UNKNOWN, 252 die (STATE_UNKNOWN,
252 _("Expiration time must be an integer (seconds)\n")); 253 _("Expiration time must be an integer (seconds)\n"));
253 break; 254 break;
255 case 't': /* timeout */
256 if (is_intnonneg (optarg))
257 timeout_interval = atoi (optarg);
258 else
259 die (STATE_UNKNOWN,
260 _("Timeout must be an integer (seconds)\n"));
261 break;
254 case 'v': 262 case 'v':
255 verbose++; 263 verbose++;
256 break; 264 break;
@@ -296,11 +304,13 @@ print_help (void)
296 printf (" %s\n", _("Minutes aging after which logfile is considered stale")); 304 printf (" %s\n", _("Minutes aging after which logfile is considered stale"));
297 printf (" %s\n", "-C, --command=STRING"); 305 printf (" %s\n", "-C, --command=STRING");
298 printf (" %s\n", _("Substring to search for in process arguments")); 306 printf (" %s\n", _("Substring to search for in process arguments"));
307 printf (" %s\n", "-t, --timeout=INTEGER");
308 printf (" %s\n", _("Timeout for the plugin in seconds"));
299 printf (UT_VERBOSE); 309 printf (UT_VERBOSE);
300 310
301 printf ("\n"); 311 printf ("\n");
302 printf ("%s\n", _("Examples:")); 312 printf ("%s\n", _("Examples:"));
303 printf (" %s\n", "check_nagios -e 5 -F /usr/local/nagios/var/status.log -C /usr/local/nagios/bin/nagios"); 313 printf (" %s\n", "check_nagios -t 20 -e 5 -F /usr/local/nagios/var/status.log -C /usr/local/nagios/bin/nagios");
304 314
305 printf (UT_SUPPORT); 315 printf (UT_SUPPORT);
306} 316}
@@ -311,5 +321,5 @@ void
311print_usage (void) 321print_usage (void)
312{ 322{
313 printf ("%s\n", _("Usage:")); 323 printf ("%s\n", _("Usage:"));
314 printf ("%s -F <status log file> -e <expire_minutes> -C <process_string>\n", progname); 324 printf ("%s -F <status log file> -t <timeout_seconds> -e <expire_minutes> -C <process_string>\n", progname);
315} 325}
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.c b/plugins/check_ntp.c
index 76d19ba3..16be7c51 100644
--- a/plugins/check_ntp.c
+++ b/plugins/check_ntp.c
@@ -398,7 +398,11 @@ double offset_request(const char *host, int *status){
398 die(STATE_UNKNOWN, "can not create new socket"); 398 die(STATE_UNKNOWN, "can not create new socket");
399 } 399 }
400 if(connect(socklist[i], ai_tmp->ai_addr, ai_tmp->ai_addrlen)){ 400 if(connect(socklist[i], ai_tmp->ai_addr, ai_tmp->ai_addrlen)){
401 die(STATE_UNKNOWN, "can't create socket connection"); 401 /* don't die here, because it is enough if there is one server
402 answering in time. This also would break for dual ipv4/6 stacked
403 ntp servers when the client only supports on of them.
404 */
405 DBG(printf("can't create socket connection on peer %i: %s\n", i, strerror(errno)));
402 } else { 406 } else {
403 ufds[i].fd=socklist[i]; 407 ufds[i].fd=socklist[i];
404 ufds[i].events=POLLIN; 408 ufds[i].events=POLLIN;
@@ -845,6 +849,7 @@ void print_help(void){
845 printf (UT_HELP_VRSN); 849 printf (UT_HELP_VRSN);
846 printf (UT_EXTRA_OPTS); 850 printf (UT_EXTRA_OPTS);
847 printf (UT_HOST_PORT, 'p', "123"); 851 printf (UT_HOST_PORT, 'p', "123");
852 printf (UT_IPv46);
848 printf (" %s\n", "-w, --warning=THRESHOLD"); 853 printf (" %s\n", "-w, --warning=THRESHOLD");
849 printf (" %s\n", _("Offset to result in warning status (seconds)")); 854 printf (" %s\n", _("Offset to result in warning status (seconds)"));
850 printf (" %s\n", "-c, --critical=THRESHOLD"); 855 printf (" %s\n", "-c, --critical=THRESHOLD");
@@ -881,5 +886,5 @@ print_usage(void)
881 printf ("%s\n", _("WARNING: check_ntp is deprecated. Please use check_ntp_peer or")); 886 printf ("%s\n", _("WARNING: check_ntp is deprecated. Please use check_ntp_peer or"));
882 printf ("%s\n\n", _("check_ntp_time instead.")); 887 printf ("%s\n\n", _("check_ntp_time instead."));
883 printf ("%s\n", _("Usage:")); 888 printf ("%s\n", _("Usage:"));
884 printf(" %s -H <host> [-w <warn>] [-c <crit>] [-j <warn>] [-k <crit>] [-v verbose]\n", progname); 889 printf(" %s -H <host> [-w <warn>] [-c <crit>] [-j <warn>] [-k <crit>] [-4|-6] [-v verbose]\n", progname);
885} 890}
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c
index f0dd2d87..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);
@@ -660,6 +666,7 @@ void print_help(void){
660 print_usage(); 666 print_usage();
661 printf (UT_HELP_VRSN); 667 printf (UT_HELP_VRSN);
662 printf (UT_EXTRA_OPTS); 668 printf (UT_EXTRA_OPTS);
669 printf (UT_IPv46);
663 printf (UT_HOST_PORT, 'p', "123"); 670 printf (UT_HOST_PORT, 'p', "123");
664 printf (" %s\n", "-q, --quiet"); 671 printf (" %s\n", "-q, --quiet");
665 printf (" %s\n", _("Returns UNKNOWN instead of CRITICAL or WARNING if server isn't synchronized")); 672 printf (" %s\n", _("Returns UNKNOWN instead of CRITICAL or WARNING if server isn't synchronized"));
@@ -668,9 +675,9 @@ void print_help(void){
668 printf (" %s\n", "-c, --critical=THRESHOLD"); 675 printf (" %s\n", "-c, --critical=THRESHOLD");
669 printf (" %s\n", _("Offset to result in critical status (seconds)")); 676 printf (" %s\n", _("Offset to result in critical status (seconds)"));
670 printf (" %s\n", "-W, --swarn=THRESHOLD"); 677 printf (" %s\n", "-W, --swarn=THRESHOLD");
671 printf (" %s\n", _("Warning threshold for stratum")); 678 printf (" %s\n", _("Warning threshold for stratum of server's synchronization peer"));
672 printf (" %s\n", "-C, --scrit=THRESHOLD"); 679 printf (" %s\n", "-C, --scrit=THRESHOLD");
673 printf (" %s\n", _("Critical threshold for stratum")); 680 printf (" %s\n", _("Critical threshold for stratum of server's synchronization peer"));
674 printf (" %s\n", "-j, --jwarn=THRESHOLD"); 681 printf (" %s\n", "-j, --jwarn=THRESHOLD");
675 printf (" %s\n", _("Warning threshold for jitter")); 682 printf (" %s\n", _("Warning threshold for jitter"));
676 printf (" %s\n", "-k, --jcrit=THRESHOLD"); 683 printf (" %s\n", "-k, --jcrit=THRESHOLD");
@@ -704,7 +711,7 @@ void print_help(void){
704 printf(" %s\n", ("./check_ntp_peer -H ntpserv -w 0.5 -c 1 -j -1:100 -k -1:200")); 711 printf(" %s\n", ("./check_ntp_peer -H ntpserv -w 0.5 -c 1 -j -1:100 -k -1:200"));
705 printf("\n"); 712 printf("\n");
706 printf(" %s\n", _("Only check the number of usable time sources (\"truechimers\"):")); 713 printf(" %s\n", _("Only check the number of usable time sources (\"truechimers\"):"));
707 printf(" %s\n", ("./check_ntp_peer -H ntpserv -m :5 -n :3")); 714 printf(" %s\n", ("./check_ntp_peer -H ntpserv -m @5 -n @3"));
708 printf("\n"); 715 printf("\n");
709 printf(" %s\n", _("Check only stratum:")); 716 printf(" %s\n", _("Check only stratum:"));
710 printf(" %s\n", ("./check_ntp_peer -H ntpserv -W 4 -C 6")); 717 printf(" %s\n", ("./check_ntp_peer -H ntpserv -W 4 -C 6"));
@@ -716,6 +723,6 @@ void
716print_usage(void) 723print_usage(void)
717{ 724{
718 printf ("%s\n", _("Usage:")); 725 printf ("%s\n", _("Usage:"));
719 printf(" %s -H <host> [-w <warn>] [-c <crit>] [-W <warn>] [-C <crit>]\n", progname); 726 printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-W <warn>] [-C <crit>]\n", progname);
720 printf(" [-j <warn>] [-k <crit>] [-v verbose]\n"); 727 printf(" [-j <warn>] [-k <crit>] [-v verbose]\n");
721} 728}
diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c
index d543d6b5..bbcaa0ba 100644
--- a/plugins/check_ntp_time.c
+++ b/plugins/check_ntp_time.c
@@ -344,7 +344,11 @@ double offset_request(const char *host, int *status){
344 die(STATE_UNKNOWN, "can not create new socket"); 344 die(STATE_UNKNOWN, "can not create new socket");
345 } 345 }
346 if(connect(socklist[i], ai_tmp->ai_addr, ai_tmp->ai_addrlen)){ 346 if(connect(socklist[i], ai_tmp->ai_addr, ai_tmp->ai_addrlen)){
347 die(STATE_UNKNOWN, "can't create socket connection"); 347 /* don't die here, because it is enough if there is one server
348 answering in time. This also would break for dual ipv4/6 stacked
349 ntp servers when the client only supports on of them.
350 */
351 DBG(printf("can't create socket connection on peer %i: %s\n", i, strerror(errno)));
348 } else { 352 } else {
349 ufds[i].fd=socklist[i]; 353 ufds[i].fd=socklist[i];
350 ufds[i].events=POLLIN; 354 ufds[i].events=POLLIN;
@@ -602,6 +606,7 @@ void print_help(void){
602 print_usage(); 606 print_usage();
603 printf (UT_HELP_VRSN); 607 printf (UT_HELP_VRSN);
604 printf (UT_EXTRA_OPTS); 608 printf (UT_EXTRA_OPTS);
609 printf (UT_IPv46);
605 printf (UT_HOST_PORT, 'p', "123"); 610 printf (UT_HOST_PORT, 'p', "123");
606 printf (" %s\n", "-q, --quiet"); 611 printf (" %s\n", "-q, --quiet");
607 printf (" %s\n", _("Returns UNKNOWN instead of CRITICAL if offset cannot be found")); 612 printf (" %s\n", _("Returns UNKNOWN instead of CRITICAL if offset cannot be found"));
@@ -635,6 +640,6 @@ void
635print_usage(void) 640print_usage(void)
636{ 641{
637 printf ("%s\n", _("Usage:")); 642 printf ("%s\n", _("Usage:"));
638 printf(" %s -H <host> [-w <warn>] [-c <crit>] [-v verbose]\n", progname); 643 printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-v verbose]\n", progname);
639} 644}
640 645
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c
index d3116b00..c109955a 100644
--- a/plugins/check_pgsql.c
+++ b/plugins/check_pgsql.c
@@ -576,7 +576,7 @@ void
576print_usage (void) 576print_usage (void)
577{ 577{
578 printf ("%s\n", _("Usage:")); 578 printf ("%s\n", _("Usage:"));
579 printf ("%s [-H <host>] [-P <port>] [-c <critical time>] [-w <warning time>]\n", progname); 579 printf ("%s [-H <host>] [-4|-6] [-P <port>] [-c <critical time>] [-w <warning time>]\n", progname);
580 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"); 581 "[-q <query>] [-C <critical query range>] [-W <warning query range>]\n");
582} 582}
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 2f2dcc58..6acedc70 100644
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
@@ -45,15 +45,13 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
45 45
46int process_arguments (int, char **); 46int process_arguments (int, char **);
47int validate_arguments (void); 47int validate_arguments (void);
48int check_thresholds (int);
49int convert_to_seconds (char *); 48int convert_to_seconds (char *);
50void print_help (void); 49void print_help (void);
51void print_usage (void); 50void print_usage (void);
52 51
53int wmax = -1; 52char *warning_range = NULL;
54int cmax = -1; 53char *critical_range = NULL;
55int wmin = -1; 54thresholds *procs_thresholds = NULL;
56int cmin = -1;
57 55
58int options = 0; /* bitmask of filter criteria to test against */ 56int options = 0; /* bitmask of filter criteria to test against */
59#define ALL 1 57#define ALL 1
@@ -238,14 +236,14 @@ main (int argc, char **argv)
238 } 236 }
239 237
240 if (metric == METRIC_VSZ) 238 if (metric == METRIC_VSZ)
241 i = check_thresholds (procvsz); 239 i = get_status ((double)procvsz, procs_thresholds);
242 else if (metric == METRIC_RSS) 240 else if (metric == METRIC_RSS)
243 i = check_thresholds (procrss); 241 i = get_status ((double)procrss, procs_thresholds);
244 /* TODO? float thresholds for --metric=CPU */ 242 /* TODO? float thresholds for --metric=CPU */
245 else if (metric == METRIC_CPU) 243 else if (metric == METRIC_CPU)
246 i = check_thresholds ((int)procpcpu); 244 i = get_status (procpcpu, procs_thresholds);
247 else if (metric == METRIC_ELAPSED) 245 else if (metric == METRIC_ELAPSED)
248 i = check_thresholds (procseconds); 246 i = get_status ((double)procseconds, procs_thresholds);
249 247
250 if (metric != METRIC_PROCS) { 248 if (metric != METRIC_PROCS) {
251 if (i == STATE_WARNING) { 249 if (i == STATE_WARNING) {
@@ -276,7 +274,7 @@ main (int argc, char **argv)
276 274
277 /* Needed if procs found, but none match filter */ 275 /* Needed if procs found, but none match filter */
278 if ( metric == METRIC_PROCS ) { 276 if ( metric == METRIC_PROCS ) {
279 result = max_state (result, check_thresholds (procs) ); 277 result = max_state (result, get_status ((double)procs, procs_thresholds) );
280 } 278 }
281 279
282 if ( result == STATE_OK ) { 280 if ( result == STATE_OK ) {
@@ -301,6 +299,13 @@ main (int argc, char **argv)
301 if ( verbose >= 1 && strcmp(fails,"") ) 299 if ( verbose >= 1 && strcmp(fails,"") )
302 printf (" [%s]", fails); 300 printf (" [%s]", fails);
303 301
302 if (metric == METRIC_PROCS)
303 printf (" | procs=%d;%s;%s;0;", procs,
304 warning_range ? warning_range : "",
305 critical_range ? critical_range : "");
306 else
307 printf (" | procs=%d;;;0; procs_warn=%d;;;0; procs_crit=%d;;;0;", procs, warn, crit);
308
304 printf ("\n"); 309 printf ("\n");
305 return result; 310 return result;
306} 311}
@@ -327,6 +332,7 @@ process_arguments (int argc, char **argv)
327 {"timeout", required_argument, 0, 't'}, 332 {"timeout", required_argument, 0, 't'},
328 {"status", required_argument, 0, 's'}, 333 {"status", required_argument, 0, 's'},
329 {"ppid", required_argument, 0, 'p'}, 334 {"ppid", required_argument, 0, 'p'},
335 {"user", required_argument, 0, 'u'},
330 {"command", required_argument, 0, 'C'}, 336 {"command", required_argument, 0, 'C'},
331 {"vsz", required_argument, 0, 'z'}, 337 {"vsz", required_argument, 0, 'z'},
332 {"rss", required_argument, 0, 'r'}, 338 {"rss", required_argument, 0, 'r'},
@@ -368,28 +374,10 @@ process_arguments (int argc, char **argv)
368 timeout_interval = atoi (optarg); 374 timeout_interval = atoi (optarg);
369 break; 375 break;
370 case 'c': /* critical threshold */ 376 case 'c': /* critical threshold */
371 if (is_integer (optarg)) 377 critical_range = optarg;
372 cmax = atoi (optarg);
373 else if (sscanf (optarg, ":%d", &cmax) == 1)
374 break;
375 else if (sscanf (optarg, "%d:%d", &cmin, &cmax) == 2)
376 break;
377 else if (sscanf (optarg, "%d:", &cmin) == 1)
378 break;
379 else
380 usage4 (_("Critical Process Count must be an integer!"));
381 break; 378 break;
382 case 'w': /* warning threshold */ 379 case 'w': /* warning threshold */
383 if (is_integer (optarg)) 380 warning_range = optarg;
384 wmax = atoi (optarg);
385 else if (sscanf (optarg, ":%d", &wmax) == 1)
386 break;
387 else if (sscanf (optarg, "%d:%d", &wmin, &wmax) == 2)
388 break;
389 else if (sscanf (optarg, "%d:", &wmin) == 1)
390 break;
391 else
392 usage4 (_("Warning Process Count must be an integer!"));
393 break; 381 break;
394 case 'p': /* process id */ 382 case 'p': /* process id */
395 if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) { 383 if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) {
@@ -518,16 +506,19 @@ process_arguments (int argc, char **argv)
518 } 506 }
519 507
520 c = optind; 508 c = optind;
521 if (wmax == -1 && argv[c]) 509 if ((! warning_range) && argv[c])
522 wmax = atoi (argv[c++]); 510 warning_range = argv[c++];
523 if (cmax == -1 && argv[c]) 511 if ((! critical_range) && argv[c])
524 cmax = atoi (argv[c++]); 512 critical_range = argv[c++];
525 if (statopts == NULL && argv[c]) { 513 if (statopts == NULL && argv[c]) {
526 xasprintf (&statopts, "%s", argv[c++]); 514 xasprintf (&statopts, "%s", argv[c++]);
527 xasprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts); 515 xasprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts);
528 options |= STAT; 516 options |= STAT;
529 } 517 }
530 518
519 /* this will abort in case of invalid ranges */
520 set_thresholds (&procs_thresholds, warning_range, critical_range);
521
531 return validate_arguments (); 522 return validate_arguments ();
532} 523}
533 524
@@ -536,27 +527,6 @@ process_arguments (int argc, char **argv)
536int 527int
537validate_arguments () 528validate_arguments ()
538{ 529{
539
540 if (wmax >= 0 && wmin == -1)
541 wmin = 0;
542 if (cmax >= 0 && cmin == -1)
543 cmin = 0;
544 if (wmax >= wmin && cmax >= cmin) { /* standard ranges */
545 if (wmax > cmax && cmax != -1) {
546 printf (_("wmax (%d) cannot be greater than cmax (%d)\n"), wmax, cmax);
547 return ERROR;
548 }
549 if (cmin > wmin && wmin != -1) {
550 printf (_("wmin (%d) cannot be less than cmin (%d)\n"), wmin, cmin);
551 return ERROR;
552 }
553 }
554
555/* if (wmax == -1 && cmax == -1 && wmin == -1 && cmin == -1) { */
556/* printf ("At least one threshold must be set\n"); */
557/* return ERROR; */
558/* } */
559
560 if (options == 0) 530 if (options == 0)
561 options = ALL; 531 options = ALL;
562 532
@@ -579,40 +549,6 @@ validate_arguments ()
579} 549}
580 550
581 551
582
583/* Check thresholds against value */
584int
585check_thresholds (int value)
586{
587 if (wmax == -1 && cmax == -1 && wmin == -1 && cmin == -1) {
588 return OK;
589 }
590 else if (cmax >= 0 && cmin >= 0 && cmax < cmin) {
591 if (value > cmax && value < cmin)
592 return STATE_CRITICAL;
593 }
594 else if (cmax >= 0 && value > cmax) {
595 return STATE_CRITICAL;
596 }
597 else if (cmin >= 0 && value < cmin) {
598 return STATE_CRITICAL;
599 }
600
601 if (wmax >= 0 && wmin >= 0 && wmax < wmin) {
602 if (value > wmax && value < wmin) {
603 return STATE_WARNING;
604 }
605 }
606 else if (wmax >= 0 && value > wmax) {
607 return STATE_WARNING;
608 }
609 else if (wmin >= 0 && value < wmin) {
610 return STATE_WARNING;
611 }
612 return STATE_OK;
613}
614
615
616/* convert the elapsed time to seconds */ 552/* convert the elapsed time to seconds */
617int 553int
618convert_to_seconds(char *etime) { 554convert_to_seconds(char *etime) {
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index a861a71e..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 */
@@ -593,7 +591,7 @@ process_arguments (int argc, char **argv)
593#ifdef USE_OPENSSL 591#ifdef USE_OPENSSL
594 if ((temp=strchr(optarg,','))!=NULL) { 592 if ((temp=strchr(optarg,','))!=NULL) {
595 *temp='\0'; 593 *temp='\0';
596 if (!is_intnonneg (temp)) 594 if (!is_intnonneg (optarg))
597 usage2 ("Invalid certificate expiration period", optarg); 595 usage2 ("Invalid certificate expiration period", optarg);
598 days_till_exp_warn = atoi(optarg); 596 days_till_exp_warn = atoi(optarg);
599 *temp=','; 597 *temp=',';
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 2d9861bc..7c5d0ec5 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -144,6 +144,25 @@ double previous_value[MAX_OIDS];
144int perf_labels = 1; 144int perf_labels = 1;
145 145
146 146
147static char *fix_snmp_range(char *th)
148{
149 double left, right;
150 char *colon, *ret;
151 if (!(colon = strchr(th, ':')))
152 return th;
153 *colon = 0;
154
155 left = strtod(th, NULL);
156 right = strtod(colon + 1, NULL);
157 if (right >= left) {
158 return th;
159 }
160 ret = malloc(strlen(th) + strlen(colon + 1) + 2);
161 sprintf(ret, "@%s:%s", colon + 1, th);
162 free(th);
163 return ret;
164}
165
147int 166int
148main (int argc, char **argv) 167main (int argc, char **argv)
149{ 168{
@@ -181,8 +200,8 @@ main (int argc, char **argv)
181 bindtextdomain (PACKAGE, LOCALEDIR); 200 bindtextdomain (PACKAGE, LOCALEDIR);
182 textdomain (PACKAGE); 201 textdomain (PACKAGE);
183 202
184 labels = malloc (labels_size); 203 labels = malloc (labels_size * sizeof(*labels));
185 unitv = malloc (unitv_size); 204 unitv = malloc (unitv_size * sizeof(*unitv));
186 for (i = 0; i < MAX_OIDS; i++) 205 for (i = 0; i < MAX_OIDS; i++)
187 eval_method[i] = CHECK_UNDEF; 206 eval_method[i] = CHECK_UNDEF;
188 207
@@ -228,6 +247,10 @@ main (int argc, char **argv)
228 for (i=0; i<numoids; i++) { 247 for (i=0; i<numoids; i++) {
229 char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL; 248 char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL;
230 char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL; 249 char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL;
250 /* translate "2:1" to "@1:2" for backwards compatibility */
251 w = w ? fix_snmp_range(w) : NULL;
252 c = c ? fix_snmp_range(c) : NULL;
253
231 /* Skip empty thresholds, while avoiding segfault */ 254 /* Skip empty thresholds, while avoiding segfault */
232 set_thresholds(&thlds[i], 255 set_thresholds(&thlds[i],
233 w ? strpbrk(w, NP_THRESHOLDS_CHARS) : NULL, 256 w ? strpbrk(w, NP_THRESHOLDS_CHARS) : NULL,
@@ -396,7 +419,7 @@ main (int argc, char **argv)
396 show = strstr (response, "Timeticks: "); 419 show = strstr (response, "Timeticks: ");
397 } 420 }
398 else 421 else
399 show = response; 422 show = response + 3;
400 423
401 iresult = STATE_DEPENDENT; 424 iresult = STATE_DEPENDENT;
402 425
@@ -405,7 +428,7 @@ main (int argc, char **argv)
405 if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { 428 if (thlds[i]->warning || thlds[i]->critical || calculate_rate) {
406 ptr = strpbrk (show, "0123456789"); 429 ptr = strpbrk (show, "0123456789");
407 if (ptr == NULL) 430 if (ptr == NULL)
408 die (STATE_UNKNOWN,_("No valid data returned")); 431 die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show);
409 response_value[i] = strtod (ptr, NULL); 432 response_value[i] = strtod (ptr, NULL);
410 433
411 if(calculate_rate) { 434 if(calculate_rate) {
@@ -745,9 +768,9 @@ process_arguments (int argc, char **argv)
745 break; 768 break;
746 case 'l': /* label */ 769 case 'l': /* label */
747 nlabels++; 770 nlabels++;
748 if (nlabels >= labels_size) { 771 if (nlabels > labels_size) {
749 labels_size += 8; 772 labels_size += 8;
750 labels = realloc (labels, labels_size); 773 labels = realloc (labels, labels_size * sizeof(*labels));
751 if (labels == NULL) 774 if (labels == NULL)
752 die (STATE_UNKNOWN, _("Could not reallocate labels[%d]"), (int)nlabels); 775 die (STATE_UNKNOWN, _("Could not reallocate labels[%d]"), (int)nlabels);
753 } 776 }
@@ -757,13 +780,13 @@ process_arguments (int argc, char **argv)
757 if (ptr[0] == '\'') 780 if (ptr[0] == '\'')
758 labels[nlabels - 1] = ptr + 1; 781 labels[nlabels - 1] = ptr + 1;
759 while (ptr && (ptr = nextarg (ptr))) { 782 while (ptr && (ptr = nextarg (ptr))) {
760 if (nlabels >= labels_size) { 783 nlabels++;
784 if (nlabels > labels_size) {
761 labels_size += 8; 785 labels_size += 8;
762 labels = realloc (labels, labels_size); 786 labels = realloc (labels, labels_size * sizeof(*labels));
763 if (labels == NULL) 787 if (labels == NULL)
764 die (STATE_UNKNOWN, _("Could not reallocate labels\n")); 788 die (STATE_UNKNOWN, _("Could not reallocate labels\n"));
765 } 789 }
766 nlabels++;
767 ptr = thisarg (ptr); 790 ptr = thisarg (ptr);
768 if (ptr[0] == '\'') 791 if (ptr[0] == '\'')
769 labels[nlabels - 1] = ptr + 1; 792 labels[nlabels - 1] = ptr + 1;
@@ -774,9 +797,9 @@ process_arguments (int argc, char **argv)
774 case 'u': /* units */ 797 case 'u': /* units */
775 units = optarg; 798 units = optarg;
776 nunits++; 799 nunits++;
777 if (nunits >= unitv_size) { 800 if (nunits > unitv_size) {
778 unitv_size += 8; 801 unitv_size += 8;
779 unitv = realloc (unitv, unitv_size); 802 unitv = realloc (unitv, unitv_size * sizeof(*unitv));
780 if (unitv == NULL) 803 if (unitv == NULL)
781 die (STATE_UNKNOWN, _("Could not reallocate units [%d]\n"), (int)nunits); 804 die (STATE_UNKNOWN, _("Could not reallocate units [%d]\n"), (int)nunits);
782 } 805 }
@@ -786,9 +809,9 @@ process_arguments (int argc, char **argv)
786 if (ptr[0] == '\'') 809 if (ptr[0] == '\'')
787 unitv[nunits - 1] = ptr + 1; 810 unitv[nunits - 1] = ptr + 1;
788 while (ptr && (ptr = nextarg (ptr))) { 811 while (ptr && (ptr = nextarg (ptr))) {
789 if (nunits >= unitv_size) { 812 if (nunits > unitv_size) {
790 unitv_size += 8; 813 unitv_size += 8;
791 unitv = realloc (unitv, unitv_size); 814 unitv = realloc (unitv, unitv_size * sizeof(*unitv));
792 if (units == NULL) 815 if (units == NULL)
793 die (STATE_UNKNOWN, _("Could not realloc() units\n")); 816 die (STATE_UNKNOWN, _("Could not realloc() units\n"));
794 } 817 }
diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c
index 4d633949..6e8a5fc5 100644
--- a/plugins/check_ssh.c
+++ b/plugins/check_ssh.c
@@ -307,6 +307,6 @@ void
307print_usage (void) 307print_usage (void)
308{ 308{
309 printf ("%s\n", _("Usage:")); 309 printf ("%s\n", _("Usage:"));
310 printf ("%s [-46] [-t <timeout>] [-r <remote version>] [-p <port>] <host>\n", progname); 310 printf ("%s [-4|-6] [-t <timeout>] [-r <remote version>] [-p <port>] <host>\n", progname);
311} 311}
312 312
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index f464b15f..ce966c38 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -1,30 +1,30 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Nagios check_tcp plugin 3* Nagios check_tcp plugin
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 1999-2008 Nagios Plugins Development Team 6* Copyright (c) 1999-2008 Nagios Plugins Development Team
7* 7*
8* Description: 8* Description:
9* 9*
10* This file contains the check_tcp plugin 10* This file contains the check_tcp plugin
11* 11*
12* 12*
13* This program is free software: you can redistribute it and/or modify 13* This program is free software: you can redistribute it and/or modify
14* it under the terms of the GNU General Public License as published by 14* it under the terms of the GNU General Public License as published by
15* the Free Software Foundation, either version 3 of the License, or 15* the Free Software Foundation, either version 3 of the License, or
16* (at your option) any later version. 16* (at your option) any later version.
17* 17*
18* This program is distributed in the hope that it will be useful, 18* This program is distributed in the hope that it will be useful,
19* but WITHOUT ANY WARRANTY; without even the implied warranty of 19* but WITHOUT ANY WARRANTY; without even the implied warranty of
20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21* GNU General Public License for more details. 21* GNU General Public License for more details.
22* 22*
23* You should have received a copy of the GNU General Public License 23* You should have received a copy of the GNU General Public License
24* along with this program. If not, see <http://www.gnu.org/licenses/>. 24* along with this program. If not, see <http://www.gnu.org/licenses/>.
25* 25*
26* $Id$ 26* $Id$
27* 27*
28*****************************************************************************/ 28*****************************************************************************/
29 29
30/* progname "check_tcp" changes depending on symlink called */ 30/* progname "check_tcp" changes depending on symlink called */
@@ -61,6 +61,7 @@ static int PORT = 0;
61 61
62static int server_port = 0; 62static int server_port = 0;
63static char *server_address = NULL; 63static char *server_address = NULL;
64static int host_specified = FALSE;
64static char *server_send = NULL; 65static char *server_send = NULL;
65static char *server_quit = NULL; 66static char *server_quit = NULL;
66static char **server_expect; 67static char **server_expect;
@@ -462,6 +463,7 @@ process_arguments (int argc, char **argv)
462#endif 463#endif
463 break; 464 break;
464 case 'H': /* hostname */ 465 case 'H': /* hostname */
466 host_specified = TRUE;
465 server_address = optarg; 467 server_address = optarg;
466 break; 468 break;
467 case 'c': /* critical */ 469 case 'c': /* critical */
@@ -555,7 +557,7 @@ process_arguments (int argc, char **argv)
555# ifdef USE_OPENSSL /* XXX */ 557# ifdef USE_OPENSSL /* XXX */
556 if ((temp=strchr(optarg,','))!=NULL) { 558 if ((temp=strchr(optarg,','))!=NULL) {
557 *temp='\0'; 559 *temp='\0';
558 if (!is_intnonneg (temp)) 560 if (!is_intnonneg (optarg))
559 usage2 (_("Invalid certificate expiration period"), optarg); days_till_exp_warn = atoi(optarg); 561 usage2 (_("Invalid certificate expiration period"), optarg); days_till_exp_warn = atoi(optarg);
560 *temp=','; 562 *temp=',';
561 temp++; 563 temp++;
@@ -588,6 +590,10 @@ process_arguments (int argc, char **argv)
588 } 590 }
589 } 591 }
590 592
593 c = optind;
594 if(host_specified == FALSE && c < argc)
595 server_address = strdup (argv[c++]);
596
591 if (server_address == NULL) 597 if (server_address == NULL)
592 usage4 (_("You must provide a server address")); 598 usage4 (_("You must provide a server address"));
593 else if (server_address[0] != '/' && is_host (server_address) == FALSE) 599 else if (server_address[0] != '/' && is_host (server_address) == FALSE)
@@ -666,4 +672,3 @@ print_usage (void)
666 printf ("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n"); 672 printf ("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n");
667 printf ("[-D <warn days cert expire>[,<crit days cert expire>]] [-S <use SSL>] [-E]\n"); 673 printf ("[-D <warn days cert expire>[,<crit days cert expire>]] [-S <use SSL>] [-E]\n");
668} 674}
669
diff --git a/plugins/common.h b/plugins/common.h
index 09af7e7e..c0dc2f41 100644
--- a/plugins/common.h
+++ b/plugins/common.h
@@ -141,6 +141,7 @@
141#ifdef HAVE_GNUTLS_OPENSSL_H 141#ifdef HAVE_GNUTLS_OPENSSL_H
142# include <gnutls/openssl.h> 142# include <gnutls/openssl.h>
143#else 143#else
144# define OPENSSL_LOAD_CONF /* See the OPENSSL_config(3) man page. */
144# ifdef HAVE_SSL_H 145# ifdef HAVE_SSL_H
145# include <rsa.h> 146# include <rsa.h>
146# include <crypto.h> 147# include <crypto.h>
diff --git a/plugins/runcmd.c b/plugins/runcmd.c
index 7574b121..8aba1e33 100644
--- a/plugins/runcmd.c
+++ b/plugins/runcmd.c
@@ -256,7 +256,7 @@ np_runcmd_close(int fd)
256 256
257 257
258void 258void
259popen_timeout_alarm_handler (int signo) 259runcmd_timeout_alarm_handler (int signo)
260{ 260{
261 size_t i; 261 size_t i;
262 262
diff --git a/plugins/runcmd.h b/plugins/runcmd.h
index 211dee2c..5957562b 100644
--- a/plugins/runcmd.h
+++ b/plugins/runcmd.h
@@ -39,7 +39,7 @@ typedef struct output output;
39 39
40/** prototypes **/ 40/** prototypes **/
41int np_runcmd(const char *, output *, output *, int); 41int np_runcmd(const char *, output *, output *, int);
42void popen_timeout_alarm_handler(int) 42void runcmd_timeout_alarm_handler(int)
43 __attribute__((__noreturn__)); 43 __attribute__((__noreturn__));
44 44
45/* only multi-threaded plugins need to bother with this */ 45/* only multi-threaded plugins need to bother with this */
diff --git a/plugins/t/check_apt.t b/plugins/t/check_apt.t
new file mode 100644
index 00000000..9ba0ff8e
--- /dev/null
+++ b/plugins/t/check_apt.t
@@ -0,0 +1,90 @@
1#!/usr/bin/perl -w -I ..
2#
3# Test check_apt using input files.
4# Contributed by Alex Bradley, October 2012
5#
6
7use strict;
8use Test::More;
9use NPTest;
10
11sub make_result_regexp {
12 my ($warning, $critical) = @_;
13 my $status;
14 if ($warning == 0 && $critical == 0) {
15 $status = "OK";
16 } elsif ($critical == 0) {
17 $status = "WARNING";
18 } else {
19 $status = "CRITICAL";
20 }
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, $warning, $critical);
23}
24
25if (-x "./check_apt") {
26 plan tests => 28;
27} else {
28 plan skip_all => "No check_apt compiled";
29}
30
31my $result;
32
33my $testfile_command = "./check_apt %s --input-file=t/check_apt_input/%s";
34
35$result = NPTest->testCmd( sprintf($testfile_command, "", "debian1") );
36is( $result->return_code, 0, "No upgrades" );
37like( $result->output, make_result_regexp(0, 0), "Output correct" );
38
39$result = NPTest->testCmd( sprintf($testfile_command, "", "debian2") );
40is( $result->return_code, 1, "Debian apt output, warning" );
41like( $result->output, make_result_regexp(13, 0), "Output correct" );
42
43$result = NPTest->testCmd( sprintf($testfile_command, "", "debian3") );
44is( $result->return_code, 2, "Debian apt output, some critical" );
45like( $result->output, make_result_regexp(19, 4), "Output correct" );
46
47$result = NPTest->testCmd( sprintf($testfile_command, "-c '^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)'", "debian3") );
48is( $result->return_code, 2, "Debian apt output - should have same result when default security regexp specified via -c" );
49like( $result->output, make_result_regexp(19, 4), "Output correct" );
50
51$result = NPTest->testCmd( sprintf($testfile_command, "-i libc6", "debian3") );
52is( $result->return_code, 1, "Debian apt output, filter for libc6" );
53like( $result->output, make_result_regexp(3, 0), "Output correct" );
54
55$result = NPTest->testCmd( sprintf($testfile_command, "-i libc6 -i xen", "debian3") );
56is( $result->return_code, 2, "Debian apt output, filter for libc6 and xen" );
57like( $result->output, make_result_regexp(9, 4), "Output correct" );
58
59$result = NPTest->testCmd( sprintf($testfile_command, "-i libc6 -i xen -i linux", "debian3") );
60is( $result->return_code, 2, "Debian apt output, filter for libc6, xen, linux" );
61like( $result->output, make_result_regexp(12, 4), "Output correct" );
62
63$result = NPTest->testCmd( sprintf($testfile_command, "-e libc6", "debian3") );
64is( $result->return_code, 2, "Debian apt output, filter out libc6" );
65like( $result->output, make_result_regexp(16, 4), "Output correct" );
66
67$result = NPTest->testCmd( sprintf($testfile_command, "-e libc6 -e xen", "debian3") );
68is( $result->return_code, 1, "Debian apt output, filter out libc6 and xen" );
69like( $result->output, make_result_regexp(10, 0), "Output correct" );
70
71$result = NPTest->testCmd( sprintf($testfile_command, "-e libc6 -e xen -e linux", "debian3") );
72is( $result->return_code, 1, "Debian apt output, filter out libc6, xen, linux" );
73like( $result->output, make_result_regexp(7, 0), "Output correct" );
74
75$result = NPTest->testCmd( sprintf($testfile_command, "-c Debian-Security -c linux", "debian3") );
76is( $result->return_code, 2, "Debian apt output, critical on Debian-Security or linux" );
77like( $result->output, make_result_regexp(19, 9), "Output correct" );
78
79$result = NPTest->testCmd( sprintf($testfile_command, "-i lib -i linux -e gc1c -c linux-image", "debian3") );
80is( $result->return_code, 2, "Debian apt output, include lib and linux, exclude gc1c, critical on linux-image" );
81like( $result->output, make_result_regexp(10, 2), "Output correct" );
82
83$result = NPTest->testCmd( sprintf($testfile_command, "", "ubuntu1") );
84is( $result->return_code, 1, "Ubuntu apt output, warning" );
85like( $result->output, make_result_regexp(5, 0), "Output correct" );
86
87$result = NPTest->testCmd( sprintf($testfile_command, "", "ubuntu2") );
88is( $result->return_code, 2, "Ubuntu apt output, some critical" );
89like( $result->output, make_result_regexp(25, 14), "Output correct" );
90
diff --git a/plugins/t/check_apt_input/debian1 b/plugins/t/check_apt_input/debian1
new file mode 100644
index 00000000..317e7ea7
--- /dev/null
+++ b/plugins/t/check_apt_input/debian1
@@ -0,0 +1,4 @@
1NOTE: This is only a simulation!
2 apt-get needs root privileges for real execution.
3 Keep also in mind that locking is deactivated,
4 so don't depend on the relevance to the real current situation!
diff --git a/plugins/t/check_apt_input/debian2 b/plugins/t/check_apt_input/debian2
new file mode 100644
index 00000000..effd1553
--- /dev/null
+++ b/plugins/t/check_apt_input/debian2
@@ -0,0 +1,37 @@
1NOTE: This is only a simulation!
2 apt-get needs root privileges for real execution.
3 Keep also in mind that locking is deactivated,
4 so don't depend on the relevance to the real current situation!
5Reading package lists... Done
6Building dependency tree
7Reading state information... Done
8The following packages will be upgraded:
9 base-files debian-archive-keyring dpkg firmware-linux-free libc-bin libc-dev-bin libc6 libc6-dev linux-base
10 linux-image-2.6.32-5-xen-amd64 linux-libc-dev locales lockfile-progs
1113 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
12Inst base-files [6.0squeeze5] (6.0squeeze6 Debian:6.0.6/stable [amd64])
13Conf base-files (6.0squeeze6 Debian:6.0.6/stable [amd64])
14Inst dpkg [1.15.8.12] (1.15.8.13 Debian:6.0.6/stable [amd64])
15Conf dpkg (1.15.8.13 Debian:6.0.6/stable [amd64])
16Inst linux-base [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [all])
17Inst linux-image-2.6.32-5-xen-amd64 [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64])
18Inst debian-archive-keyring [2010.08.28] (2010.08.28+squeeze1 Debian:6.0.6/stable [all])
19Conf debian-archive-keyring (2010.08.28+squeeze1 Debian:6.0.6/stable [all])
20Inst libc6-dev [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) []
21Inst libc-dev-bin [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) []
22Inst linux-libc-dev [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64]) []
23Inst libc-bin [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) [libc6:amd64 ]
24Conf libc-bin (2.11.3-4 Debian:6.0.6/stable [amd64]) [libc6:amd64 ]
25Inst libc6 [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64])
26Conf libc6 (2.11.3-4 Debian:6.0.6/stable [amd64])
27Inst locales [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [all])
28Inst firmware-linux-free [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [all])
29Inst lockfile-progs [0.1.15] (0.1.15+squeeze1 Debian:6.0.6/stable [amd64])
30Conf linux-base (2.6.32-46 Debian:6.0.6/stable [all])
31Conf linux-image-2.6.32-5-xen-amd64 (2.6.32-46 Debian:6.0.6/stable [amd64])
32Conf libc-dev-bin (2.11.3-4 Debian:6.0.6/stable [amd64])
33Conf linux-libc-dev (2.6.32-46 Debian:6.0.6/stable [amd64])
34Conf libc6-dev (2.11.3-4 Debian:6.0.6/stable [amd64])
35Conf locales (2.11.3-4 Debian:6.0.6/stable [all])
36Conf firmware-linux-free (2.6.32-46 Debian:6.0.6/stable [all])
37Conf lockfile-progs (0.1.15+squeeze1 Debian:6.0.6/stable [amd64])
diff --git a/plugins/t/check_apt_input/debian3 b/plugins/t/check_apt_input/debian3
new file mode 100644
index 00000000..719dce9b
--- /dev/null
+++ b/plugins/t/check_apt_input/debian3
@@ -0,0 +1,42 @@
1NOTE: This is only a simulation!
2 apt-get needs root privileges for real execution.
3 Keep also in mind that locking is deactivated,
4 so don't depend on the relevance to the real current situation!
5Inst base-files [6.0squeeze5] (6.0squeeze6 Debian:6.0.6/stable [amd64])
6Conf base-files (6.0squeeze6 Debian:6.0.6/stable [amd64])
7Inst dpkg [1.15.8.12] (1.15.8.13 Debian:6.0.6/stable [amd64])
8Conf dpkg (1.15.8.13 Debian:6.0.6/stable [amd64])
9Inst linux-base [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [all])
10Inst linux-image-2.6.32-5-amd64 [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64])
11Inst xen-hypervisor-4.0-amd64 [4.0.1-5.3] (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
12Inst xen-linux-system-2.6.32-5-xen-amd64 [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64]) []
13Inst linux-image-2.6.32-5-xen-amd64 [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64])
14Inst debian-archive-keyring [2010.08.28] (2010.08.28+squeeze1 Debian:6.0.6/stable [all])
15Conf debian-archive-keyring (2010.08.28+squeeze1 Debian:6.0.6/stable [all])
16Inst libc6-i386 [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) []
17Inst libc-bin [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) [libc6:amd64 ]
18Conf libc-bin (2.11.3-4 Debian:6.0.6/stable [amd64]) [libc6:amd64 ]
19Inst libc6 [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64])
20Conf libc6 (2.11.3-4 Debian:6.0.6/stable [amd64])
21Inst libgc1c2 [1:6.8-1.2] (1:6.8-2 Debian:6.0.6/stable [amd64])
22Inst locales [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [all])
23Inst firmware-linux-free [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [all])
24Inst libxenstore3.0 [4.0.1-5.3] (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
25Inst lockfile-progs [0.1.15] (0.1.15+squeeze1 Debian:6.0.6/stable [amd64])
26Inst xen-utils-4.0 [4.0.1-5.3] (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
27Inst xenstore-utils [4.0.1-5.3] (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
28Inst libconfig-inifiles-perl [2.52-1] (2.52-1+squeeze1 Debian:6.0.6/stable [all])
29Conf linux-base (2.6.32-46 Debian:6.0.6/stable [all])
30Conf linux-image-2.6.32-5-amd64 (2.6.32-46 Debian:6.0.6/stable [amd64])
31Conf xen-hypervisor-4.0-amd64 (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
32Conf linux-image-2.6.32-5-xen-amd64 (2.6.32-46 Debian:6.0.6/stable [amd64])
33Conf xen-linux-system-2.6.32-5-xen-amd64 (2.6.32-46 Debian:6.0.6/stable [amd64])
34Conf libc6-i386 (2.11.3-4 Debian:6.0.6/stable [amd64])
35Conf libgc1c2 (1:6.8-2 Debian:6.0.6/stable [amd64])
36Conf locales (2.11.3-4 Debian:6.0.6/stable [all])
37Conf firmware-linux-free (2.6.32-46 Debian:6.0.6/stable [all])
38Conf libxenstore3.0 (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
39Conf lockfile-progs (0.1.15+squeeze1 Debian:6.0.6/stable [amd64])
40Conf xen-utils-4.0 (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
41Conf xenstore-utils (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
42Conf libconfig-inifiles-perl (2.52-1+squeeze1 Debian:6.0.6/stable [all])
diff --git a/plugins/t/check_apt_input/ubuntu1 b/plugins/t/check_apt_input/ubuntu1
new file mode 100644
index 00000000..2f61c30e
--- /dev/null
+++ b/plugins/t/check_apt_input/ubuntu1
@@ -0,0 +1,14 @@
1NOTE: This is only a simulation!
2 apt-get needs root privileges for real execution.
3 Also keep in mind that locking is deactivated,
4 so don't depend on the relevance to the real current situation!
5Inst grub-pc [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) []
6Inst grub-pc-bin [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) []
7Inst grub2-common [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) []
8Inst grub-efi-amd64-bin [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) []
9Inst grub-common [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
10Conf grub-common (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
11Conf grub2-common (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
12Conf grub-pc-bin (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
13Conf grub-pc (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
14Conf grub-efi-amd64-bin (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
diff --git a/plugins/t/check_apt_input/ubuntu2 b/plugins/t/check_apt_input/ubuntu2
new file mode 100644
index 00000000..29a14a02
--- /dev/null
+++ b/plugins/t/check_apt_input/ubuntu2
@@ -0,0 +1,54 @@
1NOTE: This is only a simulation!
2 apt-get needs root privileges for real execution.
3 Also keep in mind that locking is deactivated,
4 so don't depend on the relevance to the real current situation!
5Inst libc6-dev [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) []
6Inst libc-dev-bin [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) []
7Inst linux-libc-dev [3.2.0-29.46] (3.2.0-31.50 Ubuntu:12.04/precise-security [amd64]) []
8Inst tzdata [2012e-0ubuntu0.12.04] (2012e-0ubuntu0.12.04.1 Ubuntu:12.04/precise-security [all]) []
9Conf tzdata (2012e-0ubuntu0.12.04.1 Ubuntu:12.04/precise-security [all]) []
10Inst libc-bin [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) [libc6:amd64 ]
11Conf libc-bin (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) [libc6:amd64 ]
12Inst libc6 [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
13Conf libc6 (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
14Inst libapt-pkg4.12 [0.8.16~exp12ubuntu10.2] (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
15Conf libapt-pkg4.12 (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
16Inst ubuntu-keyring [2011.11.21] (2011.11.21.1 Ubuntu:12.04/precise-updates [all])
17Conf ubuntu-keyring (2011.11.21.1 Ubuntu:12.04/precise-updates [all])
18Inst gpgv [1.4.11-3ubuntu2] (1.4.11-3ubuntu2.1 Ubuntu:12.04/precise-security [amd64])
19Conf gpgv (1.4.11-3ubuntu2.1 Ubuntu:12.04/precise-security [amd64])
20Inst gnupg [1.4.11-3ubuntu2] (1.4.11-3ubuntu2.1 Ubuntu:12.04/precise-security [amd64])
21Conf gnupg (1.4.11-3ubuntu2.1 Ubuntu:12.04/precise-security [amd64])
22Inst apt [0.8.16~exp12ubuntu10.2] (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
23Conf apt (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
24Inst libssl1.0.0 [1.0.1-4ubuntu5.3] (1.0.1-4ubuntu5.5 Ubuntu:12.04/precise-updates [amd64])
25Conf libssl1.0.0 (1.0.1-4ubuntu5.5 Ubuntu:12.04/precise-updates [amd64])
26Inst libapt-inst1.4 [0.8.16~exp12ubuntu10.2] (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
27Inst resolvconf [1.63ubuntu15] (1.63ubuntu16 Ubuntu:12.04/precise-updates [all])
28Inst libdbus-1-3 [1.4.18-1ubuntu1] (1.4.18-1ubuntu1.1 Ubuntu:12.04/precise-security [amd64])
29Inst libxml2 [2.7.8.dfsg-5.1ubuntu4.1] (2.7.8.dfsg-5.1ubuntu4.2 Ubuntu:12.04/precise-security [amd64])
30Inst multiarch-support [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
31Conf multiarch-support (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
32Inst apt-utils [0.8.16~exp12ubuntu10.2] (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
33Inst isc-dhcp-client [4.1.ESV-R4-0ubuntu5.2] (4.1.ESV-R4-0ubuntu5.5 Ubuntu:12.04/precise-security [amd64]) []
34Inst isc-dhcp-common [4.1.ESV-R4-0ubuntu5.2] (4.1.ESV-R4-0ubuntu5.5 Ubuntu:12.04/precise-security [amd64])
35Inst dbus [1.4.18-1ubuntu1] (1.4.18-1ubuntu1.1 Ubuntu:12.04/precise-security [amd64])
36Inst linux-firmware [1.79] (1.79.1 Ubuntu:12.04/precise-updates [all])
37Inst xserver-common [2:1.11.4-0ubuntu10.7] (2:1.11.4-0ubuntu10.8 Ubuntu:12.04/precise-updates [all])
38Inst xserver-xorg-core [2:1.11.4-0ubuntu10.7] (2:1.11.4-0ubuntu10.8 Ubuntu:12.04/precise-updates [amd64])
39Inst xserver-xorg-input-synaptics [1.6.2-1ubuntu1~precise1] (1.6.2-1ubuntu1~precise2 Ubuntu:12.04/precise-updates [amd64])
40Conf libc-dev-bin (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
41Conf linux-libc-dev (3.2.0-31.50 Ubuntu:12.04/precise-security [amd64])
42Conf libc6-dev (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
43Conf libapt-inst1.4 (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
44Conf resolvconf (1.63ubuntu16 Ubuntu:12.04/precise-updates [all])
45Conf libdbus-1-3 (1.4.18-1ubuntu1.1 Ubuntu:12.04/precise-security [amd64])
46Conf libxml2 (2.7.8.dfsg-5.1ubuntu4.2 Ubuntu:12.04/precise-security [amd64])
47Conf apt-utils (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
48Conf isc-dhcp-common (4.1.ESV-R4-0ubuntu5.5 Ubuntu:12.04/precise-security [amd64])
49Conf isc-dhcp-client (4.1.ESV-R4-0ubuntu5.5 Ubuntu:12.04/precise-security [amd64])
50Conf dbus (1.4.18-1ubuntu1.1 Ubuntu:12.04/precise-security [amd64])
51Conf linux-firmware (1.79.1 Ubuntu:12.04/precise-updates [all])
52Conf xserver-common (2:1.11.4-0ubuntu10.8 Ubuntu:12.04/precise-updates [all])
53Conf xserver-xorg-core (2:1.11.4-0ubuntu10.8 Ubuntu:12.04/precise-updates [amd64])
54Conf xserver-xorg-input-synaptics (1.6.2-1ubuntu1~precise2 Ubuntu:12.04/precise-updates [amd64])
diff --git a/plugins/t/check_dig.t b/plugins/t/check_dig.t
index 323859e8..1ab4b426 100644
--- a/plugins/t/check_dig.t
+++ b/plugins/t/check_dig.t
@@ -10,30 +10,30 @@ use NPTest;
10 10
11plan skip_all => "check_dig not compiled" unless (-x "check_dig"); 11plan skip_all => "check_dig not compiled" unless (-x "check_dig");
12 12
13plan tests => 12; 13plan tests => 16;
14 14
15my $successOutput = '/DNS OK - [\.0-9]+ seconds? response time/'; 15my $successOutput = '/DNS OK - [\.0-9]+ seconds? response time/';
16 16
17my $hostname_valid = getTestParameter( 17my $hostname_valid = getTestParameter(
18 "NP_HOSTNAME_VALID", 18 "NP_HOSTNAME_VALID",
19 "A valid (known to DNS) hostname", 19 "A valid (known to DNS) hostname",
20 "nagios.com" 20 "nagiosplugins.org"
21 ); 21 );
22 22
23my $hostname_valid_ip = getTestParameter( 23my $hostname_valid_ip = getTestParameter(
24 "NP_HOSTNAME_VALID_IP", 24 "NP_HOSTNAME_VALID_IP",
25 "The IP address of the valid hostname $hostname_valid", 25 "The IP address of the valid hostname $hostname_valid",
26 "66.118.156.50", 26 "67.207.143.200",
27 ); 27 );
28 28
29my $hostname_valid_reverse = getTestParameter( 29my $hostname_valid_reverse = getTestParameter(
30 "NP_HOSTNAME_VALID_REVERSE", 30 "NP_HOSTNAME_VALID_REVERSE",
31 "The hostname of $hostname_valid_ip", 31 "The hostname of $hostname_valid_ip",
32 "66-118-156-50.static.sagonet.net.", 32 "nagiosplugins.org.",
33 ); 33 );
34 34
35my $hostname_invalid = getTestParameter( 35my $hostname_invalid = getTestParameter(
36 "NP_HOSTNAME_INVALID", 36 "NP_HOSTNAME_INVALID",
37 "An invalid (not known to DNS) hostname", 37 "An invalid (not known to DNS) hostname",
38 "nosuchhost.altinity.com", 38 "nosuchhost.altinity.com",
39 ); 39 );
@@ -69,6 +69,14 @@ SKIP: {
69 cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server"); 69 cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
70 like ( $res->output, $successOutput, "Output OK" ); 70 like ( $res->output, $successOutput, "Output OK" );
71 71
72 $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -4");
73 cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
74 like ( $res->output, $successOutput, "Output OK for IPv4" );
75
76 $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -6");
77 cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
78 like ( $res->output, $successOutput, "Output OK for IPv6" );
79
72 $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -a $hostname_valid_ip -t 5"); 80 $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -a $hostname_valid_ip -t 5");
73 cmp_ok( $res->return_code, '==', 0, "Got expected address"); 81 cmp_ok( $res->return_code, '==', 0, "Got expected address");
74 82
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/t/check_tcp.t b/plugins/t/check_tcp.t
index 75c1e5fb..d6808bf2 100644
--- a/plugins/t/check_tcp.t
+++ b/plugins/t/check_tcp.t
@@ -9,7 +9,7 @@ use Test;
9use NPTest; 9use NPTest;
10 10
11use vars qw($tests); 11use vars qw($tests);
12BEGIN {$tests = 7; plan tests => $tests} 12BEGIN {$tests = 14; plan tests => $tests}
13 13
14my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost", 14my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost",
15 "A host providing the HTTP Service (a web server)" ); 15 "A host providing the HTTP Service (a web server)" );
@@ -27,6 +27,7 @@ my $failedExpect = '/^TCP WARNING\s-\sUnexpected response from host/socket on po
27my $t; 27my $t;
28 28
29$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0, $successOutput ); 29$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0, $successOutput );
30$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600 -6 ", 0, $successOutput );
30$t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test 31$t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test
31$t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 ); 32$t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 );
32$t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 ); 33$t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 );
@@ -34,6 +35,7 @@ $t += checkCmd( "./check_tcp -S -D 1 -H www.verisign.com -p 443", 0
34$t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 0 ); 35$t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 0 );
35$t += checkCmd( "./check_tcp -S -D 9000 -H www.verisign.com -p 443", 1 ); 36$t += checkCmd( "./check_tcp -S -D 9000 -H www.verisign.com -p 443", 1 );
36$t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443", 2 ); 37$t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443", 2 );
38$t += checkCmd( "./check_tcp -6 -p 80 www.heise.de", 0 );
37 39
38# Need the \r\n to make it more standards compliant with web servers. Need the various quotes 40# Need the \r\n to make it more standards compliant with web servers. Need the various quotes
39# so that perl doesn't interpret the \r\n and is passed onto command line correctly 41# so that perl doesn't interpret the \r\n and is passed onto command line correctly
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index 8337f52a..9f97abdc 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -12,14 +12,13 @@
12# Common Name (eg, YOUR name) []:Ton Voon 12# Common Name (eg, YOUR name) []:Ton Voon
13# Email Address []:tonvoon@mac.com 13# Email Address []:tonvoon@mac.com
14 14
15
16use strict; 15use strict;
17use Test::More; 16use Test::More;
18use NPTest; 17use NPTest;
19use FindBin qw($Bin); 18use FindBin qw($Bin);
20 19
21my $common_tests = 66; 20my $common_tests = 66;
22my $ssl_only_tests = 6; 21my $ssl_only_tests = 8;
23# Check that all dependent modules are available 22# Check that all dependent modules are available
24eval { 23eval {
25 require HTTP::Daemon; 24 require HTTP::Daemon;
@@ -160,9 +159,9 @@ sub run_server {
160 } 159 }
161} 160}
162 161
163END { 162END {
164 foreach my $pid (@pids) { 163 foreach my $pid (@pids) {
165 if ($pid) { print "Killing $pid\n"; kill "INT", $pid } 164 if ($pid) { print "Killing $pid\n"; kill "INT", $pid }
166 } 165 }
167}; 166};
168 167
@@ -179,7 +178,7 @@ run_common_tests( { command => "$command -p $port_http" } );
179SKIP: { 178SKIP: {
180 skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https}; 179 skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https};
181 run_common_tests( { command => "$command -p $port_https", ssl => 1 } ); 180 run_common_tests( { command => "$command -p $port_https", ssl => 1 } );
182 181
183 $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); 182 $result = NPTest->testCmd( "$command -p $port_https -S -C 14" );
184 is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); 183 is( $result->return_code, 0, "$command -p $port_https -S -C 14" );
185 is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on 03/03/2019 21:41.', "output ok" ); 184 is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on 03/03/2019 21:41.', "output ok" );
@@ -188,14 +187,14 @@ SKIP: {
188 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); 187 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" );
189 like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" ); 188 like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" );
190 189
191 $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" );
192 is( $result->return_code, 1, "$command -p $port_https -S -C 139600,14000" );
193 like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" );
194
195 # Expired cert tests 190 # Expired cert tests
191 $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" );
192 is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" );
193 like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" );
194
196 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); 195 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" );
197 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); 196 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" );
198 is( $result->output, 197 is( $result->output,
199 'CRITICAL - Certificate \'Ton Voon\' expired on 03/05/2009 00:13.', 198 'CRITICAL - Certificate \'Ton Voon\' expired on 03/05/2009 00:13.',
200 "output ok" ); 199 "output ok" );
201 200
@@ -406,4 +405,3 @@ sub run_common_tests {
406 isnt( $@, "alarm\n", $cmd ); 405 isnt( $@, "alarm\n", $cmd );
407 406
408} 407}
409
diff --git a/tools/np_build_from_sf b/tools/np_build_from_sf
new file mode 100755
index 00000000..7ba349a6
--- /dev/null
+++ b/tools/np_build_from_sf
@@ -0,0 +1,11 @@
1#!/bin/bash
2
3set -xeu
4
5temp=$(mktemp -d)
6trap "cd $HOME; rm -rf $temp; exit 1" EXIT
7curl -sS http://nagiosplug.sourceforge.net/snapshot/nagios-plugins-HEAD.tar.gz|tar -C "$temp" --strip-components=1 -xzf -
8cd $temp
9./configure && make
10$HOME/bin/update_man_pages
11
diff --git a/tools/sfwebcron b/tools/sfwebcron
index d836a0fd..0f31fcfb 100755
--- a/tools/sfwebcron
+++ b/tools/sfwebcron
@@ -4,32 +4,32 @@
4# To update the developers-guidelines.html and put in html area 4# To update the developers-guidelines.html and put in html area
5# 5#
6# Install in cron with something like: 6# Install in cron with something like:
7# 47 7 * * * $HOME/bin/sfwebcron 7# 47 7 * * * $HOME/bin/sfwebcron >/tmp/sfwebcron.log 2>&1 || cat /tmp/sfwebcron.log
8 8
9function die { echo $1; exit 1; } 9set -eu
10trap 'echo "Command failed at line $LINENO"' ERR
10 11
11# Set working variables 12# Set working variables
12PROJECT=nagiosplug 13PROJECT=nagiosplug
13IN=${HOME}/tmp_sfwebcron 14IN=${HOME}/sfwebcron
14OUT_SERVER="tonvoon@shell.sf.net" 15PROBE="developer-guidelines.html.last"
15OUT="/home/groups/n/na/nagiosplug/htdocs" 16OUT_SERVER="tonvoon@frs.sourceforge.net"
16 17OUT_PATH="/home/groups/n/na/nagiosplug/htdocs"
17if [[ ! -e developer-guidelines.html.last ]] ; then
18 touch developer-guidelines.html.last
19fi
20 18
21# Get latest dev guildelines 19# Get latest dev guildelines
22[[ ! -d $IN ]] && mkdir $IN 20[[ ! -d $IN ]] && mkdir $IN
23cd $IN 21cd $IN
24if [[ ! -d doc ]] ; then 22if [[ ! -d nagios-plugins ]]
25 #cvs -z3 -d:pserver:anonymous@cvs1:/cvsroot/nagiosplug co nagiosplug || die "Cannot cvs" 23then
26 svn checkout http://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk/doc doc 24 git clone https://github.com/nagios-plugins/nagios-plugins.git nagios-plugins
27fi 25fi
28cd doc 26cd nagios-plugins/doc
29svn update 27git pull
30 28
31make 29make
32if [[ developer-guidelines.html -nt developer-guidelines.html.last ]] ; then 30if [[ ! -e $PROBE || developer-guidelines.html -nt $PROBE ]]
33 scp developer-guidelines.{html,sgml} $OUT_SERVER:$OUT 31then
34 touch developer-guidelines.html.last 32 rsync -av developer-guidelines.{html,sgml} $OUT_SERVER:$OUT_PATH/
33 touch $PROBE
35fi 34fi
35
diff --git a/tools/snapshot b/tools/snapshot
deleted file mode 100755
index 9fa61cfe..00000000
--- a/tools/snapshot
+++ /dev/null
@@ -1,69 +0,0 @@
1#! /bin/sh
2
3# This scipt assumes that you have anonCVS for nagios and nagiosplug
4# in ${IN}
5
6# cvs -d:pserver:anonymous@cvs.nagiosplug.sourceforge.net:/cvsroot/nagiosplug login
7# cvs -z3 -d:pserver:anonymous@cvs.nagiosplug.sourceforge.net:/cvsroot/nagiosplug co nagiosplug
8#
9# cvs -d:pserver:anonymous@cvs.nagios.sourceforge.net:/cvsroot/nagios login
10# cvs -z3 -d:pserver:anonymous@cvs.nagios.sourceforge.net:/cvsroot/nagios co nagios
11
12# Set directories
13IN=${HOME}/sf
14OUT=/col/htdocs/src/nagios
15RPM_TOPDIR=${HOME}/redhat
16
17# Update nagiosplug CVS
18cd ${IN}/nagiosplug
19rm configure configure.in Makefile.in
20cvs update
21DS=`date -u +%Y%m%d%H%M`
22sed "s/^VER=.*/VER=${DS}/;s/^REL=.*/REL=snapshot/" configure.in > configure.tmp
23mv configure.tmp configure.in
24aclocal
25autoheader
26autoconf
27automake
28autoreconf
29
30# Make the Nagiosplug dist tarball
31rm -r build-dist
32mkdir build-dist
33cd build-dist
34../configure
35make dist
36cp -fv *.gz ${OUT}
37
38# Make the Nagiosplug custom RPM
39echo "%_topdir ${RPM_TOPDIR}" > ./.rpmrc
40mkdir -p ${RPM_TOPDIR}/RPMS/i386 ${RPM_TOPDIR}/SRPMS ${RPM_TOPDIR}/SOURCES ${RPM_TOPDIR}/BUILD ${RPM_TOPDIR}/SPECS
41rpm --rcfile "/usr/lib/rpm/rpmrc:${IN}/rpmrc" --define 'custom 1' -ta *.gz
42cp -fv ~/redhat/RPMS/i386/nagios-plugins-custom-*.i386.rpm /col/htdocs/src/nagios
43
44# Copy the new snapshot and delete the old ones
45cd ${OUT}
46GLOBIGNORE=nagios-plugins-${DS}-snapshot.tar.gz
47rm -f nagios-plugins-*.tar.gz
48GLOBIGNORE=nagios-plugins-custom-${DS}-snapshot.i386.rpm
49rm -f nagios-plugins-custom-*-snapshot.i386.rpm
50cd ~/redhat/SRPMS
51rm nagios-plugins-custom-${DS}-snapshot.src.rpm
52cd ~/redhat/RPMS/i386
53rm nagios-plugins-custom-${DS}-snapshot.i386.rpm
54
55# Update Nagios CVS
56cd ${IN}/sf/nagios
57rm configure configure.in nagios.spec base/nagios.c common/common.h \
58 html/main.html Makefile.in
59cvs update
60
61# Make the Nagios tarball
62DS=`date -u +%Y%m%d%H%M`
63./make-tarball ${DS}
64
65# Copy the new snapshot and delete the old ones
66mv ../nagios-${DS}.tar.gz /col/htdocs/src/nagios/
67GLOBIGNORE=${OUT}/nagios-${DS}.tar.gz
68rm ${OUT}/nagios-20*.tar.gz
69
diff --git a/tools/update_man_pages b/tools/update_man_pages
new file mode 100755
index 00000000..5c4a901e
--- /dev/null
+++ b/tools/update_man_pages
@@ -0,0 +1,34 @@
1#!/usr/bin/perl
2use strict;
3use DBI;
4#$ENV{PERL5LIB}="plugins-scripts"; # Needed for utils.pm
5
6unless ($ENV{DRUPAL_PASSWORD}) {
7 die "Must set envvar for DRUPAL_PASSWORD";
8}
9
10my $dbh = DBI->connect("DBI:mysql:database=www;host=127.0.0.1", "www", $ENV{DRUPAL_PASSWORD});
11
12my @plugin_paths;
13push @plugin_paths, (grep { -x $_ && -f $_ } (<plugins-root/*>, <plugins/*>) );
14
15foreach my $plugin_path (@plugin_paths) {
16 my $plugin = $plugin_path;
17 $plugin =~ s%.*/%%;
18 my $help_option = "--help";
19 $help_option = "-h" if ($plugin eq "check_icmp");
20 my $help = `$plugin_path $help_option` || die "Cannot run $plugin -h";
21 $help =~ s/</&lt;/g;
22 $help =~ s/>/&gt;/g;
23
24 my $rows = $dbh->do("UPDATE node SET created=UNIX_TIMESTAMP(NOW()) WHERE title='$plugin'");
25 unless ($rows == 1) {
26 die "Cannot find $plugin in drupal to update - create book page first";
27 }
28
29 $dbh->do("UPDATE node_revisions SET timestamp=UNIX_TIMESTAMP(NOW()), log='Updated by update_online_manpage', teaser='$plugin --help', body=? WHERE title='$plugin'",
30 {},
31 "<pre>".$help."</pre>");
32}
33
34print "Finished\n";