diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | THANKS.in | 5 | ||||
-rw-r--r-- | configure.in | 91 | ||||
-rwxr-xr-x | plugins-scripts/check_oracle.sh | 15 | ||||
-rwxr-xr-x | plugins-scripts/check_sensors.sh | 33 | ||||
-rw-r--r-- | plugins/Makefile.am | 95 | ||||
-rw-r--r-- | plugins/check_apt.c | 12 | ||||
-rw-r--r-- | plugins/check_dig.c | 2 | ||||
-rw-r--r-- | plugins/check_disk.c | 18 | ||||
-rw-r--r-- | plugins/check_dns.c | 2 | ||||
-rw-r--r-- | plugins/check_http.c | 4 | ||||
-rw-r--r-- | plugins/check_nagios.c | 16 | ||||
-rw-r--r-- | plugins/check_nt.c | 16 | ||||
-rw-r--r-- | plugins/check_ntp_peer.c | 32 | ||||
-rw-r--r-- | plugins/check_procs.c | 1 | ||||
-rw-r--r-- | plugins/check_smtp.c | 26 | ||||
-rw-r--r-- | plugins/runcmd.c | 2 | ||||
-rw-r--r-- | plugins/runcmd.h | 2 | ||||
-rw-r--r-- | plugins/t/check_http.t | 11 |
20 files changed, 208 insertions, 182 deletions
@@ -191,6 +191,7 @@ NP-VERSION-FILE /plugins/.libs /plugins/Makefile /plugins/Makefile.in +/plugins/libnpcommon.a /plugins/negate /plugins/stamp-h* /plugins/urlize @@ -4,8 +4,14 @@ 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 FIXES Change the MAIL FROM command generated by check_smtp to be RFC compliant @@ -277,3 +277,8 @@ Jochen Bern Anders Kaseorg Robin Sonefors Alex Bradley +Brian De Wolf +Richard Leitner +Diego Elio Pettenò +Vaclav Ovsik +Roman Fiedler 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/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/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 cf186611..daeb7578 100644 --- a/plugins/check_apt.c +++ b/plugins/check_apt.c @@ -112,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", @@ -124,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; @@ -444,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 3c80cb72..c113d87b 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c @@ -78,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 */ diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 6ba7bdf3..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; @@ -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 9231a559..110875d6 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -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 @@ -854,8 +853,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 */ 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_peer.c b/plugins/check_ntp_peer.c index b59c056d..76152e17 100644 --- a/plugins/check_ntp_peer.c +++ b/plugins/check_ntp_peer.c @@ -241,15 +241,19 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji 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); diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 00b032a7..6acedc70 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c @@ -332,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'}, diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index 79fa4824..d477a51e 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c @@ -99,9 +99,9 @@ char **responses = NULL; 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 */ 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_http.t b/plugins/t/check_http.t index 0a25c775..6299791f 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t @@ -8,7 +8,7 @@ use strict; use Test::More; use NPTest; -plan tests => 28; +plan tests => 27; my $successOutput = '/OK.*HTTP.*second/'; @@ -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" |