diff options
52 files changed, 893 insertions, 513 deletions
@@ -37,6 +37,8 @@ NP-VERSION-FILE # /doc/ /doc/developer-guidelines.html +/doc/developer-guidelines.html.last +/doc/jade-out.fot # /tap/ /tap/.deps @@ -189,6 +191,7 @@ NP-VERSION-FILE /plugins/.libs /plugins/Makefile /plugins/Makefile.in +/plugins/libnpcommon.a /plugins/negate /plugins/stamp-h* /plugins/urlize @@ -1,3 +1,7 @@ +2013-01-23 Robin Sonefors <robin.sonefors@op5.com> + + * plugins/check_snmp.c: fix memory allocation if using >= 8 oids + 2012-06-27 Holger Weiss <holger@zedat.fu-berlin.de> * plugins/check_tcp.c: check_tcp: Print performance data even with @@ -3,9 +3,30 @@ This file documents the major additions and syntax changes between releases. ... ENHANCEMENTS New check_dbi plugin for checking an (SQL) database using DBI + Let OpenSSL load its configuration file (see the OPENSSL_config(3) man page) + Add performance data to check_apt + Add performance data to check_procs + Added -4/-6 options to check_dig (Ville Mattila) + New check_oracle --connect option to perform real login + New check_nagios -t option to override the default timeout + New check_disk -N/--include-type option to limit the filesystem types to check + Allow for building the plugins in parallel + Add --without-{dbi,ldap,radius} options to ./configure + Made Verbose output of check_sensors compliant (Gabriele Tozzi) + New switch -E/--extended-perfdata for check_http to print additional performance data (Sebastian Nohn) FIXES Change the MAIL FROM command generated by check_smtp to be RFC compliant + Fix compilation of check_http without SSL support + Fix check_snmp reversed threshold ranges (backward-compatibility) + Fix check_snmp memory violation when using more than 8 oids (Robin Sonefors) + Fix check_apt security regular expression (Alex Bradley) + Fix check_http handling extra header (-k) containing semicolons (Richard Leitner) + Fix check_apt handling unknown exit codes from apt-get (Richard Leitner) + Fix deprecated imports of check_nmap.py (Fabio Rueda) + + WARNINGS + check_http behaviour of -k/--header changed since it does not seperate multiple headers by semicolons anymore. Use multiple -k switches instead. 1.4.16 27th June 2012 ENHANCEMENTS diff --git a/REQUIREMENTS b/REQUIREMENTS index 9f2eec0f..1f673e98 100644 --- a/REQUIREMENTS +++ b/REQUIREMENTS @@ -36,10 +36,9 @@ check_ldap: check_mysql, check_mysql_query: - Requires the MySQL libraries available from - http://www.mysql.org/ + http://dev.mysql.com/downloads/ Lib: libmysql, libmysqlclient - Redhat Powertools Source: mysql-3.20.32a-3.i386.rpm, mysql-devel-3.20.32a-3.i386.rpm (these seem to be broken, however) - RPMS from www.mysql.org work better + Redhat Source (RHEL6, YUM): mysql-devel, mysql-libs Must have mysql_config in PATH or specified with --with-mysql=DIR for DIR/bin/mysql_config check_pqsql: @@ -275,3 +275,13 @@ Tobias Brox William Leibzon Jochen Bern Anders Kaseorg +Robin Sonefors +Alex Bradley +Brian De Wolf +Richard Leitner +Diego Elio Pettenò +Vaclav Ovsik +Roman Fiedler +Fabio Rueda +Gabriele Tozzi +Sebastian Nohn diff --git a/configure.in b/configure.in index 1d4ed006..25c0c9cd 100644 --- a/configure.in +++ b/configure.in @@ -255,55 +255,66 @@ fi LIBS="$_SAVEDLIBS" CPPFLAGS="$_SAVEDCPPFLAGS" +AC_ARG_WITH([dbi], [AS_HELP_STRING([--without-dbi], [Skips the dbi plugin])]) dnl Check for DBI libraries -_SAVEDLIBS="$LIBS" -AC_CHECK_LIB(dbi,dbi_initialize) -if test "$ac_cv_lib_dbi_dbi_initialize" = "yes"; then - EXTRAS="$EXTRAS check_dbi" - DBILIBS="-ldbi" - AC_SUBST(DBILIBS) -else - AC_MSG_WARN([Skipping dbi plugin]) - AC_MSG_WARN([install DBI libs to compile this plugin (see REQUIREMENTS).]) -fi -LIBS="$_SAVEDLIBS" +AS_IF([test "x$with_dbi" != "xno"], [ + _SAVEDLIBS="$LIBS" + AC_CHECK_LIB(dbi,dbi_initialize) + if test "$ac_cv_lib_dbi_dbi_initialize" = "yes"; then + EXTRAS="$EXTRAS check_dbi" + DBILIBS="-ldbi" + AC_SUBST(DBILIBS) + else + AC_MSG_WARN([Skipping dbi plugin]) + AC_MSG_WARN([install DBI libs to compile this plugin (see REQUIREMENTS).]) + fi + LIBS="$_SAVEDLIBS" +]) + +AC_ARG_WITH([radius], [AS_HELP_STRING([--without-radius], [Skips the radius plugin])]) dnl Check for radius libraries -_SAVEDLIBS="$LIBS" -AC_CHECK_LIB(radiusclient,rc_read_config) -if test "$ac_cv_lib_radiusclient_rc_read_config" = "yes"; then - EXTRAS="$EXTRAS check_radius" - RADIUSLIBS="-lradiusclient" - AC_SUBST(RADIUSLIBS) -else - AC_CHECK_LIB(radiusclient-ng,rc_read_config) - if test "$ac_cv_lib_radiusclient_ng_rc_read_config" = "yes"; then +AS_IF([test "x$with_radius" != "xno"], [ + _SAVEDLIBS="$LIBS" + AC_CHECK_LIB(radiusclient,rc_read_config) + if test "$ac_cv_lib_radiusclient_rc_read_config" = "yes"; then EXTRAS="$EXTRAS check_radius" - RADIUSLIBS="-lradiusclient-ng" + RADIUSLIBS="-lradiusclient" AC_SUBST(RADIUSLIBS) else - AC_MSG_WARN([Skipping radius plugin]) - AC_MSG_WARN([install radius libs to compile this plugin (see REQUIREMENTS).]) + AC_CHECK_LIB(radiusclient-ng,rc_read_config) + if test "$ac_cv_lib_radiusclient_ng_rc_read_config" = "yes"; then + EXTRAS="$EXTRAS check_radius" + RADIUSLIBS="-lradiusclient-ng" + AC_SUBST(RADIUSLIBS) + else + AC_MSG_WARN([Skipping radius plugin]) + AC_MSG_WARN([install radius libs to compile this plugin (see REQUIREMENTS).]) + fi fi -fi -LIBS="$_SAVEDLIBS" + LIBS="$_SAVEDLIBS" +]) + +AC_ARG_WITH([ldap], [AS_HELP_STRING([--without-ldap], [Skips the LDAP plugin])]) dnl Check for LDAP libraries -_SAVEDLIBS="$LIBS" -AC_CHECK_LIB(ldap,main,,,-llber) -if test "$ac_cv_lib_ldap_main" = "yes"; then - LDAPLIBS="-lldap -llber"\ - LDAPINCLUDE="-I/usr/include/ldap" - AC_SUBST(LDAPLIBS) - AC_SUBST(LDAPINCLUDE) - AC_CHECK_FUNCS(ldap_set_option) - EXTRAS="$EXTRAS check_ldap" - AC_CHECK_FUNCS(ldap_init ldap_set_option ldap_get_option ldap_start_tls_s) -else - AC_MSG_WARN([Skipping LDAP plugin]) - AC_MSG_WARN([install LDAP libs to compile this plugin (see REQUIREMENTS).]) -fi -LIBS="$_SAVEDLIBS" +AS_IF([test "x$with_ldap" != "xno"], [ + _SAVEDLIBS="$LIBS" + AC_CHECK_LIB(ldap,main,,,-llber) + if test "$ac_cv_lib_ldap_main" = "yes"; then + LDAPLIBS="-lldap -llber"\ + LDAPINCLUDE="-I/usr/include/ldap" + AC_SUBST(LDAPLIBS) + AC_SUBST(LDAPINCLUDE) + AC_CHECK_FUNCS(ldap_set_option) + EXTRAS="$EXTRAS check_ldap" + AC_CHECK_FUNCS(ldap_init ldap_set_option ldap_get_option ldap_start_tls_s) + else + AC_MSG_WARN([Skipping LDAP plugin]) + AC_MSG_WARN([install LDAP libs to compile this plugin (see REQUIREMENTS).]) + fi + LIBS="$_SAVEDLIBS" +]) dnl Check for headers used by check_ide_smart AC_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){ if (defined $device) { if (/(\[[_U]+\])/) { $status{$device} = $1; - } elsif (/recovery = (.*?)\s/) { + } elsif (/recovery =\s+(.*?)\s/) { $recovery{$device} = $1; ($finish{$device}) = /finish=(.*?min)/; $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' # 0.20 2000-07-10 jaclu Initial release -import sys, os, string, whrandom +import sys, os, string, random import tempfile from getopt import getopt @@ -207,8 +207,7 @@ class CheckNmap: # _if_ two processes in deed get the same tmp-file # the only result is a normal error message to nagios # - r=whrandom.whrandom() - self.tmp_file=tempfile.mktemp('.%s')%r.randint(0,100000) + self.tmp_file=tempfile.mktemp('.%s') % random.randint(0,100000) if self.debug: print 'Tmpfile is: %s'%self.tmp_file # @@ -388,7 +387,7 @@ Version: %s""" % _version_ def doc_syntax(): print """ -Usage: check_ports [-v|--debug] [-H|--host host] [-V|--version] [-h|--help] +Usage: check_nmap.py [-v|--debug] [-H|--host host] [-V|--version] [-h|--help] [-o|--optional port1,port2,port3 ...] [-r|--range range] [-p|--port port1,port2,port3 ...] [-t|--timeout timeout]""" 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 @@ </row> <row> <entry>check_stuff -w~:0 -c10</entry> - <entry>Critical if "stuff" is above 10; Warn if "stuff" is above zero</entry> + <entry>Critical if "stuff" is above 10; Warn if "stuff" is above zero (will be critical if "stuff" is less than 0)</entry> </row> <row> <entry>check_stuff -c5:6</entry> - <entry>The only noncritical range is 5:6</entry> + <entry>Critical if "stuff" is less than 5 or more than 6</entry> </row> <row> - <entry>check_stuff -c10:20</entry> - <entry>Critical if "stuff" is less than 10 or over 20</entry> + <entry>check_stuff -c@10:20</entry> + <entry>OK if stuff is less than 10 or higher than 20, otherwise critical </entry> </row> </tbody> </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 fi clean: - rm -f developer-guidelines.html + 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) state_data *temp_state_data; time_t current_time; - plan_tests(141); + plan_tests(150); ok( this_nagios_plugin==NULL, "nagios_plugin not initialised"); @@ -132,6 +132,18 @@ main (int argc, char **argv) ok( check_range(0, range) == TRUE, "0 - alert"); free(range); + range = parse_range_string("@1:1"); + ok( range != NULL, "'@1:1' is a valid range"); + ok( range->start == 1, "Start correct"); + ok( range->start_infinity == FALSE, "Not using negative infinity"); + ok( range->end == 1, "End correct"); + ok( range->end_infinity == FALSE, "Not using infinity"); + ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); + ok( check_range(0.5, range) == FALSE, "0.5 - no alert"); + ok( check_range(1, range) == TRUE, "1 - alert"); + ok( check_range(5.2, range) == FALSE, "5.2 - no alert"); + free(range); + range = parse_range_string("1:1"); ok( range != NULL, "'1:1' is a valid range"); 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; void np_init( char *plugin_name, int argc, char **argv ) { if (this_nagios_plugin==NULL) { - this_nagios_plugin = malloc(sizeof(nagios_plugin)); + this_nagios_plugin = calloc(1, sizeof(nagios_plugin)); if (this_nagios_plugin==NULL) { die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); @@ -108,7 +108,7 @@ range double end; char *end_str; - temp_range = (range *) malloc(sizeof(range)); + temp_range = (range *) calloc(1, sizeof(range)); /* Set defaults */ temp_range->start = 0; @@ -154,7 +154,7 @@ _set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_st { thresholds *temp_thresholds = NULL; - if ((temp_thresholds = malloc(sizeof(thresholds))) == NULL) + if ((temp_thresholds = calloc(1, sizeof(thresholds))) == NULL) die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); @@ -335,13 +335,13 @@ char *np_extract_value(const char *varlist, const char *name, char sep) { if (tmp = index(varlist, sep)) { /* Value is delimited by a comma */ if (tmp-varlist == 0) continue; - value = (char *)malloc(tmp-varlist+1); + value = (char *)calloc(1, tmp-varlist+1); strncpy(value, varlist, tmp-varlist); value[tmp-varlist] = '\0'; } else { /* Value is delimited by a \0 */ if (strlen(varlist) == 0) continue; - value = (char *)malloc(strlen(varlist) + 1); + value = (char *)calloc(1, strlen(varlist) + 1); strncpy(value, varlist, strlen(varlist)); value[strlen(varlist)] = '\0'; } @@ -431,7 +431,7 @@ void np_enable_state(char *keyname, int expected_data_version) { if(this_nagios_plugin==NULL) die(STATE_UNKNOWN, _("This requires np_init to be called")); - this_state = (state_key *) malloc(sizeof(state_key)); + this_state = (state_key *) calloc(1, sizeof(state_key)); if(this_state==NULL) die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); @@ -482,7 +482,7 @@ state_data *np_state_read() { statefile = fopen( this_nagios_plugin->state->_filename, "r" ); if(statefile!=NULL) { - this_state_data = (state_data *) malloc(sizeof(state_data)); + this_state_data = (state_data *) calloc(1, sizeof(state_data)); if(this_state_data==NULL) die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); @@ -517,7 +517,7 @@ int _np_state_read_file(FILE *f) { time(¤t_time); /* Note: This introduces a limit of 1024 bytes in the string data */ - line = (char *) malloc(1024); + line = (char *) calloc(1, 1024); if(line==NULL) die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), 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() { echo " $PROGNAME --tns <Oracle Sid or Hostname/IP address>" echo " $PROGNAME --db <ORACLE_SID>" echo " $PROGNAME --login <ORACLE_SID>" + echo " $PROGNAME --connect <ORACLE_SID>" echo " $PROGNAME --cache <ORACLE_SID> <USER> <PASS> <CRITICAL> <WARNING>" echo " $PROGNAME --tablespace <ORACLE_SID> <USER> <PASS> <TABLESPACE> <CRITICAL> <WARNING>" echo " $PROGNAME --oranames <Hostname>" @@ -39,6 +40,8 @@ print_help() { echo " filesystem for sgadefORACLE_SID.dbf" echo "--login SID" echo " Attempt a dummy login and alert if not ORA-01017: invalid username/password" + echo "--connect SID" + echo " Attempt a login and alert if an ORA- error is returned" echo "--cache" echo " Check local database for library and buffer cache hit ratios" echo " ---> Requires Oracle user/password and SID specified." @@ -187,6 +190,18 @@ case "$cmd" in exit $STATE_CRITICAL fi ;; +--connect) + connectchk=`sqlplus $2 < /dev/null` + connectchk2=` echo $connectchk | grep -c ORA-` + if [ ${connectchk2} -eq 0 ] ; then + echo "OK - login successful" + exit $STATE_OK + else + connectchk3=` echo "$connectchk" | grep "ORA-" | head -1` + echo "CRITICAL - $connectchk3" + exit $STATE_CRITICAL + fi + ;; --cache) if [ ${5} -gt ${6} ] ; then 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 *) sensordata=`sensors 2>&1` status=$? - if test "$1" = "-v" -o "$1" = "--verbose"; then - echo ${sensordata} - fi if test ${status} -eq 127; then - echo "SENSORS UNKNOWN - command not found (did you install lmsensors?)" - exit $STATE_UNKNOWN + text="SENSORS UNKNOWN - command not found (did you install lmsensors?)" + exit=$STATE_UNKNOWN elif test ${status} -ne 0; then - echo "WARNING - sensors returned state $status" - exit $STATE_WARNING - fi - if echo ${sensordata} | egrep ALARM > /dev/null; then - echo SENSOR CRITICAL - Sensor alarm detected! - exit $STATE_CRITICAL + text="WARNING - sensors returned state $status" + exit=$STATE_WARNING + elif echo ${sensordata} | egrep ALARM > /dev/null; then + text="SENSOR CRITICAL - Sensor alarm detected!" + exit=$STATE_CRITICAL elif echo ${sensordata} | egrep FAULT > /dev/null \ && test "$1" != "-i" -a "$1" != "--ignore-fault"; then - echo SENSOR UNKNOWN - Sensor reported fault - exit $STATE_UNKNOWN + text="SENSOR UNKNOWN - Sensor reported fault" + exit=$STATE_UNKNOWN + else + text="SENSORS OK" + exit=$STATE_OK fi - echo sensor ok - exit $STATE_OK + + echo "$text" + if test "$1" = "-v" -o "$1" = "--verbose"; then + echo ${sensordata} + fi + exit $exit ;; esac 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() { # # check_range takes a value and a range string, returning successfully if an -# alert should be raised based on the range. +# alert should be raised based on the range. Range values are inclusive. +# Values may be integers or floats. +# +# Example usage: +# +# Generating an exit code of 1: +# check_range 5 2:8 +# +# Generating an exit code of 0: +# check_range 1 2:8 # check_range() { 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 \ check_nagios check_by_ssh check_dns check_nt check_ide_smart \ check_procs check_mysql_query check_apt check_dbi -EXTRA_DIST = t tests utils.c netutils.c sslutils.c popen.c utils.h netutils.h \ - popen.h common.h runcmd.c runcmd.h +EXTRA_DIST = t tests PLUGINHDRS = common.h -BASEOBJS = utils.o ../lib/libnagiosplug.a ../gl/libgnu.a -NETOBJS = netutils.o $(BASEOBJS) $(EXTRA_NETOBJS) -SSLOBJS = sslutils.o +noinst_LIBRARIES = libnpcommon.a + +libnpcommon_a_SOURCES = utils.c netutils.c sslutils.c runcmd.c \ + popen.c utils.h netutils.h popen.h common.h runcmd.c runcmd.h + +BASEOBJS = libnpcommon.a ../lib/libnagiosplug.a ../gl/libgnu.a +NETOBJS = $(BASEOBJS) $(EXTRA_NETOBLS) NETLIBS = $(NETOBJS) $(SOCKETLIBS) +SSLOBJS = $(BASEOBJS) $(NETLIBS) $(SSLLIBS) TESTS_ENVIRONMENT = perl -I $(top_builddir) -I $(top_srcdir) @@ -62,19 +66,19 @@ test-debug: ############################################################################## # the actual targets -check_apt_LDADD = $(BASEOBJS) runcmd.o +check_apt_LDADD = $(BASEOBJS) check_cluster_LDADD = $(BASEOBJS) check_dbi_LDADD = $(NETLIBS) $(DBILIBS) -check_dig_LDADD = $(NETLIBS) runcmd.o -check_disk_LDADD = $(BASEOBJS) popen.o -check_dns_LDADD = $(NETLIBS) runcmd.o +check_dig_LDADD = $(NETLIBS) +check_disk_LDADD = $(BASEOBJS) +check_dns_LDADD = $(NETLIBS) check_dummy_LDADD = $(BASEOBJS) -check_fping_LDADD = $(NETLIBS) popen.o -check_game_LDADD = $(BASEOBJS) runcmd.o -check_http_LDADD = $(SSLOBJS) $(NETLIBS) $(SSLLIBS) -check_hpjd_LDADD = $(NETLIBS) popen.o +check_fping_LDADD = $(NETLIBS) +check_game_LDADD = $(BASEOBJS) +check_http_LDADD = $(SSLOBJS) +check_hpjd_LDADD = $(NETLIBS) check_ldap_LDADD = $(NETLIBS) $(LDAPLIBS) -check_load_LDADD = $(BASEOBJS) popen.o +check_load_LDADD = $(BASEOBJS) check_mrtg_LDADD = $(BASEOBJS) check_mrtgtraf_LDADD = $(BASEOBJS) check_mysql_CFLAGS = $(MYSQLCFLAGS) -DNP_VERSION='"$(NP_VERSION)"' @@ -83,22 +87,22 @@ check_mysql_LDADD = $(NETLIBS) $(MYSQLLIBS) check_mysql_query_CFLAGS = $(MYSQLCFLAGS) -DNP_VERSION='"$(NP_VERSION)"' check_mysql_query_CPPFLAGS = $(MYSQLINCLUDE) check_mysql_query_LDADD = $(NETLIBS) $(MYSQLLIBS) -check_nagios_LDADD = $(BASEOBJS) runcmd.o +check_nagios_LDADD = $(BASEOBJS) check_nt_LDADD = $(NETLIBS) check_ntp_LDADD = $(NETLIBS) $(MATHLIBS) check_ntp_peer_LDADD = $(NETLIBS) $(MATHLIBS) check_nwstat_LDADD = $(NETLIBS) check_overcr_LDADD = $(NETLIBS) check_pgsql_LDADD = $(NETLIBS) $(PGLIBS) -check_ping_LDADD = $(NETLIBS) popen.o +check_ping_LDADD = $(NETLIBS) check_procs_LDADD = $(BASEOBJS) check_radius_LDADD = $(NETLIBS) $(RADIUSLIBS) check_real_LDADD = $(NETLIBS) check_snmp_LDADD = $(BASEOBJS) -check_smtp_LDADD = $(SSLOBJS) $(NETLIBS) $(SSLLIBS) +check_smtp_LDADD = $(SSLOBJS) check_ssh_LDADD = $(NETLIBS) -check_swap_LDADD = $(MATHLIBS) $(BASEOBJS) popen.o -check_tcp_LDADD = $(SSLOBJS) $(NETLIBS) $(SSLLIBS) +check_swap_LDADD = $(MATHLIBS) $(BASEOBJS) +check_tcp_LDADD = $(SSLOBJS) check_time_LDADD = $(NETLIBS) check_ntp_time_LDADD = $(NETLIBS) $(MATHLIBS) check_ups_LDADD = $(NETLIBS) @@ -106,62 +110,11 @@ check_users_LDADD = $(BASEOBJS) check_by_ssh_LDADD = $(NETLIBS) check_ide_smart_LDADD = $(BASEOBJS) negate_LDADD = $(BASEOBJS) -urlize_LDADD = $(BASEOBJS) popen.o - -check_apt_DEPENDENCIES = check_apt.c $(BASEOBJS) runcmd.o $(DEPLIBS) -check_cluster_DEPENDENCIES = check_cluster.c $(BASEOBJS) $(DEPLIBS) -check_dbi_DEPENDENCIES = check_dbi.c $(NETOBJS) $(DEPLIBS) -check_dig_DEPENDENCIES = check_dig.c $(NETOBJS) runcmd.o $(DEPLIBS) -check_disk_DEPENDENCIES = check_disk.c $(BASEOBJS) popen.o $(DEPLIBS) -check_dns_DEPENDENCIES = check_dns.c $(NETOBJS) runcmd.o $(DEPLIBS) -check_dummy_DEPENDENCIES = check_dummy.c $(DEPLIBS) -check_fping_DEPENDENCIES = check_fping.c $(NETOBJS) popen.o $(DEPLIBS) -check_game_DEPENDENCIES = check_game.c $(DEPLIBS) runcmd.o -check_http_DEPENDENCIES = check_http.c $(SSLOBJS) $(NETOBJS) $(DEPLIBS) -check_hpjd_DEPENDENCIES = check_hpjd.c $(NETOBJS) popen.o $(DEPLIBS) -check_ide_smart_DEPENDENCIES = check_ide_smart.c $(BASEOBJS) $(DEPLIBS) -check_ldap_DEPENDENCIES = check_ldap.c $(NETOBJS) $(DEPLIBS) -check_load_DEPENDENCIES = check_load.c $(BASEOBJS) popen.o $(DEPLIBS) -check_mrtg_DEPENDENCIES = check_mrtg.c $(DEPLIBS) -check_mrtgtraf_DEPENDENCIES = check_mrtgtraf.c $(DEPLIBS) -check_mysql_DEPENDENCIES = check_mysql.c $(NETOBJS) $(DEPLIBS) -check_mysql_query_DEPENDENCIES = check_mysql_query.c $(NETOBJS) $(DEPLIBS) -check_nagios_DEPENDENCIES = check_nagios.c $(BASEOBJS) runcmd.o $(DEPLIBS) -check_nt_DEPENDENCIES = check_nt.c $(NETOBJS) $(DEPLIBS) -check_ntp_DEPENDENCIES = check_ntp.c $(NETOBJS) $(DEPLIBS) -check_ntp_peer_DEPENDENCIES = check_ntp_peer.c $(NETOBJS) $(DEPLIBS) -check_nwstat_DEPENDENCIES = check_nwstat.c $(NETOBJS) $(DEPLIBS) -check_overcr_DEPENDENCIES = check_overcr.c $(NETOBJS) $(DEPLIBS) -check_pgsql_DEPENDENCIES = check_pgsql.c $(NETOBJS) $(DEPLIBS) -check_ping_DEPENDENCIES = check_ping.c $(NETOBJS) popen.o $(DEPLIBS) -check_procs_DEPENDENCIES = check_procs.c $(BASEOBJS) popen.o $(DEPLIBS) -check_radius_DEPENDENCIES = check_radius.c $(NETOBJS) $(DEPLIBS) -check_real_DEPENDENCIES = check_real.c $(NETOBJS) $(DEPLIBS) -check_snmp_DEPENDENCIES = check_snmp.c $(BASEOBJS) $(DEPLIBS) -check_smtp_DEPENDENCIES = check_smtp.c $(SSLOBJS) $(NETOBJS) $(DEPLIBS) -check_ssh_DEPENDENCIES = check_ssh.c $(NETOBJS) $(DEPLIBS) -check_swap_DEPENDENCIES = check_swap.c $(BASEOBJS) popen.o $(DEPLIBS) -check_tcp_DEPENDENCIES = check_tcp.c $(SSLOBJS) $(NETOBJS) $(DEPLIBS) -check_time_DEPENDENCIES = check_time.c $(NETOBJS) $(DEPLIBS) -check_ntp_time_DEPENDENCIES = check_ntp_time.c $(NETOBJS) $(DEPLIBS) -check_ups_DEPENDENCIES = check_ups.c $(NETOBJS) $(DEPLIBS) -check_users_DEPENDENCIES = check_users.c $(BASEOBJS) popen.o $(DEPLIBS) -check_by_ssh_DEPENDENCIES = check_by_ssh.c $(NETOBJS) $(DEPLIBS) -negate_DEPENDENCIES = negate.c $(BASEOBJS) $(DEPLIBS) -urlize_DEPENDENCIES = urlize.c $(BASEOBJS) popen.o $(DEPLIBS) +urlize_LDADD = $(BASEOBJS) ############################################################################## # secondary dependencies -popen.o: popen.c popen.h $(PLUGINHDRS) - -runcmd.o: runcmd.c runcmd.h $(PLUGINHDRS) - -utils.o: utils.c utils.h $(PLUGINHDRS) - -netutils.o: netutils.c netutils.h $(PLUGINHDRS) -sslutils.o: sslutils.c netutils.h $(PLUGINHDRS) - all-local: $(check_tcp_programs) $(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"; /* some constants */ typedef enum { UPGRADE, DIST_UPGRADE, NO_UPGRADE } upgrade_type; +/* Character for hidden input file option (for testing). */ +#define INPUT_FILE_OPT CHAR_MAX+1 /* the default opts can be overridden via the cmdline */ #define UPGRADE_DEFAULT_OPTS "-o 'Debug::NoLocking=true' -s -qq" #define UPDATE_DEFAULT_OPTS "-q" @@ -49,8 +51,10 @@ typedef enum { UPGRADE, DIST_UPGRADE, NO_UPGRADE } upgrade_type; #ifndef PATH_TO_APTGET # define PATH_TO_APTGET "/usr/bin/apt-get" #endif /* PATH_TO_APTGET */ +/* String found at the beginning of the apt output lines we're interested in */ +#define PKGINST_PREFIX "Inst " /* the RE that catches security updates */ -#define SECURITY_RE "^[^\\(]*\\([^ ]* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)" +#define SECURITY_RE "^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)" /* some standard functions */ int process_arguments(int, char **); @@ -75,6 +79,7 @@ static char *update_opts = NULL; /* options to override defaults for update */ static char *do_include = NULL; /* regexp to only include certain packages */ static char *do_exclude = NULL; /* regexp to only exclude certain packages */ static char *do_critical = NULL; /* regexp specifying critical packages */ +static char *input_filename = NULL; /* input filename for testing */ /* other global variables */ static int stderr_warning = 0; /* if a cmd issued output on stderr */ @@ -107,11 +112,11 @@ int main (int argc, char **argv) { result = max_state(result, STATE_CRITICAL); } else if(packages_available > 0){ result = max_state(result, STATE_WARNING); - } else { - result = max_state(result, STATE_OK); + } else if(result > STATE_UNKNOWN){ + result = STATE_UNKNOWN; } - printf(_("APT %s: %d packages available for %s (%d critical updates). %s%s%s%s\n"), + printf(_("APT %s: %d packages available for %s (%d critical updates). %s%s%s%s|available_upgrades=%d;;;0 critical_updates=%d;;;0\n"), state_text(result), packages_available, (upgrade==DIST_UPGRADE)?"dist-upgrade":"upgrade", @@ -119,7 +124,9 @@ int main (int argc, char **argv) { (stderr_warning)?" warnings detected":"", (stderr_warning && exec_warning)?",":"", (exec_warning)?" errors detected":"", - (stderr_warning||exec_warning)?". run with -v for information.":"" + (stderr_warning||exec_warning)?". run with -v for information.":"", + packages_available, + sec_count ); return result; @@ -141,6 +148,7 @@ int process_arguments (int argc, char **argv) { {"include", required_argument, 0, 'i'}, {"exclude", required_argument, 0, 'e'}, {"critical", required_argument, 0, 'c'}, + {"input-file", required_argument, 0, INPUT_FILE_OPT}, {0, 0, 0, 0} }; @@ -195,6 +203,9 @@ int process_arguments (int argc, char **argv) { case 'c': do_critical=add_to_regexp(do_critical, optarg); break; + case INPUT_FILE_OPT: + input_filename = optarg; + break; default: /* print short usage statement if args not parsable */ usage5(); @@ -211,22 +222,18 @@ int run_upgrade(int *pkgcount, int *secpkgcount){ struct output chld_out, chld_err; regex_t ireg, ereg, sreg; char *cmdline=NULL, rerrbuf[64]; - const char *include_ptr=NULL, *crit_ptr=NULL; if(upgrade==NO_UPGRADE) return STATE_OK; /* compile the regexps */ - if(do_include!=NULL) include_ptr=do_include; - else include_ptr="^Inst"; - if(do_critical!=NULL) crit_ptr=do_critical; - else crit_ptr=SECURITY_RE; - - regres=regcomp(&ireg, include_ptr, REG_EXTENDED); - if(regres!=0) { - regerror(regres, &ireg, rerrbuf, 64); - die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), progname, rerrbuf); + if (do_include != NULL) { + regres=regcomp(&ireg, do_include, REG_EXTENDED); + if (regres!=0) { + regerror(regres, &ireg, rerrbuf, 64); + die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), progname, rerrbuf); + } } - + if(do_exclude!=NULL){ regres=regcomp(&ereg, do_exclude, REG_EXTENDED); if(regres!=0) { @@ -235,6 +242,8 @@ int run_upgrade(int *pkgcount, int *secpkgcount){ progname, rerrbuf); } } + + const char *crit_ptr = (do_critical != NULL) ? do_critical : SECURITY_RE; regres=regcomp(&sreg, crit_ptr, REG_EXTENDED); if(regres!=0) { regerror(regres, &ereg, rerrbuf, 64); @@ -243,8 +252,14 @@ int run_upgrade(int *pkgcount, int *secpkgcount){ } cmdline=construct_cmdline(upgrade, upgrade_opts); - /* run the upgrade */ - result = np_runcmd(cmdline, &chld_out, &chld_err, 0); + if (input_filename != NULL) { + /* read input from a file for testing */ + result = cmd_file_read(input_filename, &chld_out, 0); + } else { + /* run the upgrade */ + result = np_runcmd(cmdline, &chld_out, &chld_err, 0); + } + /* apt-get upgrade only changes exit status if there is an * internal error when run in dry-run mode. therefore we will * treat such an error as UNKNOWN */ @@ -269,7 +284,8 @@ int run_upgrade(int *pkgcount, int *secpkgcount){ printf("%s\n", chld_out.line[i]); } /* if it is a package we care about */ - if(regexec(&ireg, chld_out.line[i], 0, NULL, 0)==0){ + if (strncmp(PKGINST_PREFIX, chld_out.line[i], strlen(PKGINST_PREFIX)) == 0 && + (do_include == NULL || regexec(&ireg, chld_out.line[i], 0, NULL, 0) == 0)) { /* if we're not excluding, or it's not in the * list of stuff to exclude */ if(do_exclude==NULL || @@ -289,7 +305,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount){ *secpkgcount=spc; /* If we get anything on stderr, at least set warning */ - if(chld_err.buflen){ + if (input_filename == NULL && chld_err.buflen) { stderr_warning=1; result = max_state(result, STATE_WARNING); if(verbose){ @@ -298,7 +314,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount){ } } } - regfree(&ireg); + if (do_include != NULL) regfree(&ireg); regfree(&sreg); if(do_exclude!=NULL) regfree(&ereg); free(cmdline); @@ -348,15 +364,15 @@ char* add_to_regexp(char *expr, const char *next){ char *re=NULL; if(expr==NULL){ - re=malloc(sizeof(char)*(strlen("^Inst () ")+strlen(next)+1)); + re=malloc(sizeof(char)*(strlen("()")+strlen(next)+1)); if(!re) die(STATE_UNKNOWN, "malloc failed!\n"); - sprintf(re, "^Inst (%s) ", next); + sprintf(re, "(%s)", next); } else { /* resize it, adding an extra char for the new '|' separator */ - re=realloc(expr, sizeof(char)*strlen(expr)+1+strlen(next)+1); + re=realloc(expr, sizeof(char)*(strlen(expr)+1+strlen(next)+1)); if(!re) die(STATE_UNKNOWN, "realloc failed!\n"); /* append it starting at ')' in the old re */ - sprintf((char*)(re+strlen(re)-2), "|%s) ", next); + sprintf((char*)(re+strlen(re)-1), "|%s)", next); } return re; @@ -430,7 +446,7 @@ print_help (void) printf (" %s\n", _("Do not run the upgrade. Probably not useful (without -u at least).")); printf (" %s\n", "-i, --include=REGEXP"); printf (" %s\n", _("Include only packages matching REGEXP. Can be specified multiple times")); - printf (" %s\n", _("the values will be combined together. Any patches matching this list")); + printf (" %s\n", _("the values will be combined together. Any packages matching this list")); printf (" %s\n", _("cause the plugin to return WARNING status. Others will be ignored.")); printf (" %s\n", _("Default is to include all packages.")); 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"; char *expected_address = NULL; char *dns_server = NULL; char *dig_args = ""; +char *query_transport = ""; int verbose = FALSE; int server_port = DEFAULT_PORT; double warning_interval = UNDEFINED; @@ -77,7 +78,7 @@ main (int argc, char **argv) textdomain (PACKAGE); /* Set signal handling and alarm */ - if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) + if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) usage_va(_("Cannot catch SIGALRM")); /* Parse extra opts if any */ @@ -87,8 +88,8 @@ main (int argc, char **argv) usage_va(_("Could not parse arguments")); /* get the command to run */ - xasprintf (&command_line, "%s @%s -p %d %s -t %s %s", - PATH_TO_DIG, dns_server, server_port, query_address, record_type, dig_args); + xasprintf (&command_line, "%s @%s -p %d %s -t %s %s %s", + PATH_TO_DIG, dns_server, server_port, query_address, record_type, dig_args, query_transport); alarm (timeout_interval); gettimeofday (&tv, NULL); @@ -199,6 +200,8 @@ process_arguments (int argc, char **argv) {"record_type", required_argument, 0, 'T'}, {"expected_address", required_argument, 0, 'a'}, {"port", required_argument, 0, 'p'}, + {"use-ipv4", no_argument, 0, '4'}, + {"use-ipv6", no_argument, 0, '6'}, {0, 0, 0, 0} }; @@ -206,7 +209,7 @@ process_arguments (int argc, char **argv) return ERROR; while (1) { - c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:p:a:A:", longopts, &option); + c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:p:a:A:46", longopts, &option); if (c == -1 || c == EOF) break; @@ -269,6 +272,12 @@ process_arguments (int argc, char **argv) case 'a': expected_address = optarg; break; + case '4': + query_transport = "-4"; + break; + case '6': + query_transport = "-6"; + break; default: /* usage5 */ usage5(); } @@ -325,6 +334,10 @@ print_help (void) printf (UT_HOST_PORT, 'p', myport); + printf (" %s\n","-4, --use-ipv4"); + printf (" %s\n",_("Force dig to only use IPv4 query transport")); + printf (" %s\n","-6, --use-ipv6"); + printf (" %s\n",_("Force dig to only use IPv6 query transport")); printf (" %s\n","-l, --query_address=STRING"); printf (" %s\n",_("Machine name to lookup")); 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; /* Linked list of filesystem types to omit. If the list is empty, don't exclude any types. */ - static struct name_list *fs_exclude_list; +/* Linked list of filesystem types to check. + If the list is empty, include all types. */ +static struct name_list *fs_include_list; + static struct name_list *dp_exclude_list; static struct parameter_list *path_select_list = NULL; @@ -255,6 +258,9 @@ main (int argc, char **argv) (np_find_name (dp_exclude_list, me->me_devname) || np_find_name (dp_exclude_list, me->me_mountdir))) { continue; + /* Skip not included fstypes */ + } else if (fs_include_list && !np_find_name (fs_include_list, me->me_type)) { + continue; } stat_path(path); @@ -419,6 +425,7 @@ process_arguments (int argc, char **argv) {"partition", required_argument, 0, 'p'}, {"exclude_device", required_argument, 0, 'x'}, {"exclude-type", required_argument, 0, 'X'}, + {"include-type", required_argument, 0, 'N'}, {"group", required_argument, 0, 'g'}, {"eregi-path", required_argument, 0, 'R'}, {"eregi-partition", required_argument, 0, 'R'}, @@ -452,7 +459,7 @@ process_arguments (int argc, char **argv) strcpy (argv[c], "-t"); while (1) { - c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklLg:R:r:i:I:MEA", longopts, &option); + c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:N:mklLg:R:r:i:I:MEA", longopts, &option); if (c == -1 || c == EOF) break; @@ -591,6 +598,9 @@ process_arguments (int argc, char **argv) case 'X': /* exclude file system type */ np_add_name(&fs_exclude_list, optarg); break; + case 'N': /* include file system type */ + np_add_name(&fs_include_list, optarg); + break; case 'v': /* verbose */ verbose++; break; @@ -856,7 +866,7 @@ print_help (void) printf (" %s\n", "-c, --critical=INTEGER"); printf (" %s\n", _("Exit with CRITICAL status if less than INTEGER units of disk are free")); printf (" %s\n", "-c, --critical=PERCENT%"); - printf (" %s\n", _("Exit with CRITCAL status if less than PERCENT of disk space is free")); + printf (" %s\n", _("Exit with CRITICAL status if less than PERCENT of disk space is free")); printf (" %s\n", "-W, --iwarning=PERCENT%"); printf (" %s\n", _("Exit with WARNING status if less than PERCENT of inode space is free")); printf (" %s\n", "-K, --icritical=PERCENT%"); @@ -900,6 +910,8 @@ print_help (void) printf (UT_VERBOSE); printf (" %s\n", "-X, --exclude-type=TYPE"); printf (" %s\n", _("Ignore all filesystems of indicated type (may be repeated)")); + printf (" %s\n", "-N, --include-type=TYPE"); + printf (" %s\n", _("Check only filesystems of indicated type (may be repeated)")); printf ("\n"); printf ("%s\n", _("Examples:")); @@ -922,7 +934,7 @@ print_usage (void) printf ("%s\n", _("Usage:")); printf (" %s -w limit -c limit [-W limit] [-K limit] {-p path | -x device}\n", progname); printf ("[-C] [-E] [-e] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n"); - printf ("[-t timeout] [-u unit] [-v] [-X type]\n"); + printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type]\n"); } void 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) textdomain (PACKAGE); /* Set signal handling and alarm */ - if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { + if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { usage_va(_("Cannot catch SIGALRM")); } 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 @@ /***************************************************************************** -* +* * Nagios check_http plugin -* +* * License: GPL -* Copyright (c) 1999-2008 Nagios Plugins Development Team -* +* Copyright (c) 1999-2013 Nagios Plugins Development Team +* * Description: -* +* * This file contains the check_http plugin -* +* * This plugin tests the HTTP service on the specified host. It can test * normal (http) and secure (https) servers, follow redirects, search for * strings and regular expressions, check connection times, and report on * certificate expiration times. -* -* +* +* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* +* +* *****************************************************************************/ /* splint -I. -I../../plugins -I../../lib/ -I/usr/kerberos/include/ ../../plugins/check_http.c */ const char *progname = "check_http"; -const char *copyright = "1999-2011"; +const char *copyright = "1999-2013"; const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "common.h" @@ -43,7 +43,6 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "base64.h" #include <ctype.h> -#define INPUT_DELIMITER ";" #define STICKY_NONE 0 #define STICKY_HOST 1 #define STICKY_PORT 2 @@ -85,6 +84,7 @@ int errcode; int invert_regex = 0; struct timeval tv; +struct timeval tv_temp; #define HTTP_URL "/" #define CRLF "\r\n" @@ -115,6 +115,7 @@ int followsticky = STICKY_NONE; int use_ssl = FALSE; int use_sni = FALSE; int verbose = FALSE; +int show_extended_perfdata = FALSE; int sd; int min_page_len = 0; int max_page_len = 0; @@ -131,6 +132,11 @@ void redir (char *pos, char *status_line); int server_type_check(const char *type); int server_port_check(int ssl_flag); char *perfd_time (double microsec); +char *perfd_time_connect (double microsec); +char *perfd_time_ssl (double microsec); +char *perfd_time_firstbyte (double microsec); +char *perfd_time_headers (double microsec); +char *perfd_time_transfer (double microsec); char *perfd_size (int page_len); void print_help (void); void print_usage (void); @@ -216,6 +222,7 @@ process_arguments (int argc, char **argv) {"invert-regex", no_argument, NULL, INVERT_REGEX}, {"use-ipv4", no_argument, 0, '4'}, {"use-ipv6", no_argument, 0, '6'}, + {"extended-perfdata", no_argument, 0, 'E'}, {0, 0, 0, 0} }; @@ -236,7 +243,7 @@ process_arguments (int argc, char **argv) } while (1) { - 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); + 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); if (c == -1 || c == EOF) break; @@ -284,18 +291,18 @@ process_arguments (int argc, char **argv) case 'C': /* Check SSL cert validity */ #ifdef HAVE_SSL if ((temp=strchr(optarg,','))!=NULL) { - *temp='\0'; - if (!is_intnonneg (temp)) - usage2 (_("Invalid certificate expiration period"), optarg); - days_till_exp_warn = atoi(optarg); - *temp=','; - temp++; - if (!is_intnonneg (temp)) - usage2 (_("Invalid certificate expiration period"), temp); - days_till_exp_crit = atoi (temp); + *temp='\0'; + if (!is_intnonneg (optarg)) + usage2 (_("Invalid certificate expiration period"), optarg); + days_till_exp_warn = atoi(optarg); + *temp=','; + temp++; + if (!is_intnonneg (temp)) + usage2 (_("Invalid certificate expiration period"), temp); + days_till_exp_crit = atoi (temp); } else { - days_till_exp_crit=0; + days_till_exp_crit=0; if (!is_intnonneg (optarg)) usage2 (_("Invalid certificate expiration period"), optarg); days_till_exp_warn = atoi (optarg); @@ -304,9 +311,7 @@ process_arguments (int argc, char **argv) /* Fall through to -S option */ #endif case 'S': /* use SSL */ -#ifndef HAVE_SSL - usage4 (_("Invalid option - SSL is not available")); -#endif +#ifdef HAVE_SSL use_ssl = TRUE; if (optarg == NULL || c != 'S') ssl_version = 0; @@ -317,6 +322,9 @@ process_arguments (int argc, char **argv) } if (specify_port == FALSE) server_port = HTTPS_PORT; +#else + usage4 (_("Invalid option - SSL is not available")); +#endif break; case SNI_OPTION: use_sni = TRUE; @@ -470,6 +478,9 @@ process_arguments (int argc, char **argv) } } break; + case 'E': /* show extended perfdata */ + show_extended_perfdata = TRUE; + break; } } @@ -811,17 +822,33 @@ check_http (void) char *pos; long microsec; double elapsed_time; + long microsec_connect; + double elapsed_time_connect; + long microsec_ssl; + double elapsed_time_ssl; + long microsec_firstbyte; + double elapsed_time_firstbyte; + long microsec_headers; + double elapsed_time_headers; + long microsec_transfer; + double elapsed_time_transfer; int page_len = 0; int result = STATE_OK; /* try to connect to the host at the given port number */ + gettimeofday (&tv_temp, NULL); if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n")); + microsec_connect = deltime (tv_temp); #ifdef HAVE_SSL + elapsed_time_connect = (double)microsec_connect / 1.0e6; if (use_ssl == TRUE) { + gettimeofday (&tv_temp, NULL); result = np_net_ssl_init_with_hostname_and_version(sd, (use_sni ? host_name : NULL), ssl_version); if (result != STATE_OK) return result; + microsec_ssl = deltime (tv_temp); + elapsed_time_ssl = (double)microsec_ssl / 1.0e6; if (check_cert == TRUE) { result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); np_net_ssl_cleanup(); @@ -853,8 +880,7 @@ check_http (void) /* optionally send any other header tag */ if (http_opt_headers_count) { for (i = 0; i < http_opt_headers_count ; i++) { - for ((pos = strtok(http_opt_headers[i], INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER))) - xasprintf (&buf, "%s%s\r\n", buf, pos); + xasprintf (&buf, "%s%s\r\n", buf, http_opt_headers[i]); } /* This cannot be free'd here because a redirection will then try to access this and segfault */ /* Covered in a testcase in tests/check_http.t */ @@ -890,11 +916,19 @@ check_http (void) } if (verbose) printf ("%s\n", buf); + gettimeofday (&tv_temp, NULL); my_send (buf, strlen (buf)); + microsec_headers = deltime (tv_temp); + elapsed_time_headers = (double)microsec_headers / 1.0e6; /* fetch the page */ full_page = strdup(""); + gettimeofday (&tv_temp, NULL); while ((i = my_recv (buffer, MAX_INPUT_BUFFER-1)) > 0) { + if ((i >= 1) && (elapsed_time_firstbyte <= 0.000001)) { + microsec_firstbyte = deltime (tv_temp); + elapsed_time_firstbyte = (double)microsec_firstbyte / 1.0e6; + } buffer[i] = '\0'; xasprintf (&full_page_new, "%s%s", full_page, buffer); free (full_page); @@ -906,6 +940,8 @@ check_http (void) break; } } + microsec_transfer = deltime (tv_temp); + elapsed_time_transfer = (double)microsec_transfer / 1.0e6; if (i < 0 && errno != ECONNRESET) { #ifdef HAVE_SSL @@ -1107,11 +1143,25 @@ check_http (void) msg[strlen(msg)-3] = '\0'; /* check elapsed time */ - xasprintf (&msg, - _("%s - %d bytes in %.3f second response time %s|%s %s"), - msg, page_len, elapsed_time, - (display_html ? "</A>" : ""), - perfd_time (elapsed_time), perfd_size (page_len)); + if (show_extended_perfdata) + xasprintf (&msg, + _("%s - %d bytes in %.3f second response time %s|%s %s %s %s %s %s %s"), + msg, page_len, elapsed_time, + (display_html ? "</A>" : ""), + perfd_time (elapsed_time), + perfd_size (page_len), + perfd_time_connect (elapsed_time_connect), + use_ssl == TRUE ? perfd_time_ssl (elapsed_time_ssl) : "", + perfd_time_headers (elapsed_time_headers), + perfd_time_firstbyte (elapsed_time_firstbyte), + perfd_time_transfer (elapsed_time_transfer)); + else + xasprintf (&msg, + _("%s - %d bytes in %.3f second response time %s|%s %s"), + msg, page_len, elapsed_time, + (display_html ? "</A>" : ""), + perfd_time (elapsed_time), + perfd_size (page_len)); result = max_state_alt(get_status(elapsed_time, thlds), result); @@ -1300,7 +1350,30 @@ char *perfd_time (double elapsed_time) TRUE, 0, FALSE, 0); } +char *perfd_time_connect (double elapsed_time_connect) +{ + return fperfdata ("time_connect", elapsed_time_connect, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); +} + +char *perfd_time_ssl (double elapsed_time_ssl) +{ + return fperfdata ("time_ssl", elapsed_time_ssl, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); +} + +char *perfd_time_headers (double elapsed_time_headers) +{ + return fperfdata ("time_headers", elapsed_time_headers, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); +} +char *perfd_time_firstbyte (double elapsed_time_firstbyte) +{ + return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); +} + +char *perfd_time_transfer (double elapsed_time_transfer) +{ + return fperfdata ("time_transfer", elapsed_time_transfer, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); +} char *perfd_size (int page_len) { @@ -1351,7 +1424,7 @@ print_help (void) printf (" %s\n", _("auto-negotiation (1 = TLSv1, 2 = SSLv2, 3 = SSLv3).")); printf (" %s\n", "--sni"); printf (" %s\n", _("Enable SSL/TLS hostname extension support (SNI)")); - printf (" %s\n", "-C, --certificate=INTEGER"); + printf (" %s\n", "-C, --certificate=INTEGER[,INTEGER]"); printf (" %s\n", _("Minimum number of days a certificate has to be valid. Port defaults to 443")); printf (" %s\n", _("(when this option is used the URL is not checked.)\n")); #endif @@ -1433,14 +1506,14 @@ print_help (void) printf (" %s\n", _("When the 'www.verisign.com' server returns its content within 5 seconds,")); printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds")); printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,")); - printf (" %s\n\n", _("a STATE_CRITICAL will be returned.")); - + printf (" %s\n", _("a STATE_CRITICAL will be returned.")); + printf ("\n"); printf (" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 14"); printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 14 days,")); printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than")); printf (" %s\n", _("14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when")); printf (" %s\n", _("the certificate is expired.")); - + printf ("\n"); printf (" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 30,14"); printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 30 days,")); 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) printf (UT_SUPPORT); } -/* todo -* add option -4 and -6 to the long manual -* -*/ - void print_usage (void) { 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 @@ * License: GPL * Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at) * Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net) -* Copyright (c) 1999-2009 Nagios Plugins Development Team +* Copyright (c) 1999-2011 Nagios Plugins Development Team * * Description: * @@ -31,7 +31,7 @@ *****************************************************************************/ const char *progname = "check_mysql"; -const char *copyright = "1999-2007"; +const char *copyright = "1999-2011"; const char *email = "nagiosplug-devel@lists.sourceforge.net"; #define SLAVERESULTSIZE 70 @@ -157,7 +157,7 @@ main (int argc, char **argv) } } else { - /* mysql 4.x.x */ + /* mysql 4.x.x and mysql 5.x.x */ int slave_io_field = -1 , slave_sql_field = -1, seconds_behind_field = -1, i, num_fields; MYSQL_FIELD* fields; @@ -178,13 +178,17 @@ main (int argc, char **argv) } } + /* Check if slave status is available */ if ((slave_io_field < 0) || (slave_sql_field < 0) || (num_fields == 0)) { mysql_free_result (res); mysql_close (&mysql); die (STATE_CRITICAL, "Slave status unavailable\n"); } + /* Save slave status in slaveresult */ 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"); + + /* Raise critical error if SQL THREAD or IO THREAD are stopped */ if (strcmp (row[slave_io_field], "Yes") != 0 || strcmp (row[slave_sql_field], "Yes") != 0) { mysql_free_result (res); mysql_close (&mysql); @@ -199,6 +203,7 @@ main (int argc, char **argv) } } + /* Check Seconds Behind against threshold */ if ((seconds_behind_field != -1) && (strcmp (row[seconds_behind_field], "NULL") != 0)) { double value = atof(row[seconds_behind_field]); 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) {"filename", required_argument, 0, 'F'}, {"expires", required_argument, 0, 'e'}, {"command", required_argument, 0, 'C'}, + {"timeout", optional_argument, 0, 't'}, {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, {"verbose", no_argument, 0, 'v'}, @@ -226,7 +227,7 @@ process_arguments (int argc, char **argv) } while (1) { - c = getopt_long (argc, argv, "+hVvF:C:e:", longopts, &option); + c = getopt_long (argc, argv, "+hVvF:C:e:t:", longopts, &option); if (c == -1 || c == EOF || c == 1) break; @@ -251,6 +252,13 @@ process_arguments (int argc, char **argv) die (STATE_UNKNOWN, _("Expiration time must be an integer (seconds)\n")); break; + case 't': /* timeout */ + if (is_intnonneg (optarg)) + timeout_interval = atoi (optarg); + else + die (STATE_UNKNOWN, + _("Timeout must be an integer (seconds)\n")); + break; case 'v': verbose++; break; @@ -296,11 +304,13 @@ print_help (void) printf (" %s\n", _("Minutes aging after which logfile is considered stale")); printf (" %s\n", "-C, --command=STRING"); printf (" %s\n", _("Substring to search for in process arguments")); + printf (" %s\n", "-t, --timeout=INTEGER"); + printf (" %s\n", _("Timeout for the plugin in seconds")); printf (UT_VERBOSE); printf ("\n"); printf ("%s\n", _("Examples:")); - printf (" %s\n", "check_nagios -e 5 -F /usr/local/nagios/var/status.log -C /usr/local/nagios/bin/nagios"); + printf (" %s\n", "check_nagios -t 20 -e 5 -F /usr/local/nagios/var/status.log -C /usr/local/nagios/bin/nagios"); printf (UT_SUPPORT); } @@ -311,5 +321,5 @@ void print_usage (void) { printf ("%s\n", _("Usage:")); - printf ("%s -F <status log file> -e <expire_minutes> -C <process_string>\n", progname); + printf ("%s -F <status log file> -t <timeout_seconds> -e <expire_minutes> -C <process_string>\n", progname); } 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){ char *description=NULL,*counter_unit = NULL; char *minval = NULL, *maxval = NULL, *errcvt = NULL; char *fds=NULL, *tds=NULL; + char *numstr; double total_disk_space=0; double free_disk_space=0; @@ -265,7 +266,10 @@ int main(int argc, char **argv){ xasprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6, (show_all==TRUE) ? "ShowAll" : "ShowFail",value_list); fetch_data (server_address, server_port, send_buffer); - return_code=atoi(strtok(recv_buffer,"&")); + numstr = strtok(recv_buffer,"&"); + if (numstr == NULL) + die(STATE_UNKNOWN, _("could not fetch information from server\n")); + return_code=atoi(numstr); temp_string=strtok(NULL,"&"); output_message = strdup (temp_string); } @@ -275,8 +279,14 @@ int main(int argc, char **argv){ xasprintf(&send_buffer,"%s&7", req_password); fetch_data (server_address, server_port, send_buffer); - mem_commitLimit=atof(strtok(recv_buffer,"&")); - mem_commitByte=atof(strtok(NULL,"&")); + numstr = strtok(recv_buffer,"&"); + if (numstr == NULL) + die(STATE_UNKNOWN, _("could not fetch information from server\n")); + mem_commitLimit=atof(numstr); + numstr = strtok(NULL,"&"); + if (numstr == NULL) + die(STATE_UNKNOWN, _("could not fetch information from server\n")); + mem_commitByte=atof(numstr); percent_used_space = (mem_commitByte / mem_commitLimit) * 100; warning_used_space = ((float)warning_value / 100) * mem_commitLimit; 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){ die(STATE_UNKNOWN, "can not create new socket"); } if(connect(socklist[i], ai_tmp->ai_addr, ai_tmp->ai_addrlen)){ - die(STATE_UNKNOWN, "can't create socket connection"); + /* don't die here, because it is enough if there is one server + answering in time. This also would break for dual ipv4/6 stacked + ntp servers when the client only supports on of them. + */ + DBG(printf("can't create socket connection on peer %i: %s\n", i, strerror(errno))); } else { ufds[i].fd=socklist[i]; ufds[i].events=POLLIN; @@ -845,6 +849,7 @@ void print_help(void){ printf (UT_HELP_VRSN); printf (UT_EXTRA_OPTS); printf (UT_HOST_PORT, 'p', "123"); + printf (UT_IPv46); printf (" %s\n", "-w, --warning=THRESHOLD"); printf (" %s\n", _("Offset to result in warning status (seconds)")); printf (" %s\n", "-c, --critical=THRESHOLD"); @@ -881,5 +886,5 @@ print_usage(void) printf ("%s\n", _("WARNING: check_ntp is deprecated. Please use check_ntp_peer or")); printf ("%s\n\n", _("check_ntp_time instead.")); printf ("%s\n", _("Usage:")); - printf(" %s -H <host> [-w <warn>] [-c <crit>] [-j <warn>] [-k <crit>] [-v verbose]\n", progname); + printf(" %s -H <host> [-w <warn>] [-c <crit>] [-j <warn>] [-k <crit>] [-4|-6] [-v verbose]\n", progname); } 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 DBG(printf("sending READSTAT request")); write(conn, &req, SIZEOF_NTPCM(req)); DBG(print_ntp_control_message(&req)); - /* Attempt to read the largest size packet possible */ - req.count=htons(MAX_CM_SIZE); - DBG(printf("recieving READSTAT response")) - if(read(conn, &req, SIZEOF_NTPCM(req)) == -1) - die(STATE_CRITICAL, "NTP CRITICAL: No response from NTP server\n"); - DBG(print_ntp_control_message(&req)); - /* discard obviously invalid packets */ - if (ntohs(req.count) > MAX_CM_SIZE) - die(STATE_CRITICAL, "NTP CRITICAL: Invalid packet received from NTP server\n"); + + do { + /* Attempt to read the largest size packet possible */ + req.count=htons(MAX_CM_SIZE); + DBG(printf("recieving READSTAT response")) + if(read(conn, &req, SIZEOF_NTPCM(req)) == -1) + die(STATE_CRITICAL, "NTP CRITICAL: No response from NTP server\n"); + DBG(print_ntp_control_message(&req)); + /* discard obviously invalid packets */ + if (ntohs(req.count) > MAX_CM_SIZE) + die(STATE_CRITICAL, "NTP CRITICAL: Invalid packet received from NTP server\n"); + } while (!(req.op&OP_READSTAT && ntohs(req.seq) == 1)); + if (LI(req.flags) == LI_ALARM) li_alarm = 1; /* Each peer identifier is 4 bytes in the data section, which * 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 write(conn, &req, SIZEOF_NTPCM(req)); DBG(print_ntp_control_message(&req)); - req.count = htons(MAX_CM_SIZE); - DBG(printf("receiving READVAR response...\n")); - read(conn, &req, SIZEOF_NTPCM(req)); - DBG(print_ntp_control_message(&req)); + do { + req.count = htons(MAX_CM_SIZE); + DBG(printf("receiving READVAR response...\n")); + read(conn, &req, SIZEOF_NTPCM(req)); + DBG(print_ntp_control_message(&req)); + } while (!(req.op&OP_READVAR && ntohs(req.seq) == 2)); if(!(req.op&REM_ERROR)) xasprintf(&data, "%s%s", data, req.data); @@ -660,6 +666,7 @@ void print_help(void){ print_usage(); printf (UT_HELP_VRSN); printf (UT_EXTRA_OPTS); + printf (UT_IPv46); printf (UT_HOST_PORT, 'p', "123"); printf (" %s\n", "-q, --quiet"); printf (" %s\n", _("Returns UNKNOWN instead of CRITICAL or WARNING if server isn't synchronized")); @@ -668,9 +675,9 @@ void print_help(void){ printf (" %s\n", "-c, --critical=THRESHOLD"); printf (" %s\n", _("Offset to result in critical status (seconds)")); printf (" %s\n", "-W, --swarn=THRESHOLD"); - printf (" %s\n", _("Warning threshold for stratum")); + printf (" %s\n", _("Warning threshold for stratum of server's synchronization peer")); printf (" %s\n", "-C, --scrit=THRESHOLD"); - printf (" %s\n", _("Critical threshold for stratum")); + printf (" %s\n", _("Critical threshold for stratum of server's synchronization peer")); printf (" %s\n", "-j, --jwarn=THRESHOLD"); printf (" %s\n", _("Warning threshold for jitter")); printf (" %s\n", "-k, --jcrit=THRESHOLD"); @@ -704,7 +711,7 @@ void print_help(void){ printf(" %s\n", ("./check_ntp_peer -H ntpserv -w 0.5 -c 1 -j -1:100 -k -1:200")); printf("\n"); printf(" %s\n", _("Only check the number of usable time sources (\"truechimers\"):")); - printf(" %s\n", ("./check_ntp_peer -H ntpserv -m :5 -n :3")); + printf(" %s\n", ("./check_ntp_peer -H ntpserv -m @5 -n @3")); printf("\n"); printf(" %s\n", _("Check only stratum:")); printf(" %s\n", ("./check_ntp_peer -H ntpserv -W 4 -C 6")); @@ -716,6 +723,6 @@ void print_usage(void) { printf ("%s\n", _("Usage:")); - printf(" %s -H <host> [-w <warn>] [-c <crit>] [-W <warn>] [-C <crit>]\n", progname); + printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-W <warn>] [-C <crit>]\n", progname); printf(" [-j <warn>] [-k <crit>] [-v verbose]\n"); } 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){ die(STATE_UNKNOWN, "can not create new socket"); } if(connect(socklist[i], ai_tmp->ai_addr, ai_tmp->ai_addrlen)){ - die(STATE_UNKNOWN, "can't create socket connection"); + /* don't die here, because it is enough if there is one server + answering in time. This also would break for dual ipv4/6 stacked + ntp servers when the client only supports on of them. + */ + DBG(printf("can't create socket connection on peer %i: %s\n", i, strerror(errno))); } else { ufds[i].fd=socklist[i]; ufds[i].events=POLLIN; @@ -602,6 +606,7 @@ void print_help(void){ print_usage(); printf (UT_HELP_VRSN); printf (UT_EXTRA_OPTS); + printf (UT_IPv46); printf (UT_HOST_PORT, 'p', "123"); printf (" %s\n", "-q, --quiet"); printf (" %s\n", _("Returns UNKNOWN instead of CRITICAL if offset cannot be found")); @@ -635,6 +640,6 @@ void print_usage(void) { printf ("%s\n", _("Usage:")); - printf(" %s -H <host> [-w <warn>] [-c <crit>] [-v verbose]\n", progname); + printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-v verbose]\n", progname); } 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 print_usage (void) { printf ("%s\n", _("Usage:")); - printf ("%s [-H <host>] [-P <port>] [-c <critical time>] [-w <warning time>]\n", progname); + printf ("%s [-H <host>] [-4|-6] [-P <port>] [-c <critical time>] [-w <warning time>]\n", progname); printf (" [-t <timeout>] [-d <database>] [-l <logname>] [-p <password>]\n" "[-q <query>] [-C <critical query range>] [-W <warning query range>]\n"); } 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"; int process_arguments (int, char **); int validate_arguments (void); -int check_thresholds (int); int convert_to_seconds (char *); void print_help (void); void print_usage (void); -int wmax = -1; -int cmax = -1; -int wmin = -1; -int cmin = -1; +char *warning_range = NULL; +char *critical_range = NULL; +thresholds *procs_thresholds = NULL; int options = 0; /* bitmask of filter criteria to test against */ #define ALL 1 @@ -238,14 +236,14 @@ main (int argc, char **argv) } if (metric == METRIC_VSZ) - i = check_thresholds (procvsz); + i = get_status ((double)procvsz, procs_thresholds); else if (metric == METRIC_RSS) - i = check_thresholds (procrss); + i = get_status ((double)procrss, procs_thresholds); /* TODO? float thresholds for --metric=CPU */ else if (metric == METRIC_CPU) - i = check_thresholds ((int)procpcpu); + i = get_status (procpcpu, procs_thresholds); else if (metric == METRIC_ELAPSED) - i = check_thresholds (procseconds); + i = get_status ((double)procseconds, procs_thresholds); if (metric != METRIC_PROCS) { if (i == STATE_WARNING) { @@ -276,7 +274,7 @@ main (int argc, char **argv) /* Needed if procs found, but none match filter */ if ( metric == METRIC_PROCS ) { - result = max_state (result, check_thresholds (procs) ); + result = max_state (result, get_status ((double)procs, procs_thresholds) ); } if ( result == STATE_OK ) { @@ -301,6 +299,13 @@ main (int argc, char **argv) if ( verbose >= 1 && strcmp(fails,"") ) printf (" [%s]", fails); + if (metric == METRIC_PROCS) + printf (" | procs=%d;%s;%s;0;", procs, + warning_range ? warning_range : "", + critical_range ? critical_range : ""); + else + printf (" | procs=%d;;;0; procs_warn=%d;;;0; procs_crit=%d;;;0;", procs, warn, crit); + printf ("\n"); return result; } @@ -327,6 +332,7 @@ process_arguments (int argc, char **argv) {"timeout", required_argument, 0, 't'}, {"status", required_argument, 0, 's'}, {"ppid", required_argument, 0, 'p'}, + {"user", required_argument, 0, 'u'}, {"command", required_argument, 0, 'C'}, {"vsz", required_argument, 0, 'z'}, {"rss", required_argument, 0, 'r'}, @@ -368,28 +374,10 @@ process_arguments (int argc, char **argv) timeout_interval = atoi (optarg); break; case 'c': /* critical threshold */ - if (is_integer (optarg)) - cmax = atoi (optarg); - else if (sscanf (optarg, ":%d", &cmax) == 1) - break; - else if (sscanf (optarg, "%d:%d", &cmin, &cmax) == 2) - break; - else if (sscanf (optarg, "%d:", &cmin) == 1) - break; - else - usage4 (_("Critical Process Count must be an integer!")); + critical_range = optarg; break; case 'w': /* warning threshold */ - if (is_integer (optarg)) - wmax = atoi (optarg); - else if (sscanf (optarg, ":%d", &wmax) == 1) - break; - else if (sscanf (optarg, "%d:%d", &wmin, &wmax) == 2) - break; - else if (sscanf (optarg, "%d:", &wmin) == 1) - break; - else - usage4 (_("Warning Process Count must be an integer!")); + warning_range = optarg; break; case 'p': /* process id */ if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) { @@ -518,16 +506,19 @@ process_arguments (int argc, char **argv) } c = optind; - if (wmax == -1 && argv[c]) - wmax = atoi (argv[c++]); - if (cmax == -1 && argv[c]) - cmax = atoi (argv[c++]); + if ((! warning_range) && argv[c]) + warning_range = argv[c++]; + if ((! critical_range) && argv[c]) + critical_range = argv[c++]; if (statopts == NULL && argv[c]) { xasprintf (&statopts, "%s", argv[c++]); xasprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts); options |= STAT; } + /* this will abort in case of invalid ranges */ + set_thresholds (&procs_thresholds, warning_range, critical_range); + return validate_arguments (); } @@ -536,27 +527,6 @@ process_arguments (int argc, char **argv) int validate_arguments () { - - if (wmax >= 0 && wmin == -1) - wmin = 0; - if (cmax >= 0 && cmin == -1) - cmin = 0; - if (wmax >= wmin && cmax >= cmin) { /* standard ranges */ - if (wmax > cmax && cmax != -1) { - printf (_("wmax (%d) cannot be greater than cmax (%d)\n"), wmax, cmax); - return ERROR; - } - if (cmin > wmin && wmin != -1) { - printf (_("wmin (%d) cannot be less than cmin (%d)\n"), wmin, cmin); - return ERROR; - } - } - -/* if (wmax == -1 && cmax == -1 && wmin == -1 && cmin == -1) { */ -/* printf ("At least one threshold must be set\n"); */ -/* return ERROR; */ -/* } */ - if (options == 0) options = ALL; @@ -579,40 +549,6 @@ validate_arguments () } - -/* Check thresholds against value */ -int -check_thresholds (int value) -{ - if (wmax == -1 && cmax == -1 && wmin == -1 && cmin == -1) { - return OK; - } - else if (cmax >= 0 && cmin >= 0 && cmax < cmin) { - if (value > cmax && value < cmin) - return STATE_CRITICAL; - } - else if (cmax >= 0 && value > cmax) { - return STATE_CRITICAL; - } - else if (cmin >= 0 && value < cmin) { - return STATE_CRITICAL; - } - - if (wmax >= 0 && wmin >= 0 && wmax < wmin) { - if (value > wmax && value < wmin) { - return STATE_WARNING; - } - } - else if (wmax >= 0 && value > wmax) { - return STATE_WARNING; - } - else if (wmin >= 0 && value < wmin) { - return STATE_WARNING; - } - return STATE_OK; -} - - /* convert the elapsed time to seconds */ int convert_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; char *authtype = NULL; char *authuser = NULL; char *authpass = NULL; -int warning_time = 0; +double warning_time = 0; int check_warning_time = FALSE; -int critical_time = 0; +double critical_time = 0; int check_critical_time = FALSE; int verbose = 0; int use_ssl = FALSE; @@ -417,9 +417,9 @@ main (int argc, char **argv) elapsed_time = (double)microsec / 1.0e6; if (result == STATE_OK) { - if (check_critical_time && elapsed_time > (double) critical_time) + if (check_critical_time && elapsed_time > critical_time) result = STATE_CRITICAL; - else if (check_warning_time && elapsed_time > (double) warning_time) + else if (check_warning_time && elapsed_time > warning_time) result = STATE_WARNING; } @@ -552,21 +552,19 @@ process_arguments (int argc, char **argv) nresponses++; break; case 'c': /* critical time threshold */ - if (is_intnonneg (optarg)) { - critical_time = atoi (optarg); - check_critical_time = TRUE; - } + if (!is_nonnegative (optarg)) + usage4 (_("Critical time must be a positive")); else { - usage4 (_("Critical time must be a positive integer")); + critical_time = strtod (optarg, NULL); + check_critical_time = TRUE; } break; case 'w': /* warning time threshold */ - if (is_intnonneg (optarg)) { - warning_time = atoi (optarg); - check_warning_time = TRUE; - } + if (!is_nonnegative (optarg)) + usage4 (_("Warning time must be a positive")); else { - usage4 (_("Warning time must be a positive integer")); + warning_time = strtod (optarg, NULL); + check_warning_time = TRUE; } break; case 'v': /* verbose */ @@ -593,7 +591,7 @@ process_arguments (int argc, char **argv) #ifdef USE_OPENSSL if ((temp=strchr(optarg,','))!=NULL) { *temp='\0'; - if (!is_intnonneg (temp)) + if (!is_intnonneg (optarg)) usage2 ("Invalid certificate expiration period", optarg); days_till_exp_warn = atoi(optarg); *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]; int perf_labels = 1; +static char *fix_snmp_range(char *th) +{ + double left, right; + char *colon, *ret; + if (!(colon = strchr(th, ':'))) + return th; + *colon = 0; + + left = strtod(th, NULL); + right = strtod(colon + 1, NULL); + if (right >= left) { + return th; + } + ret = malloc(strlen(th) + strlen(colon + 1) + 2); + sprintf(ret, "@%s:%s", colon + 1, th); + free(th); + return ret; +} + int main (int argc, char **argv) { @@ -181,8 +200,8 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); - labels = malloc (labels_size); - unitv = malloc (unitv_size); + labels = malloc (labels_size * sizeof(*labels)); + unitv = malloc (unitv_size * sizeof(*unitv)); for (i = 0; i < MAX_OIDS; i++) eval_method[i] = CHECK_UNDEF; @@ -228,6 +247,10 @@ main (int argc, char **argv) for (i=0; i<numoids; i++) { char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL; char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL; + /* translate "2:1" to "@1:2" for backwards compatibility */ + w = w ? fix_snmp_range(w) : NULL; + c = c ? fix_snmp_range(c) : NULL; + /* Skip empty thresholds, while avoiding segfault */ set_thresholds(&thlds[i], w ? strpbrk(w, NP_THRESHOLDS_CHARS) : NULL, @@ -396,7 +419,7 @@ main (int argc, char **argv) show = strstr (response, "Timeticks: "); } else - show = response; + show = response + 3; iresult = STATE_DEPENDENT; @@ -405,7 +428,7 @@ main (int argc, char **argv) if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { ptr = strpbrk (show, "0123456789"); if (ptr == NULL) - die (STATE_UNKNOWN,_("No valid data returned")); + die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); response_value[i] = strtod (ptr, NULL); if(calculate_rate) { @@ -745,9 +768,9 @@ process_arguments (int argc, char **argv) break; case 'l': /* label */ nlabels++; - if (nlabels >= labels_size) { + if (nlabels > labels_size) { labels_size += 8; - labels = realloc (labels, labels_size); + labels = realloc (labels, labels_size * sizeof(*labels)); if (labels == NULL) die (STATE_UNKNOWN, _("Could not reallocate labels[%d]"), (int)nlabels); } @@ -757,13 +780,13 @@ process_arguments (int argc, char **argv) if (ptr[0] == '\'') labels[nlabels - 1] = ptr + 1; while (ptr && (ptr = nextarg (ptr))) { - if (nlabels >= labels_size) { + nlabels++; + if (nlabels > labels_size) { labels_size += 8; - labels = realloc (labels, labels_size); + labels = realloc (labels, labels_size * sizeof(*labels)); if (labels == NULL) die (STATE_UNKNOWN, _("Could not reallocate labels\n")); } - nlabels++; ptr = thisarg (ptr); if (ptr[0] == '\'') labels[nlabels - 1] = ptr + 1; @@ -774,9 +797,9 @@ process_arguments (int argc, char **argv) case 'u': /* units */ units = optarg; nunits++; - if (nunits >= unitv_size) { + if (nunits > unitv_size) { unitv_size += 8; - unitv = realloc (unitv, unitv_size); + unitv = realloc (unitv, unitv_size * sizeof(*unitv)); if (unitv == NULL) die (STATE_UNKNOWN, _("Could not reallocate units [%d]\n"), (int)nunits); } @@ -786,9 +809,9 @@ process_arguments (int argc, char **argv) if (ptr[0] == '\'') unitv[nunits - 1] = ptr + 1; while (ptr && (ptr = nextarg (ptr))) { - if (nunits >= unitv_size) { + if (nunits > unitv_size) { unitv_size += 8; - unitv = realloc (unitv, unitv_size); + unitv = realloc (unitv, unitv_size * sizeof(*unitv)); if (units == NULL) die (STATE_UNKNOWN, _("Could not realloc() units\n")); } 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 print_usage (void) { printf ("%s\n", _("Usage:")); - printf ("%s [-46] [-t <timeout>] [-r <remote version>] [-p <port>] <host>\n", progname); + printf ("%s [-4|-6] [-t <timeout>] [-r <remote version>] [-p <port>] <host>\n", progname); } 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 @@ /***************************************************************************** -* +* * Nagios check_tcp plugin -* +* * License: GPL * Copyright (c) 1999-2008 Nagios Plugins Development Team -* +* * Description: -* +* * This file contains the check_tcp plugin -* -* +* +* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * $Id$ -* +* *****************************************************************************/ /* progname "check_tcp" changes depending on symlink called */ @@ -61,6 +61,7 @@ static int PORT = 0; static int server_port = 0; static char *server_address = NULL; +static int host_specified = FALSE; static char *server_send = NULL; static char *server_quit = NULL; static char **server_expect; @@ -462,6 +463,7 @@ process_arguments (int argc, char **argv) #endif break; case 'H': /* hostname */ + host_specified = TRUE; server_address = optarg; break; case 'c': /* critical */ @@ -555,7 +557,7 @@ process_arguments (int argc, char **argv) # ifdef USE_OPENSSL /* XXX */ if ((temp=strchr(optarg,','))!=NULL) { *temp='\0'; - if (!is_intnonneg (temp)) + if (!is_intnonneg (optarg)) usage2 (_("Invalid certificate expiration period"), optarg); days_till_exp_warn = atoi(optarg); *temp=','; temp++; @@ -588,6 +590,10 @@ process_arguments (int argc, char **argv) } } + c = optind; + if(host_specified == FALSE && c < argc) + server_address = strdup (argv[c++]); + if (server_address == NULL) usage4 (_("You must provide a server address")); else if (server_address[0] != '/' && is_host (server_address) == FALSE) @@ -666,4 +672,3 @@ print_usage (void) printf ("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n"); printf ("[-D <warn days cert expire>[,<crit days cert expire>]] [-S <use SSL>] [-E]\n"); } - 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 @@ #ifdef HAVE_GNUTLS_OPENSSL_H # include <gnutls/openssl.h> #else +# define OPENSSL_LOAD_CONF /* See the OPENSSL_config(3) man page. */ # ifdef HAVE_SSL_H # include <rsa.h> # 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) void -popen_timeout_alarm_handler (int signo) +runcmd_timeout_alarm_handler (int signo) { size_t i; 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; /** prototypes **/ int np_runcmd(const char *, output *, output *, int); -void popen_timeout_alarm_handler(int) +void runcmd_timeout_alarm_handler(int) __attribute__((__noreturn__)); /* 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 @@ +#!/usr/bin/perl -w -I .. +# +# Test check_apt using input files. +# Contributed by Alex Bradley, October 2012 +# + +use strict; +use Test::More; +use NPTest; + +sub make_result_regexp { + my ($warning, $critical) = @_; + my $status; + if ($warning == 0 && $critical == 0) { + $status = "OK"; + } elsif ($critical == 0) { + $status = "WARNING"; + } else { + $status = "CRITICAL"; + } + return sprintf('/^APT %s: %d packages available for upgrade \(%d critical updates\)\. |available_upgrades=%d;;;0 critical_updates=%d;;;0$/', + $status, $warning, $critical, $warning, $critical); +} + +if (-x "./check_apt") { + plan tests => 28; +} else { + plan skip_all => "No check_apt compiled"; +} + +my $result; + +my $testfile_command = "./check_apt %s --input-file=t/check_apt_input/%s"; + +$result = NPTest->testCmd( sprintf($testfile_command, "", "debian1") ); +is( $result->return_code, 0, "No upgrades" ); +like( $result->output, make_result_regexp(0, 0), "Output correct" ); + +$result = NPTest->testCmd( sprintf($testfile_command, "", "debian2") ); +is( $result->return_code, 1, "Debian apt output, warning" ); +like( $result->output, make_result_regexp(13, 0), "Output correct" ); + +$result = NPTest->testCmd( sprintf($testfile_command, "", "debian3") ); +is( $result->return_code, 2, "Debian apt output, some critical" ); +like( $result->output, make_result_regexp(19, 4), "Output correct" ); + +$result = NPTest->testCmd( sprintf($testfile_command, "-c '^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)'", "debian3") ); +is( $result->return_code, 2, "Debian apt output - should have same result when default security regexp specified via -c" ); +like( $result->output, make_result_regexp(19, 4), "Output correct" ); + +$result = NPTest->testCmd( sprintf($testfile_command, "-i libc6", "debian3") ); +is( $result->return_code, 1, "Debian apt output, filter for libc6" ); +like( $result->output, make_result_regexp(3, 0), "Output correct" ); + +$result = NPTest->testCmd( sprintf($testfile_command, "-i libc6 -i xen", "debian3") ); +is( $result->return_code, 2, "Debian apt output, filter for libc6 and xen" ); +like( $result->output, make_result_regexp(9, 4), "Output correct" ); + +$result = NPTest->testCmd( sprintf($testfile_command, "-i libc6 -i xen -i linux", "debian3") ); +is( $result->return_code, 2, "Debian apt output, filter for libc6, xen, linux" ); +like( $result->output, make_result_regexp(12, 4), "Output correct" ); + +$result = NPTest->testCmd( sprintf($testfile_command, "-e libc6", "debian3") ); +is( $result->return_code, 2, "Debian apt output, filter out libc6" ); +like( $result->output, make_result_regexp(16, 4), "Output correct" ); + +$result = NPTest->testCmd( sprintf($testfile_command, "-e libc6 -e xen", "debian3") ); +is( $result->return_code, 1, "Debian apt output, filter out libc6 and xen" ); +like( $result->output, make_result_regexp(10, 0), "Output correct" ); + +$result = NPTest->testCmd( sprintf($testfile_command, "-e libc6 -e xen -e linux", "debian3") ); +is( $result->return_code, 1, "Debian apt output, filter out libc6, xen, linux" ); +like( $result->output, make_result_regexp(7, 0), "Output correct" ); + +$result = NPTest->testCmd( sprintf($testfile_command, "-c Debian-Security -c linux", "debian3") ); +is( $result->return_code, 2, "Debian apt output, critical on Debian-Security or linux" ); +like( $result->output, make_result_regexp(19, 9), "Output correct" ); + +$result = NPTest->testCmd( sprintf($testfile_command, "-i lib -i linux -e gc1c -c linux-image", "debian3") ); +is( $result->return_code, 2, "Debian apt output, include lib and linux, exclude gc1c, critical on linux-image" ); +like( $result->output, make_result_regexp(10, 2), "Output correct" ); + +$result = NPTest->testCmd( sprintf($testfile_command, "", "ubuntu1") ); +is( $result->return_code, 1, "Ubuntu apt output, warning" ); +like( $result->output, make_result_regexp(5, 0), "Output correct" ); + +$result = NPTest->testCmd( sprintf($testfile_command, "", "ubuntu2") ); +is( $result->return_code, 2, "Ubuntu apt output, some critical" ); +like( $result->output, make_result_regexp(25, 14), "Output correct" ); + 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 @@ +NOTE: This is only a simulation! + apt-get needs root privileges for real execution. + Keep also in mind that locking is deactivated, + 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 @@ +NOTE: This is only a simulation! + apt-get needs root privileges for real execution. + Keep also in mind that locking is deactivated, + so don't depend on the relevance to the real current situation! +Reading package lists... Done +Building dependency tree +Reading state information... Done +The following packages will be upgraded: + base-files debian-archive-keyring dpkg firmware-linux-free libc-bin libc-dev-bin libc6 libc6-dev linux-base + linux-image-2.6.32-5-xen-amd64 linux-libc-dev locales lockfile-progs +13 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. +Inst base-files [6.0squeeze5] (6.0squeeze6 Debian:6.0.6/stable [amd64]) +Conf base-files (6.0squeeze6 Debian:6.0.6/stable [amd64]) +Inst dpkg [1.15.8.12] (1.15.8.13 Debian:6.0.6/stable [amd64]) +Conf dpkg (1.15.8.13 Debian:6.0.6/stable [amd64]) +Inst linux-base [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [all]) +Inst linux-image-2.6.32-5-xen-amd64 [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64]) +Inst debian-archive-keyring [2010.08.28] (2010.08.28+squeeze1 Debian:6.0.6/stable [all]) +Conf debian-archive-keyring (2010.08.28+squeeze1 Debian:6.0.6/stable [all]) +Inst libc6-dev [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) [] +Inst libc-dev-bin [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) [] +Inst linux-libc-dev [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64]) [] +Inst libc-bin [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) [libc6:amd64 ] +Conf libc-bin (2.11.3-4 Debian:6.0.6/stable [amd64]) [libc6:amd64 ] +Inst libc6 [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) +Conf libc6 (2.11.3-4 Debian:6.0.6/stable [amd64]) +Inst locales [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [all]) +Inst firmware-linux-free [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [all]) +Inst lockfile-progs [0.1.15] (0.1.15+squeeze1 Debian:6.0.6/stable [amd64]) +Conf linux-base (2.6.32-46 Debian:6.0.6/stable [all]) +Conf linux-image-2.6.32-5-xen-amd64 (2.6.32-46 Debian:6.0.6/stable [amd64]) +Conf libc-dev-bin (2.11.3-4 Debian:6.0.6/stable [amd64]) +Conf linux-libc-dev (2.6.32-46 Debian:6.0.6/stable [amd64]) +Conf libc6-dev (2.11.3-4 Debian:6.0.6/stable [amd64]) +Conf locales (2.11.3-4 Debian:6.0.6/stable [all]) +Conf firmware-linux-free (2.6.32-46 Debian:6.0.6/stable [all]) +Conf 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 @@ +NOTE: This is only a simulation! + apt-get needs root privileges for real execution. + Keep also in mind that locking is deactivated, + so don't depend on the relevance to the real current situation! +Inst base-files [6.0squeeze5] (6.0squeeze6 Debian:6.0.6/stable [amd64]) +Conf base-files (6.0squeeze6 Debian:6.0.6/stable [amd64]) +Inst dpkg [1.15.8.12] (1.15.8.13 Debian:6.0.6/stable [amd64]) +Conf dpkg (1.15.8.13 Debian:6.0.6/stable [amd64]) +Inst linux-base [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [all]) +Inst linux-image-2.6.32-5-amd64 [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64]) +Inst 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]) +Inst xen-linux-system-2.6.32-5-xen-amd64 [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64]) [] +Inst linux-image-2.6.32-5-xen-amd64 [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64]) +Inst debian-archive-keyring [2010.08.28] (2010.08.28+squeeze1 Debian:6.0.6/stable [all]) +Conf debian-archive-keyring (2010.08.28+squeeze1 Debian:6.0.6/stable [all]) +Inst libc6-i386 [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) [] +Inst libc-bin [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) [libc6:amd64 ] +Conf libc-bin (2.11.3-4 Debian:6.0.6/stable [amd64]) [libc6:amd64 ] +Inst libc6 [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) +Conf libc6 (2.11.3-4 Debian:6.0.6/stable [amd64]) +Inst libgc1c2 [1:6.8-1.2] (1:6.8-2 Debian:6.0.6/stable [amd64]) +Inst locales [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [all]) +Inst firmware-linux-free [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [all]) +Inst libxenstore3.0 [4.0.1-5.3] (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64]) +Inst lockfile-progs [0.1.15] (0.1.15+squeeze1 Debian:6.0.6/stable [amd64]) +Inst 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]) +Inst xenstore-utils [4.0.1-5.3] (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64]) +Inst libconfig-inifiles-perl [2.52-1] (2.52-1+squeeze1 Debian:6.0.6/stable [all]) +Conf linux-base (2.6.32-46 Debian:6.0.6/stable [all]) +Conf linux-image-2.6.32-5-amd64 (2.6.32-46 Debian:6.0.6/stable [amd64]) +Conf xen-hypervisor-4.0-amd64 (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64]) +Conf linux-image-2.6.32-5-xen-amd64 (2.6.32-46 Debian:6.0.6/stable [amd64]) +Conf xen-linux-system-2.6.32-5-xen-amd64 (2.6.32-46 Debian:6.0.6/stable [amd64]) +Conf libc6-i386 (2.11.3-4 Debian:6.0.6/stable [amd64]) +Conf libgc1c2 (1:6.8-2 Debian:6.0.6/stable [amd64]) +Conf locales (2.11.3-4 Debian:6.0.6/stable [all]) +Conf firmware-linux-free (2.6.32-46 Debian:6.0.6/stable [all]) +Conf libxenstore3.0 (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64]) +Conf lockfile-progs (0.1.15+squeeze1 Debian:6.0.6/stable [amd64]) +Conf xen-utils-4.0 (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64]) +Conf xenstore-utils (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64]) +Conf 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 @@ +NOTE: This is only a simulation! + apt-get needs root privileges for real execution. + Also keep in mind that locking is deactivated, + so don't depend on the relevance to the real current situation! +Inst grub-pc [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) [] +Inst grub-pc-bin [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) [] +Inst grub2-common [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) [] +Inst grub-efi-amd64-bin [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) [] +Inst grub-common [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) +Conf grub-common (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) +Conf grub2-common (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) +Conf grub-pc-bin (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) +Conf grub-pc (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) +Conf 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 @@ +NOTE: This is only a simulation! + apt-get needs root privileges for real execution. + Also keep in mind that locking is deactivated, + so don't depend on the relevance to the real current situation! +Inst libc6-dev [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) [] +Inst libc-dev-bin [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) [] +Inst linux-libc-dev [3.2.0-29.46] (3.2.0-31.50 Ubuntu:12.04/precise-security [amd64]) [] +Inst tzdata [2012e-0ubuntu0.12.04] (2012e-0ubuntu0.12.04.1 Ubuntu:12.04/precise-security [all]) [] +Conf tzdata (2012e-0ubuntu0.12.04.1 Ubuntu:12.04/precise-security [all]) [] +Inst libc-bin [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) [libc6:amd64 ] +Conf libc-bin (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) [libc6:amd64 ] +Inst libc6 [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) +Conf libc6 (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) +Inst libapt-pkg4.12 [0.8.16~exp12ubuntu10.2] (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64]) +Conf libapt-pkg4.12 (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64]) +Inst ubuntu-keyring [2011.11.21] (2011.11.21.1 Ubuntu:12.04/precise-updates [all]) +Conf ubuntu-keyring (2011.11.21.1 Ubuntu:12.04/precise-updates [all]) +Inst gpgv [1.4.11-3ubuntu2] (1.4.11-3ubuntu2.1 Ubuntu:12.04/precise-security [amd64]) +Conf gpgv (1.4.11-3ubuntu2.1 Ubuntu:12.04/precise-security [amd64]) +Inst gnupg [1.4.11-3ubuntu2] (1.4.11-3ubuntu2.1 Ubuntu:12.04/precise-security [amd64]) +Conf gnupg (1.4.11-3ubuntu2.1 Ubuntu:12.04/precise-security [amd64]) +Inst apt [0.8.16~exp12ubuntu10.2] (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64]) +Conf apt (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64]) +Inst libssl1.0.0 [1.0.1-4ubuntu5.3] (1.0.1-4ubuntu5.5 Ubuntu:12.04/precise-updates [amd64]) +Conf libssl1.0.0 (1.0.1-4ubuntu5.5 Ubuntu:12.04/precise-updates [amd64]) +Inst libapt-inst1.4 [0.8.16~exp12ubuntu10.2] (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64]) +Inst resolvconf [1.63ubuntu15] (1.63ubuntu16 Ubuntu:12.04/precise-updates [all]) +Inst libdbus-1-3 [1.4.18-1ubuntu1] (1.4.18-1ubuntu1.1 Ubuntu:12.04/precise-security [amd64]) +Inst libxml2 [2.7.8.dfsg-5.1ubuntu4.1] (2.7.8.dfsg-5.1ubuntu4.2 Ubuntu:12.04/precise-security [amd64]) +Inst multiarch-support [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) +Conf multiarch-support (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) +Inst apt-utils [0.8.16~exp12ubuntu10.2] (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64]) +Inst isc-dhcp-client [4.1.ESV-R4-0ubuntu5.2] (4.1.ESV-R4-0ubuntu5.5 Ubuntu:12.04/precise-security [amd64]) [] +Inst isc-dhcp-common [4.1.ESV-R4-0ubuntu5.2] (4.1.ESV-R4-0ubuntu5.5 Ubuntu:12.04/precise-security [amd64]) +Inst dbus [1.4.18-1ubuntu1] (1.4.18-1ubuntu1.1 Ubuntu:12.04/precise-security [amd64]) +Inst linux-firmware [1.79] (1.79.1 Ubuntu:12.04/precise-updates [all]) +Inst xserver-common [2:1.11.4-0ubuntu10.7] (2:1.11.4-0ubuntu10.8 Ubuntu:12.04/precise-updates [all]) +Inst xserver-xorg-core [2:1.11.4-0ubuntu10.7] (2:1.11.4-0ubuntu10.8 Ubuntu:12.04/precise-updates [amd64]) +Inst xserver-xorg-input-synaptics [1.6.2-1ubuntu1~precise1] (1.6.2-1ubuntu1~precise2 Ubuntu:12.04/precise-updates [amd64]) +Conf libc-dev-bin (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) +Conf linux-libc-dev (3.2.0-31.50 Ubuntu:12.04/precise-security [amd64]) +Conf libc6-dev (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) +Conf libapt-inst1.4 (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64]) +Conf resolvconf (1.63ubuntu16 Ubuntu:12.04/precise-updates [all]) +Conf libdbus-1-3 (1.4.18-1ubuntu1.1 Ubuntu:12.04/precise-security [amd64]) +Conf libxml2 (2.7.8.dfsg-5.1ubuntu4.2 Ubuntu:12.04/precise-security [amd64]) +Conf apt-utils (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64]) +Conf isc-dhcp-common (4.1.ESV-R4-0ubuntu5.5 Ubuntu:12.04/precise-security [amd64]) +Conf isc-dhcp-client (4.1.ESV-R4-0ubuntu5.5 Ubuntu:12.04/precise-security [amd64]) +Conf dbus (1.4.18-1ubuntu1.1 Ubuntu:12.04/precise-security [amd64]) +Conf linux-firmware (1.79.1 Ubuntu:12.04/precise-updates [all]) +Conf xserver-common (2:1.11.4-0ubuntu10.8 Ubuntu:12.04/precise-updates [all]) +Conf xserver-xorg-core (2:1.11.4-0ubuntu10.8 Ubuntu:12.04/precise-updates [amd64]) +Conf 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; plan skip_all => "check_dig not compiled" unless (-x "check_dig"); -plan tests => 12; +plan tests => 16; my $successOutput = '/DNS OK - [\.0-9]+ seconds? response time/'; -my $hostname_valid = getTestParameter( +my $hostname_valid = getTestParameter( "NP_HOSTNAME_VALID", "A valid (known to DNS) hostname", - "nagios.com" + "nagiosplugins.org" ); my $hostname_valid_ip = getTestParameter( "NP_HOSTNAME_VALID_IP", "The IP address of the valid hostname $hostname_valid", - "66.118.156.50", + "67.207.143.200", ); my $hostname_valid_reverse = getTestParameter( "NP_HOSTNAME_VALID_REVERSE", "The hostname of $hostname_valid_ip", - "66-118-156-50.static.sagonet.net.", + "nagiosplugins.org.", ); -my $hostname_invalid = getTestParameter( - "NP_HOSTNAME_INVALID", +my $hostname_invalid = getTestParameter( + "NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost.altinity.com", ); @@ -69,6 +69,14 @@ SKIP: { cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server"); like ( $res->output, $successOutput, "Output OK" ); + $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -4"); + cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server"); + like ( $res->output, $successOutput, "Output OK for IPv4" ); + + $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -6"); + cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server"); + like ( $res->output, $successOutput, "Output OK for IPv6" ); + $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -a $hostname_valid_ip -t 5"); cmp_ok( $res->return_code, '==', 0, "Got expected address"); 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; use Test::More; use NPTest; -plan tests => 28; +plan tests => 30; my $successOutput = '/OK.*HTTP.*second/'; my $res; -my $host_tcp_http = getTestParameter( "NP_HOST_TCP_HTTP", - "A host providing the HTTP Service (a web server)", +my $host_tcp_http = getTestParameter( "NP_HOST_TCP_HTTP", + "A host providing the HTTP Service (a web server)", "localhost" ); -my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", +my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1" ); -my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", - "An invalid (not known to DNS) hostname", +my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", + "An invalid (not known to DNS) hostname", "nosuchhost"); my $internet_access = getTestParameter( "NP_INTERNET_ACCESS", @@ -32,8 +32,8 @@ my $internet_access = getTestParameter( "NP_INTERNET_ACCESS", my $host_tcp_http2; if ($internet_access eq "no") { - $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2", - "A host providing an index page containing the string 'nagios'", + $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2", + "A host providing an index page containing the string 'nagios'", "www.nagios.com" ); } @@ -45,14 +45,9 @@ cmp_ok( $res->return_code, '==', 0, "Webserver $host_tcp_http responded" ); like( $res->output, $successOutput, "Output OK" ); $res = NPTest->testCmd( - "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there;fred:here'" + "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there' -k 'carl:frown'" ); -like( $res->output, '/bob:there\r\nfred:here\r\n/', "Got headers, delimited with ';'" ); - -$res = NPTest->testCmd( - "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there;fred:here' -k 'carl:frown'" - ); -like( $res->output, '/bob:there\r\nfred:here\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); +like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); $res = NPTest->testCmd( "./check_http $host_nonresponsive -wt 1 -ct 2" @@ -123,6 +118,10 @@ SKIP: { $res = NPTest->testCmd( "./check_http www.verisign.com -C 1" ); cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works"); + $res = NPTest->testCmd( "./check_http --ssl www.verisign.com -E" ); + like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); + like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); + $res = NPTest->testCmd( "./check_http --ssl www.e-paycobalt.com" ); @@ -131,4 +130,7 @@ SKIP: { $res = NPTest->testCmd( "./check_http -H www.mozilla.com -u /firefox -f follow" ); is( $res->return_code, 0, "Redirection based on location is okay"); + + $res = NPTest->testCmd( "./check_http -H www.mozilla.com --extended-perfdata" ); + like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); } 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; $result = NPTest->testCmd( "./check_procs -w 100000 -c 100000" ); is( $result->return_code, 0, "Checking less than 10000 processes" ); -like( $result->output, '/^PROCS OK: [0-9]+ process(es)?$/', "Output correct" ); +like( $result->output, '/^PROCS OK: [0-9]+ process(es)? | procs=[0-9]+;100000;100000;0;$/', "Output correct" ); $result = NPTest->testCmd( "./check_procs -w 100000 -c 100000 -s Z" ); is( $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 $result = NPTest->testCmd( "./check_procs -w 0 -c 100000" ); is( $result->return_code, 1, "Checking warning if processes > 0" ); -like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)?$/', "Output correct" ); +like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)? | procs=[0-9]+;0;100000;0;$/', "Output correct" ); $result = NPTest->testCmd( "./check_procs -w 0 -c 0" ); is( $result->return_code, 2, "Checking critical if processes > 0" ); -like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)?$/', "Output correct" ); +like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)? | procs=[0-9]+;0;0;0;$/', "Output correct" ); $result = NPTest->testCmd( "./check_procs -w 0 -c 0 -s S" ); is( $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; use NPTest; use vars qw($tests); -BEGIN {$tests = 7; plan tests => $tests} +BEGIN {$tests = 14; plan tests => $tests} my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost", "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 my $t; $t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0, $successOutput ); +$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600 -6 ", 0, $successOutput ); $t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test $t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 ); $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 $t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 0 ); $t += checkCmd( "./check_tcp -S -D 9000 -H www.verisign.com -p 443", 1 ); $t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443", 2 ); +$t += checkCmd( "./check_tcp -6 -p 80 www.heise.de", 0 ); # Need the \r\n to make it more standards compliant with web servers. Need the various quotes # 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 @@ # Common Name (eg, YOUR name) []:Ton Voon # Email Address []:tonvoon@mac.com - use strict; use Test::More; use NPTest; use FindBin qw($Bin); my $common_tests = 66; -my $ssl_only_tests = 6; +my $ssl_only_tests = 8; # Check that all dependent modules are available eval { require HTTP::Daemon; @@ -160,9 +159,9 @@ sub run_server { } } -END { +END { foreach my $pid (@pids) { - if ($pid) { print "Killing $pid\n"; kill "INT", $pid } + if ($pid) { print "Killing $pid\n"; kill "INT", $pid } } }; @@ -179,7 +178,7 @@ run_common_tests( { command => "$command -p $port_http" } ); SKIP: { skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https}; run_common_tests( { command => "$command -p $port_https", ssl => 1 } ); - + $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on 03/03/2019 21:41.', "output ok" ); @@ -188,14 +187,14 @@ SKIP: { is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" ); - $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); - is( $result->return_code, 1, "$command -p $port_https -S -C 139600,14000" ); - like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" ); - # Expired cert tests + $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); + is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); + like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" ); + $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); - is( $result->output, + is( $result->output, 'CRITICAL - Certificate \'Ton Voon\' expired on 03/05/2009 00:13.', "output ok" ); @@ -406,4 +405,3 @@ sub run_common_tests { isnt( $@, "alarm\n", $cmd ); } - 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 @@ +#!/bin/bash + +set -xeu + +temp=$(mktemp -d) +trap "cd $HOME; rm -rf $temp; exit 1" EXIT +curl -sS http://nagiosplug.sourceforge.net/snapshot/nagios-plugins-HEAD.tar.gz|tar -C "$temp" --strip-components=1 -xzf - +cd $temp +./configure && make +$HOME/bin/update_man_pages + diff --git a/tools/sfwebcron b/tools/sfwebcron index d836a0fd..0f31fcfb 100755 --- a/tools/sfwebcron +++ b/tools/sfwebcron @@ -4,32 +4,32 @@ # To update the developers-guidelines.html and put in html area # # Install in cron with something like: -# 47 7 * * * $HOME/bin/sfwebcron +# 47 7 * * * $HOME/bin/sfwebcron >/tmp/sfwebcron.log 2>&1 || cat /tmp/sfwebcron.log -function die { echo $1; exit 1; } +set -eu +trap 'echo "Command failed at line $LINENO"' ERR # Set working variables PROJECT=nagiosplug -IN=${HOME}/tmp_sfwebcron -OUT_SERVER="tonvoon@shell.sf.net" -OUT="/home/groups/n/na/nagiosplug/htdocs" - -if [[ ! -e developer-guidelines.html.last ]] ; then - touch developer-guidelines.html.last -fi +IN=${HOME}/sfwebcron +PROBE="developer-guidelines.html.last" +OUT_SERVER="tonvoon@frs.sourceforge.net" +OUT_PATH="/home/groups/n/na/nagiosplug/htdocs" # Get latest dev guildelines [[ ! -d $IN ]] && mkdir $IN cd $IN -if [[ ! -d doc ]] ; then - #cvs -z3 -d:pserver:anonymous@cvs1:/cvsroot/nagiosplug co nagiosplug || die "Cannot cvs" - svn checkout http://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk/doc doc +if [[ ! -d nagios-plugins ]] +then + git clone https://github.com/nagios-plugins/nagios-plugins.git nagios-plugins fi -cd doc -svn update +cd nagios-plugins/doc +git pull make -if [[ developer-guidelines.html -nt developer-guidelines.html.last ]] ; then - scp developer-guidelines.{html,sgml} $OUT_SERVER:$OUT - touch developer-guidelines.html.last +if [[ ! -e $PROBE || developer-guidelines.html -nt $PROBE ]] +then + rsync -av developer-guidelines.{html,sgml} $OUT_SERVER:$OUT_PATH/ + touch $PROBE fi + diff --git a/tools/snapshot b/tools/snapshot deleted file mode 100755 index 9fa61cfe..00000000 --- a/tools/snapshot +++ /dev/null @@ -1,69 +0,0 @@ -#! /bin/sh - -# This scipt assumes that you have anonCVS for nagios and nagiosplug -# in ${IN} - -# cvs -d:pserver:anonymous@cvs.nagiosplug.sourceforge.net:/cvsroot/nagiosplug login -# cvs -z3 -d:pserver:anonymous@cvs.nagiosplug.sourceforge.net:/cvsroot/nagiosplug co nagiosplug -# -# cvs -d:pserver:anonymous@cvs.nagios.sourceforge.net:/cvsroot/nagios login -# cvs -z3 -d:pserver:anonymous@cvs.nagios.sourceforge.net:/cvsroot/nagios co nagios - -# Set directories -IN=${HOME}/sf -OUT=/col/htdocs/src/nagios -RPM_TOPDIR=${HOME}/redhat - -# Update nagiosplug CVS -cd ${IN}/nagiosplug -rm configure configure.in Makefile.in -cvs update -DS=`date -u +%Y%m%d%H%M` -sed "s/^VER=.*/VER=${DS}/;s/^REL=.*/REL=snapshot/" configure.in > configure.tmp -mv configure.tmp configure.in -aclocal -autoheader -autoconf -automake -autoreconf - -# Make the Nagiosplug dist tarball -rm -r build-dist -mkdir build-dist -cd build-dist -../configure -make dist -cp -fv *.gz ${OUT} - -# Make the Nagiosplug custom RPM -echo "%_topdir ${RPM_TOPDIR}" > ./.rpmrc -mkdir -p ${RPM_TOPDIR}/RPMS/i386 ${RPM_TOPDIR}/SRPMS ${RPM_TOPDIR}/SOURCES ${RPM_TOPDIR}/BUILD ${RPM_TOPDIR}/SPECS -rpm --rcfile "/usr/lib/rpm/rpmrc:${IN}/rpmrc" --define 'custom 1' -ta *.gz -cp -fv ~/redhat/RPMS/i386/nagios-plugins-custom-*.i386.rpm /col/htdocs/src/nagios - -# Copy the new snapshot and delete the old ones -cd ${OUT} -GLOBIGNORE=nagios-plugins-${DS}-snapshot.tar.gz -rm -f nagios-plugins-*.tar.gz -GLOBIGNORE=nagios-plugins-custom-${DS}-snapshot.i386.rpm -rm -f nagios-plugins-custom-*-snapshot.i386.rpm -cd ~/redhat/SRPMS -rm nagios-plugins-custom-${DS}-snapshot.src.rpm -cd ~/redhat/RPMS/i386 -rm nagios-plugins-custom-${DS}-snapshot.i386.rpm - -# Update Nagios CVS -cd ${IN}/sf/nagios -rm configure configure.in nagios.spec base/nagios.c common/common.h \ - html/main.html Makefile.in -cvs update - -# Make the Nagios tarball -DS=`date -u +%Y%m%d%H%M` -./make-tarball ${DS} - -# Copy the new snapshot and delete the old ones -mv ../nagios-${DS}.tar.gz /col/htdocs/src/nagios/ -GLOBIGNORE=${OUT}/nagios-${DS}.tar.gz -rm ${OUT}/nagios-20*.tar.gz - 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 @@ +#!/usr/bin/perl +use strict; +use DBI; +#$ENV{PERL5LIB}="plugins-scripts"; # Needed for utils.pm + +unless ($ENV{DRUPAL_PASSWORD}) { + die "Must set envvar for DRUPAL_PASSWORD"; +} + +my $dbh = DBI->connect("DBI:mysql:database=www;host=127.0.0.1", "www", $ENV{DRUPAL_PASSWORD}); + +my @plugin_paths; +push @plugin_paths, (grep { -x $_ && -f $_ } (<plugins-root/*>, <plugins/*>) ); + +foreach my $plugin_path (@plugin_paths) { + my $plugin = $plugin_path; + $plugin =~ s%.*/%%; + my $help_option = "--help"; + $help_option = "-h" if ($plugin eq "check_icmp"); + my $help = `$plugin_path $help_option` || die "Cannot run $plugin -h"; + $help =~ s/</</g; + $help =~ s/>/>/g; + + my $rows = $dbh->do("UPDATE node SET created=UNIX_TIMESTAMP(NOW()) WHERE title='$plugin'"); + unless ($rows == 1) { + die "Cannot find $plugin in drupal to update - create book page first"; + } + + $dbh->do("UPDATE node_revisions SET timestamp=UNIX_TIMESTAMP(NOW()), log='Updated by update_online_manpage', teaser='$plugin --help', body=? WHERE title='$plugin'", + {}, + "<pre>".$help."</pre>"); +} + +print "Finished\n"; |