summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--.travis.yml8
-rw-r--r--FAQ36
-rw-r--r--LEGAL10
-rw-r--r--Makefile.am4
-rw-r--r--NEWS54
-rwxr-xr-xNP-VERSION-GEN2
-rw-r--r--THANKS.in10
-rw-r--r--configure.ac42
-rw-r--r--doc/RELEASING44
-rw-r--r--lib/utils_base.c15
-rw-r--r--lib/utils_cmd.c14
-rw-r--r--monitoring-plugins.spec.in201
-rw-r--r--perlmods/Monitoring-Plugin-0.37.tar.gzbin62278 -> 0 bytes
-rw-r--r--perlmods/Monitoring-Plugin-0.39.tar.gzbin0 -> 62733 bytes
-rw-r--r--plugins-root/check_icmp.c89
-rwxr-xr-xplugins-scripts/check_breeze.pl1
-rwxr-xr-xplugins-scripts/check_disk_smb.pl1
-rwxr-xr-xplugins-scripts/check_file_age.pl6
-rwxr-xr-xplugins-scripts/check_flexlm.pl1
-rwxr-xr-xplugins-scripts/check_ifoperstatus.pl1
-rwxr-xr-xplugins-scripts/check_ifstatus.pl58
-rwxr-xr-xplugins-scripts/check_ircd.pl1
-rwxr-xr-xplugins-scripts/check_log.sh7
-rwxr-xr-xplugins-scripts/check_mailq.pl35
-rwxr-xr-xplugins-scripts/check_mssql.pl1
-rwxr-xr-xplugins-scripts/check_netdns.pl3
-rwxr-xr-xplugins-scripts/check_oracle.sh5
-rwxr-xr-xplugins-scripts/check_rpc.pl1
-rwxr-xr-xplugins-scripts/check_sensors.sh5
-rwxr-xr-xplugins-scripts/check_wave.pl1
-rw-r--r--plugins-scripts/t/check_disk_smb.t2
-rw-r--r--plugins-scripts/t/check_file_age.t8
-rw-r--r--plugins-scripts/utils.pm.in1
-rw-r--r--plugins/Makefile.am2
-rw-r--r--plugins/check_apt.c2
-rw-r--r--plugins/check_by_ssh.c3
-rw-r--r--plugins/check_dig.c9
-rw-r--r--plugins/check_disk.c59
-rw-r--r--plugins/check_dns.c22
-rw-r--r--plugins/check_fping.c2
-rw-r--r--plugins/check_http.c45
-rw-r--r--plugins/check_ldap.c95
-rw-r--r--plugins/check_mrtgtraf.c14
-rw-r--r--plugins/check_nt.c51
-rw-r--r--plugins/check_ntp.c25
-rw-r--r--plugins/check_ntp_peer.c9
-rw-r--r--plugins/check_real.c10
-rw-r--r--plugins/check_snmp.c57
-rw-r--r--plugins/check_ssh.c12
-rw-r--r--plugins/check_swap.c3
-rw-r--r--plugins/check_tcp.c7
-rw-r--r--plugins/sslutils.c33
-rw-r--r--plugins/t/NPTest.cache.travis4
-rw-r--r--plugins/t/check_dns.t12
-rw-r--r--plugins/t/check_http.t43
-rw-r--r--plugins/t/check_ldap.t80
-rw-r--r--plugins/t/negate.t5
-rwxr-xr-xplugins/tests/check_http.t8
-rwxr-xr-xplugins/tests/check_snmp.t33
-rw-r--r--plugins/utils.c42
-rwxr-xr-xtools/generate-change-log2
-rwxr-xr-xtools/update-thanks56
63 files changed, 914 insertions, 499 deletions
diff --git a/.gitignore b/.gitignore
index 8ea2d8e..3093c6e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,6 +35,7 @@ NP-VERSION-FILE
35/build-aux/install-sh 35/build-aux/install-sh
36/build-aux/missing 36/build-aux/missing
37/build-aux/mkinstalldirs 37/build-aux/mkinstalldirs
38/build-aux/test-driver
38 39
39# /doc/ 40# /doc/
40/doc/developer-guidelines.html 41/doc/developer-guidelines.html
diff --git a/.travis.yml b/.travis.yml
index cec7878..c892eb2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,16 +4,20 @@ before_install:
4 - sudo add-apt-repository -y ppa:waja/precise-backports 4 - sudo add-apt-repository -y ppa:waja/precise-backports
5 - sudo apt-get update -qq 5 - sudo apt-get update -qq
6 - sudo apt-get purge -qq gawk 6 - sudo apt-get purge -qq gawk
7 # ensure we have a test database in place for tests
8 - mysql -e "create database IF NOT EXISTS test;" -uroot
7 9
8install: 10install:
9 - sudo apt-get install -qq --no-install-recommends perl autotools-dev libdbi-dev libldap2-dev libpq-dev libmysqlclient-dev libfreeradius-client-dev libkrb5-dev libnet-snmp-perl procps 11 - sudo apt-get install -qq --no-install-recommends perl autotools-dev libdbi-dev libldap2-dev libpq-dev libmysqlclient-dev libfreeradius-client-dev libkrb5-dev libnet-snmp-perl procps
10 - sudo apt-get install -qq --no-install-recommends libdbi0-dev libdbd-sqlite3 libssl-dev dnsutils snmp-mibs-downloader 12 - sudo apt-get install -qq --no-install-recommends libdbi0-dev libdbd-sqlite3 libssl-dev dnsutils snmp-mibs-downloader libsnmp-perl snmpd
11 - sudo apt-get install -qq --no-install-recommends fping snmp netcat smbclient fping pure-ftpd apache2 postfix libhttp-daemon-ssl-perl 13 - sudo apt-get install -qq --no-install-recommends fping snmp netcat smbclient fping pure-ftpd apache2 postfix libhttp-daemon-ssl-perl
14 - sudo apt-get install -qq --no-install-recommends slapd ldap-utils
12 - sudo apt-get install -qq --no-install-recommends autoconf automake 15 - sudo apt-get install -qq --no-install-recommends autoconf automake
16 - sudo apt-get install -qq --no-install-recommends faketime
13 17
14before_script: 18before_script:
15 - tools/setup 19 - tools/setup
16 - ./configure 20 - ./configure --enable-libtap
17 - make 21 - make
18 - export NPTEST_CACHE="$(pwd)/plugins/t/NPTest.cache.travis" 22 - export NPTEST_CACHE="$(pwd)/plugins/t/NPTest.cache.travis"
19 - ssh-keygen -t dsa -N "" -f ~/.ssh/id_dsa 23 - ssh-keygen -t dsa -N "" -f ~/.ssh/id_dsa
diff --git a/FAQ b/FAQ
index 20b837c..be8e7af 100644
--- a/FAQ
+++ b/FAQ
@@ -29,42 +29,6 @@ A: At a minimum, the output from 'uname -a' and the version string
29 problem and any solution/patch. 29 problem and any solution/patch.
30 30
31 31
32Q: I'm using Redhat Linux (or some other RPM-based distribution).
33 Which packages should I install?
34
35A: The package monitoring-plugins-<version>.<arch>.rpm contains only
36 those plugins that should work on any POSIX compliant system. In
37 other words, you should be able to install this package on your
38 system, no matter what else is or in not installed.
39
40 However, most of us have more complex systems than barebones
41 POSIX. We tried creating a variety of separate packages so
42 each dependency could be installed cleanly, but many people
43 found that this resulted in too many packages. So in the end,
44 all the non-POSIX plugins were folded into one RPM
45 (monitoring-plugins-<version>.<arch>.rpm). Most people will need to
46 use RPM's '--nodeps' option to install this package.
47
48
49Q: My system uses the .deb package format. What packages should I
50 install?
51
52A: We strive for cooperation between all packagers and developers.
53 The answers for .deb are the same as for RPM, after changing the
54 package name suffixes accordingly.
55
56
57Q: I prefer to build my own RPMs. Do I need to install all of the
58 various dependencies?
59
60A: Beginning with the 1.2.9-1 release, you may run
61
62 rpm --define 'custom 1' -ta monitoring-plugins-<release>.tar.gz
63
64 In prior releases, you must unpack the tarball and build the
65 RPM using monitoring-custom.spec with 'rpm -ba'.
66
67
68Q: I get an error like 32Q: I get an error like
69 33
70 Warning: Return code of 127 for check of service 'PING' on host 'anyhost' was out of bounds. 34 Warning: Return code of 127 for check of service 'PING' on host 'anyhost' was out of bounds.
diff --git a/LEGAL b/LEGAL
deleted file mode 100644
index 147fc98..0000000
--- a/LEGAL
+++ /dev/null
@@ -1,10 +0,0 @@
1
2All source code, binaries, documentation, and information contained
3in this distribution are provided AS IS with NO WARRANTY OF ANY KIND,
4INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY, AND FITNESS FOR
5A PARTICULAR PURPOSE.
6
7Nagios and the Nagios logo are trademarks of Ethan Galstad. All
8other trademarks, servicemarks, registered trademarks, and
9registered servicemarks are the property of their respective owner(s).
10
diff --git a/Makefile.am b/Makefile.am
index 517068c..7e0d413 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,9 +3,9 @@
3SUBDIRS = gl tap lib plugins plugins-scripts plugins-root po @PERLMODS_DIR@ 3SUBDIRS = gl tap lib plugins plugins-scripts plugins-root po @PERLMODS_DIR@
4 4
5EXTRA_DIST = config.rpath \ 5EXTRA_DIST = config.rpath \
6 ABOUT-NLS ACKNOWLEDGEMENTS AUTHORS CODING ChangeLog FAQ LEGAL NEWS \ 6 ABOUT-NLS ACKNOWLEDGEMENTS AUTHORS CODING ChangeLog FAQ NEWS \
7 NP-VERSION-GEN REQUIREMENTS SUPPORT THANKS \ 7 NP-VERSION-GEN REQUIREMENTS SUPPORT THANKS \
8 NPTest.pm pkg monitoring-plugins.spec \ 8 NPTest.pm pkg \
9 config_test/Makefile config_test/run_tests config_test/child_test.c \ 9 config_test/Makefile config_test/run_tests config_test/child_test.c \
10 perlmods tools/build_perl_modules \ 10 perlmods tools/build_perl_modules \
11 tools/tinderbox_build 11 tools/tinderbox_build
diff --git a/NEWS b/NEWS
index d48e1d8..1a4aead 100644
--- a/NEWS
+++ b/NEWS
@@ -1,8 +1,60 @@
1This file documents the major additions and syntax changes between releases. 1This file documents the major additions and syntax changes between releases.
2 2
32.1 32.2 [...]
4 ENHANCEMENTS
5 check_snmp's performance data now also includes warning/critical
6 thresholds
7 New check_snmp "-N" option to specify SNMPv3 context name
8 New check_nt "-l" parameters: seconds|minutes|hours|days
9 Make sure check_disk won't hang on hanging (network) file systems
10 New check_mailq -s option which tells the plugin to use sudo(8)
11 New -W/-C option for check_ldap to check number of entries (Gerhard Lausser)
12
13 FIXES
14 Let check_real terminate lines with CRLF when talking to the server, as
15 mandated by 2326
16 Fix check_procs on HP-UX
17
18 WARNINGS
19 The format of the performance data emitted by check_mrtgtraf has been
20 changed to comply with the development guidelines
21 check_ssh not returns CRITICAL for protocal/version errors
22
232.1.1 2nd December 2014
24 FIXES
25 Fix check_ntp's jitter checking
26 Fix check_ntp's handling of invalid server responses
27 Fix check_apt's handling of invalid regular expressions
28 Fix check_real's server response processing
29 Fix backslash escaping in check_tcp's --help output
30
312.1 15th October 2014
4 ENHANCEMENTS 32 ENHANCEMENTS
5 New check_hpjd -p option for port specification (abrist) 33 New check_hpjd -p option for port specification (abrist)
34 New ./configure --with-qmail-qstat-command option to specify the path to
35 qmail-qstat(8)
36 New check_ifstatus -n option to ignore interfaces by name
37 check_ntp_peer has now specific state output for each metric
38 New check_mysql -n option to ignore authentication failures
39 Added IP and port or socket name to error messages
40 New check_ntp_time -o option to add expected offset
41 check_disk shows now troubled partions in verbose mode
42 check_dig has now support for drill and dig
43 check_dig has now support for -6 option
44 Add performance data to check_file_age
45
46 FIXES
47 Fix check_jabber to work with Openfire servers
48 Fix check_oracle bad string matching when testing TNS server
49 Fixed check_ifstatus performance data output
50 Fixed expire time output for sslutils
51 check_dns now verifies if the answer is returning from the queried
52 server
53 Fix check_by_ssh to accept --hostname as argument
54
55 WARNINGS
56 This release doesn't ship with an RPM spec file, please contribute to
57 PR #1283 if you are interested in it
6 58
72.0 11th July 2014 592.0 11th July 2014
8 ENHANCEMENTS 60 ENHANCEMENTS
diff --git a/NP-VERSION-GEN b/NP-VERSION-GEN
index 26f94e7..12efad7 100755
--- a/NP-VERSION-GEN
+++ b/NP-VERSION-GEN
@@ -6,7 +6,7 @@
6SRC_ROOT=`dirname $0` 6SRC_ROOT=`dirname $0`
7 7
8NPVF=NP-VERSION-FILE 8NPVF=NP-VERSION-FILE
9DEF_VER=2.0.git 9DEF_VER=2.1.1.git
10 10
11LF=' 11LF='
12' 12'
diff --git a/THANKS.in b/THANKS.in
index b6dc294..59c90fe 100644
--- a/THANKS.in
+++ b/THANKS.in
@@ -326,3 +326,13 @@ Mikael Falkvidd
326Patric Wust 326Patric Wust
327Julius Kriukas 327Julius Kriukas
328Patrick McAndrew 328Patrick McAndrew
329Alexander Wittig
330Jason Benguerel
331Matthew Kent
332Frederic Krueger
333Simon Meggle
334Jonas Genannt
335Nick Peelman
336Sebastian Herbszt
337Christopher Schultz
338Matthias Hähnel
diff --git a/configure.ac b/configure.ac
index f6ead58..ce1728e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,9 +1,8 @@
1dnl Process this file with autoconf to produce a configure script. 1dnl Process this file with autoconf to produce a configure script.
2AC_PREREQ(2.59) 2AC_PREREQ(2.59)
3AC_INIT(monitoring-plugins,2.0) 3AC_INIT(monitoring-plugins,2.1.1)
4AC_CONFIG_SRCDIR(NPTest.pm) 4AC_CONFIG_SRCDIR(NPTest.pm)
5AC_CONFIG_FILES([gl/Makefile 5AC_CONFIG_FILES([gl/Makefile])
6 monitoring-plugins.spec])
7AC_CONFIG_AUX_DIR(build-aux) 6AC_CONFIG_AUX_DIR(build-aux)
8AM_INIT_AUTOMAKE([1.8.3]) 7AM_INIT_AUTOMAKE([1.8.3])
9AM_MAINTAINER_MODE([enable]) 8AM_MAINTAINER_MODE([enable])
@@ -157,6 +156,12 @@ AC_CHECK_LIB(socket,socket,SOCKETLIBS="$SOCKETLIBS -lsocket")
157AC_CHECK_LIB(resolv,main,SOCKETLIBS="$SOCKETLIBS -lresolv") 156AC_CHECK_LIB(resolv,main,SOCKETLIBS="$SOCKETLIBS -lresolv")
158AC_SUBST(SOCKETLIBS) 157AC_SUBST(SOCKETLIBS)
159 158
159dnl Check for POSIX thread libraries
160AC_CHECK_HEADERS(pthread.h)
161AC_CHECK_LIB(pthread,pthread_create,THREADLIBS="-lpthread",
162 AC_CHECK_LIB(pthread,pthread_create,THREADLIBS="-lpthread -lrt",-lrt))
163AC_SUBST(THREADLIBS)
164
160dnl 165dnl
161dnl check for math-related functions needing -lm 166dnl check for math-related functions needing -lm
162AC_CHECK_HEADERS(math.h) 167AC_CHECK_HEADERS(math.h)
@@ -611,6 +616,7 @@ AC_DEFINE_UNQUOTED(SOCKET_SIZE_TYPE, $ac_cv_socket_size_type ,
611dnl #### Process table test 616dnl #### Process table test
612 617
613AC_PATH_PROG(PATH_TO_PS,ps) 618AC_PATH_PROG(PATH_TO_PS,ps)
619AC_PATH_PROG(PATH_TO_ENV,env)
614 620
615AC_MSG_CHECKING(for ps syntax) 621AC_MSG_CHECKING(for ps syntax)
616AC_ARG_WITH(ps_command, 622AC_ARG_WITH(ps_command,
@@ -932,6 +938,19 @@ then
932 ac_cv_ps_cols=6 938 ac_cv_ps_cols=6
933 AC_MSG_RESULT([$ac_cv_ps_command]) 939 AC_MSG_RESULT([$ac_cv_ps_command])
934 940
941dnl HP-UX:
942dnl S UID RUID USER RUSER PID PPID VSZ %CPU COMMAND COMMAND
943dnl S 0 400 root oracle 2805 1 12904 0.00 ora_dism_SEA1X ora_dism_SEA1X
944dnl S 400 400 oracle oracle 19261 1 126488 0.00 tnslsnr /u01/app/oracle/product/db/11.2.0.3/bin/tnslsnr LISTENER -inherit
945elif env UNIX95=1 ps -eo 'state uid ruid user ruser pid ppid vsz pcpu comm args' 2>/dev/null | head -n 1 | \
946 egrep -i ["^ *S +UID +RUID +USER +RUSER +PID +PPID +VSZ +%CPU +COMMAND +COMMAND"] >/dev/null
947then
948 ac_cv_ps_varlist="[procstat,&procuid,&procpid,&procppid,&procvsz,&procpcpu,procprog,&pos]"
949 ac_cv_ps_command="$PATH_TO_ENV UNIX95=1 $PATH_TO_PS -eo 'state uid pid ppid vsz pcpu comm args'"
950 ac_cv_ps_format="%s %d %d %d %d %f %s %n"
951 ac_cv_ps_cols=8
952 AC_MSG_RESULT([$ac_cv_ps_command])
953
935dnl AIX 4.1: 954dnl AIX 4.1:
936dnl F S UID PID PPID C PRI NI ADDR SZ RSS WCHAN TTY TIME CMD 955dnl F S UID PID PPID C PRI NI ADDR SZ RSS WCHAN TTY TIME CMD
937dnl 303 A 0 0 0 120 16 -- 1c07 20 24 - 0:45 swapper 956dnl 303 A 0 0 0 120 16 -- 1c07 20 24 - 0:45 swapper
@@ -1465,6 +1484,16 @@ else
1465 AC_MSG_WARN([Get ssh in order to make check_by_ssh plugin]) 1484 AC_MSG_WARN([Get ssh in order to make check_by_ssh plugin])
1466fi 1485fi
1467 1486
1487AC_PATH_PROG(PATH_TO_SUDO,sudo)
1488AC_ARG_WITH(sudo_command,
1489 ACX_HELP_STRING([--with-sudo-command=PATH],
1490 [sets path to sudo]), PATH_TO_SUDO=$withval)
1491if test -n "$PATH_TO_SUDO"
1492then
1493 AC_DEFINE_UNQUOTED(PATH_TO_SUDO,"$PATH_TO_SUDO",[path to sudo])
1494else
1495 AC_MSG_WARN([Could not find sudo or eqivalent])
1496fi
1468 1497
1469AC_PATH_PROG(PATH_TO_MAILQ,mailq) 1498AC_PATH_PROG(PATH_TO_MAILQ,mailq)
1470AC_ARG_WITH(mailq_command, 1499AC_ARG_WITH(mailq_command,
@@ -1478,9 +1507,12 @@ else
1478fi 1507fi
1479 1508
1480AC_PATH_PROG(PATH_TO_QMAIL_QSTAT,qmail-qstat) 1509AC_PATH_PROG(PATH_TO_QMAIL_QSTAT,qmail-qstat)
1481if test -x "$PATH_TO_QMAIL_QSTAT" 1510AC_ARG_WITH(qmail_qstat_command,
1511 ACX_HELP_STRING([--with-qmail-qstat-command=PATH],
1512 [sets path to qmail-qstat]), PATH_TO_QMAIL_QSTAT=$withval)
1513if test -n "$PATH_TO_QMAIL_QSTAT"
1482then 1514then
1483 AC_DEFINE_UNQUOTED(PATH_TO_MAILQ,"$PATH_TO_QMAIL_QSTAT",[path to qmail-qstat]) 1515 AC_DEFINE_UNQUOTED(PATH_TO_QMAIL_QSTAT,"$PATH_TO_QMAIL_QSTAT",[path to qmail-qstat])
1484else 1516else
1485 AC_MSG_WARN([Could not find qmail-qstat or eqivalent]) 1517 AC_MSG_WARN([Could not find qmail-qstat or eqivalent])
1486fi 1518fi
diff --git a/doc/RELEASING b/doc/RELEASING
index 1eaec9d..30c81cc 100644
--- a/doc/RELEASING
+++ b/doc/RELEASING
@@ -1,4 +1,4 @@
1NOTES ON RELEASING NEW VERSION OF NAGIOSPLUG 1NOTES ON RELEASING NEW VERSION OF MONITORING-PLUGINS
2 2
3*** Pre-release 3*** Pre-release
4git pull 4git pull
@@ -6,55 +6,33 @@ git pull
6check compilation, check tinderbox screens 6check compilation, check tinderbox screens
7 7
8*** Prepare and commit files 8*** Prepare and commit files
9Update BUGS, NEWS file 9Update NEWS file
10Update AUTHORS if new members 10Update AUTHORS if new members
11Update configure.in, package.def and NP-VERSION-GEN with version 11Update configure.ac and NP-VERSION-GEN with version
12Run git2cl (get from http://josefsson.org/git2cl/): 12commit NEWS configure.ac NP-VERSION-GEN
13git2cl >Changelog
14commit BUGS NEWS configure.in package.def ChangeLog
15 13
16*** Create new annotated tag 14*** Create new annotated tag
17git tag -a release-1.4.14 -m release-1.4.14 15git tag -a v2.1.1 -m v2.1.1
18 16
19*** Push the code and tag to origin 17*** Push the code and tag to origin
20git push origin master 18git push origin master
21git push origin release-1.4.14 19git push origin v2.1.1
22 20
23*** Checkout new version 21*** Checkout new version
24rm -fr /tmp/monitoringlug 22rm -fr /tmp/monitoringplug
25# If you need to checkout the tag, don't forget to "checkout master" later to 23# If you need to checkout the tag, don't forget to "checkout master" later to
26# get back to your development branch: 24# get back to your development branch:
27git checkout tags/release-1.4.14 25git checkout tags/v2.1.1
28# Beware: the trailing slash of --prefix is REQUIRED 26# Beware: the trailing slash of --prefix is REQUIRED
29git checkout-index --prefix=/tmp/monitoringlug/ -a 27git checkout-index --prefix=/tmp/monitoringplug/ -a
30 28
31*** Build the tarball 29*** Build the tarball
32cd /tmp/monitoringlug 30cd /tmp/monitoringplug
33tools/setup 31tools/setup
34./configure 32./configure
35make dist 33make dist
36 34
37*** Upload generated tarball to sourceforge 35*** Upload generated tarball to our Project Site
38sftp frs.sourceforge.net
39SF username and password
40cd /uploads
41put file
42
43SF -> Submit News about release. Make sure it is called "Monitoring Plugins" (with those caps)
44Link to download at http://sourceforge.net/project/showfiles.php?group_id=29880
45Include contents of NEWS for this release
46List all people on team involved.
47Add acknowledgement to contributors
48Submit. Get URL to news item
49
50SF -> Admin -> File Releases
51Add a release to nagiosplug and create a file release
52Name: 1.4.14
53Create release
54Step 1: Add release notes pointing to news item
55Step 2: add file
56Step 3: *.tar.gz, Platform Independent, Source .gz
57Step 4: Send notice
58 36
59*** Announce new release 37*** Announce new release
60Send email to help, announce with the news text 38Send email to help, announce with the news text
diff --git a/lib/utils_base.c b/lib/utils_base.c
index addf26b..3822bcf 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -446,6 +446,7 @@ void np_enable_state(char *keyname, int expected_data_version) {
446 char *temp_filename = NULL; 446 char *temp_filename = NULL;
447 char *temp_keyname = NULL; 447 char *temp_keyname = NULL;
448 char *p=NULL; 448 char *p=NULL;
449 int ret;
449 450
450 if(this_monitoring_plugin==NULL) 451 if(this_monitoring_plugin==NULL)
451 die(STATE_UNKNOWN, _("This requires np_init to be called")); 452 die(STATE_UNKNOWN, _("This requires np_init to be called"));
@@ -476,9 +477,13 @@ void np_enable_state(char *keyname, int expected_data_version) {
476 this_state->state_data=NULL; 477 this_state->state_data=NULL;
477 478
478 /* Calculate filename */ 479 /* Calculate filename */
479 asprintf(&temp_filename, "%s/%lu/%s/%s", 480 ret = asprintf(&temp_filename, "%s/%lu/%s/%s",
480 _np_state_calculate_location_prefix(), (unsigned long)geteuid(), 481 _np_state_calculate_location_prefix(), (unsigned long)geteuid(),
481 this_monitoring_plugin->plugin_name, this_state->name); 482 this_monitoring_plugin->plugin_name, this_state->name);
483 if (ret < 0)
484 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
485 strerror(errno));
486
482 this_state->_filename=temp_filename; 487 this_state->_filename=temp_filename;
483 488
484 this_monitoring_plugin->state = this_state; 489 this_monitoring_plugin->state = this_state;
@@ -614,8 +619,8 @@ void np_state_write_string(time_t data_time, char *data_string) {
614 619
615 /* If file doesn't currently exist, create directories */ 620 /* If file doesn't currently exist, create directories */
616 if(access(this_monitoring_plugin->state->_filename,F_OK)!=0) { 621 if(access(this_monitoring_plugin->state->_filename,F_OK)!=0) {
617 asprintf(&directories, "%s", this_monitoring_plugin->state->_filename); 622 result = asprintf(&directories, "%s", this_monitoring_plugin->state->_filename);
618 if(directories==NULL) 623 if(result < 0)
619 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), 624 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
620 strerror(errno)); 625 strerror(errno));
621 626
@@ -633,8 +638,8 @@ void np_state_write_string(time_t data_time, char *data_string) {
633 np_free(directories); 638 np_free(directories);
634 } 639 }
635 640
636 asprintf(&temp_file,"%s.XXXXXX",this_monitoring_plugin->state->_filename); 641 result = asprintf(&temp_file,"%s.XXXXXX",this_monitoring_plugin->state->_filename);
637 if(temp_file==NULL) 642 if(result < 0)
638 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), 643 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
639 strerror(errno)); 644 strerror(errno));
640 645
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c
index 9e214bd..7eb9a3a 100644
--- a/lib/utils_cmd.c
+++ b/lib/utils_cmd.c
@@ -79,12 +79,14 @@ static pid_t *_cmd_pids = NULL;
79 * If that fails and the macro isn't defined, we fall back to an educated 79 * If that fails and the macro isn't defined, we fall back to an educated
80 * guess. There's no guarantee that our guess is adequate and the program 80 * guess. There's no guarantee that our guess is adequate and the program
81 * will die with SIGSEGV if it isn't and the upper boundary is breached. */ 81 * will die with SIGSEGV if it isn't and the upper boundary is breached. */
82#define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */
83#define MAXFD_LIMIT 8192 /* upper limit of open files */
82#ifdef _SC_OPEN_MAX 84#ifdef _SC_OPEN_MAX
83static long maxfd = 0; 85static long maxfd = 0;
84#elif defined(OPEN_MAX) 86#elif defined(OPEN_MAX)
85# define maxfd OPEN_MAX 87# define maxfd OPEN_MAX
86#else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */ 88#else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */
87# define maxfd 256 89# define maxfd DEFAULT_MAXFD
88#endif 90#endif
89 91
90 92
@@ -112,10 +114,18 @@ cmd_init (void)
112 if (!maxfd && (maxfd = sysconf (_SC_OPEN_MAX)) < 0) { 114 if (!maxfd && (maxfd = sysconf (_SC_OPEN_MAX)) < 0) {
113 /* possibly log or emit a warning here, since there's no 115 /* possibly log or emit a warning here, since there's no
114 * guarantee that our guess at maxfd will be adequate */ 116 * guarantee that our guess at maxfd will be adequate */
115 maxfd = 256; 117 maxfd = DEFAULT_MAXFD;
116 } 118 }
117#endif 119#endif
118 120
121 /* if maxfd is unnaturally high, we force it to a lower value
122 * ( e.g. on SunOS, when ulimit is set to unlimited: 2147483647 this would cause
123 * a segfault when following calloc is called ... ) */
124
125 if ( maxfd > MAXFD_LIMIT ) {
126 maxfd = MAXFD_LIMIT;
127 }
128
119 if (!_cmd_pids) 129 if (!_cmd_pids)
120 _cmd_pids = calloc (maxfd, sizeof (pid_t)); 130 _cmd_pids = calloc (maxfd, sizeof (pid_t));
121} 131}
diff --git a/monitoring-plugins.spec.in b/monitoring-plugins.spec.in
deleted file mode 100644
index f003498..0000000
--- a/monitoring-plugins.spec.in
+++ /dev/null
@@ -1,201 +0,0 @@
1# Macros
2%define isaix %(test "`uname -s`" = "AIX" && echo "1" || echo "0")
3%define islinux %(test "`uname -s`" = "Linux" && echo "1" || echo "0")
4%define isredhatfamily %(test -f /etc/redhat-release && echo "1" || echo "0")
5
6%if %{isaix}
7 %define _prefix /opt/nagios
8# %define _defaultdocdir %{_datadir}/doc
9%else
10 %define _libexecdir %{_exec_prefix}/lib/nagios/plugins
11%endif
12%define _sysconfdir /etc/nagios
13
14%define npusr nagios
15%define nphome /opt/nagios
16%define npgrp nagios
17
18Name: monitoring-plugins
19Version: @PACKAGE_VERSION@
20Release: @RELEASE@
21Summary: Host/service/network monitoring program plugins for Nagios and compatible
22
23Group: Applications/System
24License: GPL
25URL: https://www.monitoring-plugins.org/
26Source0: https://www.monitoring-plugins.org/download/%{name}-%{version}.tar.gz
27BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
28
29%define npdir %{_builddir}/%{name}-%{version}
30
31%if %{isaix}
32Prefix: %{_prefix}
33%else
34Prefix: %{_prefix}/lib/nagios/plugins
35%endif
36Packager: Karl DeBisschop <kdebisschop@users.sourceforge.net>
37Vendor: Monitoring Plugins Development Team
38Provides: monitoring-plugins
39
40%{!?custom:%global custom 0}
41Obsoletes: monitoring-plugins-custom monitoring-plugins-extras
42
43
44# Requires
45%if %{isaix}
46Requires: fping
47Requires: gawk
48Requires: net-snmp
49Requires: net-snmp-perl
50Requires: net-snmp-utils
51Requires: openldap
52Requires: openssl
53Requires: perl
54Requires: python
55Requires: openssl
56BuildRequires: fping
57BuildRequires: gawk
58BuildRequires: net-snmp
59BuildRequires: net-snmp-perl
60BuildRequires: net-snmp-utils
61BuildRequires: openldap-devel
62%endif
63%if %{isredhatfamily}
64Requires: bind-utils
65Requires: coreutils
66Requires: fping
67Requires: gawk
68Requires: grep
69Requires: iputils
70Requires: mysql
71Requires: net-snmp-utils
72Requires: ntp
73Requires: openldap
74Requires: openssl
75Requires: openssh-clients
76Requires: perl
77Requires: postgresql-libs
78Requires: procps
79Requires: python
80Requires: samba-client
81Requires: shadow-utils
82Requires: traceroute
83Requires: /usr/bin/mailq
84BuildRequires: bind-utils
85BuildRequires: coreutils
86BuildRequires: iputils
87BuildRequires: mysql-devel
88BuildRequires: net-snmp-utils
89BuildRequires: net-tools
90BuildRequires: ntp
91BuildRequires: openldap-devel
92BuildRequires: openssh-clients
93BuildRequires: openssl-devel
94BuildRequires: postgresql-devel
95BuildRequires: procps
96BuildRequires: samba-client
97BuildRequires: /usr/bin/mailq
98%endif
99
100
101%description
102
103Nagios is a program that will monitor hosts and services on your
104network, and to email or page you when a problem arises or is
105resolved. Nagios runs on a unix server as a background or daemon
106process, intermittently running checks on various services that you
107specify. The actual service checks are performed by separate "plugin"
108programs which return the status of the checks to the monitoring
109system. This package contains those plugins.
110
111
112%prep
113%setup -q
114
115
116%build
117%{?isaix: MAKE=gmake} ./configure \
118--prefix=%{_prefix} \
119--exec-prefix=%{_exec_prefix} \
120--libexecdir=%{_libexecdir} \
121--sysconfdir=%{_sysconfdir} \
122--datadir=%{_datadir} \
123--with-cgiurl=/nagios/cgi-bin
124ls -1 %{npdir}/plugins > %{npdir}/ls-plugins-before
125ls -1 %{npdir}/plugins-root > %{npdir}/ls-plugins-root-before
126ls -1 %{npdir}/plugins-scripts > %{npdir}/ls-plugins-scripts-before
127make %{?_smp_mflags}
128ls -1 %{npdir}/plugins > %{npdir}/ls-plugins-after
129ls -1 %{npdir}/plugins-root > %{npdir}/ls-plugins-root-after
130ls -1 %{npdir}/plugins-scripts > %{npdir}/ls-plugins-scripts-after
131
132%pre
133# Create `nagios' group on the system if necessary
134%if %{isaix}
135lsgroup %{npgrp} > /dev/null 2> /dev/null
136if [ $? -eq 2 ] ; then
137 mkgroup %{npgrp} || %nnmmsg Unexpected error adding group "%{npgrp}". Aborting install process.
138fi
139%endif
140%if %{islinux}
141getent group %{npgrp} > /dev/null 2> /dev/null
142if [ $? -ne 0 ] ; then
143 groupadd %{npgrp} || %nnmmsg Unexpected error adding group "%{npgrp}". Aborting install process.
144fi
145%endif
146
147# Create `nagios' user on the system if necessary
148%if %{isaix}
149lsuser %{npusr} > /dev/null 2> /dev/null
150if [ $? -eq 2 ] ; then
151 useradd -d %{nphome} -c "%{npusr}" -g %{npgrp} %{npusr} || \
152 %nnmmsg Unexpected error adding user "%{npusr}". Aborting install process.
153fi
154%endif
155%if %{islinux}
156getent passwd %{npusr} > /dev/null 2> /dev/null
157if [ $? -ne 0 ] ; then
158 useradd -r -d %{nshome} -c "%{npusr}" -g %{npgrp} %{npusr} || \
159 %nnmmsg Unexpected error adding user "%{npusr}". Aborting install process.
160fi
161%endif
162
163%install
164rm -rf $RPM_BUILD_ROOT
165make AM_INSTALL_PROGRAM_FLAGS="" DESTDIR=${RPM_BUILD_ROOT} install
166%find_lang %{name}
167echo "%defattr(755,%{npusr},%{npgrp})" >> %{name}.lang
168comm -13 %{npdir}/ls-plugins-before %{npdir}/ls-plugins-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecdir} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
169echo "%defattr(755,root,root)" >> %{name}.lang
170comm -13 %{npdir}/ls-plugins-root-before %{npdir}/ls-plugins-root-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecdir} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
171echo "%defattr(755,%{npusr},%{npgrp})" >> %{name}.lang
172comm -13 %{npdir}/ls-plugins-scripts-before %{npdir}/ls-plugins-scripts-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecdir} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
173echo "%{_libexecdir}/utils.pm" >> %{name}.lang
174echo "%{_libexecdir}/utils.sh" >> %{name}.lang
175echo "%{_libexecdir}/check_ldaps" >> %{name}.lang
176
177sed -i '/libnpcommon/d' %{name}.lang
178sed -i '/monitoring-plugins.mo/d' %{name}.lang
179
180%clean
181rm -rf $RPM_BUILD_ROOT
182
183
184%files -f %{name}.lang
185%config(missingok,noreplace) %{_sysconfdir}/command.cfg
186%doc CODING COPYING FAQ INSTALL LEGAL README REQUIREMENTS SUPPORT THANKS
187%doc ChangeLog command.cfg
188%if ! %{isaix}
189%{_datadir}/locale/de/LC_MESSAGES/monitoring-plugins.mo
190%{_datadir}/locale/fr/LC_MESSAGES/monitoring-plugins.mo
191%endif
192
193%changelog
194* Mon May 23 2005 Sean Finney <seanius@seanius.net> - cvs head
195- just include the nagios plugins directory, which will automatically include
196 all generated plugins (which keeps the build from failing on systems that
197 don't have all build-dependencies for every plugin)
198* Tue Mar 04 2004 Karl DeBisschop <karl[AT]debisschop.net> - 1.4.0alpha1
199- extensive rewrite to facilitate processing into various distro-compatible specs
200* Tue Mar 04 2004 Karl DeBisschop <karl[AT]debisschop.net> - 1.4.0alpha1
201- extensive rewrite to facilitate processing into various distro-compatible specs
diff --git a/perlmods/Monitoring-Plugin-0.37.tar.gz b/perlmods/Monitoring-Plugin-0.37.tar.gz
deleted file mode 100644
index bb6fe69..0000000
--- a/perlmods/Monitoring-Plugin-0.37.tar.gz
+++ /dev/null
Binary files differ
diff --git a/perlmods/Monitoring-Plugin-0.39.tar.gz b/perlmods/Monitoring-Plugin-0.39.tar.gz
new file mode 100644
index 0000000..7a35d9e
--- /dev/null
+++ b/perlmods/Monitoring-Plugin-0.39.tar.gz
Binary files differ
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 8b563e4..f420837 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -184,7 +184,7 @@ static u_int get_timevar(const char *);
184static u_int get_timevaldiff(struct timeval *, struct timeval *); 184static u_int get_timevaldiff(struct timeval *, struct timeval *);
185static in_addr_t get_ip_address(const char *); 185static in_addr_t get_ip_address(const char *);
186static int wait_for_reply(int, u_int); 186static int wait_for_reply(int, u_int);
187static int recvfrom_wto(int, void *, unsigned int, struct sockaddr *, u_int *); 187static int recvfrom_wto(int, void *, unsigned int, struct sockaddr *, u_int *, struct timeval*);
188static int send_icmp_ping(int, struct rta_host *); 188static int send_icmp_ping(int, struct rta_host *);
189static int get_threshold(char *str, threshold *th); 189static int get_threshold(char *str, threshold *th);
190static void run_checks(void); 190static void run_checks(void);
@@ -378,6 +378,9 @@ main(int argc, char **argv)
378 int icmp_sockerrno, udp_sockerrno, tcp_sockerrno; 378 int icmp_sockerrno, udp_sockerrno, tcp_sockerrno;
379 int result; 379 int result;
380 struct rta_host *host; 380 struct rta_host *host;
381#ifdef SO_TIMESTAMP
382 int on = 1;
383#endif
381 384
382 setlocale (LC_ALL, ""); 385 setlocale (LC_ALL, "");
383 bindtextdomain (PACKAGE, LOCALEDIR); 386 bindtextdomain (PACKAGE, LOCALEDIR);
@@ -402,6 +405,11 @@ main(int argc, char **argv)
402 /* now drop privileges (no effect if not setsuid or geteuid() == 0) */ 405 /* now drop privileges (no effect if not setsuid or geteuid() == 0) */
403 setuid(getuid()); 406 setuid(getuid());
404 407
408#ifdef SO_TIMESTAMP
409 if(setsockopt(icmp_sock, SOL_SOCKET, SO_TIMESTAMP, &on, sizeof(on)))
410 if(debug) printf("Warning: no SO_TIMESTAMP support\n");
411#endif // SO_TIMESTAMP
412
405 /* POSIXLY_CORRECT might break things, so unset it (the portable way) */ 413 /* POSIXLY_CORRECT might break things, so unset it (the portable way) */
406 environ = NULL; 414 environ = NULL;
407 415
@@ -462,13 +470,13 @@ main(int argc, char **argv)
462 /* parse the arguments */ 470 /* parse the arguments */
463 for(i = 1; i < argc; i++) { 471 for(i = 1; i < argc; i++) {
464 while((arg = getopt(argc, argv, "vhVw:c:n:p:t:H:s:i:b:I:l:m:")) != EOF) { 472 while((arg = getopt(argc, argv, "vhVw:c:n:p:t:H:s:i:b:I:l:m:")) != EOF) {
465 long size; 473 unsigned short size;
466 switch(arg) { 474 switch(arg) {
467 case 'v': 475 case 'v':
468 debug++; 476 debug++;
469 break; 477 break;
470 case 'b': 478 case 'b':
471 size = strtol(optarg,NULL,0); 479 size = (unsigned short)strtol(optarg,NULL,0);
472 if (size >= (sizeof(struct icmp) + sizeof(struct icmp_ping_data)) && 480 if (size >= (sizeof(struct icmp) + sizeof(struct icmp_ping_data)) &&
473 size < MAX_PING_DATA) { 481 size < MAX_PING_DATA) {
474 icmp_data_size = size; 482 icmp_data_size = size;
@@ -727,7 +735,7 @@ wait_for_reply(int sock, u_int t)
727 735
728 /* reap responses until we hit a timeout */ 736 /* reap responses until we hit a timeout */
729 n = recvfrom_wto(sock, buf, sizeof(buf), 737 n = recvfrom_wto(sock, buf, sizeof(buf),
730 (struct sockaddr *)&resp_addr, &t); 738 (struct sockaddr *)&resp_addr, &t, &now);
731 if(!n) { 739 if(!n) {
732 if(debug > 1) { 740 if(debug > 1) {
733 printf("recvfrom_wto() timed out during a %u usecs wait\n", 741 printf("recvfrom_wto() timed out during a %u usecs wait\n",
@@ -777,11 +785,11 @@ wait_for_reply(int sock, u_int t)
777 /* this is indeed a valid response */ 785 /* this is indeed a valid response */
778 memcpy(&data, icp.icmp_data, sizeof(data)); 786 memcpy(&data, icp.icmp_data, sizeof(data));
779 if (debug > 2) 787 if (debug > 2)
780 printf("ICMP echo-reply of len %u, id %u, seq %u, cksum 0x%X\n", 788 printf("ICMP echo-reply of len %lu, id %u, seq %u, cksum 0x%X\n",
781 sizeof(data), ntohs(icp.icmp_id), ntohs(icp.icmp_seq), icp.icmp_cksum); 789 (unsigned long)sizeof(data), ntohs(icp.icmp_id),
790 ntohs(icp.icmp_seq), icp.icmp_cksum);
782 791
783 host = table[ntohs(icp.icmp_seq)/packets]; 792 host = table[ntohs(icp.icmp_seq)/packets];
784 gettimeofday(&now, &tz);
785 tdiff = get_timevaldiff(&data.stime, &now); 793 tdiff = get_timevaldiff(&data.stime, &now);
786 794
787 host->time_waited += tdiff; 795 host->time_waited += tdiff;
@@ -823,6 +831,8 @@ send_icmp_ping(int sock, struct rta_host *host)
823 } packet = { NULL }; 831 } packet = { NULL };
824 long int len; 832 long int len;
825 struct icmp_ping_data data; 833 struct icmp_ping_data data;
834 struct msghdr hdr;
835 struct iovec iov;
826 struct timeval tv; 836 struct timeval tv;
827 struct sockaddr *addr; 837 struct sockaddr *addr;
828 838
@@ -855,11 +865,27 @@ send_icmp_ping(int sock, struct rta_host *host)
855 packet.icp->icmp_cksum = icmp_checksum(packet.cksum_in, icmp_pkt_size); 865 packet.icp->icmp_cksum = icmp_checksum(packet.cksum_in, icmp_pkt_size);
856 866
857 if (debug > 2) 867 if (debug > 2)
858 printf("Sending ICMP echo-request of len %u, id %u, seq %u, cksum 0x%X to host %s\n", 868 printf("Sending ICMP echo-request of len %lu, id %u, seq %u, cksum 0x%X to host %s\n",
859 sizeof(data), ntohs(packet.icp->icmp_id), ntohs(packet.icp->icmp_seq), packet.icp->icmp_cksum, host->name); 869 (unsigned long)sizeof(data), ntohs(packet.icp->icmp_id),
860 870 ntohs(packet.icp->icmp_seq), packet.icp->icmp_cksum,
861 len = sendto(sock, packet.buf, icmp_pkt_size, 0, (struct sockaddr *)addr, 871 host->name);
862 sizeof(struct sockaddr)); 872
873 memset(&iov, 0, sizeof(iov));
874 iov.iov_base = packet.buf;
875 iov.iov_len = icmp_pkt_size;
876
877 memset(&hdr, 0, sizeof(hdr));
878 hdr.msg_name = addr;
879 hdr.msg_namelen = sizeof(struct sockaddr);
880 hdr.msg_iov = &iov;
881 hdr.msg_iovlen = 1;
882
883/* MSG_CONFIRM is a linux thing and only available on linux kernels >= 2.3.15, see send(2) */
884#ifdef MSG_CONFIRM
885 len = sendmsg(sock, &hdr, MSG_CONFIRM);
886#else
887 len = sendmsg(sock, &hdr, 0);
888#endif
863 889
864 if(len < 0 || (unsigned int)len != icmp_pkt_size) { 890 if(len < 0 || (unsigned int)len != icmp_pkt_size) {
865 if(debug) printf("Failed to send ping to %s\n", 891 if(debug) printf("Failed to send ping to %s\n",
@@ -875,12 +901,18 @@ send_icmp_ping(int sock, struct rta_host *host)
875 901
876static int 902static int
877recvfrom_wto(int sock, void *buf, unsigned int len, struct sockaddr *saddr, 903recvfrom_wto(int sock, void *buf, unsigned int len, struct sockaddr *saddr,
878 u_int *timo) 904 u_int *timo, struct timeval* tv)
879{ 905{
880 u_int slen; 906 u_int slen;
881 int n; 907 int n, ret;
882 struct timeval to, then, now; 908 struct timeval to, then, now;
883 fd_set rd, wr; 909 fd_set rd, wr;
910 char ans_data[4096];
911 struct msghdr hdr;
912 struct iovec iov;
913#ifdef SO_TIMESTAMP
914 struct cmsghdr* chdr;
915#endif
884 916
885 if(!*timo) { 917 if(!*timo) {
886 if(debug) printf("*timo is not\n"); 918 if(debug) printf("*timo is not\n");
@@ -904,7 +936,32 @@ recvfrom_wto(int sock, void *buf, unsigned int len, struct sockaddr *saddr,
904 936
905 slen = sizeof(struct sockaddr); 937 slen = sizeof(struct sockaddr);
906 938
907 return recvfrom(sock, buf, len, 0, saddr, &slen); 939 memset(&iov, 0, sizeof(iov));
940 iov.iov_base = buf;
941 iov.iov_len = len;
942
943 memset(&hdr, 0, sizeof(hdr));
944 hdr.msg_name = saddr;
945 hdr.msg_namelen = slen;
946 hdr.msg_iov = &iov;
947 hdr.msg_iovlen = 1;
948 hdr.msg_control = ans_data;
949 hdr.msg_controllen = sizeof(ans_data);
950
951 ret = recvmsg(sock, &hdr, 0);
952#ifdef SO_TIMESTAMP
953 for(chdr = CMSG_FIRSTHDR(&hdr); chdr; chdr = CMSG_NXTHDR(&hdr, chdr)) {
954 if(chdr->cmsg_level == SOL_SOCKET
955 && chdr->cmsg_type == SO_TIMESTAMP
956 && chdr->cmsg_len >= CMSG_LEN(sizeof(struct timeval))) {
957 memcpy(tv, CMSG_DATA(chdr), sizeof(*tv));
958 break ;
959 }
960 }
961 if (!chdr)
962#endif // SO_TIMESTAMP
963 gettimeofday(tv, &tz);
964 return (ret);
908} 965}
909 966
910static void 967static void
@@ -1183,7 +1240,7 @@ static u_int
1183get_timevar(const char *str) 1240get_timevar(const char *str)
1184{ 1241{
1185 char p, u, *ptr; 1242 char p, u, *ptr;
1186 unsigned int len; 1243 size_t len;
1187 u_int i, d; /* integer and decimal, respectively */ 1244 u_int i, d; /* integer and decimal, respectively */
1188 u_int factor = 1000; /* default to milliseconds */ 1245 u_int factor = 1000; /* default to milliseconds */
1189 1246
diff --git a/plugins-scripts/check_breeze.pl b/plugins-scripts/check_breeze.pl
index 1a3aceb..12a60ee 100755
--- a/plugins-scripts/check_breeze.pl
+++ b/plugins-scripts/check_breeze.pl
@@ -6,7 +6,6 @@ use Getopt::Long;
6use vars qw($opt_V $opt_h $opt_w $opt_c $opt_H $opt_C $PROGNAME); 6use vars qw($opt_V $opt_h $opt_w $opt_c $opt_H $opt_C $PROGNAME);
7use FindBin; 7use FindBin;
8use lib "$FindBin::Bin"; 8use lib "$FindBin::Bin";
9use lib '@libexecdir@';
10use utils qw(%ERRORS &print_revision &support &usage); 9use utils qw(%ERRORS &print_revision &support &usage);
11 10
12$PROGNAME = "check_breeze"; 11$PROGNAME = "check_breeze";
diff --git a/plugins-scripts/check_disk_smb.pl b/plugins-scripts/check_disk_smb.pl
index 4805434..99948a4 100755
--- a/plugins-scripts/check_disk_smb.pl
+++ b/plugins-scripts/check_disk_smb.pl
@@ -26,7 +26,6 @@ use vars qw($opt_P $opt_V $opt_h $opt_H $opt_s $opt_W $opt_u $opt_p $opt_w $opt_
26use vars qw($PROGNAME); 26use vars qw($PROGNAME);
27use FindBin; 27use FindBin;
28use lib "$FindBin::Bin"; 28use lib "$FindBin::Bin";
29use lib '@libexecdir@';
30use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); 29use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
31 30
32sub print_help (); 31sub print_help ();
diff --git a/plugins-scripts/check_file_age.pl b/plugins-scripts/check_file_age.pl
index 453e0f5..15330f7 100755
--- a/plugins-scripts/check_file_age.pl
+++ b/plugins-scripts/check_file_age.pl
@@ -27,14 +27,13 @@ use File::stat;
27use vars qw($PROGNAME); 27use vars qw($PROGNAME);
28use FindBin; 28use FindBin;
29use lib "$FindBin::Bin"; 29use lib "$FindBin::Bin";
30use lib '@libexecdir@';
31use utils qw (%ERRORS &print_revision &support); 30use utils qw (%ERRORS &print_revision &support);
32 31
33sub print_help (); 32sub print_help ();
34sub print_usage (); 33sub print_usage ();
35 34
36my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V, $opt_i); 35my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V, $opt_i);
37my ($result, $message, $age, $size, $st); 36my ($result, $message, $age, $size, $st, $perfdata);
38 37
39$PROGNAME="check_file_age"; 38$PROGNAME="check_file_age";
40 39
@@ -92,6 +91,7 @@ unless (-e $opt_f) {
92$st = File::stat::stat($opt_f); 91$st = File::stat::stat($opt_f);
93$age = time - $st->mtime; 92$age = time - $st->mtime;
94$size = $st->size; 93$size = $st->size;
94$perfdata = "age=${age}s;${opt_w};${opt_c} size=${size}B;${opt_W};${opt_C};0";
95 95
96 96
97$result = 'OK'; 97$result = 'OK';
@@ -103,7 +103,7 @@ elsif (($opt_w and $age > $opt_w) or ($opt_W and $size < $opt_W)) {
103 $result = 'WARNING'; 103 $result = 'WARNING';
104} 104}
105 105
106print "FILE_AGE $result: $opt_f is $age seconds old and $size bytes\n"; 106print "FILE_AGE $result: $opt_f is $age seconds old and $size bytes | $perfdata\n";
107exit $ERRORS{$result}; 107exit $ERRORS{$result};
108 108
109sub print_usage () { 109sub print_usage () {
diff --git a/plugins-scripts/check_flexlm.pl b/plugins-scripts/check_flexlm.pl
index 5f3ed59..49d674d 100755
--- a/plugins-scripts/check_flexlm.pl
+++ b/plugins-scripts/check_flexlm.pl
@@ -37,7 +37,6 @@ use Getopt::Long;
37use vars qw($opt_V $opt_h $opt_F $opt_t $verbose $PROGNAME); 37use vars qw($opt_V $opt_h $opt_F $opt_t $verbose $PROGNAME);
38use FindBin; 38use FindBin;
39use lib "$FindBin::Bin"; 39use lib "$FindBin::Bin";
40use lib '@libexecdir@';
41use utils qw(%ERRORS &print_revision &support &usage); 40use utils qw(%ERRORS &print_revision &support &usage);
42 41
43$PROGNAME="check_flexlm"; 42$PROGNAME="check_flexlm";
diff --git a/plugins-scripts/check_ifoperstatus.pl b/plugins-scripts/check_ifoperstatus.pl
index cf2c7b5..1a7fbba 100755
--- a/plugins-scripts/check_ifoperstatus.pl
+++ b/plugins-scripts/check_ifoperstatus.pl
@@ -37,7 +37,6 @@ use POSIX;
37use strict; 37use strict;
38use FindBin; 38use FindBin;
39use lib "$FindBin::Bin"; 39use lib "$FindBin::Bin";
40use lib '@libexecdir@';
41use utils qw($TIMEOUT %ERRORS &print_revision &support); 40use utils qw($TIMEOUT %ERRORS &print_revision &support);
42 41
43use Net::SNMP; 42use Net::SNMP;
diff --git a/plugins-scripts/check_ifstatus.pl b/plugins-scripts/check_ifstatus.pl
index 709ad17..2c76d0c 100755
--- a/plugins-scripts/check_ifstatus.pl
+++ b/plugins-scripts/check_ifstatus.pl
@@ -9,6 +9,7 @@
9# Added -u option (4/2003) 9# Added -u option (4/2003)
10# Added -M option (10/2003) 10# Added -M option (10/2003)
11# Added SNMPv3 support (10/2003) 11# Added SNMPv3 support (10/2003)
12# Added -n option (07/2014)
12# 13#
13# This program is free software; you can redistribute it and/or 14# This program is free software; you can redistribute it and/or
14# modify it under the terms of the GNU General Public License 15# modify it under the terms of the GNU General Public License
@@ -34,7 +35,6 @@ use POSIX;
34use strict; 35use strict;
35use FindBin; 36use FindBin;
36use lib "$FindBin::Bin"; 37use lib "$FindBin::Bin";
37use lib '@libexecdir@';
38use utils qw($TIMEOUT %ERRORS &print_revision &support); 38use utils qw($TIMEOUT %ERRORS &print_revision &support);
39 39
40use Net::SNMP; 40use Net::SNMP;
@@ -95,8 +95,10 @@ my $ifXTable;
95my $opt_h ; 95my $opt_h ;
96my $opt_V ; 96my $opt_V ;
97my $opt_u; 97my $opt_u;
98my $opt_n;
98my $opt_x ; 99my $opt_x ;
99my %excluded ; 100my %excluded ;
101my %unused_names ;
100my @unused_ports ; 102my @unused_ports ;
101my %session_opts; 103my %session_opts;
102 104
@@ -171,27 +173,30 @@ alarm(0);
171foreach $key (keys %ifStatus) { 173foreach $key (keys %ifStatus) {
172 174
173 # skip unused interfaces 175 # skip unused interfaces
174 if (!defined($ifStatus{$key}{'notInUse'})) { 176 my $ifName = $ifStatus{$key}{$snmpIfDescr};
177
178 if (!defined($ifStatus{$key}{'notInUse'}) && !grep(/^${ifName}/, @unused_ports )) {
175 # check only if interface is administratively up 179 # check only if interface is administratively up
176 if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) { 180 if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) {
177 181 #check only if interface is not excluded
178 # check only if interface type is not listed in %excluded 182 if (!defined $unused_names{$ifStatus{$key}{$snmpIfDescr}} ) {
179 if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) { 183 # check only if interface type is not listed in %excluded
180 if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ;} 184 if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) {
181 if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) { 185 if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ; }
182 $ifdown++ ; 186 if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) {
183 if (defined $ifXTable) { 187 $ifdown++ ;
184 $ifmessage .= sprintf("%s: down -> %s<BR>", 188 if (defined $ifXTable) {
185 $ifStatus{$key}{$snmpIfName}, 189 $ifmessage .= sprintf("%s: down -> %s<BR>\n", $ifStatus{$key}{$snmpIfName}, $ifStatus{$key}{$snmpIfAlias});
186 $ifStatus{$key}{$snmpIfAlias}); 190 }else{
187 }else{ 191 $ifmessage .= sprintf("%s: down <BR>\n",$ifStatus{$key}{$snmpIfDescr});
188 $ifmessage .= sprintf("%s: down <BR>", 192 }
189 $ifStatus{$key}{$snmpIfDescr}); 193 }
190 } 194 if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;}
195 } else {
196 $ifexclude++;
191 } 197 }
192 if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;} 198 } else {
193 }else{ 199 $ifunused++;
194 $ifexclude++;
195 } 200 }
196 201
197 } 202 }
@@ -259,6 +264,8 @@ sub print_help() {
259 printf " the descriptive name. Do not use if you don't know what this is. \n"; 264 printf " the descriptive name. Do not use if you don't know what this is. \n";
260 printf " -x (--exclude) A comma separated list of ifType values that should be excluded \n"; 265 printf " -x (--exclude) A comma separated list of ifType values that should be excluded \n";
261 printf " from the report (default for an empty list is PPP(23).\n"; 266 printf " from the report (default for an empty list is PPP(23).\n";
267 printf " -n (--unused_ports_by_name) A comma separated list of ifDescr values that should be excluded \n";
268 printf " from the report (default is an empty exclusion list).\n";
262 printf " -u (--unused_ports) A comma separated list of ifIndex values that should be excluded \n"; 269 printf " -u (--unused_ports) A comma separated list of ifIndex values that should be excluded \n";
263 printf " from the report (default is an empty exclusion list).\n"; 270 printf " from the report (default is an empty exclusion list).\n";
264 printf " See the IANAifType-MIB for a list of interface types.\n"; 271 printf " See the IANAifType-MIB for a list of interface types.\n";
@@ -299,6 +306,7 @@ sub process_arguments() {
299 "I" => \$ifXTable, "ifmib" => \$ifXTable, 306 "I" => \$ifXTable, "ifmib" => \$ifXTable,
300 "x:s" => \$opt_x, "exclude:s" => \$opt_x, 307 "x:s" => \$opt_x, "exclude:s" => \$opt_x,
301 "u=s" => \$opt_u, "unused_ports=s" => \$opt_u, 308 "u=s" => \$opt_u, "unused_ports=s" => \$opt_u,
309 "n=s" => \$opt_n, "unused_ports_by_name=s" => \$opt_n,
302 "M=i" => \$maxmsgsize, "maxmsgsize=i" => \$maxmsgsize, 310 "M=i" => \$maxmsgsize, "maxmsgsize=i" => \$maxmsgsize,
303 "t=i" => \$timeout, "timeout=i" => \$timeout, 311 "t=i" => \$timeout, "timeout=i" => \$timeout,
304 ); 312 );
@@ -406,6 +414,16 @@ sub process_arguments() {
406 } 414 }
407 } 415 }
408 416
417 # Excluded interface descriptors
418 if (defined $opt_n) {
419 my @unused = split(/,/,$opt_n);
420 if ( @unused ) {
421 foreach $key (@unused) {
422 $unused_names{$key} = 1;
423 }
424 }
425 }
426
409 # Excluded interface ports (ifIndex) - management reasons 427 # Excluded interface ports (ifIndex) - management reasons
410 if ($opt_u) { 428 if ($opt_u) {
411 @unused_ports = split(/,/,$opt_u); 429 @unused_ports = split(/,/,$opt_u);
diff --git a/plugins-scripts/check_ircd.pl b/plugins-scripts/check_ircd.pl
index 6d40cf5..afedfb9 100755
--- a/plugins-scripts/check_ircd.pl
+++ b/plugins-scripts/check_ircd.pl
@@ -51,7 +51,6 @@ use vars qw($opt_V $opt_h $opt_t $opt_p $opt_H $opt_w $opt_c $verbose);
51use vars qw($PROGNAME); 51use vars qw($PROGNAME);
52use FindBin; 52use FindBin;
53use lib "$FindBin::Bin"; 53use lib "$FindBin::Bin";
54use lib '@libexecdir@';
55use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); 54use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
56 55
57# ----------------------------------------------------[ Function Prototypes ]-- 56# ----------------------------------------------------[ Function Prototypes ]--
diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh
index 8653a5e..d28c8d0 100755
--- a/plugins-scripts/check_log.sh
+++ b/plugins-scripts/check_log.sh
@@ -58,12 +58,11 @@
58# Paths to commands used in this script. These 58# Paths to commands used in this script. These
59# may have to be modified to match your system setup. 59# may have to be modified to match your system setup.
60 60
61PROGNAME=`/bin/basename $0`
62PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
63REVISION="@NP_VERSION@"
64PATH="@TRUSTED_PATH@" 61PATH="@TRUSTED_PATH@"
65
66export PATH 62export PATH
63PROGNAME=`basename $0`
64PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
65REVISION="@NP_VERSION@"
67 66
68. $PROGPATH/utils.sh 67. $PROGPATH/utils.sh
69 68
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl
index bd78981..3086e94 100755
--- a/plugins-scripts/check_mailq.pl
+++ b/plugins-scripts/check_mailq.pl
@@ -28,14 +28,14 @@
28use POSIX; 28use POSIX;
29use strict; 29use strict;
30use Getopt::Long; 30use Getopt::Long;
31use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t 31use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t $opt_s
32 $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $mailq @lines 32 $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $mailq @lines
33 %srcdomains %dstdomains); 33 %srcdomains %dstdomains);
34use FindBin; 34use FindBin;
35use lib "$FindBin::Bin"; 35use lib "$FindBin::Bin";
36use lib '@libexecdir@';
37use utils qw(%ERRORS &print_revision &support &usage ); 36use utils qw(%ERRORS &print_revision &support &usage );
38 37
38my ($sudo);
39 39
40sub print_help (); 40sub print_help ();
41sub print_usage (); 41sub print_usage ();
@@ -57,6 +57,17 @@ if ($status){
57 exit $ERRORS{"UNKNOWN"}; 57 exit $ERRORS{"UNKNOWN"};
58} 58}
59 59
60if ($opt_s) {
61 if (defined $utils::PATH_TO_SUDO && -x $utils::PATH_TO_SUDO) {
62 $sudo = $utils::PATH_TO_SUDO;
63 } else {
64 print "ERROR: Cannot execute sudo\n";
65 exit $ERRORS{'UNKNOWN'};
66 }
67} else {
68 $sudo = "";
69}
70
60$SIG{'ALRM'} = sub { 71$SIG{'ALRM'} = sub {
61 print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n"); 72 print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n");
62 exit $ERRORS{"WARNING"}; 73 exit $ERRORS{"WARNING"};
@@ -69,7 +80,7 @@ if ($mailq eq "sendmail") {
69 80
70 ## open mailq 81 ## open mailq
71 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 82 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
72 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { 83 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
73 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 84 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
74 exit $ERRORS{'UNKNOWN'}; 85 exit $ERRORS{'UNKNOWN'};
75 } 86 }
@@ -298,7 +309,7 @@ elsif ( $mailq eq "postfix" ) {
298 309
299 ## open mailq 310 ## open mailq
300 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 311 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
301 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { 312 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
302 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 313 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
303 exit $ERRORS{'UNKNOWN'}; 314 exit $ERRORS{'UNKNOWN'};
304 } 315 }
@@ -332,7 +343,7 @@ elsif ( $mailq eq "postfix" ) {
332 }elsif ($lines[0]=~/Mail queue is empty/) { 343 }elsif ($lines[0]=~/Mail queue is empty/) {
333 $msg_q = 0; 344 $msg_q = 0;
334 }else{ 345 }else{
335 print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n"; 346 print "Couldn't match $utils::PATH_TO_MAILQ output\n";
336 exit $ERRORS{'UNKNOWN'}; 347 exit $ERRORS{'UNKNOWN'};
337 } 348 }
338 349
@@ -340,7 +351,7 @@ elsif ( $mailq eq "postfix" ) {
340 #if ($lines[1]=~/^messages in queue but not yet preprocessed: (\d+)/) { 351 #if ($lines[1]=~/^messages in queue but not yet preprocessed: (\d+)/) {
341 # my $msg_p = $1; 352 # my $msg_p = $1;
342 #}else{ 353 #}else{
343 # print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n"; 354 # print "Couldn't match $utils::PATH_TO_MAILQ output\n";
344 # exit $ERRORS{'UNKNOWN'}; 355 # exit $ERRORS{'UNKNOWN'};
345 #} 356 #}
346 357
@@ -380,7 +391,7 @@ elsif ( $mailq eq "qmail" ) {
380 391
381 # open qmail-qstat 392 # open qmail-qstat
382 if ( defined $utils::PATH_TO_QMAIL_QSTAT && -x $utils::PATH_TO_QMAIL_QSTAT ) { 393 if ( defined $utils::PATH_TO_QMAIL_QSTAT && -x $utils::PATH_TO_QMAIL_QSTAT ) {
383 if (! open (MAILQ, "$utils::PATH_TO_QMAIL_QSTAT | " ) ) { 394 if (! open (MAILQ, "$sudo $utils::PATH_TO_QMAIL_QSTAT | " ) ) {
384 print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n"; 395 print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n";
385 exit $ERRORS{'UNKNOWN'}; 396 exit $ERRORS{'UNKNOWN'};
386 } 397 }
@@ -462,7 +473,7 @@ elsif ( $mailq eq "qmail" ) {
462elsif ( $mailq eq "exim" ) { 473elsif ( $mailq eq "exim" ) {
463 ## open mailq 474 ## open mailq
464 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 475 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
465 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { 476 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
466 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 477 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
467 exit $ERRORS{'UNKNOWN'}; 478 exit $ERRORS{'UNKNOWN'};
468 } 479 }
@@ -505,7 +516,7 @@ elsif ( $mailq eq "exim" ) {
505elsif ( $mailq eq "nullmailer" ) { 516elsif ( $mailq eq "nullmailer" ) {
506 ## open mailq 517 ## open mailq
507 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 518 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
508 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { 519 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
509 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 520 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
510 exit $ERRORS{'UNKNOWN'}; 521 exit $ERRORS{'UNKNOWN'};
511 } 522 }
@@ -556,7 +567,8 @@ sub process_arguments(){
556 "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail) 567 "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail)
557 "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number 568 "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number
558 "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number 569 "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number
559 "t=i" => \$opt_t, "timeout=i" => \$opt_t 570 "t=i" => \$opt_t, "timeout=i" => \$opt_t,
571 "s" => \$opt_s, "sudo" => \$opt_s
560 ); 572 );
561 573
562 if ($opt_V) { 574 if ($opt_V) {
@@ -637,7 +649,7 @@ sub process_arguments(){
637} 649}
638 650
639sub print_usage () { 651sub print_usage () {
640 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-v verbose]\n"; 652 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-v]\n";
641} 653}
642 654
643sub print_help () { 655sub print_help () {
@@ -654,6 +666,7 @@ sub print_help () {
654 print "-C (--Critical) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; 666 print "-C (--Critical) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n";
655 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; 667 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n";
656 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; 668 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n";
669 print "-s (--sudo) = Use sudo to call the mailq command\n";
657 print "-h (--help)\n"; 670 print "-h (--help)\n";
658 print "-V (--version)\n"; 671 print "-V (--version)\n";
659 print "-v (--verbose) = debugging output\n"; 672 print "-v (--verbose) = debugging output\n";
diff --git a/plugins-scripts/check_mssql.pl b/plugins-scripts/check_mssql.pl
index 1f38788..a436a8f 100755
--- a/plugins-scripts/check_mssql.pl
+++ b/plugins-scripts/check_mssql.pl
@@ -31,7 +31,6 @@ use DBD::Sybase;
31use Getopt::Long; 31use Getopt::Long;
32use FindBin; 32use FindBin;
33use lib "$FindBin::Bin"; 33use lib "$FindBin::Bin";
34use lib '@libexecdir@';
35use utils qw($TIMEOUT %ERRORS &print_revision &support); 34use utils qw($TIMEOUT %ERRORS &print_revision &support);
36use strict; 35use strict;
37 36
diff --git a/plugins-scripts/check_netdns.pl b/plugins-scripts/check_netdns.pl
index 59c81a9..af1456b 100755
--- a/plugins-scripts/check_netdns.pl
+++ b/plugins-scripts/check_netdns.pl
@@ -29,8 +29,7 @@ use Getopt::Long;
29use Net::DNS; 29use Net::DNS;
30use FindBin; 30use FindBin;
31use lib "$FindBin::Bin"; 31use lib "$FindBin::Bin";
32use lib '@libexecdir@'; 32use utils;
33use utils ;
34 33
35my $PROGNAME = "check_netdns"; 34my $PROGNAME = "check_netdns";
36 35
diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh
index ceac95d..96078ac 100755
--- a/plugins-scripts/check_oracle.sh
+++ b/plugins-scripts/check_oracle.sh
@@ -6,10 +6,11 @@
6# This Monitoring plugin was created to check Oracle status 6# This Monitoring plugin was created to check Oracle status
7# 7#
8 8
9PATH="@TRUSTED_PATH@"
10export PATH
9PROGNAME=`basename $0` 11PROGNAME=`basename $0`
10PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` 12PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
11REVISION="@NP_VERSION@" 13REVISION="@NP_VERSION@"
12PATH="@TRUSTED_PATH@"
13 14
14. $PROGPATH/utils.sh 15. $PROGPATH/utils.sh
15 16
@@ -137,7 +138,7 @@ case "$cmd" in
137 tnschk=` tnsping $2` 138 tnschk=` tnsping $2`
138 tnschk2=` echo $tnschk | grep -c OK` 139 tnschk2=` echo $tnschk | grep -c OK`
139 if [ ${tnschk2} -eq 1 ] ; then 140 if [ ${tnschk2} -eq 1 ] ; then
140 tnschk3=` echo $tnschk | sed -e 's/.*(//' -e 's/).*//'` 141 tnschk3=${tnschk##*(}; tnschk3=${tnschk3%)*}
141 echo "OK - reply time ${tnschk3} from $2" 142 echo "OK - reply time ${tnschk3} from $2"
142 exit $STATE_OK 143 exit $STATE_OK
143 else 144 else
diff --git a/plugins-scripts/check_rpc.pl b/plugins-scripts/check_rpc.pl
index b1c6147..cbdeceb 100755
--- a/plugins-scripts/check_rpc.pl
+++ b/plugins-scripts/check_rpc.pl
@@ -22,7 +22,6 @@
22use strict; 22use strict;
23use FindBin; 23use FindBin;
24use lib "$FindBin::Bin"; 24use lib "$FindBin::Bin";
25use lib '@libexecdir@';
26use utils qw($TIMEOUT %ERRORS &print_revision &support); 25use utils qw($TIMEOUT %ERRORS &print_revision &support);
27use vars qw($PROGNAME); 26use vars qw($PROGNAME);
28my ($verbose,@proto,%prognum,$host,$response,$prognum,$port,$cmd,$progver,$state); 27my ($verbose,@proto,%prognum,$host,$response,$prognum,$port,$cmd,$progver,$state);
diff --git a/plugins-scripts/check_sensors.sh b/plugins-scripts/check_sensors.sh
index 05c64c4..f742830 100755
--- a/plugins-scripts/check_sensors.sh
+++ b/plugins-scripts/check_sensors.sh
@@ -1,11 +1,10 @@
1#!/bin/sh 1#!/bin/sh
2 2
3PATH="@TRUSTED_PATH@"
4export PATH
3PROGNAME=`basename $0` 5PROGNAME=`basename $0`
4PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` 6PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
5REVISION="@NP_VERSION@" 7REVISION="@NP_VERSION@"
6PATH="@TRUSTED_PATH@"
7
8export PATH
9 8
10. $PROGPATH/utils.sh 9. $PROGPATH/utils.sh
11 10
diff --git a/plugins-scripts/check_wave.pl b/plugins-scripts/check_wave.pl
index ee0fda4..979416e 100755
--- a/plugins-scripts/check_wave.pl
+++ b/plugins-scripts/check_wave.pl
@@ -5,7 +5,6 @@
5use strict; 5use strict;
6use FindBin; 6use FindBin;
7use lib "$FindBin::Bin"; 7use lib "$FindBin::Bin";
8use lib '@libexecdir@';
9use utils qw($TIMEOUT %ERRORS &print_revision &support); 8use utils qw($TIMEOUT %ERRORS &print_revision &support);
10use vars qw($PROGNAME); 9use vars qw($PROGNAME);
11use Getopt::Long; 10use Getopt::Long;
diff --git a/plugins-scripts/t/check_disk_smb.t b/plugins-scripts/t/check_disk_smb.t
index 831f388..c2e8bbb 100644
--- a/plugins-scripts/t/check_disk_smb.t
+++ b/plugins-scripts/t/check_disk_smb.t
@@ -90,7 +90,7 @@ SKIP: {
90 SKIP: { 90 SKIP: {
91 skip "no non responsive host defined", 1 if ( ! $host_nonresponsive ); 91 skip "no non responsive host defined", 1 if ( ! $host_nonresponsive );
92 $res = NPTest->testCmd( "./$plugin -H $host_nonresponsive -s np_foobar "); 92 $res = NPTest->testCmd( "./$plugin -H $host_nonresponsive -s np_foobar ");
93 cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); 93 cmp_ok( $res->return_code, '>=', 2, "Exit CRITICAL/UNKNOWN with non responsive host" );
94 } 94 }
95 95
96} 96}
diff --git a/plugins-scripts/t/check_file_age.t b/plugins-scripts/t/check_file_age.t
index a515649..50a2e69 100644
--- a/plugins-scripts/t/check_file_age.t
+++ b/plugins-scripts/t/check_file_age.t
@@ -5,13 +5,14 @@
5# 5#
6 6
7use strict; 7use strict;
8use Test::More tests => 16; 8use Test::More tests => 17;
9use NPTest; 9use NPTest;
10 10
11my $successOutput = '/^FILE_AGE OK: /'; 11my $successOutput = '/^FILE_AGE OK: /';
12my $warningOutput = '/^FILE_AGE WARNING: /'; 12my $warningOutput = '/^FILE_AGE WARNING: /';
13my $criticalOutput = '/^FILE_AGE CRITICAL: /'; 13my $criticalOutput = '/^FILE_AGE CRITICAL: /';
14my $unknownOutput = '/^FILE_AGE UNKNOWN: /'; 14my $unknownOutput = '/^FILE_AGE UNKNOWN: /';
15my $performanceOutput = '/ \| age=[0-9]+s;[0-9]+;[0-9]+ size=[0-9]+B;[0-9]+;[0-9]+;0$/';
15 16
16my $result; 17my $result;
17my $temp_file = "/tmp/check_file_age.tmp"; 18my $temp_file = "/tmp/check_file_age.tmp";
@@ -58,6 +59,11 @@ $result = NPTest->testCmd(
58cmp_ok( $result->return_code, '==', 0, "Checking file size" ); 59cmp_ok( $result->return_code, '==', 0, "Checking file size" );
59 60
60$result = NPTest->testCmd( 61$result = NPTest->testCmd(
62 "./check_file_age -f $temp_file -c 1000 -W 100"
63 );
64like( $result->output, $performanceOutput, "Checking for performance Output" );
65
66$result = NPTest->testCmd(
61 "./check_file_age -f /non/existent --ignore-missing" 67 "./check_file_age -f /non/existent --ignore-missing"
62 ); 68 );
63cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" ); 69cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" );
diff --git a/plugins-scripts/utils.pm.in b/plugins-scripts/utils.pm.in
index 0f53243..386831e 100644
--- a/plugins-scripts/utils.pm.in
+++ b/plugins-scripts/utils.pm.in
@@ -17,6 +17,7 @@ sub support();
17sub is_hostname; 17sub is_hostname;
18 18
19## updated by autoconf 19## updated by autoconf
20$PATH_TO_SUDO = "@PATH_TO_SUDO@";
20$PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ; 21$PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ;
21$PATH_TO_LMSTAT = "@PATH_TO_LMSTAT@" ; 22$PATH_TO_LMSTAT = "@PATH_TO_LMSTAT@" ;
22$PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ; 23$PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ;
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 0ddf9bd..41906c5 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -71,7 +71,7 @@ check_apt_LDADD = $(BASEOBJS)
71check_cluster_LDADD = $(BASEOBJS) 71check_cluster_LDADD = $(BASEOBJS)
72check_dbi_LDADD = $(NETLIBS) $(DBILIBS) 72check_dbi_LDADD = $(NETLIBS) $(DBILIBS)
73check_dig_LDADD = $(NETLIBS) 73check_dig_LDADD = $(NETLIBS)
74check_disk_LDADD = $(BASEOBJS) 74check_disk_LDADD = $(BASEOBJS) $(THREADLIBS)
75check_dns_LDADD = $(NETLIBS) 75check_dns_LDADD = $(NETLIBS)
76check_dummy_LDADD = $(BASEOBJS) 76check_dummy_LDADD = $(BASEOBJS)
77check_fping_LDADD = $(NETLIBS) 77check_fping_LDADD = $(NETLIBS)
diff --git a/plugins/check_apt.c b/plugins/check_apt.c
index 07622c2..8747f90 100644
--- a/plugins/check_apt.c
+++ b/plugins/check_apt.c
@@ -224,7 +224,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
224 char *cmdline=NULL, rerrbuf[64]; 224 char *cmdline=NULL, rerrbuf[64];
225 225
226 /* initialize ereg as it is possible it is printed while uninitialized */ 226 /* initialize ereg as it is possible it is printed while uninitialized */
227 memset(&ereg, "\0", sizeof(ereg.buffer)); 227 memset(&ereg, '\0', sizeof(ereg.buffer));
228 228
229 if(upgrade==NO_UPGRADE) return STATE_OK; 229 if(upgrade==NO_UPGRADE) return STATE_OK;
230 230
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 58f333d..a877f88 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -169,7 +169,8 @@ process_arguments (int argc, char **argv)
169 {"verbose", no_argument, 0, 'v'}, 169 {"verbose", no_argument, 0, 'v'},
170 {"fork", no_argument, 0, 'f'}, 170 {"fork", no_argument, 0, 'f'},
171 {"timeout", required_argument, 0, 't'}, 171 {"timeout", required_argument, 0, 't'},
172 {"host", required_argument, 0, 'H'}, 172 {"host", required_argument, 0, 'H'}, /* backward compatibility */
173 {"hostname", required_argument, 0, 'H'},
173 {"port", required_argument,0,'p'}, 174 {"port", required_argument,0,'p'},
174 {"output", required_argument, 0, 'O'}, 175 {"output", required_argument, 0, 'O'},
175 {"name", required_argument, 0, 'n'}, 176 {"name", required_argument, 0, 'n'},
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index d9481f2..d899b11 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -94,8 +94,8 @@ main (int argc, char **argv)
94 timeout_interval_dig = timeout_interval / number_tries + number_tries; 94 timeout_interval_dig = timeout_interval / number_tries + number_tries;
95 95
96 /* get the command to run */ 96 /* get the command to run */
97 xasprintf (&command_line, "%s @%s -p %d %s -t %s %s %s +tries=%d +time=%d", 97 xasprintf (&command_line, "%s %s %s -p %d @%s %s %s +tries=%d +time=%d",
98 PATH_TO_DIG, dns_server, server_port, query_address, record_type, dig_args, query_transport, number_tries, timeout_interval_dig); 98 PATH_TO_DIG, dig_args, query_transport, server_port, dns_server, query_address, record_type, number_tries, timeout_interval_dig);
99 99
100 alarm (timeout_interval); 100 alarm (timeout_interval);
101 gettimeofday (&tv, NULL); 101 gettimeofday (&tv, NULL);
@@ -296,7 +296,10 @@ process_arguments (int argc, char **argv)
296 dns_server = argv[c]; 296 dns_server = argv[c];
297 } 297 }
298 else { 298 else {
299 dns_server = strdup ("127.0.0.1"); 299 if (strcmp(query_transport,"-6") == 0)
300 dns_server = strdup("::1");
301 else
302 dns_server = strdup ("127.0.0.1");
300 } 303 }
301 } 304 }
302 305
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 925dfa8..eb573f5 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -51,6 +51,9 @@ const char *email = "devel@monitoring-plugins.org";
51# include <limits.h> 51# include <limits.h>
52#endif 52#endif
53#include "regex.h" 53#include "regex.h"
54#if HAVE_PTHREAD_H
55# include <pthread.h>
56#endif
54 57
55#ifdef __CYGWIN__ 58#ifdef __CYGWIN__
56# include <windows.h> 59# include <windows.h>
@@ -130,6 +133,7 @@ void print_help (void);
130void print_usage (void); 133void print_usage (void);
131double calculate_percent(uintmax_t, uintmax_t); 134double calculate_percent(uintmax_t, uintmax_t);
132void stat_path (struct parameter_list *p); 135void stat_path (struct parameter_list *p);
136void *do_stat_path (void *p);
133void get_stats (struct parameter_list *p, struct fs_usage *fsp); 137void get_stats (struct parameter_list *p, struct fs_usage *fsp);
134void get_path_stats (struct parameter_list *p, struct fs_usage *fsp); 138void get_path_stats (struct parameter_list *p, struct fs_usage *fsp);
135 139
@@ -171,6 +175,7 @@ main (int argc, char **argv)
171 char *details; 175 char *details;
172 char *perf; 176 char *perf;
173 char *preamble; 177 char *preamble;
178 char *flag_header;
174 double inode_space_pct; 179 double inode_space_pct;
175 double warning_high_tide; 180 double warning_high_tide;
176 double critical_high_tide; 181 double critical_high_tide;
@@ -353,18 +358,23 @@ main (int argc, char **argv)
353 if (disk_result==STATE_OK && erronly && !verbose) 358 if (disk_result==STATE_OK && erronly && !verbose)
354 continue; 359 continue;
355 360
356 xasprintf (&output, "%s %s %.0f %s (%.0f%%", 361 if(disk_result && verbose >= 1) {
357 output, 362 xasprintf(&flag_header, " %s [", state_text (disk_result));
363 } else {
364 xasprintf(&flag_header, "");
365 }
366 xasprintf (&output, "%s%s %s %.0f %s (%.0f%%",
367 output, flag_header,
358 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 368 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
359 path->dfree_units, 369 path->dfree_units,
360 units, 370 units,
361 path->dfree_pct); 371 path->dfree_pct);
362 if (path->dused_inodes_percent < 0) { 372 if (path->dused_inodes_percent < 0) {
363 xasprintf(&output, "%s inode=-);", output); 373 xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : ""));
364 } else { 374 } else {
365 xasprintf(&output, "%s inode=%.0f%%);", output, path->dfree_inodes_percent ); 375 xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : ""));
366 } 376 }
367 377 free(flag_header);
368 /* TODO: Need to do a similar debug line 378 /* TODO: Need to do a similar debug line
369 xasprintf (&details, _("%s\n\ 379 xasprintf (&details, _("%s\n\
370%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), 380%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
@@ -962,6 +972,44 @@ print_usage (void)
962void 972void
963stat_path (struct parameter_list *p) 973stat_path (struct parameter_list *p)
964{ 974{
975#ifdef HAVE_PTHREAD_H
976 pthread_t stat_thread;
977 int statdone = 0;
978 int timer = timeout_interval;
979 struct timespec req, rem;
980
981 req.tv_sec = 0;
982 pthread_create(&stat_thread, NULL, do_stat_path, p);
983 while (timer-- > 0) {
984 req.tv_nsec = 10000000;
985 nanosleep(&req, &rem);
986 if (pthread_kill(stat_thread, 0)) {
987 statdone = 1;
988 break;
989 } else {
990 req.tv_nsec = 990000000;
991 nanosleep(&req, &rem);
992 }
993 }
994 if (statdone == 1) {
995 pthread_join(stat_thread, NULL);
996 } else {
997 pthread_detach(stat_thread);
998 if (verbose >= 3)
999 printf("stat did not return within %ds on %s\n", timeout_interval, p->name);
1000 printf("DISK %s - ", _("CRITICAL"));
1001 die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("hangs"), _("Timeout"));
1002 }
1003#else
1004 do_stat_path(p);
1005#endif
1006}
1007
1008void *
1009do_stat_path (void *in)
1010{
1011 struct parameter_list *p = in;
1012
965 /* Stat entry to check that dir exists and is accessible */ 1013 /* Stat entry to check that dir exists and is accessible */
966 if (verbose >= 3) 1014 if (verbose >= 3)
967 printf("calling stat on %s\n", p->name); 1015 printf("calling stat on %s\n", p->name);
@@ -971,6 +1019,7 @@ stat_path (struct parameter_list *p)
971 printf("DISK %s - ", _("CRITICAL")); 1019 printf("DISK %s - ", _("CRITICAL"));
972 die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno)); 1020 die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno));
973 } 1021 }
1022 return NULL;
974} 1023}
975 1024
976 1025
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 31a953d..2212122 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -136,6 +136,28 @@ main (int argc, char **argv)
136 } 136 }
137 } 137 }
138 138
139 /* bug ID: 2946553 - Older versions of bind will use all available dns
140 servers, we have to match the one specified */
141 if (strstr (chld_out.line[i], "Server:") && strlen(dns_server) > 0) {
142 temp_buffer = strchr (chld_out.line[i], ':');
143 temp_buffer++;
144
145 /* Strip leading tabs */
146 for (; *temp_buffer != '\0' && *temp_buffer == '\t'; temp_buffer++)
147 /* NOOP */;
148
149 strip(temp_buffer);
150 if (temp_buffer==NULL || strlen(temp_buffer)==0) {
151 die (STATE_CRITICAL,
152 _("DNS CRITICAL - '%s' returned empty server string\n"),
153 NSLOOKUP_COMMAND);
154 }
155
156 if (strcmp(temp_buffer, dns_server) != 0) {
157 die (STATE_CRITICAL, _("DNS CRITICAL - No response from DNS %s\n"), dns_server);
158 }
159 }
160
139 /* the server is responding, we just got the host name... */ 161 /* the server is responding, we just got the host name... */
140 if (strstr (chld_out.line[i], "Name:")) 162 if (strstr (chld_out.line[i], "Name:"))
141 parse_address = TRUE; 163 parse_address = TRUE;
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index 46046b4..274dd75 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -105,7 +105,7 @@ main (int argc, char **argv)
105 xasprintf(&option_string, "%s-I %s ", option_string, sourceif); 105 xasprintf(&option_string, "%s-I %s ", option_string, sourceif);
106 106
107#ifdef PATH_TO_FPING6 107#ifdef PATH_TO_FPING6
108 if (address_family == AF_INET6) 108 if (address_family != AF_INET && is_inet6_addr(server))
109 fping_prog = strdup(PATH_TO_FPING6); 109 fping_prog = strdup(PATH_TO_FPING6);
110 else 110 else
111 fping_prog = strdup(PATH_TO_FPING); 111 fping_prog = strdup(PATH_TO_FPING);
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 5167997..2437406 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -875,11 +875,35 @@ check_http (void)
875 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) 875 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK)
876 die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n")); 876 die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n"));
877 microsec_connect = deltime (tv_temp); 877 microsec_connect = deltime (tv_temp);
878
879 /* if we are called with the -I option, the -j method is CONNECT and */
880 /* we received -S for SSL, then we tunnel the request through a proxy*/
881 /* @20100414, public[at]frank4dd.com, http://www.frank4dd.com/howto */
882
883 if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0
884 && host_name != NULL && use_ssl == TRUE) {
885
886 if (verbose) printf ("Entering CONNECT tunnel mode with proxy %s:%d to dst %s:%d\n", server_address, server_port, host_name, HTTPS_PORT);
887 asprintf (&buf, "%s %s:%d HTTP/1.1\r\n%s\r\n", http_method, host_name, HTTPS_PORT, user_agent);
888 asprintf (&buf, "%sProxy-Connection: keep-alive\r\n", buf);
889 asprintf (&buf, "%sHost: %s\r\n", buf, host_name);
890 /* we finished our request, send empty line with CRLF */
891 asprintf (&buf, "%s%s", buf, CRLF);
892 if (verbose) printf ("%s\n", buf);
893 send(sd, buf, strlen (buf), 0);
894 buf[0]='\0';
895
896 if (verbose) printf ("Receive response from proxy\n");
897 read (sd, buffer, MAX_INPUT_BUFFER-1);
898 if (verbose) printf ("%s", buffer);
899 /* Here we should check if we got HTTP/1.1 200 Connection established */
900 }
878#ifdef HAVE_SSL 901#ifdef HAVE_SSL
879 elapsed_time_connect = (double)microsec_connect / 1.0e6; 902 elapsed_time_connect = (double)microsec_connect / 1.0e6;
880 if (use_ssl == TRUE) { 903 if (use_ssl == TRUE) {
881 gettimeofday (&tv_temp, NULL); 904 gettimeofday (&tv_temp, NULL);
882 result = np_net_ssl_init_with_hostname_version_and_cert(sd, (use_sni ? host_name : NULL), ssl_version, client_cert, client_privkey); 905 result = np_net_ssl_init_with_hostname_version_and_cert(sd, (use_sni ? host_name : NULL), ssl_version, client_cert, client_privkey);
906 if (verbose) printf ("SSL initialized\n");
883 if (result != STATE_OK) 907 if (result != STATE_OK)
884 die (STATE_CRITICAL, NULL); 908 die (STATE_CRITICAL, NULL);
885 microsec_ssl = deltime (tv_temp); 909 microsec_ssl = deltime (tv_temp);
@@ -893,7 +917,11 @@ check_http (void)
893 } 917 }
894#endif /* HAVE_SSL */ 918#endif /* HAVE_SSL */
895 919
896 xasprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); 920 if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0
921 && host_name != NULL && use_ssl == TRUE)
922 asprintf (&buf, "%s %s %s\r\n%s\r\n", "GET", server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent);
923 else
924 asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent);
897 925
898 /* tell HTTP/1.1 servers not to keep the connection alive */ 926 /* tell HTTP/1.1 servers not to keep the connection alive */
899 xasprintf (&buf, "%sConnection: close\r\n", buf); 927 xasprintf (&buf, "%sConnection: close\r\n", buf);
@@ -906,7 +934,9 @@ check_http (void)
906 * (default) port is explicitly specified in the "Host:" header line. 934 * (default) port is explicitly specified in the "Host:" header line.
907 */ 935 */
908 if ((use_ssl == FALSE && server_port == HTTP_PORT) || 936 if ((use_ssl == FALSE && server_port == HTTP_PORT) ||
909 (use_ssl == TRUE && server_port == HTTPS_PORT)) 937 (use_ssl == TRUE && server_port == HTTPS_PORT) ||
938 ( server_address != NULL && strcmp(http_method, "CONNECT") == 0
939 && host_name != NULL && use_ssl == TRUE))
910 xasprintf (&buf, "%sHost: %s\r\n", buf, host_name); 940 xasprintf (&buf, "%sHost: %s\r\n", buf, host_name);
911 else 941 else
912 xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port); 942 xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port);
@@ -1496,7 +1526,7 @@ print_help (void)
1496 printf (" %s\n", _("URL to GET or POST (default: /)")); 1526 printf (" %s\n", _("URL to GET or POST (default: /)"));
1497 printf (" %s\n", "-P, --post=STRING"); 1527 printf (" %s\n", "-P, --post=STRING");
1498 printf (" %s\n", _("URL encoded http POST data")); 1528 printf (" %s\n", _("URL encoded http POST data"));
1499 printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE)"); 1529 printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT)");
1500 printf (" %s\n", _("Set HTTP method.")); 1530 printf (" %s\n", _("Set HTTP method."));
1501 printf (" %s\n", "-N, --no-body"); 1531 printf (" %s\n", "-N, --no-body");
1502 printf (" %s\n", _("Don't wait for document body: stop reading after headers.")); 1532 printf (" %s\n", _("Don't wait for document body: stop reading after headers."));
@@ -1570,7 +1600,7 @@ print_help (void)
1570 printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 14 days,")); 1600 printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 14 days,"));
1571 printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than")); 1601 printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than"));
1572 printf (" %s\n", _("14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when")); 1602 printf (" %s\n", _("14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when"));
1573 printf (" %s\n", _("the certificate is expired.")); 1603 printf (" %s\n\n", _("the certificate is expired."));
1574 printf ("\n"); 1604 printf ("\n");
1575 printf (" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 30,14"); 1605 printf (" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 30,14");
1576 printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 30 days,")); 1606 printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 30 days,"));
@@ -1578,6 +1608,13 @@ print_help (void)
1578 printf (" %s\n", _("30 days, but more than 14 days, a STATE_WARNING is returned.")); 1608 printf (" %s\n", _("30 days, but more than 14 days, a STATE_WARNING is returned."));
1579 printf (" %s\n", _("A STATE_CRITICAL will be returned when certificate expires in less than 14 days")); 1609 printf (" %s\n", _("A STATE_CRITICAL will be returned when certificate expires in less than 14 days"));
1580 1610
1611 printf (" %s\n\n", "CHECK SSL WEBSERVER CONTENT VIA PROXY USING HTTP 1.1 CONNECT: ");
1612 printf (" %s\n", _("check_http -I 192.168.100.35 -p 80 -u https://www.verisign.com/ -S -j CONNECT -H www.verisign.com "));
1613 printf (" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> -S(sl) -j CONNECT -H <webserver>"));
1614 printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds"));
1615 printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,"));
1616 printf (" %s\n", _("a STATE_CRITICAL will be returned."));
1617
1581#endif 1618#endif
1582 1619
1583 printf (UT_SUPPORT); 1620 printf (UT_SUPPORT);
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c
index c371be9..cfc8222 100644
--- a/plugins/check_ldap.c
+++ b/plugins/check_ldap.c
@@ -1,29 +1,29 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Monitoring check_ldap plugin 3* Monitoring check_ldap plugin
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 2000-2008 Monitoring Plugins Development Team 6* Copyright (c) 2000-2008 Monitoring Plugins Development Team
7* 7*
8* Description: 8* Description:
9* 9*
10* This file contains the check_ldap plugin 10* This file contains the check_ldap plugin
11* 11*
12* 12*
13* This program is free software: you can redistribute it and/or modify 13* This program is free software: you can redistribute it and/or modify
14* it under the terms of the GNU General Public License as published by 14* it under the terms of the GNU General Public License as published by
15* the Free Software Foundation, either version 3 of the License, or 15* the Free Software Foundation, either version 3 of the License, or
16* (at your option) any later version. 16* (at your option) any later version.
17* 17*
18* This program is distributed in the hope that it will be useful, 18* This program is distributed in the hope that it will be useful,
19* but WITHOUT ANY WARRANTY; without even the implied warranty of 19* but WITHOUT ANY WARRANTY; without even the implied warranty of
20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21* GNU General Public License for more details. 21* GNU General Public License for more details.
22* 22*
23* You should have received a copy of the GNU General Public License 23* You should have received a copy of the GNU General Public License
24* along with this program. If not, see <http://www.gnu.org/licenses/>. 24* along with this program. If not, see <http://www.gnu.org/licenses/>.
25* 25*
26* 26*
27*****************************************************************************/ 27*****************************************************************************/
28 28
29/* progname may be check_ldaps */ 29/* progname may be check_ldaps */
@@ -67,7 +67,10 @@ int ld_protocol = DEFAULT_PROTOCOL;
67#endif 67#endif
68double warn_time = UNDEFINED; 68double warn_time = UNDEFINED;
69double crit_time = UNDEFINED; 69double crit_time = UNDEFINED;
70thresholds *entries_thresholds = NULL;
70struct timeval tv; 71struct timeval tv;
72char* warn_entries = NULL;
73char* crit_entries = NULL;
71int starttls = FALSE; 74int starttls = FALSE;
72int ssl_on_connect = FALSE; 75int ssl_on_connect = FALSE;
73int verbose = 0; 76int verbose = 0;
@@ -94,6 +97,12 @@ main (int argc, char *argv[])
94 int tls; 97 int tls;
95 int version=3; 98 int version=3;
96 99
100 /* for entry counting */
101
102 LDAPMessage *next_entry;
103 int status_entries = STATE_OK;
104 int num_entries = 0;
105
97 setlocale (LC_ALL, ""); 106 setlocale (LC_ALL, "");
98 bindtextdomain (PACKAGE, LOCALEDIR); 107 bindtextdomain (PACKAGE, LOCALEDIR);
99 textdomain (PACKAGE); 108 textdomain (PACKAGE);
@@ -197,12 +206,14 @@ main (int argc, char *argv[])
197 } 206 }
198 207
199 /* do a search of all objectclasses in the base dn */ 208 /* do a search of all objectclasses in the base dn */
200 if (ldap_search_s (ld, ld_base, LDAP_SCOPE_BASE, ld_attr, NULL, 0, &result) 209 if (ldap_search_s (ld, ld_base, (crit_entries!=NULL || warn_entries!=NULL) ? LDAP_SCOPE_SUBTREE : LDAP_SCOPE_BASE, ld_attr, NULL, 0, &result)
201 != LDAP_SUCCESS) { 210 != LDAP_SUCCESS) {
202 if (verbose) 211 if (verbose)
203 ldap_perror(ld, "ldap_search"); 212 ldap_perror(ld, "ldap_search");
204 printf (_("Could not search/find objectclasses in %s\n"), ld_base); 213 printf (_("Could not search/find objectclasses in %s\n"), ld_base);
205 return STATE_CRITICAL; 214 return STATE_CRITICAL;
215 } else if (crit_entries!=NULL || warn_entries!=NULL) {
216 num_entries = ldap_count_entries(ld, result);
206 } 217 }
207 218
208 /* unbind from the ldap server */ 219 /* unbind from the ldap server */
@@ -223,14 +234,42 @@ main (int argc, char *argv[])
223 else 234 else
224 status = STATE_OK; 235 status = STATE_OK;
225 236
237 if(entries_thresholds != NULL) {
238 if (verbose) {
239 printf ("entries found: %d\n", num_entries);
240 print_thresholds("entry threasholds", entries_thresholds);
241 }
242 status_entries = get_status(num_entries, entries_thresholds);
243 if (status_entries == STATE_CRITICAL) {
244 status = STATE_CRITICAL;
245 } else if (status != STATE_CRITICAL) {
246 status = status_entries;
247 }
248 }
249
226 /* print out the result */ 250 /* print out the result */
227 printf (_("LDAP %s - %.3f seconds response time|%s\n"), 251 if (crit_entries!=NULL || warn_entries!=NULL) {
228 state_text (status), 252 printf (_("LDAP %s - found %d entries in %.3f seconds|%s %s\n"),
229 elapsed_time, 253 state_text (status),
230 fperfdata ("time", elapsed_time, "s", 254 num_entries,
231 (int)warn_time, warn_time, 255 elapsed_time,
232 (int)crit_time, crit_time, 256 fperfdata ("time", elapsed_time, "s",
233 TRUE, 0, FALSE, 0)); 257 (int)warn_time, warn_time,
258 (int)crit_time, crit_time,
259 TRUE, 0, FALSE, 0),
260 sperfdata ("entries", (double)num_entries, "",
261 warn_entries,
262 crit_entries,
263 TRUE, 0.0, FALSE, 0.0));
264 } else {
265 printf (_("LDAP %s - %.3f seconds response time|%s\n"),
266 state_text (status),
267 elapsed_time,
268 fperfdata ("time", elapsed_time, "s",
269 (int)warn_time, warn_time,
270 (int)crit_time, crit_time,
271 TRUE, 0, FALSE, 0));
272 }
234 273
235 return status; 274 return status;
236} 275}
@@ -263,6 +302,8 @@ process_arguments (int argc, char **argv)
263 {"port", required_argument, 0, 'p'}, 302 {"port", required_argument, 0, 'p'},
264 {"warn", required_argument, 0, 'w'}, 303 {"warn", required_argument, 0, 'w'},
265 {"crit", required_argument, 0, 'c'}, 304 {"crit", required_argument, 0, 'c'},
305 {"warn-entries", required_argument, 0, 'W'},
306 {"crit-entries", required_argument, 0, 'C'},
266 {"verbose", no_argument, 0, 'v'}, 307 {"verbose", no_argument, 0, 'v'},
267 {0, 0, 0, 0} 308 {0, 0, 0, 0}
268 }; 309 };
@@ -276,7 +317,7 @@ process_arguments (int argc, char **argv)
276 } 317 }
277 318
278 while (1) { 319 while (1) {
279 c = getopt_long (argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:", longopts, &option); 320 c = getopt_long (argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:C:W:", longopts, &option);
280 321
281 if (c == -1 || c == EOF) 322 if (c == -1 || c == EOF)
282 break; 323 break;
@@ -318,6 +359,12 @@ process_arguments (int argc, char **argv)
318 case 'c': 359 case 'c':
319 crit_time = strtod (optarg, NULL); 360 crit_time = strtod (optarg, NULL);
320 break; 361 break;
362 case 'W':
363 warn_entries = optarg;
364 break;
365 case 'C':
366 crit_entries = optarg;
367 break;
321#ifdef HAVE_LDAP_SET_OPTION 368#ifdef HAVE_LDAP_SET_OPTION
322 case '2': 369 case '2':
323 ld_protocol = 2; 370 ld_protocol = 2;
@@ -381,6 +428,10 @@ validate_arguments ()
381 if (ld_base==NULL) 428 if (ld_base==NULL)
382 usage4 (_("Please specify the LDAP base\n")); 429 usage4 (_("Please specify the LDAP base\n"));
383 430
431 if (crit_entries!=NULL || warn_entries!=NULL) {
432 set_thresholds(&entries_thresholds,
433 warn_entries, crit_entries);
434 }
384 return OK; 435 return OK;
385} 436}
386 437
@@ -430,6 +481,11 @@ print_help (void)
430 481
431 printf (UT_WARN_CRIT); 482 printf (UT_WARN_CRIT);
432 483
484 printf (" %s\n", "-W [--warn-entries]");
485 printf (" %s\n", _("Number of found entries to result in warning status"));
486 printf (" %s\n", "-W [--crit-entries]");
487 printf (" %s\n", _("Number of found entries to result in critical status"));
488
433 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 489 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
434 490
435 printf (UT_VERBOSE); 491 printf (UT_VERBOSE);
@@ -441,6 +497,7 @@ print_help (void)
441 printf (" %s\n", _("'SSL on connect' will be used no matter how the plugin was called.")); 497 printf (" %s\n", _("'SSL on connect' will be used no matter how the plugin was called."));
442 printf (" %s\n", _("This detection is deprecated, please use 'check_ldap' with the '--starttls' or '--ssl' flags")); 498 printf (" %s\n", _("This detection is deprecated, please use 'check_ldap' with the '--starttls' or '--ssl' flags"));
443 printf (" %s\n", _("to define the behaviour explicitly instead.")); 499 printf (" %s\n", _("to define the behaviour explicitly instead."));
500 printf (" %s\n", _("The parameters --warn-entries and --crit-entries are optional."));
444 501
445 printf (UT_SUPPORT); 502 printf (UT_SUPPORT);
446} 503}
diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c
index 32ba050..3b038cf 100644
--- a/plugins/check_mrtgtraf.c
+++ b/plugins/check_mrtgtraf.c
@@ -148,37 +148,37 @@ main (int argc, char **argv)
148 148
149 /* report incoming traffic in Bytes/sec */ 149 /* report incoming traffic in Bytes/sec */
150 if (incoming_rate < 1024) { 150 if (incoming_rate < 1024) {
151 strcpy (incoming_speed_rating, "B/s"); 151 strcpy (incoming_speed_rating, "B");
152 adjusted_incoming_rate = (double) incoming_rate; 152 adjusted_incoming_rate = (double) incoming_rate;
153 } 153 }
154 154
155 /* report incoming traffic in KBytes/sec */ 155 /* report incoming traffic in KBytes/sec */
156 else if (incoming_rate < (1024 * 1024)) { 156 else if (incoming_rate < (1024 * 1024)) {
157 strcpy (incoming_speed_rating, "KB/s"); 157 strcpy (incoming_speed_rating, "KB");
158 adjusted_incoming_rate = (double) (incoming_rate / 1024.0); 158 adjusted_incoming_rate = (double) (incoming_rate / 1024.0);
159 } 159 }
160 160
161 /* report incoming traffic in MBytes/sec */ 161 /* report incoming traffic in MBytes/sec */
162 else { 162 else {
163 strcpy (incoming_speed_rating, "MB/s"); 163 strcpy (incoming_speed_rating, "MB");
164 adjusted_incoming_rate = (double) (incoming_rate / 1024.0 / 1024.0); 164 adjusted_incoming_rate = (double) (incoming_rate / 1024.0 / 1024.0);
165 } 165 }
166 166
167 /* report outgoing traffic in Bytes/sec */ 167 /* report outgoing traffic in Bytes/sec */
168 if (outgoing_rate < 1024) { 168 if (outgoing_rate < 1024) {
169 strcpy (outgoing_speed_rating, "B/s"); 169 strcpy (outgoing_speed_rating, "B");
170 adjusted_outgoing_rate = (double) outgoing_rate; 170 adjusted_outgoing_rate = (double) outgoing_rate;
171 } 171 }
172 172
173 /* report outgoing traffic in KBytes/sec */ 173 /* report outgoing traffic in KBytes/sec */
174 else if (outgoing_rate < (1024 * 1024)) { 174 else if (outgoing_rate < (1024 * 1024)) {
175 strcpy (outgoing_speed_rating, "KB/s"); 175 strcpy (outgoing_speed_rating, "KB");
176 adjusted_outgoing_rate = (double) (outgoing_rate / 1024.0); 176 adjusted_outgoing_rate = (double) (outgoing_rate / 1024.0);
177 } 177 }
178 178
179 /* report outgoing traffic in MBytes/sec */ 179 /* report outgoing traffic in MBytes/sec */
180 else { 180 else {
181 strcpy (outgoing_speed_rating, "MB/s"); 181 strcpy (outgoing_speed_rating, "MB");
182 adjusted_outgoing_rate = (double) (outgoing_rate / 1024.0 / 1024.0); 182 adjusted_outgoing_rate = (double) (outgoing_rate / 1024.0 / 1024.0);
183 } 183 }
184 184
@@ -191,7 +191,7 @@ main (int argc, char **argv)
191 result = STATE_WARNING; 191 result = STATE_WARNING;
192 } 192 }
193 193
194 xasprintf (&error_message, _("%s. In = %0.1f %s, %s. Out = %0.1f %s|%s %s\n"), 194 xasprintf (&error_message, _("%s. In = %0.1f %s/s, %s. Out = %0.1f %s/s|%s %s\n"),
195 (use_average == TRUE) ? _("Avg") : _("Max"), adjusted_incoming_rate, 195 (use_average == TRUE) ? _("Avg") : _("Max"), adjusted_incoming_rate,
196 incoming_speed_rating, (use_average == TRUE) ? _("Avg") : _("Max"), 196 incoming_speed_rating, (use_average == TRUE) ? _("Avg") : _("Max"),
197 adjusted_outgoing_rate, outgoing_speed_rating, 197 adjusted_outgoing_rate, outgoing_speed_rating,
diff --git a/plugins/check_nt.c b/plugins/check_nt.c
index fefbfb7..f621b0a 100644
--- a/plugins/check_nt.c
+++ b/plugins/check_nt.c
@@ -197,19 +197,40 @@ int main(int argc, char **argv){
197 197
198 case CHECK_UPTIME: 198 case CHECK_UPTIME:
199 199
200 xasprintf(&send_buffer, "%s&3", req_password); 200 if (value_list == NULL) {
201 fetch_data (server_address, server_port, send_buffer); 201 value_list = "minutes";
202 uptime=strtoul(recv_buffer,NULL,10); 202 }
203 updays = uptime / 86400; 203 if (strncmp(value_list, "seconds", strlen("seconds") + 1 ) &&
204 uphours = (uptime % 86400) / 3600; 204 strncmp(value_list, "minutes", strlen("minutes") + 1) &&
205 upminutes = ((uptime % 86400) % 3600) / 60; 205 strncmp(value_list, "hours", strlen("hours") + 1) &&
206 xasprintf(&output_message,_("System Uptime - %u day(s) %u hour(s) %u minute(s)|uptime=%lu"), updays, uphours, upminutes, uptime); 206 strncmp(value_list, "days", strlen("days") + 1)) {
207 if (check_critical_value==TRUE && uptime <= critical_value) 207
208 return_code=STATE_CRITICAL; 208 output_message = strdup (_("wrong -l argument"));
209 else if (check_warning_value==TRUE && uptime <= warning_value) 209 } else {
210 return_code=STATE_WARNING; 210 xasprintf(&send_buffer, "%s&3", req_password);
211 else 211 fetch_data (server_address, server_port, send_buffer);
212 return_code=STATE_OK; 212 uptime=strtoul(recv_buffer,NULL,10);
213 updays = uptime / 86400;
214 uphours = (uptime % 86400) / 3600;
215 upminutes = ((uptime % 86400) % 3600) / 60;
216
217 if (!strncmp(value_list, "minutes", strlen("minutes")))
218 uptime = uptime / 60;
219 else if (!strncmp(value_list, "hours", strlen("hours")))
220 uptime = uptime / 3600;
221 else if (!strncmp(value_list, "days", strlen("days")))
222 uptime = uptime / 86400;
223 /* else uptime in seconds, nothing to do */
224
225 xasprintf(&output_message,_("System Uptime - %u day(s) %u hour(s) %u minute(s) |uptime=%lu"),updays, uphours, upminutes, uptime);
226
227 if (check_critical_value==TRUE && uptime <= critical_value)
228 return_code=STATE_CRITICAL;
229 else if (check_warning_value==TRUE && uptime <= warning_value)
230 return_code=STATE_WARNING;
231 else
232 return_code=STATE_OK;
233 }
213 break; 234 break;
214 235
215 case CHECK_USEDDISKSPACE: 236 case CHECK_USEDDISKSPACE:
@@ -713,7 +734,9 @@ void print_help(void)
713 printf (" %s\n", "ie: -l 60,90,95,120,90,95"); 734 printf (" %s\n", "ie: -l 60,90,95,120,90,95");
714 printf (" %s\n", "UPTIME ="); 735 printf (" %s\n", "UPTIME =");
715 printf (" %s\n", _("Get the uptime of the machine.")); 736 printf (" %s\n", _("Get the uptime of the machine."));
716 printf (" %s\n", _("No specific parameters. No warning or critical threshold")); 737 printf (" %s\n", _("-l <unit> "));
738 printf (" %s\n", _("<unit> = seconds, minutes, hours, or days. (default: minutes)"));
739 printf (" %s\n", _("Thresholds will use the unit specified above."));
717 printf (" %s\n", "USEDDISKSPACE ="); 740 printf (" %s\n", "USEDDISKSPACE =");
718 printf (" %s\n", _("Size and percentage of disk use.")); 741 printf (" %s\n", _("Size and percentage of disk use."));
719 printf (" %s\n", _("Request a -l parameter containing the drive letter only.")); 742 printf (" %s\n", _("Request a -l parameter containing the drive letter only."));
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c
index 09a923e..a7d278d 100644
--- a/plugins/check_ntp.c
+++ b/plugins/check_ntp.c
@@ -517,14 +517,13 @@ setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){
517double jitter_request(const char *host, int *status){ 517double jitter_request(const char *host, int *status){
518 int conn=-1, i, npeers=0, num_candidates=0, syncsource_found=0; 518 int conn=-1, i, npeers=0, num_candidates=0, syncsource_found=0;
519 int run=0, min_peer_sel=PEER_INCLUDED, num_selected=0, num_valid=0; 519 int run=0, min_peer_sel=PEER_INCLUDED, num_selected=0, num_valid=0;
520 int peers_size=0, peer_offset=0, bytes_read=0; 520 int peers_size=0, peer_offset=0;
521 ntp_assoc_status_pair *peers=NULL; 521 ntp_assoc_status_pair *peers=NULL;
522 ntp_control_message req; 522 ntp_control_message req;
523 const char *getvar = "jitter"; 523 const char *getvar = "jitter";
524 double rval = 0.0, jitter = -1.0; 524 double rval = 0.0, jitter = -1.0;
525 char *startofvalue=NULL, *nptr=NULL; 525 char *startofvalue=NULL, *nptr=NULL;
526 void *tmp; 526 void *tmp;
527 int ntp_cm_ints = sizeof(uint16_t) * 5 + sizeof(uint8_t) * 2;
528 527
529 /* Long-winded explanation: 528 /* Long-winded explanation:
530 * Getting the jitter requires a number of steps: 529 * Getting the jitter requires a number of steps:
@@ -591,6 +590,9 @@ double jitter_request(const char *host, int *status){
591 for (i = 0; i < npeers; i++){ 590 for (i = 0; i < npeers; i++){
592 /* Only query this server if it is the current sync source */ 591 /* Only query this server if it is the current sync source */
593 if (PEER_SEL(peers[i].status) >= min_peer_sel){ 592 if (PEER_SEL(peers[i].status) >= min_peer_sel){
593 char jitter_data[MAX_CM_SIZE+1];
594 size_t jitter_data_count;
595
594 num_selected++; 596 num_selected++;
595 setup_control_request(&req, OP_READVAR, 2); 597 setup_control_request(&req, OP_READVAR, 2);
596 req.assoc = peers[i].assoc; 598 req.assoc = peers[i].assoc;
@@ -609,15 +611,7 @@ double jitter_request(const char *host, int *status){
609 611
610 req.count = htons(MAX_CM_SIZE); 612 req.count = htons(MAX_CM_SIZE);
611 DBG(printf("recieving READVAR response...\n")); 613 DBG(printf("recieving READVAR response...\n"));
612 614 read(conn, &req, SIZEOF_NTPCM(req));
613 /* cov-66524 - req.data not null terminated before usage. Also covers verifying struct was returned correctly*/
614 if ((bytes_read = read(conn, &req, SIZEOF_NTPCM(req))) == -1)
615 die(STATE_UNKNOWN, _("Cannot read from socket: %s"), strerror(errno));
616 if (bytes_read != ntp_cm_ints + req.count)
617 die(STATE_UNKNOWN, _("Invalid NTP response: %d bytes read does not equal %d plus %d data segment"), bytes_read, ntp_cm_ints, req.count);
618 /* else null terminate */
619 strncpy(req.data[req.count], "\0", 1);
620
621 DBG(print_ntp_control_message(&req)); 615 DBG(print_ntp_control_message(&req));
622 616
623 if(req.op&REM_ERROR && strstr(getvar, "jitter")) { 617 if(req.op&REM_ERROR && strstr(getvar, "jitter")) {
@@ -632,7 +626,14 @@ double jitter_request(const char *host, int *status){
632 if(verbose) { 626 if(verbose) {
633 printf("parsing jitter from peer %.2x: ", ntohs(peers[i].assoc)); 627 printf("parsing jitter from peer %.2x: ", ntohs(peers[i].assoc));
634 } 628 }
635 startofvalue = strchr(req.data, '='); 629 if((jitter_data_count = ntohs(req.count)) >= sizeof(jitter_data)){
630 die(STATE_UNKNOWN,
631 _("jitter response too large (%lu bytes)\n"),
632 (unsigned long)jitter_data_count);
633 }
634 memcpy(jitter_data, req.data, jitter_data_count);
635 jitter_data[jitter_data_count] = '\0';
636 startofvalue = strchr(jitter_data, '=');
636 if(startofvalue != NULL) { 637 if(startofvalue != NULL) {
637 startofvalue++; 638 startofvalue++;
638 jitter = strtod(startofvalue, &nptr); 639 jitter = strtod(startofvalue, &nptr);
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c
index d3ae599..44424af 100644
--- a/plugins/check_ntp_peer.c
+++ b/plugins/check_ntp_peer.c
@@ -599,17 +599,20 @@ int main(int argc, char *argv[]){
599 } 599 }
600 oresult = result; 600 oresult = result;
601 601
602 if(do_truechimers) 602 if(do_truechimers) {
603 tresult = get_status(num_truechimers, truechimer_thresholds); 603 tresult = get_status(num_truechimers, truechimer_thresholds);
604 result = max_state_alt(result, tresult); 604 result = max_state_alt(result, tresult);
605 }
605 606
606 if(do_stratum) 607 if(do_stratum) {
607 sresult = get_status(stratum, stratum_thresholds); 608 sresult = get_status(stratum, stratum_thresholds);
608 result = max_state_alt(result, sresult); 609 result = max_state_alt(result, sresult);
610 }
609 611
610 if(do_jitter) 612 if(do_jitter) {
611 jresult = get_status(jitter, jitter_thresholds); 613 jresult = get_status(jitter, jitter_thresholds);
612 result = max_state_alt(result, jresult); 614 result = max_state_alt(result, jresult);
615 }
613 616
614 switch (result) { 617 switch (result) {
615 case STATE_CRITICAL : 618 case STATE_CRITICAL :
diff --git a/plugins/check_real.c b/plugins/check_real.c
index 36f6413..00bd4d2 100644
--- a/plugins/check_real.c
+++ b/plugins/check_real.c
@@ -163,22 +163,22 @@ main (int argc, char **argv)
163 163
164 /* Part I - Server Check */ 164 /* Part I - Server Check */
165 165
166 /* send the OPTIONS request */ 166 /* send the DESCRIBE request */
167 sprintf (buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\n", host_name, 167 sprintf (buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\r\n", host_name,
168 server_port, server_url); 168 server_port, server_url);
169 result = send (sd, buffer, strlen (buffer), 0); 169 result = send (sd, buffer, strlen (buffer), 0);
170 170
171 /* send the header sync */ 171 /* send the header sync */
172 sprintf (buffer, "CSeq: 2\n"); 172 sprintf (buffer, "CSeq: 2\r\n");
173 result = send (sd, buffer, strlen (buffer), 0); 173 result = send (sd, buffer, strlen (buffer), 0);
174 174
175 /* send a newline so the server knows we're done with the request */ 175 /* send a newline so the server knows we're done with the request */
176 sprintf (buffer, "\n"); 176 sprintf (buffer, "\r\n");
177 result = send (sd, buffer, strlen (buffer), 0); 177 result = send (sd, buffer, strlen (buffer), 0);
178 178
179 /* watch for the REAL connection string */ 179 /* watch for the REAL connection string */
180 result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); 180 result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0);
181 buffer[result] = "\0"; /* null terminate recieved buffer */ 181 buffer[result] = '\0'; /* null terminate recieved buffer */
182 182
183 /* return a CRITICAL status if we couldn't read any data */ 183 /* return a CRITICAL status if we couldn't read any data */
184 if (result == -1) { 184 if (result == -1) {
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 2c62a23..62e6b8b 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -104,6 +104,8 @@ int errcode, excode;
104 104
105char *server_address = NULL; 105char *server_address = NULL;
106char *community = NULL; 106char *community = NULL;
107char **contextargs = NULL;
108char *context = NULL;
107char **authpriv = NULL; 109char **authpriv = NULL;
108char *proto = NULL; 110char *proto = NULL;
109char *seclevel = NULL; 111char *seclevel = NULL;
@@ -128,6 +130,7 @@ size_t nunits = 0;
128size_t unitv_size = OID_COUNT_STEP; 130size_t unitv_size = OID_COUNT_STEP;
129int numoids = 0; 131int numoids = 0;
130int numauthpriv = 0; 132int numauthpriv = 0;
133int numcontext = 0;
131int verbose = 0; 134int verbose = 0;
132int usesnmpgetnext = FALSE; 135int usesnmpgetnext = FALSE;
133char *warning_thresholds = NULL; 136char *warning_thresholds = NULL;
@@ -297,8 +300,8 @@ main (int argc, char **argv)
297 snmpcmd = strdup (PATH_TO_SNMPGET); 300 snmpcmd = strdup (PATH_TO_SNMPGET);
298 } 301 }
299 302
300 /* 10 arguments to pass before authpriv options + 1 for host and numoids. Add one for terminating NULL */ 303 /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */
301 command_line = calloc (10 + numauthpriv + 1 + numoids + 1, sizeof (char *)); 304 command_line = calloc (10 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *));
302 command_line[0] = snmpcmd; 305 command_line[0] = snmpcmd;
303 command_line[1] = strdup ("-Le"); 306 command_line[1] = strdup ("-Le");
304 command_line[2] = strdup ("-t"); 307 command_line[2] = strdup ("-t");
@@ -310,23 +313,27 @@ main (int argc, char **argv)
310 command_line[8] = "-v"; 313 command_line[8] = "-v";
311 command_line[9] = strdup (proto); 314 command_line[9] = strdup (proto);
312 315
316 for (i = 0; i < numcontext; i++) {
317 command_line[10 + i] = contextargs[i];
318 }
319
313 for (i = 0; i < numauthpriv; i++) { 320 for (i = 0; i < numauthpriv; i++) {
314 command_line[10 + i] = authpriv[i]; 321 command_line[10 + numcontext + i] = authpriv[i];
315 } 322 }
316 323
317 xasprintf (&command_line[10 + numauthpriv], "%s:%s", server_address, port); 324 xasprintf (&command_line[10 + numcontext + numauthpriv], "%s:%s", server_address, port);
318 325
319 /* This is just for display purposes, so it can remain a string */ 326 /* This is just for display purposes, so it can remain a string */
320 xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s:%s", 327 xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s %s:%s",
321 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]", 328 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[context]", "[authpriv]",
322 server_address, port); 329 server_address, port);
323 330
324 for (i = 0; i < numoids; i++) { 331 for (i = 0; i < numoids; i++) {
325 command_line[10 + numauthpriv + 1 + i] = oids[i]; 332 command_line[10 + numcontext + numauthpriv + 1 + i] = oids[i];
326 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); 333 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
327 } 334 }
328 335
329 command_line[10 + numauthpriv + 1 + numoids] = NULL; 336 command_line[10 + numcontext + numauthpriv + 1 + numoids] = NULL;
330 337
331 if (verbose) 338 if (verbose)
332 printf ("%s\n", cl_hidden_auth); 339 printf ("%s\n", cl_hidden_auth);
@@ -411,6 +418,9 @@ main (int argc, char **argv)
411 else if (strstr (response, "INTEGER: ")) { 418 else if (strstr (response, "INTEGER: ")) {
412 show = strstr (response, "INTEGER: ") + 9; 419 show = strstr (response, "INTEGER: ") + 9;
413 } 420 }
421 else if (strstr (response, "OID: ")) {
422 show = strstr (response, "OID: ") + 5;
423 }
414 else if (strstr (response, "STRING: ")) { 424 else if (strstr (response, "STRING: ")) {
415 show = strstr (response, "STRING: ") + 8; 425 show = strstr (response, "STRING: ") + 8;
416 conv = "%.10g"; 426 conv = "%.10g";
@@ -567,6 +577,18 @@ main (int argc, char **argv)
567 len = sizeof(perfstr)-strlen(perfstr)-1; 577 len = sizeof(perfstr)-strlen(perfstr)-1;
568 strncat(perfstr, show, len>ptr-show ? ptr-show : len); 578 strncat(perfstr, show, len>ptr-show ? ptr-show : len);
569 579
580 if (warning_thresholds) {
581 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1);
582 strncat(perfstr, warning_thresholds, sizeof(perfstr)-strlen(perfstr)-1);
583 }
584
585 if (critical_thresholds) {
586 if (!warning_thresholds)
587 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1);
588 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1);
589 strncat(perfstr, critical_thresholds, sizeof(perfstr)-strlen(perfstr)-1);
590 }
591
570 if (type) 592 if (type)
571 strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); 593 strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);
572 strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); 594 strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1);
@@ -646,6 +668,7 @@ process_arguments (int argc, char **argv)
646 {"retries", required_argument, 0, 'e'}, 668 {"retries", required_argument, 0, 'e'},
647 {"miblist", required_argument, 0, 'm'}, 669 {"miblist", required_argument, 0, 'm'},
648 {"protocol", required_argument, 0, 'P'}, 670 {"protocol", required_argument, 0, 'P'},
671 {"context", required_argument, 0, 'N'},
649 {"seclevel", required_argument, 0, 'L'}, 672 {"seclevel", required_argument, 0, 'L'},
650 {"secname", required_argument, 0, 'U'}, 673 {"secname", required_argument, 0, 'U'},
651 {"authproto", required_argument, 0, 'a'}, 674 {"authproto", required_argument, 0, 'a'},
@@ -675,7 +698,7 @@ process_arguments (int argc, char **argv)
675 } 698 }
676 699
677 while (1) { 700 while (1) {
678 c = getopt_long (argc, argv, "nhvVOt:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:L:U:a:x:A:X:", 701 c = getopt_long (argc, argv, "nhvVOt:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:N:L:U:a:x:A:X:",
679 longopts, &option); 702 longopts, &option);
680 703
681 if (c == -1 || c == EOF) 704 if (c == -1 || c == EOF)
@@ -713,6 +736,9 @@ process_arguments (int argc, char **argv)
713 case 'P': /* SNMP protocol version */ 736 case 'P': /* SNMP protocol version */
714 proto = optarg; 737 proto = optarg;
715 break; 738 break;
739 case 'N': /* SNMPv3 context */
740 context = optarg;
741 break;
716 case 'L': /* security level */ 742 case 'L': /* security level */
717 seclevel = optarg; 743 seclevel = optarg;
718 break; 744 break;
@@ -960,6 +986,13 @@ validate_arguments ()
960 authpriv[1] = strdup (community); 986 authpriv[1] = strdup (community);
961 } 987 }
962 else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */ 988 else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */
989 if (!(context == NULL)) {
990 numcontext = 2;
991 contextargs = calloc (numcontext, sizeof (char *));
992 contextargs[0] = strdup ("-n");
993 contextargs[1] = strdup (context);
994 }
995
963 if (seclevel == NULL) 996 if (seclevel == NULL)
964 xasprintf(&seclevel, "noAuthNoPriv"); 997 xasprintf(&seclevel, "noAuthNoPriv");
965 998
@@ -1103,6 +1136,8 @@ print_help (void)
1103 printf (" %s\n", _("Use SNMP GETNEXT instead of SNMP GET")); 1136 printf (" %s\n", _("Use SNMP GETNEXT instead of SNMP GET"));
1104 printf (" %s\n", "-P, --protocol=[1|2c|3]"); 1137 printf (" %s\n", "-P, --protocol=[1|2c|3]");
1105 printf (" %s\n", _("SNMP protocol version")); 1138 printf (" %s\n", _("SNMP protocol version"));
1139 printf (" %s\n", "-N, --context=CONTEXT");
1140 printf (" %s\n", _("SNMPv3 context"));
1106 printf (" %s\n", "-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]"); 1141 printf (" %s\n", "-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]");
1107 printf (" %s\n", _("SNMPv3 securityLevel")); 1142 printf (" %s\n", _("SNMPv3 securityLevel"));
1108 printf (" %s\n", "-a, --authproto=[MD5|SHA]"); 1143 printf (" %s\n", "-a, --authproto=[MD5|SHA]");
@@ -1210,6 +1245,6 @@ print_usage (void)
1210 printf ("%s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range]\n",progname); 1245 printf ("%s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range]\n",progname);
1211 printf ("[-C community] [-s string] [-r regex] [-R regexi] [-t timeout] [-e retries]\n"); 1246 printf ("[-C community] [-s string] [-r regex] [-R regexi] [-t timeout] [-e retries]\n");
1212 printf ("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n"); 1247 printf ("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n");
1213 printf ("[-m miblist] [-P snmp version] [-L seclevel] [-U secname] [-a authproto]\n"); 1248 printf ("[-m miblist] [-P snmp version] [-N context] [-L seclevel] [-U secname]\n");
1214 printf ("[-A authpasswd] [-x privproto] [-X privpasswd]\n"); 1249 printf ("[-a authproto] [-A authpasswd] [-x privproto] [-X privpasswd]\n");
1215} 1250}
diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c
index b6187d6..3658965 100644
--- a/plugins/check_ssh.c
+++ b/plugins/check_ssh.c
@@ -253,18 +253,18 @@ ssh_connect (char *haddr, int hport, char *remote_version, char *remote_protocol
253 253
254 if (remote_version && strcmp(remote_version, ssh_server)) { 254 if (remote_version && strcmp(remote_version, ssh_server)) {
255 printf 255 printf
256 (_("SSH WARNING - %s (protocol %s) version mismatch, expected '%s'\n"), 256 (_("SSH CRITICAL - %s (protocol %s) version mismatch, expected '%s'\n"),
257 ssh_server, ssh_proto, remote_version); 257 ssh_server, ssh_proto, remote_version);
258 close(sd); 258 close(sd);
259 exit (STATE_WARNING); 259 exit (STATE_CRITICAL);
260 } 260 }
261 261
262 if (remote_protocol && strcmp(remote_protocol, ssh_proto)) { 262 if (remote_protocol && strcmp(remote_protocol, ssh_proto)) {
263 printf 263 printf
264 (_("SSH WARNING - %s (protocol %s) protocol version mismatch, expected '%s'\n"), 264 (_("SSH CRITICAL - %s (protocol %s) protocol version mismatch, expected '%s'\n"),
265 ssh_server, ssh_proto, remote_protocol); 265 ssh_server, ssh_proto, remote_protocol);
266 close(sd); 266 close(sd);
267 exit (STATE_WARNING); 267 exit (STATE_CRITICAL);
268 } 268 }
269 269
270 elapsed_time = (double)deltime(tv) / 1.0e6; 270 elapsed_time = (double)deltime(tv) / 1.0e6;
@@ -307,10 +307,10 @@ print_help (void)
307 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 307 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
308 308
309 printf (" %s\n", "-r, --remote-version=STRING"); 309 printf (" %s\n", "-r, --remote-version=STRING");
310 printf (" %s\n", _("Warn if string doesn't match expected server version (ex: OpenSSH_3.9p1)")); 310 printf (" %s\n", _("Alert if string doesn't match expected server version (ex: OpenSSH_3.9p1)"));
311 311
312 printf (" %s\n", "-P, --remote-protocol=STRING"); 312 printf (" %s\n", "-P, --remote-protocol=STRING");
313 printf (" %s\n", _("Warn if protocol doesn't match expected protocol version (ex: 2.0)")); 313 printf (" %s\n", _("Alert if protocol doesn't match expected protocol version (ex: 2.0)"));
314 314
315 printf (UT_VERBOSE); 315 printf (UT_VERBOSE);
316 316
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 88a2a2a..25e0bac 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -1,6 +1,6 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Monitoring check_disk plugin 3* Monitoring check_swap plugin
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net) 6* Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net)
@@ -352,6 +352,7 @@ main (int argc, char **argv)
352 percent_used = 100 * ((double) used_swap_mb) / ((double) total_swap_mb); 352 percent_used = 100 * ((double) used_swap_mb) / ((double) total_swap_mb);
353 } else { 353 } else {
354 percent_used = 100; 354 percent_used = 100;
355 status = "- Swap is either disabled, not present, or of zero size. ";
355 } 356 }
356 357
357 result = max_state (result, check_swap (percent_used, free_swap_mb)); 358 result = max_state (result, check_swap (percent_used, free_swap_mb));
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index f75c523..5c563d8 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -172,7 +172,7 @@ main (int argc, char **argv)
172 } 172 }
173 else if (!strncmp(SERVICE, "JABBER", 6)) { 173 else if (!strncmp(SERVICE, "JABBER", 6)) {
174 SEND = "<stream:stream to=\'host\' xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'>\n"; 174 SEND = "<stream:stream to=\'host\' xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'>\n";
175 EXPECT = "<?xml version=\'1.0\'?><stream:stream xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'"; 175 EXPECT = "<?xml version=\'1.0\'";
176 QUIT = "</stream:stream>\n"; 176 QUIT = "</stream:stream>\n";
177 flags |= FLAG_HIDE_OUTPUT; 177 flags |= FLAG_HIDE_OUTPUT;
178 PORT = 5222; 178 PORT = 5222;
@@ -577,7 +577,8 @@ process_arguments (int argc, char **argv)
577 if ((temp=strchr(optarg,','))!=NULL) { 577 if ((temp=strchr(optarg,','))!=NULL) {
578 *temp='\0'; 578 *temp='\0';
579 if (!is_intnonneg (optarg)) 579 if (!is_intnonneg (optarg))
580 usage2 (_("Invalid certificate expiration period"), optarg); days_till_exp_warn = atoi(optarg); 580 usage2 (_("Invalid certificate expiration period"), optarg);
581 days_till_exp_warn = atoi (optarg);
581 *temp=','; 582 *temp=',';
582 temp++; 583 temp++;
583 if (!is_intnonneg (temp)) 584 if (!is_intnonneg (temp))
@@ -643,7 +644,7 @@ print_help (void)
643 printf (UT_IPv46); 644 printf (UT_IPv46);
644 645
645 printf (" %s\n", "-E, --escape"); 646 printf (" %s\n", "-E, --escape");
646 printf (" %s\n", _("Can use \\n, \\r, \\t or \\ in send or quit string. Must come before send or quit option")); 647 printf (" %s\n", _("Can use \\n, \\r, \\t or \\\\ in send or quit string. Must come before send or quit option"));
647 printf (" %s\n", _("Default: nothing added to send, \\r\\n added to end of quit")); 648 printf (" %s\n", _("Default: nothing added to send, \\r\\n added to end of quit"));
648 printf (" %s\n", "-s, --send=STRING"); 649 printf (" %s\n", "-s, --send=STRING");
649 printf (" %s\n", _("String to send to the server")); 650 printf (" %s\n", _("String to send to the server"));
diff --git a/plugins/sslutils.c b/plugins/sslutils.c
index d0ae474..c9882c6 100644
--- a/plugins/sslutils.c
+++ b/plugins/sslutils.c
@@ -144,7 +144,9 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
144# ifdef USE_OPENSSL 144# ifdef USE_OPENSSL
145 X509 *certificate=NULL; 145 X509 *certificate=NULL;
146 X509_NAME *subj=NULL; 146 X509_NAME *subj=NULL;
147 char timestamp[50] = "";
147 char cn[MAX_CN_LENGTH]= ""; 148 char cn[MAX_CN_LENGTH]= "";
149
148 int cnlen =-1; 150 int cnlen =-1;
149 int status=STATE_UNKNOWN; 151 int status=STATE_UNKNOWN;
150 152
@@ -153,7 +155,7 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
153 struct tm stamp; 155 struct tm stamp;
154 float time_left; 156 float time_left;
155 int days_left; 157 int days_left;
156 char timestamp[50] = ""; 158 int time_remaining;
157 time_t tm_t; 159 time_t tm_t;
158 160
159 certificate=SSL_get_peer_certificate(s); 161 certificate=SSL_get_peer_certificate(s);
@@ -207,7 +209,8 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
207 (tm->data[6 + offset] - '0') * 10 + (tm->data[7 + offset] - '0'); 209 (tm->data[6 + offset] - '0') * 10 + (tm->data[7 + offset] - '0');
208 stamp.tm_min = 210 stamp.tm_min =
209 (tm->data[8 + offset] - '0') * 10 + (tm->data[9 + offset] - '0'); 211 (tm->data[8 + offset] - '0') * 10 + (tm->data[9 + offset] - '0');
210 stamp.tm_sec = 0; 212 stamp.tm_sec =
213 (tm->data[10 + offset] - '0') * 10 + (tm->data[11 + offset] - '0');
211 stamp.tm_isdst = -1; 214 stamp.tm_isdst = -1;
212 215
213 time_left = difftime(timegm(&stamp), time(NULL)); 216 time_left = difftime(timegm(&stamp), time(NULL));
@@ -218,21 +221,35 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
218 if (days_left > 0 && days_left <= days_till_exp_warn) { 221 if (days_left > 0 && days_left <= days_till_exp_warn) {
219 printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, days_left, timestamp); 222 printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, days_left, timestamp);
220 if (days_left > days_till_exp_crit) 223 if (days_left > days_till_exp_crit)
221 return STATE_WARNING; 224 status = STATE_WARNING;
222 else 225 else
223 return STATE_CRITICAL; 226 status = STATE_CRITICAL;
227 } else if (days_left == 0 && time_left > 0) {
228 if (time_left >= 3600)
229 time_remaining = (int) time_left / 3600;
230 else
231 time_remaining = (int) time_left / 60;
232
233 printf (_("%s - Certificate '%s' expires in %u %s (%s)\n"),
234 (days_left>days_till_exp_crit) ? "WARNING" : "CRITICAL", cn, time_remaining,
235 time_left >= 3600 ? "hours" : "minutes", timestamp);
236
237 if ( days_left > days_till_exp_crit)
238 status = STATE_WARNING;
239 else
240 status = STATE_CRITICAL;
224 } else if (time_left < 0) { 241 } else if (time_left < 0) {
225 printf(_("CRITICAL - Certificate '%s' expired on %s.\n"), cn, timestamp); 242 printf(_("CRITICAL - Certificate '%s' expired on %s.\n"), cn, timestamp);
226 status=STATE_CRITICAL; 243 status=STATE_CRITICAL;
227 } else if (days_left == 0) { 244 } else if (days_left == 0) {
228 printf (_("%s - Certificate '%s' expires today (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, timestamp); 245 printf (_("%s - Certificate '%s' just expired (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, timestamp);
229 if (days_left > days_till_exp_crit) 246 if (days_left > days_till_exp_crit)
230 return STATE_WARNING; 247 status = STATE_WARNING;
231 else 248 else
232 return STATE_CRITICAL; 249 status = STATE_CRITICAL;
233 } else { 250 } else {
234 printf(_("OK - Certificate '%s' will expire on %s.\n"), cn, timestamp); 251 printf(_("OK - Certificate '%s' will expire on %s.\n"), cn, timestamp);
235 status=STATE_OK; 252 status = STATE_OK;
236 } 253 }
237 X509_free(certificate); 254 X509_free(certificate);
238 return status; 255 return status;
diff --git a/plugins/t/NPTest.cache.travis b/plugins/t/NPTest.cache.travis
index 4ebfb90..fe8aabd 100644
--- a/plugins/t/NPTest.cache.travis
+++ b/plugins/t/NPTest.cache.travis
@@ -17,13 +17,15 @@
17 'NP_HOST_HPJD_PORT_INVALID' => '161', 17 'NP_HOST_HPJD_PORT_INVALID' => '161',
18 'NP_HOST_HPJD_PORT_VALID' => '', 18 'NP_HOST_HPJD_PORT_VALID' => '',
19 'NP_HOST_TCP_HTTP' => 'localhost', 19 'NP_HOST_TCP_HTTP' => 'localhost',
20 'NP_HOST_TCP_HTTP2' => 'labs.consol.de', 20 'NP_HOST_TCP_HTTP2' => 'test.monitoring-plugins.org',
21 'NP_HOST_TCP_IMAP' => 'imap.web.de', 21 'NP_HOST_TCP_IMAP' => 'imap.web.de',
22 'NP_HOST_TCP_LDAP' => 'localhost',
22 'NP_HOST_TCP_POP' => 'pop.web.de', 23 'NP_HOST_TCP_POP' => 'pop.web.de',
23 'NP_HOST_TCP_SMTP' => 'localhost', 24 'NP_HOST_TCP_SMTP' => 'localhost',
24 'NP_HOST_TCP_SMTP_NOTLS' => '', 25 'NP_HOST_TCP_SMTP_NOTLS' => '',
25 'NP_HOST_TCP_SMTP_TLS' => '', 26 'NP_HOST_TCP_SMTP_TLS' => '',
26 'NP_INTERNET_ACCESS' => 'yes', 27 'NP_INTERNET_ACCESS' => 'yes',
28 'NP_LDAP_BASE_DN' => 'cn=admin,dc=nodomain',
27 'NP_MOUNTPOINT2_VALID' => '', 29 'NP_MOUNTPOINT2_VALID' => '',
28 'NP_MOUNTPOINT_VALID' => '/', 30 'NP_MOUNTPOINT_VALID' => '/',
29 'NP_MYSQL_SERVER' => 'localhost', 31 'NP_MYSQL_SERVER' => 'localhost',
diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t
index b885880..035e768 100644
--- a/plugins/t/check_dns.t
+++ b/plugins/t/check_dns.t
@@ -10,7 +10,7 @@ use NPTest;
10 10
11plan skip_all => "check_dns not compiled" unless (-x "check_dns"); 11plan skip_all => "check_dns not compiled" unless (-x "check_dns");
12 12
13plan tests => 14; 13plan tests => 16;
14 14
15my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/'; 15my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/';
16 16
@@ -43,6 +43,12 @@ my $dns_server = getTestParameter(
43 "A non default (remote) DNS server", 43 "A non default (remote) DNS server",
44 ); 44 );
45 45
46my $host_nonresponsive = getTestParameter(
47 "NP_HOST_NONRESPONSIVE",
48 "The hostname of system not responsive to network requests",
49 "10.0.0.1",
50 );
51
46my $res; 52my $res;
47 53
48$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5"); 54$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5");
@@ -66,6 +72,10 @@ like ( $res->output, $successOutput, "Output OK" );
66$res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1"); 72$res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1");
67cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server"); 73cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server");
68 74
75$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -s $host_nonresponsive -t 2");
76cmp_ok( $res->return_code, '==', 2, "Got no answer from unresponsive server");
77like ( $res->output, "/CRITICAL - /", "Output OK");
78
69$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5"); 79$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5");
70cmp_ok( $res->return_code, '==', 0, "Got expected address"); 80cmp_ok( $res->return_code, '==', 0, "Got expected address");
71 81
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index 2539a28..c2caec6 100644
--- a/plugins/t/check_http.t
+++ b/plugins/t/check_http.t
@@ -6,9 +6,10 @@
6 6
7use strict; 7use strict;
8use Test::More; 8use Test::More;
9use POSIX qw/mktime strftime/;
9use NPTest; 10use NPTest;
10 11
11plan tests => 30; 12plan tests => 42;
12 13
13my $successOutput = '/OK.*HTTP.*second/'; 14my $successOutput = '/OK.*HTTP.*second/';
14 15
@@ -34,6 +35,8 @@ my $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2",
34 "A host providing an index page containing the string 'monitoring'", 35 "A host providing an index page containing the string 'monitoring'",
35 "test.monitoring-plugins.org" ); 36 "test.monitoring-plugins.org" );
36 37
38my $faketime = -x '/usr/bin/faketime' ? 1 : 0;
39
37 40
38$res = NPTest->testCmd( 41$res = NPTest->testCmd(
39 "./check_http $host_tcp_http -wt 300 -ct 600" 42 "./check_http $host_tcp_http -wt 300 -ct 600"
@@ -47,10 +50,10 @@ $res = NPTest->testCmd(
47like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); 50like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" );
48 51
49$res = NPTest->testCmd( 52$res = NPTest->testCmd(
50 "./check_http $host_nonresponsive -wt 1 -ct 2" 53 "./check_http $host_nonresponsive -wt 1 -ct 2 -t 3"
51 ); 54 );
52cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); 55cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" );
53cmp_ok( $res->output, 'eq', "CRITICAL - Socket timeout after 10 seconds", "Output OK"); 56cmp_ok( $res->output, 'eq', "CRITICAL - Socket timeout after 3 seconds", "Output OK");
54 57
55$res = NPTest->testCmd( 58$res = NPTest->testCmd(
56 "./check_http $hostname_invalid -wt 1 -ct 2" 59 "./check_http $hostname_invalid -wt 1 -ct 2"
@@ -112,6 +115,40 @@ SKIP: {
112 $res = NPTest->testCmd( "./check_http www.verisign.com -C 1" ); 115 $res = NPTest->testCmd( "./check_http www.verisign.com -C 1" );
113 cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works"); 116 cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works");
114 117
118 # run some certificate checks with faketime
119 SKIP: {
120 skip "No faketime binary found", 12 if !$faketime;
121 $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./check_http -C 1 www.verisign.com");
122 like($res->output, qr/OK - Certificate 'www.verisign.com' will expire on/, "Catch cert output");
123 is( $res->return_code, 0, "Catch cert output exit code" );
124 my($mon,$day,$hour,$min,$sec,$year) = ($res->output =~ /(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)\./);
125 if(!defined $year) {
126 die("parsing date failed from: ".$res);
127 }
128 my $months = {'Jan' => 0, 'Feb' => 1, 'Mar' => 2, 'Apr' => 3, 'May' => 4, 'Jun' => 5, 'Jul' => 6, 'Aug' => 7, 'Sep' => 8, 'Oct' => 9, 'Nov' => 10, 'Dec' => 11};
129 my $ts = mktime($sec, $min, $hour, $day, $months->{$mon}, $year-1900);
130 my $time = strftime("%Y-%m-%d %H:%M:%S", localtime($ts));
131 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_http -C 1 www.verisign.com");
132 like($res->output, qr/CRITICAL - Certificate 'www.verisign.com' just expired/, "Output on expire date");
133 is( $res->return_code, 2, "Output on expire date" );
134
135 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-1))."' ./check_http -C 1 www.verisign.com");
136 like($res->output, qr/CRITICAL - Certificate 'www.verisign.com' expires in 0 minutes/, "cert expires in 1 second output");
137 is( $res->return_code, 2, "cert expires in 1 second exit code" );
138
139 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-120))."' ./check_http -C 1 www.verisign.com");
140 like($res->output, qr/CRITICAL - Certificate 'www.verisign.com' expires in 2 minutes/, "cert expires in 2 minutes output");
141 is( $res->return_code, 2, "cert expires in 2 minutes exit code" );
142
143 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-7200))."' ./check_http -C 1 www.verisign.com");
144 like($res->output, qr/CRITICAL - Certificate 'www.verisign.com' expires in 2 hours/, "cert expires in 2 hours output");
145 is( $res->return_code, 2, "cert expires in 2 hours exit code" );
146
147 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_http -C 1 www.verisign.com");
148 like($res->output, qr/CRITICAL - Certificate 'www.verisign.com' expired on/, "Certificate expired output");
149 is( $res->return_code, 2, "Certificate expired exit code" );
150 };
151
115 $res = NPTest->testCmd( "./check_http --ssl www.verisign.com -E" ); 152 $res = NPTest->testCmd( "./check_http --ssl www.verisign.com -E" );
116 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); 153 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
117 like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); 154 like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' );
diff --git a/plugins/t/check_ldap.t b/plugins/t/check_ldap.t
new file mode 100644
index 0000000..b8944d4
--- /dev/null
+++ b/plugins/t/check_ldap.t
@@ -0,0 +1,80 @@
1#!/usr/bin/env perl -I ..
2#
3# Lightweight Directory Access Protocol (LDAP) Test via check_ldap
4#
5#
6
7use strict;
8use warnings;
9use Test::More;
10use NPTest;
11
12my $host_tcp_ldap = getTestParameter("NP_HOST_TCP_LDAP",
13 "A host providing the LDAP Service",
14 "localhost" );
15
16my $ldap_base_dn = getTestParameter("NP_LDAP_BASE_DN",
17 "A base dn for the LDAP Service",
18 "cn=admin" );
19
20my $host_nonresponsive = getTestParameter("host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
21 "The hostname of system not responsive to network requests" );
22
23my $hostname_invalid = getTestParameter("hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
24 "An invalid (not known to DNS) hostname" );
25
26my($result, $cmd);
27my $command = './check_ldap';
28
29plan tests => 16;
30
31SKIP: {
32 skip "NP_HOST_NONRESPONSIVE not set", 2 if ! $host_nonresponsive;
33
34 $result = NPTest->testCmd("$command -H $host_nonresponsive -b ou=blah -t 2 -w 1 -c 1");
35 is( $result->return_code, 2, "$command -H $host_nonresponsive -b ou=blah -t 5 -w 2 -c 3" );
36 is( $result->output, 'CRITICAL - Socket timeout after 2 seconds', "output ok" );
37};
38
39SKIP: {
40 skip "NP_HOSTNAME_INVALID not set", 2 if ! $hostname_invalid;
41
42 $result = NPTest->testCmd("$command -H $hostname_invalid -b ou=blah -t 5");
43 is( $result->return_code, 2, "$command -H $hostname_invalid -b ou=blah -t 5" );
44 is( $result->output, 'Could not bind to the LDAP server', "output ok" );
45};
46
47SKIP: {
48 skip "NP_HOST_TCP_LDAP not set", 12 if ! $host_tcp_ldap;
49 skip "NP_LDAP_BASE_DN not set", 12 if ! $ldap_base_dn;
50
51 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3";
52 $result = NPTest->testCmd($cmd);
53 is( $result->return_code, 0, $cmd );
54 like( $result->output, '/^LDAP OK - \d+.\d+ seconds response time\|time=\d+\.\d+s;2\.0+;3\.0+;0\.0+$/', "output ok" );
55
56 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000 -C 10000001";
57 $result = NPTest->testCmd($cmd);
58 is( $result->return_code, 0, $cmd );
59 like( $result->output, '/^LDAP OK - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000;10000001;0\.0+$/', "output ok" );
60
61 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000: -C 10000001:";
62 $result = NPTest->testCmd($cmd);
63 is( $result->return_code, 2, $cmd );
64 like( $result->output, '/^LDAP CRITICAL - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000:;10000001:;0\.0+$/', "output ok" );
65
66 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 0 -C 0";
67 $result = NPTest->testCmd($cmd);
68 is( $result->return_code, 2, $cmd );
69 like( $result->output, '/^LDAP CRITICAL - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;0;0;0\.0+$/', "output ok" );
70
71 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000: -C 10000001";
72 $result = NPTest->testCmd($cmd);
73 is( $result->return_code, 1, $cmd );
74 like( $result->output, '/^LDAP WARNING - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000:;10000001;0\.0+$/', "output ok" );
75
76 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -C 10000001";
77 $result = NPTest->testCmd($cmd);
78 is( $result->return_code, 0, $cmd );
79 like( $result->output, '/^LDAP OK - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;;10000001;0\.0+$/', "output ok" );
80};
diff --git a/plugins/t/negate.t b/plugins/t/negate.t
index f18acc3..d96a109 100644
--- a/plugins/t/negate.t
+++ b/plugins/t/negate.t
@@ -6,6 +6,7 @@
6 6
7use strict; 7use strict;
8use Test::More; 8use Test::More;
9use Cwd;
9use NPTest; 10use NPTest;
10 11
11# 15 tests in the first part, 9 in timeout tests and 2 * 32 in the last loops 12# 15 tests in the first part, 9 in timeout tests and 2 * 32 in the last loops
@@ -13,7 +14,7 @@ plan tests => 88;
13 14
14my $res; 15my $res;
15 16
16my $PWD = $ENV{PWD}; 17my $PWD = getcwd();
17 18
18$res = NPTest->testCmd( "./negate" ); 19$res = NPTest->testCmd( "./negate" );
19is( $res->return_code, 3, "Not enough parameters"); 20is( $res->return_code, 3, "Not enough parameters");
@@ -50,7 +51,7 @@ is( $res->output, "OK: a dummy okay", "The quoted string is passed through to su
50$res = NPTest->testCmd( "./negate '$PWD/check_dummy 0' 'a dummy okay'" ); 51$res = NPTest->testCmd( "./negate '$PWD/check_dummy 0' 'a dummy okay'" );
51is( $res->output, "No data returned from command", "Bad command, as expected (trying to execute './check_dummy 0')"); 52is( $res->output, "No data returned from command", "Bad command, as expected (trying to execute './check_dummy 0')");
52 53
53$res = NPTest->testCmd( './negate $PWD/check_dummy 0 \'$$ a dummy okay\'' ); 54$res = NPTest->testCmd( './negate '.$PWD.'/check_dummy 0 \'$$ a dummy okay\'' );
54is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' ); 55is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' );
55 56
56my %state = ( 57my %state = (
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index d93a0ec..e72d243 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -186,21 +186,21 @@ SKIP: {
186 186
187 $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); 187 $result = NPTest->testCmd( "$command -p $port_https -S -C 14" );
188 is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); 188 is( $result->return_code, 0, "$command -p $port_https -S -C 14" );
189 is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:00 2019.', "output ok" ); 189 is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:28 2019.', "output ok" );
190 190
191 $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); 191 $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" );
192 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); 192 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" );
193 like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:00 2019\)./', "output ok" ); 193 like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019\)./', "output ok" );
194 194
195 # Expired cert tests 195 # Expired cert tests
196 $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); 196 $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" );
197 is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); 197 is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" );
198 like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:00 2019\)./', "output ok" ); 198 like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019\)./', "output ok" );
199 199
200 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); 200 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" );
201 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); 201 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" );
202 is( $result->output, 202 is( $result->output,
203 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:00 2009.', 203 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:16 2009.',
204 "output ok" ); 204 "output ok" );
205 205
206} 206}
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t
index aace9bc..73a68b2 100755
--- a/plugins/tests/check_snmp.t
+++ b/plugins/tests/check_snmp.t
@@ -20,7 +20,16 @@ if ($@) {
20 plan skip_all => "Missing required module for test: $@"; 20 plan skip_all => "Missing required module for test: $@";
21} else { 21} else {
22 if (-x "./check_snmp") { 22 if (-x "./check_snmp") {
23 plan tests => $tests; 23 # check if snmpd has perl support
24 my $test = `snmpd -c tests/conf/snmpd.conf -C -r -H 2>&1`;
25 if(!defined $test) {
26 plan skip_all => "snmpd required";
27 }
28 elsif($test =~ m/Warning: Unknown token: perl/) {
29 plan skip_all => "snmpd has no perl support";
30 } else {
31 plan tests => $tests;
32 }
24 } else { 33 } else {
25 plan skip_all => "No check_snmp compiled"; 34 plan skip_all => "No check_snmp compiled";
26 } 35 }
@@ -119,7 +128,7 @@ sleep 1;
119 128
120$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); 129$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" );
121is($res->return_code, 1, "WARNING - due to going above rate calculation" ); 130is($res->return_code, 1, "WARNING - due to going above rate calculation" );
122is($res->output, "SNMP RATE WARNING - *666* | iso.3.6.1.4.1.8072.3.2.67.10=666 "); 131is($res->output, "SNMP RATE WARNING - *666* | iso.3.6.1.4.1.8072.3.2.67.10=666;600 ");
123 132
124$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); 133$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" );
125is($res->return_code, 3, "UNKNOWN - basically the divide by zero error" ); 134is($res->return_code, 3, "UNKNOWN - basically the divide by zero error" );
@@ -200,7 +209,7 @@ is($res->output, 'SNMP OK - "stringtests" | ', "OK as inverted string no match"
200 209
201$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.12 -w 4:5" ); 210$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.12 -w 4:5" );
202is($res->return_code, 1, "Numeric in string test" ); 211is($res->return_code, 1, "Numeric in string test" );
203is($res->output, 'SNMP WARNING - *3.5* | iso.3.6.1.4.1.8072.3.2.67.12=3.5 ', "WARNING threshold checks for string masquerading as number" ); 212is($res->output, 'SNMP WARNING - *3.5* | iso.3.6.1.4.1.8072.3.2.67.12=3.5;4:5 ', "WARNING threshold checks for string masquerading as number" );
204 213
205$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.13" ); 214$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.13" );
206is($res->return_code, 0, "Not really numeric test" ); 215is($res->return_code, 0, "Not really numeric test" );
@@ -216,29 +225,29 @@ is($res->output, 'SNMP OK - "CUSTOM CHECK OK: foo is 12345" | ', "String check w
216 225
217$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); 226$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" );
218is($res->return_code, 0, "Negative integer check OK" ); 227is($res->return_code, 0, "Negative integer check OK" );
219is($res->output, 'SNMP OK - -2 | iso.3.6.1.4.1.8072.3.2.67.16=-2 ', "Negative integer check OK output" ); 228is($res->output, 'SNMP OK - -2 | iso.3.6.1.4.1.8072.3.2.67.16=-2;-2:;-3: ', "Negative integer check OK output" );
220 229
221$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); 230$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" );
222is($res->return_code, 1, "Negative integer check WARNING" ); 231is($res->return_code, 1, "Negative integer check WARNING" );
223is($res->output, 'SNMP WARNING - *-3* | iso.3.6.1.4.1.8072.3.2.67.16=-3 ', "Negative integer check WARNING output" ); 232is($res->output, 'SNMP WARNING - *-3* | iso.3.6.1.4.1.8072.3.2.67.16=-3;-2:;-3: ', "Negative integer check WARNING output" );
224 233
225$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); 234$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" );
226is($res->return_code, 2, "Negative integer check CRITICAL" ); 235is($res->return_code, 2, "Negative integer check CRITICAL" );
227is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.16=-4 ', "Negative integer check CRITICAL output" ); 236is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.16=-4;-2:;-3: ', "Negative integer check CRITICAL output" );
228 237
229$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.17 -w -3: -c -6:" ); 238$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.17 -w -3: -c -6:" );
230is($res->return_code, 1, "Negative integer as string, WARNING" ); 239is($res->return_code, 1, "Negative integer as string, WARNING" );
231is($res->output, 'SNMP WARNING - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4 ', "Negative integer as string, WARNING output" ); 240is($res->output, 'SNMP WARNING - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4;-3:;-6: ', "Negative integer as string, WARNING output" );
232 241
233$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.17 -w -2: -c -3:" ); 242$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.17 -w -2: -c -3:" );
234is($res->return_code, 2, "Negative integer as string, CRITICAL" ); 243is($res->return_code, 2, "Negative integer as string, CRITICAL" );
235is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4 ', "Negative integer as string, CRITICAL output" ); 244is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4;-2:;-3: ', "Negative integer as string, CRITICAL output" );
236 245
237$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -c ~:-6.5" ); 246$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -c '~:-6.5'" );
238is($res->return_code, 0, "Negative float OK" ); 247is($res->return_code, 0, "Negative float OK" );
239is($res->output, 'SNMP OK - -6.6 | iso.3.6.1.4.1.8072.3.2.67.18=-6.6 ', "Negative float OK output" ); 248is($res->output, 'SNMP OK - -6.6 | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;;~:-6.5 ', "Negative float OK output" );
240 249
241$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -w ~:-6.65 -c ~:-6.55" ); 250$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -w '~:-6.65' -c '~:-6.55'" );
242is($res->return_code, 1, "Negative float WARNING" ); 251is($res->return_code, 1, "Negative float WARNING" );
243is($res->output, 'SNMP WARNING - *-6.6* | iso.3.6.1.4.1.8072.3.2.67.18=-6.6 ', "Negative float WARNING output" ); 252is($res->output, 'SNMP WARNING - *-6.6* | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;~:-6.65;~:-6.55 ', "Negative float WARNING output" );
244 253
diff --git a/plugins/utils.c b/plugins/utils.c
index 58b153d..a864e4a 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -144,8 +144,6 @@ usage5 (void)
144void 144void
145print_revision (const char *command_name, const char *revision) 145print_revision (const char *command_name, const char *revision)
146{ 146{
147 char plugin_revision[STRLEN];
148
149 printf ("%s v%s (%s %s)\n", 147 printf ("%s v%s (%s %s)\n",
150 command_name, revision, PACKAGE, VERSION); 148 command_name, revision, PACKAGE, VERSION);
151} 149}
@@ -630,3 +628,43 @@ char *fperfdata (const char *label,
630 628
631 return data; 629 return data;
632} 630}
631
632char *sperfdata (const char *label,
633 double val,
634 const char *uom,
635 char *warn,
636 char *crit,
637 int minp,
638 double minv,
639 int maxp,
640 double maxv)
641{
642 char *data = NULL;
643 if (strpbrk (label, "'= "))
644 xasprintf (&data, "'%s'=", label);
645 else
646 xasprintf (&data, "%s=", label);
647
648 xasprintf (&data, "%s%f", data, val);
649 xasprintf (&data, "%s%s;", data, uom);
650
651 if (warn!=NULL)
652 xasprintf (&data, "%s%s", data, warn);
653
654 xasprintf (&data, "%s;", data);
655
656 if (crit!=NULL)
657 xasprintf (&data, "%s%s", data, crit);
658
659 xasprintf (&data, "%s;", data);
660
661 if (minp)
662 xasprintf (&data, "%s%f", data, minv);
663
664 if (maxp) {
665 xasprintf (&data, "%s;", data);
666 xasprintf (&data, "%s%f", data, maxv);
667 }
668
669 return data;
670}
diff --git a/tools/generate-change-log b/tools/generate-change-log
index 3a6b38e..ad19ce9 100755
--- a/tools/generate-change-log
+++ b/tools/generate-change-log
@@ -19,6 +19,7 @@ use Text::Wrap;
19 19
20# The lines will have a length of no more than $columns - 1. 20# The lines will have a length of no more than $columns - 1.
21$Text::Wrap::columns = 81; 21$Text::Wrap::columns = 81;
22$Text::Wrap::huge = 'overflow';
22 23
23if (system('git rev-parse --git-dir >/dev/null 2>&1') != 0) { 24if (system('git rev-parse --git-dir >/dev/null 2>&1') != 0) {
24 print "Not a Git repository, so I won't update the ChangeLog.\n"; 25 print "Not a Git repository, so I won't update the ChangeLog.\n";
@@ -51,6 +52,7 @@ while ($git_log =~ /$regex/gm) {
51 $prev_date = $commit{date}; 52 $prev_date = $commit{date};
52 $prev_name = $commit{name}; 53 $prev_name = $commit{name};
53 $prev_email = $commit{email}; 54 $prev_email = $commit{email};
55 $commit{message} =~ s/\s*Signed\-off\-by.*$//sgmx;
54 56
55 my @files = split(/\n/, $commit{files}); 57 my @files = split(/\n/, $commit{files});
56 my @message = map { s/^ {4}//; $_ } split(/\n/, $commit{message}); 58 my @message = map { s/^ {4}//; $_ } split(/\n/, $commit{message});
diff --git a/tools/update-thanks b/tools/update-thanks
new file mode 100755
index 0000000..27932f9
--- /dev/null
+++ b/tools/update-thanks
@@ -0,0 +1,56 @@
1#!/bin/sh
2
3# Copyright (c) 2014 Monitoring Plugins Development Team
4#
5# Originally written by Holger Weiss <holger@zedat.fu-berlin.de>.
6#
7# This file is free software; the Monitoring Plugins Development Team gives
8# unlimited permission to copy and/or distribute it, with or without
9# modifications, as long as this notice is preserved.
10#
11# This program is distributed in the hope that it will be useful, but WITHOUT
12# ANY WARRANTY, to the extent permitted by law; without even the implied
13# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15set -e
16set -u
17
18tempfile=$(mktemp '/tmp/.plugins.XXXXXX')
19trap 'rm -f $tempfile' EXIT INT TERM
20
21if [ ! -e THANKS.in ]
22then
23 echo >&2 'Please change into the "monitoring-plugins" repository.'
24 exit 2
25fi
26
27case $# in
28 1) since=$1; git cat-file -e "$since";;
29 0) since=$(git tag -l 'v*' | tail -n 1);;
30 *) echo >&2 "Usage: $0 [<since>]"; exit 2;;
31esac
32
33git log --pretty='%an' "$since.." | sort -u | while read first last rest
34do
35 if [ -n "$first" -a -n "$last" -a -z "$rest" ]
36 then
37 if ! grep -q "^$first $last$" AUTHORS THANKS.in
38 then
39 echo "$first $last" >> THANKS.in
40 fi
41 else
42 echo "$first $last $rest" | sed 's/ *$//' >> "$tempfile"
43 fi
44done
45
46if ! git diff --quiet THANKS.in
47then
48 echo 'Please check/commit the changes in the THANKS.in file.'
49fi
50
51if [ -s "$tempfile" ]
52then
53 echo 'The following authors were NOT added to the THANKS.in file:'
54 echo
55 cat "$tempfile"
56fi