summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.github/NPTest.cache (renamed from plugins/t/NPTest.cache.travis)8
-rwxr-xr-x.github/prepare_debian.sh101
-rw-r--r--.github/workflows/test.yml47
-rw-r--r--.travis.yml98
-rw-r--r--NEWS1
-rw-r--r--configure.ac10
-rw-r--r--lib/utils_base.c2
-rw-r--r--lib/utils_base.h1
-rw-r--r--lib/utils_disk.h2
-rw-r--r--plugins-root/Makefile.am3
-rw-r--r--plugins-root/check_icmp.c2
-rw-r--r--plugins-root/t/check_dhcp.t9
-rwxr-xr-xplugins-scripts/check_ifoperstatus.pl2
-rwxr-xr-xplugins-scripts/check_ircd.pl4
-rw-r--r--plugins/check_by_ssh.c2
-rw-r--r--plugins/check_curl.c184
-rw-r--r--plugins/check_disk.c189
-rw-r--r--plugins/check_dns.c81
-rw-r--r--plugins/check_http.c14
-rw-r--r--plugins/check_load.c2
-rw-r--r--plugins/check_mysql_query.c12
-rw-r--r--plugins/check_pgsql.c2
-rw-r--r--plugins/check_procs.c50
-rw-r--r--plugins/check_smtp.c18
-rw-r--r--plugins/check_snmp.c14
-rw-r--r--plugins/check_swap.c237
-rw-r--r--plugins/t/check_curl.t16
-rw-r--r--plugins/t/check_disk.t7
-rw-r--r--plugins/t/check_dns.t10
-rw-r--r--plugins/t/check_fping.t32
-rw-r--r--plugins/t/check_http.t4
-rw-r--r--plugins/t/check_load.t4
-rw-r--r--plugins/t/check_swap.t6
-rwxr-xr-xplugins/tests/check_curl.t21
-rwxr-xr-xplugins/tests/check_http.t17
-rwxr-xr-xplugins/tests/check_procs.t24
-rwxr-xr-xplugins/tests/check_snmp.t17
-rw-r--r--plugins/tests/var/ps-axwo.debian219
-rw-r--r--plugins/tests/var/ps_axwo.debian84
-rw-r--r--plugins/utils.c124
-rw-r--r--plugins/utils.h9
41 files changed, 1160 insertions, 529 deletions
diff --git a/plugins/t/NPTest.cache.travis b/.github/NPTest.cache
index 9b9f805..232305a 100644
--- a/plugins/t/NPTest.cache.travis
+++ b/.github/NPTest.cache
@@ -11,7 +11,7 @@
11 'NP_HOSTNAME_VALID_IP' => '130.133.8.40', 11 'NP_HOSTNAME_VALID_IP' => '130.133.8.40',
12 'NP_HOSTNAME_VALID' => 'monitoring-plugins.org', 12 'NP_HOSTNAME_VALID' => 'monitoring-plugins.org',
13 'NP_HOSTNAME_VALID_REVERSE' => 'orwell.monitoring-plugins.org.', 13 'NP_HOSTNAME_VALID_REVERSE' => 'orwell.monitoring-plugins.org.',
14 'NP_HOST_NONRESPONSIVE' => '10.0.0.1', 14 'NP_HOST_NONRESPONSIVE' => '192.168.1.2',
15 'NP_HOST_RESPONSIVE' => 'localhost', 15 'NP_HOST_RESPONSIVE' => 'localhost',
16 'NP_HOST_SMB' => '', 16 'NP_HOST_SMB' => '',
17 'NP_HOST_SNMP' => '', 17 'NP_HOST_SNMP' => '',
@@ -27,12 +27,12 @@
27 'NP_HOST_TCP_SMTP' => 'localhost', 27 'NP_HOST_TCP_SMTP' => 'localhost',
28 'NP_HOST_TCP_SMTP_NOTLS' => '', 28 'NP_HOST_TCP_SMTP_NOTLS' => '',
29 'NP_HOST_TCP_SMTP_TLS' => '', 29 'NP_HOST_TCP_SMTP_TLS' => '',
30 'NP_HOST_TLS_CERT' => 'localhost, 30 'NP_HOST_TLS_CERT' => 'localhost',
31 'NP_HOST_TLS_HTTP' => 'localhost', 31 'NP_HOST_TLS_HTTP' => 'localhost',
32 'NP_HOST_UDP_TIME' => 'none', 32 'NP_HOST_UDP_TIME' => 'none',
33 'NP_INTERNET_ACCESS' => 'yes', 33 'NP_INTERNET_ACCESS' => 'yes',
34 'NP_LDAP_BASE_DN' => 'cn=admin,dc=nodomain', 34 'NP_LDAP_BASE_DN' => 'dc=nodomain',
35 'NP_MOUNTPOINT2_VALID' => '/media/ramdisk', 35 'NP_MOUNTPOINT2_VALID' => '/media/ramdisk1',
36 'NP_MOUNTPOINT_VALID' => '/', 36 'NP_MOUNTPOINT_VALID' => '/',
37 'NP_MYSQL_LOGIN_DETAILS' => '-u root -d test', 37 'NP_MYSQL_LOGIN_DETAILS' => '-u root -d test',
38 'NP_MYSQL_SERVER' => 'localhost', 38 'NP_MYSQL_SERVER' => 'localhost',
diff --git a/.github/prepare_debian.sh b/.github/prepare_debian.sh
new file mode 100755
index 0000000..4021c10
--- /dev/null
+++ b/.github/prepare_debian.sh
@@ -0,0 +1,101 @@
1#!/bin/bash
2
3set -x
4set -e
5
6export DEBIAN_FRONTEND=noninteractive
7
8apt-get update
9apt-get -y install software-properties-common
10if [ $(lsb_release -is) = "Debian" ]; then
11 apt-add-repository non-free
12 apt-get update
13fi
14apt-get -y install perl autotools-dev libdbi-dev libldap2-dev libpq-dev libradcli-dev libnet-snmp-perl procps
15apt-get -y install libdbi0-dev libdbd-sqlite3 libssl-dev dnsutils snmp-mibs-downloader libsnmp-perl snmpd
16apt-get -y install fping snmp netcat-openbsd smbclient vsftpd apache2 ssl-cert postfix libhttp-daemon-ssl-perl
17apt-get -y install libdbd-sybase-perl libnet-dns-perl
18apt-get -y install slapd ldap-utils
19apt-get -y install gcc make autoconf automake gettext
20apt-get -y install faketime
21apt-get -y install libmonitoring-plugin-perl
22apt-get -y install libcurl4-openssl-dev
23apt-get -y install liburiparser-dev
24apt-get -y install squid
25apt-get -y install openssh-server
26apt-get -y install mariadb-server mariadb-client libmariadb-dev
27apt-get -y install cron iputils-ping
28apt-get -y install iproute2
29
30# remove ipv6 interface from hosts
31if [ $(ip addr show | grep "inet6 ::1" | wc -l) -eq "0" ]; then
32 sed '/^::1/d' /etc/hosts > /tmp/hosts
33 cp -f /tmp/hosts /etc/hosts
34fi
35
36ip addr show
37
38cat /etc/hosts
39
40
41# apache
42a2enmod ssl
43a2ensite default-ssl
44# replace snakeoil certs with openssl generated ones as the make-ssl-cert ones
45# seems to cause problems with our plugins
46rm /etc/ssl/certs/ssl-cert-snakeoil.pem
47rm /etc/ssl/private/ssl-cert-snakeoil.key
48openssl req -nodes -newkey rsa:2048 -x509 -sha256 -days 365 -nodes -keyout /etc/ssl/private/ssl-cert-snakeoil.key -out /etc/ssl/certs/ssl-cert-snakeoil.pem -subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=$(hostname)"
49service apache2 restart
50
51# squid
52cp tools/squid.conf /etc/squid/squid.conf
53service squid start
54
55# mariadb
56service mariadb start
57mysql -e "create database IF NOT EXISTS test;" -uroot
58
59# ldap
60sed -e 's/cn=admin,dc=nodomain/'$(/usr/sbin/slapcat|grep ^dn:|awk '{print $2}')'/' -i .github/NPTest.cache
61service slapd start
62
63# sshd
64ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
65cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
66service ssh start
67sleep 1
68ssh-keyscan localhost >> ~/.ssh/known_hosts
69touch ~/.ssh/config
70
71# start one login session, required for check_users
72ssh -tt localhost </dev/null >/dev/null 2>/dev/null &
73disown %1
74
75# snmpd
76for DIR in /usr/share/snmp/mibs /usr/share/mibs; do
77 rm -f $DIR/ietf/SNMPv2-PDU \
78 $DIR/ietf/IPSEC-SPD-MIB \
79 $DIR/ietf/IPATM-IPMC-MIB \
80 $DIR/iana/IANA-IPPM-METRICS-REGISTRY-MIB
81done
82mkdir -p /var/lib/snmp/mib_indexes
83sed -e 's/^agentaddress.*/agentaddress 127.0.0.1/' -i /etc/snmp/snmpd.conf
84service snmpd start
85
86# start cron, will be used by check_nagios
87cron
88
89# start postfix
90service postfix start
91
92# start ftpd
93service vsftpd start
94
95# hostname
96sed "/NP_HOST_TLS_CERT/s/.*/'NP_HOST_TLS_CERT' => '$(hostname)',/" -i /src/.github/NPTest.cache
97
98# create some test files to lower inodes
99for i in $(seq 10); do
100 touch /media/ramdisk2/test.$1
101done
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..0f93930
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,47 @@
1name: Test
2
3on:
4 push:
5 branches:
6 - '*'
7 pull_request:
8
9jobs:
10# macos:
11# ...
12 linux:
13 runs-on: ubuntu-latest
14 name: Running tests on ${{ matrix.distro }}
15 strategy:
16 fail-fast: false
17 matrix:
18 distro:
19 - 'debian:testing'
20 #...
21 include:
22 - distro: 'debian:testing'
23 prepare: .github/prepare_debian.sh
24 #...
25 steps:
26 - name: Git clone repository
27 uses: actions/checkout@v2
28 #- name: Setup tmate session, see https://github.com/marketplace/actions/debugging-with-tmate
29 # uses: mxschmitt/action-tmate@v3
30 - name: Run the tests on ${{ matrix.distro }}
31 run: |
32 docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=size=100m,uid=1000 tmp-vol
33 docker run \
34 -e NPTEST_ACCEPTDEFAULT=1 \
35 -e NPTEST_CACHE="/src/.github/NPTest.cache" \
36 -w /src -v ${PWD}:/src \
37 --tmpfs /media/ramdisk1 \
38 -v /var/run/utmp:/var/run/utmp \
39 --mount source=tmp-vol,destination=/src,target=/media/ramdisk2 \
40 ${{ matrix.distro }} \
41 /bin/sh -c '${{ matrix.prepare }} && \
42 tools/setup && \
43 ./configure --enable-libtap --with-ipv6=no && \
44 make && \
45 make test'
46 docker container prune -f
47 docker volume prune -f
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 3d9fe64..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,98 +0,0 @@
1sudo: required
2dist: xenial
3language: c
4
5env:
6 global:
7 # This is the encrypted COVERITY_SCAN_TOKEN, created via the "travis
8 # encrypt" command using the project repository's public key.
9 - secure: "ggJ9c/VfKcwtrwz/My+ne4My7D8g3qi3vz5Hh+yLiri0+oIXCy313ZD6ssIEY/5beQZEOnuHhBgBJd/Y3clSQNc2M9fRNc+wxOkIO992lgnY0MZJN3y9MLfpqUbTClhU9Fst0qXQqGpI6UI8yz1tj7yKi7DPrycJLRrjMpyTfyo="
10
11matrix:
12 include:
13 - compiler: "gcc"
14 os: linux
15 env:
16 - PLATFORM=linux BITS=64 HOST=x86_64
17 addons:
18 coverity_scan:
19 project:
20 name: "monitoring-plugins/monitoring-plugins"
21 description: "Monitoring Plugins"
22 notification_email: team@monitoring-plugins.org
23 build_command_prepend: tools/setup && ./configure
24 build_command: make
25 branch_pattern: coverity.*
26 - compiler: "clang"
27 os: linux
28 env:
29 - PLATFORM=linux BITS=64 HOST=x86_64
30
31before_install:
32 # Trusty related fixed
33 # multiverse is no on trusty activated (https://github.com/travis-ci/travis-ci/issues/4979)
34 - sudo apt-get install -qq --no-install-recommends software-properties-common
35 - sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ trusty multiverse" && sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ trusty-updates multiverse"
36 # /etc/hosts has IPv6 hosts (https://github.com/travis-ci/travis-ci/issues/4978)
37 - sudo [ $(ip addr show | grep "inet6 ::1" | wc -l) -eq "0" ] || sudo sed -i '/^::1/d' /etc/hosts
38 # Trusty has running ntpd on localhost, but we don't like that for our tests
39 - "sudo killall -9 ntpd ||:"
40 # Trusty has no swap, lets create some
41 - sudo fallocate -l 20M /swapfile; sudo chmod 600 /swapfile; sudo mkswap /swapfile; sudo swapon /swapfile
42 - sudo apt-get update -qq
43 - sudo apt-get purge -qq gawk
44
45install:
46 - sudo apt-get install -qq --no-install-recommends perl autotools-dev libdbi-dev libldap2-dev libpq-dev libmysqlclient-dev libradcli-dev libkrb5-dev libnet-snmp-perl procps
47 - sudo apt-get install -qq --no-install-recommends libdbi0-dev libdbd-sqlite3 libssl-dev dnsutils snmp-mibs-downloader libsnmp-perl snmpd
48 - sudo apt-get install -qq --no-install-recommends fping snmp netcat smbclient fping pure-ftpd apache2 ssl-cert postfix libhttp-daemon-ssl-perl
49 - sudo apt-get install -qq --no-install-recommends libdbd-sybase-perl libnet-dns-perl
50 - sudo apt-get install -qq --no-install-recommends slapd ldap-utils
51 - sudo apt-get install -qq --no-install-recommends autoconf automake
52 - sudo apt-get install -qq --no-install-recommends faketime
53 - sudo apt-get install -qq --no-install-recommends libmonitoring-plugin-perl
54 - sudo apt-get install -qq --no-install-recommends libcurl4-openssl-dev
55 - sudo apt-get install -qq --no-install-recommends liburiparser-dev
56 - sudo apt-get install -qq --no-install-recommends squid
57 # Trusty related dependencies (not yet provided)
58 - test "$(dpkg -l | grep -E "mysql-(client|server)-[0-9].[0-9]" | grep -c ^ii)" -gt 0 || sudo apt-get install -qq --no-install-recommends mariadb-client mariadb-server
59 # enable ssl apache
60 - sudo a2enmod ssl
61 - sudo a2ensite default-ssl
62 - sudo make-ssl-cert generate-default-snakeoil --force-overwrite
63 - sudo service apache2 reload
64 - sudo cp tools/squid.conf /etc/squid/squid.conf
65 - sudo service squid reload
66 - sudo service mysql restart
67
68before_script:
69 # ensure we have a test database in place for tests
70 - mysql -e "create database IF NOT EXISTS test;" -uroot
71 # Detect LDAP configuration (seems volatile on trusty env)
72 - sed -e 's/cn=admin,dc=nodomain/'$(sudo /usr/sbin/slapcat|grep ^dn:|grep cn=|awk '{print $2}')'/' -i plugins/t/NPTest.cache.travis
73 - tools/setup
74 - ./configure --enable-libtap
75 - make
76 - export NPTEST_ACCEPTDEFAULT=1
77 - export NPTEST_CACHE="$(pwd)/plugins/t/NPTest.cache.travis"
78 - ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
79 - cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
80 - ssh-keyscan localhost >> ~/.ssh/known_hosts
81 - touch ~/.ssh/config
82 - sudo rm -f /usr/share/mibs/ietf/SNMPv2-PDU /usr/share/mibs/ietf/IPSEC-SPD-MIB /usr/share/mibs/ietf/IPATM-IPMC-MIB /usr/share/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB
83 - sudo mkdir -p /var/lib/snmp/mib_indexes
84 - sudo mkdir /media/ramdisk && sudo chmod 777 /media/ramdisk && sudo mount -t tmpfs -o size=20% none /media/ramdisk
85 - sed "/NP_HOST_TLS_CERT/s/.*/'NP_HOST_TLS_CERT' => '$(hostname)',/" -i $NPTEST_CACHE
86
87script:
88 - if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then make test; fi
89
90notifications:
91 irc:
92 channels:
93 - "chat.freenode.net#Monitoring-Plugins"
94 on_success: change
95 on_failure: always
96 skip_join: true
97 email:
98 # - team@monitoring-plugins.org
diff --git a/NEWS b/NEWS
index 4061c03..3790e8a 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@ This file documents the major additions and syntax changes between releases.
13 check_dns: Accept CIDR 13 check_dns: Accept CIDR
14 check_dns: allow unsorted addresses 14 check_dns: allow unsorted addresses
15 check_dns: allow forcing complete match of all addresses 15 check_dns: allow forcing complete match of all addresses
16 check_dns: option to expect NXDOMAIN
16 check_apt: add --only-critical switch 17 check_apt: add --only-critical switch
17 check_apt: add -l/--list option to print packages 18 check_apt: add -l/--list option to print packages
18 check_file_age: add range checking 19 check_file_age: add range checking
diff --git a/configure.ac b/configure.ac
index 7c17dcd..dfc37b5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -783,6 +783,16 @@ dnl ac_cv_ps_format=["%*s %d %d %d %d %*d %*d %d %d%*[ 0123456789abcdef]%[OSRZT
783dnl ac_cv_ps_cols=8 783dnl ac_cv_ps_cols=8
784dnl AC_MSG_RESULT([$ac_cv_ps_command]) 784dnl AC_MSG_RESULT([$ac_cv_ps_command])
785 785
786dnl This one is the exact same test as the next one but includes etime
787elif ps axwo 'stat comm vsz rss user uid pid ppid etime args' 2>/dev/null | \
788 egrep -i ["^ *STAT +[UCOMAND]+ +VSZ +RSS +USER +UID +PID +PPID +ELAPSED +COMMAND"] > /dev/null
789then
790 ac_cv_ps_varlist="[procstat,&procuid,&procpid,&procppid,&procvsz,&procrss,&procpcpu,procetime,procprog,&pos]"
791 ac_cv_ps_command="$PATH_TO_PS axwo 'stat uid pid ppid vsz rss pcpu etime comm args'"
792 ac_cv_ps_format="%s %d %d %d %d %d %f %s %s %n"
793 ac_cv_ps_cols=10
794 AC_MSG_RESULT([$ac_cv_ps_command])
795
786dnl Some gnu/linux systems (debian for one) don't like -axwo and need axwo. 796dnl Some gnu/linux systems (debian for one) don't like -axwo and need axwo.
787dnl so test for this first... 797dnl so test for this first...
788elif ps axwo 'stat comm vsz rss user uid pid ppid args' 2>/dev/null | \ 798elif ps axwo 'stat comm vsz rss user uid pid ppid args' 2>/dev/null | \
diff --git a/lib/utils_base.c b/lib/utils_base.c
index fd7058d..08fa215 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -128,6 +128,7 @@ range
128 temp_range->end = 0; 128 temp_range->end = 0;
129 temp_range->end_infinity = TRUE; 129 temp_range->end_infinity = TRUE;
130 temp_range->alert_on = OUTSIDE; 130 temp_range->alert_on = OUTSIDE;
131 temp_range->text = strdup(str);
131 132
132 if (str[0] == '@') { 133 if (str[0] == '@') {
133 temp_range->alert_on = INSIDE; 134 temp_range->alert_on = INSIDE;
@@ -706,4 +707,3 @@ void np_state_write_string(time_t data_time, char *data_string) {
706 707
707 np_free(temp_file); 708 np_free(temp_file);
708} 709}
709
diff --git a/lib/utils_base.h b/lib/utils_base.h
index d7e7dff..9482f23 100644
--- a/lib/utils_base.h
+++ b/lib/utils_base.h
@@ -23,6 +23,7 @@ typedef struct range_struct {
23 double end; 23 double end;
24 int end_infinity; 24 int end_infinity;
25 int alert_on; /* OUTSIDE (default) or INSIDE */ 25 int alert_on; /* OUTSIDE (default) or INSIDE */
26 char* text; /* original unparsed text input */
26 } range; 27 } range;
27 28
28typedef struct thresholds_struct { 29typedef struct thresholds_struct {
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index 999270c..bf52e4c 100644
--- a/lib/utils_disk.h
+++ b/lib/utils_disk.h
@@ -27,7 +27,7 @@ struct parameter_list
27 uintmax_t total, available, available_to_root, used, 27 uintmax_t total, available, available_to_root, used,
28 inodes_free, inodes_free_to_root, inodes_used, inodes_total; 28 inodes_free, inodes_free_to_root, inodes_used, inodes_total;
29 double dfree_pct, dused_pct; 29 double dfree_pct, dused_pct;
30 double dused_units, dfree_units, dtotal_units; 30 uint64_t dused_units, dfree_units, dtotal_units;
31 double dused_inodes_percent, dfree_inodes_percent; 31 double dused_inodes_percent, dfree_inodes_percent;
32}; 32};
33 33
diff --git a/plugins-root/Makefile.am b/plugins-root/Makefile.am
index a1ebb6d..7cd2675 100644
--- a/plugins-root/Makefile.am
+++ b/plugins-root/Makefile.am
@@ -37,6 +37,9 @@ TESTS = @PLUGIN_TEST@
37test: 37test:
38 perl -I $(top_builddir) -I $(top_srcdir) ../test.pl 38 perl -I $(top_builddir) -I $(top_srcdir) ../test.pl
39 39
40test-debug:
41 NPTEST_DEBUG=1 HARNESS_VERBOSE=1 perl -I $(top_builddir) -I $(top_srcdir) ../test.pl
42
40setuid_root_mode = ug=rx,u+s 43setuid_root_mode = ug=rx,u+s
41 44
42# /* Author Coreutils team - see ACKNOWLEDGEMENTS */ 45# /* Author Coreutils team - see ACKNOWLEDGEMENTS */
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 31eb4c6..519b93c 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -921,7 +921,7 @@ wait_for_reply(int sock, u_int t)
921 /* if we're in hostcheck mode, exit with limited printouts */ 921 /* if we're in hostcheck mode, exit with limited printouts */
922 if(mode == MODE_HOSTCHECK) { 922 if(mode == MODE_HOSTCHECK) {
923 printf("OK - %s responds to ICMP. Packet %u, rta %0.3fms|" 923 printf("OK - %s responds to ICMP. Packet %u, rta %0.3fms|"
924 "pkt=%u;;0;%u rta=%0.3f;%0.3f;%0.3f;;\n", 924 "pkt=%u;;;0;%u rta=%0.3f;%0.3f;%0.3f;;\n",
925 host->name, icmp_recv, (float)tdiff / 1000, 925 host->name, icmp_recv, (float)tdiff / 1000,
926 icmp_recv, packets, (float)tdiff / 1000, 926 icmp_recv, packets, (float)tdiff / 1000,
927 (float)warn.rta / 1000, (float)crit.rta / 1000); 927 (float)warn.rta / 1000, (float)crit.rta / 1000);
diff --git a/plugins-root/t/check_dhcp.t b/plugins-root/t/check_dhcp.t
index 222f454..ce62773 100644
--- a/plugins-root/t/check_dhcp.t
+++ b/plugins-root/t/check_dhcp.t
@@ -19,7 +19,7 @@ if ($allow_sudo eq "yes" or $> == 0) {
19my $sudo = $> == 0 ? '' : 'sudo'; 19my $sudo = $> == 0 ? '' : 'sudo';
20 20
21my $successOutput = '/OK: Received \d+ DHCPOFFER\(s\), \d+ of 1 requested servers responded, max lease time = \d+ sec\./'; 21my $successOutput = '/OK: Received \d+ DHCPOFFER\(s\), \d+ of 1 requested servers responded, max lease time = \d+ sec\./';
22my $failureOutput = '/CRITICAL: No DHCPOFFERs were received/'; 22my $failureOutput = '/CRITICAL: (No DHCPOFFERs were received|Received \d+ DHCPOFFER\(s\), 0 of 1 requested servers responded, max lease time = \d+ sec\.)/';
23my $invalidOutput = '/Invalid hostname/'; 23my $invalidOutput = '/Invalid hostname/';
24 24
25my $host_responsive = getTestParameter( "NP_HOST_DHCP_RESPONSIVE", 25my $host_responsive = getTestParameter( "NP_HOST_DHCP_RESPONSIVE",
@@ -36,7 +36,12 @@ my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
36 36
37# try to determince interface 37# try to determince interface
38my $interface = ''; 38my $interface = '';
39if(`ifconfig -a 2>/dev/null` =~ m/^(e\w*\d+)/mx and $1 ne 'eth0') { 39
40# find interface used for default route
41if (-x '/usr/sbin/ip' and `/usr/sbin/ip route get 1.1.1.1 2>/dev/null` =~ m/\sdev\s(\S+)/) {
42 $interface = "-i $1";
43}
44elsif (`ifconfig -a 2>/dev/null` =~ m/^(e\w*\d+)/mx and $1 ne 'eth0') {
40 $interface = ' -i '.$1; 45 $interface = ' -i '.$1;
41} 46}
42 47
diff --git a/plugins-scripts/check_ifoperstatus.pl b/plugins-scripts/check_ifoperstatus.pl
index 9ede163..c190ce9 100755
--- a/plugins-scripts/check_ifoperstatus.pl
+++ b/plugins-scripts/check_ifoperstatus.pl
@@ -124,10 +124,10 @@ if (!defined($session)) {
124## map ifdescr to ifindex - should look at being able to cache this value 124## map ifdescr to ifindex - should look at being able to cache this value
125 125
126if (defined $ifdescr || defined $iftype) { 126if (defined $ifdescr || defined $iftype) {
127 # escape "/" in ifdescr - very common in the Cisco world
128 if (defined $iftype) { 127 if (defined $iftype) {
129 $status=fetch_ifindex($snmpIfType, $iftype); 128 $status=fetch_ifindex($snmpIfType, $iftype);
130 } else { 129 } else {
130 # escape "/" in ifdescr - very common in the Cisco world
131 $ifdescr =~ s/\//\\\//g; 131 $ifdescr =~ s/\//\\\//g;
132 $status=fetch_ifindex($snmpIfDescr, $ifdescr); # if using on device with large number of interfaces 132 $status=fetch_ifindex($snmpIfDescr, $ifdescr); # if using on device with large number of interfaces
133 # recommend use of SNMP v2 (get-bulk) 133 # recommend use of SNMP v2 (get-bulk)
diff --git a/plugins-scripts/check_ircd.pl b/plugins-scripts/check_ircd.pl
index 22d21c2..d869ae7 100755
--- a/plugins-scripts/check_ircd.pl
+++ b/plugins-scripts/check_ircd.pl
@@ -69,7 +69,9 @@ $ENV{'ENV'}='';
69# -----------------------------------------------------------------[ Global ]-- 69# -----------------------------------------------------------------[ Global ]--
70 70
71$PROGNAME = "check_ircd"; 71$PROGNAME = "check_ircd";
72my $NICK="ircd$$"; 72# nickname shouldn't be longer than 9 chars, this might happen with large PIDs
73# To prevent this, we cut of the part over 10000
74my $NICK="ircd" . $$ % 10000;
73my $USER_INFO="monitor localhost localhost : "; 75my $USER_INFO="monitor localhost localhost : ";
74 76
75# -------------------------------------------------------------[ connection ]-- 77# -------------------------------------------------------------[ connection ]--
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 13d8bc3..485bf3b 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -230,7 +230,6 @@ process_arguments (int argc, char **argv)
230 timeout_interval = atoi (optarg); 230 timeout_interval = atoi (optarg);
231 break; 231 break;
232 case 'H': /* host */ 232 case 'H': /* host */
233 host_or_die(optarg);
234 hostname = optarg; 233 hostname = optarg;
235 break; 234 break;
236 case 'p': /* port number */ 235 case 'p': /* port number */
@@ -329,7 +328,6 @@ process_arguments (int argc, char **argv)
329 if (c <= argc) { 328 if (c <= argc) {
330 die (STATE_UNKNOWN, _("%s: You must provide a host name\n"), progname); 329 die (STATE_UNKNOWN, _("%s: You must provide a host name\n"), progname);
331 } 330 }
332 host_or_die(argv[c]);
333 hostname = argv[c++]; 331 hostname = argv[c++];
334 } 332 }
335 333
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 2d69b31..14cc846 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -55,6 +55,12 @@ const char *email = "devel@monitoring-plugins.org";
55 55
56#include <arpa/inet.h> 56#include <arpa/inet.h>
57 57
58#if defined(HAVE_SSL) && defined(USE_OPENSSL)
59#include <openssl/opensslv.h>
60#endif
61
62#include <netdb.h>
63
58#define MAKE_LIBCURL_VERSION(major, minor, patch) ((major)*0x10000 + (minor)*0x100 + (patch)) 64#define MAKE_LIBCURL_VERSION(major, minor, patch) ((major)*0x10000 + (minor)*0x100 + (patch))
59 65
60#define DEFAULT_BUFFER_SIZE 2048 66#define DEFAULT_BUFFER_SIZE 2048
@@ -117,7 +123,7 @@ typedef enum curlhelp_ssl_library {
117 123
118enum { 124enum {
119 REGS = 2, 125 REGS = 2,
120 MAX_RE_SIZE = 256 126 MAX_RE_SIZE = 1024
121}; 127};
122#include "regex.h" 128#include "regex.h"
123regex_t preg; 129regex_t preg;
@@ -145,6 +151,7 @@ thresholds *thlds;
145char user_agent[DEFAULT_BUFFER_SIZE]; 151char user_agent[DEFAULT_BUFFER_SIZE];
146int verbose = 0; 152int verbose = 0;
147int show_extended_perfdata = FALSE; 153int show_extended_perfdata = FALSE;
154int show_body = FALSE;
148int min_page_len = 0; 155int min_page_len = 0;
149int max_page_len = 0; 156int max_page_len = 0;
150int redir_depth = 0; 157int redir_depth = 0;
@@ -195,6 +202,7 @@ int ssl_version = CURL_SSLVERSION_DEFAULT;
195char *client_cert = NULL; 202char *client_cert = NULL;
196char *client_privkey = NULL; 203char *client_privkey = NULL;
197char *ca_cert = NULL; 204char *ca_cert = NULL;
205int verify_peer_and_host = FALSE;
198int is_openssl_callback = FALSE; 206int is_openssl_callback = FALSE;
199#if defined(HAVE_SSL) && defined(USE_OPENSSL) 207#if defined(HAVE_SSL) && defined(USE_OPENSSL)
200X509 *cert = NULL; 208X509 *cert = NULL;
@@ -204,6 +212,7 @@ int maximum_age = -1;
204int address_family = AF_UNSPEC; 212int address_family = AF_UNSPEC;
205curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; 213curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN;
206int curl_http_version = CURL_HTTP_VERSION_NONE; 214int curl_http_version = CURL_HTTP_VERSION_NONE;
215int automatic_decompression = FALSE;
207 216
208int process_arguments (int, char**); 217int process_arguments (int, char**);
209void handle_curl_option_return_code (CURLcode res, const char* option); 218void handle_curl_option_return_code (CURLcode res, const char* option);
@@ -283,6 +292,20 @@ int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx)
283 * TODO: is the last certificate always the server certificate? 292 * TODO: is the last certificate always the server certificate?
284 */ 293 */
285 cert = X509_STORE_CTX_get_current_cert(x509_ctx); 294 cert = X509_STORE_CTX_get_current_cert(x509_ctx);
295#if OPENSSL_VERSION_NUMBER >= 0x10100000L
296 X509_up_ref(cert);
297#endif
298 if (verbose>=2) {
299 puts("* SSL verify callback with certificate:");
300 X509_NAME *subject, *issuer;
301 printf("* issuer:\n");
302 issuer = X509_get_issuer_name( cert );
303 X509_NAME_print_ex_fp(stdout, issuer, 5, XN_FLAG_MULTILINE);
304 printf("* curl verify_callback:\n* subject:\n");
305 subject = X509_get_subject_name( cert );
306 X509_NAME_print_ex_fp(stdout, subject, 5, XN_FLAG_MULTILINE);
307 puts("");
308 }
286 return 1; 309 return 1;
287} 310}
288 311
@@ -296,6 +319,28 @@ CURLcode sslctxfun(CURL *curl, SSL_CTX *sslctx, void *parm)
296#endif /* USE_OPENSSL */ 319#endif /* USE_OPENSSL */
297#endif /* HAVE_SSL */ 320#endif /* HAVE_SSL */
298 321
322/* returns a string "HTTP/1.x" or "HTTP/2" */
323static char *string_statuscode (int major, int minor)
324{
325 static char buf[10];
326
327 switch (major) {
328 case 1:
329 snprintf (buf, sizeof (buf), "HTTP/%d.%d", major, minor);
330 break;
331 case 2:
332 case 3:
333 snprintf (buf, sizeof (buf), "HTTP/%d", major);
334 break;
335 default:
336 /* assuming here HTTP/N with N>=4 */
337 snprintf (buf, sizeof (buf), "HTTP/%d", major);
338 break;
339 }
340
341 return buf;
342}
343
299/* Checks if the server 'reply' is one of the expected 'statuscodes' */ 344/* Checks if the server 'reply' is one of the expected 'statuscodes' */
300static int 345static int
301expected_statuscode (const char *reply, const char *statuscodes) 346expected_statuscode (const char *reply, const char *statuscodes)
@@ -327,12 +372,55 @@ handle_curl_option_return_code (CURLcode res, const char* option)
327} 372}
328 373
329int 374int
375lookup_host (const char *host, char *buf, size_t buflen)
376{
377 struct addrinfo hints, *res, *result;
378 int errcode;
379 void *ptr;
380
381 memset (&hints, 0, sizeof (hints));
382 hints.ai_family = address_family;
383 hints.ai_socktype = SOCK_STREAM;
384 hints.ai_flags |= AI_CANONNAME;
385
386 errcode = getaddrinfo (host, NULL, &hints, &result);
387 if (errcode != 0)
388 return errcode;
389
390 res = result;
391
392 while (res) {
393 inet_ntop (res->ai_family, res->ai_addr->sa_data, buf, buflen);
394 switch (res->ai_family) {
395 case AF_INET:
396 ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr;
397 break;
398 case AF_INET6:
399 ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
400 break;
401 }
402 inet_ntop (res->ai_family, ptr, buf, buflen);
403 if (verbose >= 1)
404 printf ("* getaddrinfo IPv%d address: %s\n",
405 res->ai_family == PF_INET6 ? 6 : 4, buf);
406 res = res->ai_next;
407 }
408
409 freeaddrinfo(result);
410
411 return 0;
412}
413
414int
330check_http (void) 415check_http (void)
331{ 416{
332 int result = STATE_OK; 417 int result = STATE_OK;
333 int page_len = 0; 418 int page_len = 0;
334 int i; 419 int i;
335 char *force_host_header = NULL; 420 char *force_host_header = NULL;
421 struct curl_slist *host = NULL;
422 char addrstr[100];
423 char dnscache[DEFAULT_BUFFER_SIZE];
336 424
337 /* initialize curl */ 425 /* initialize curl */
338 if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) 426 if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK)
@@ -347,6 +435,13 @@ check_http (void)
347 /* print everything on stdout like check_http would do */ 435 /* print everything on stdout like check_http would do */
348 handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_STDERR, stdout), "CURLOPT_STDERR"); 436 handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_STDERR, stdout), "CURLOPT_STDERR");
349 437
438 if (automatic_decompression)
439#if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 21, 6)
440 handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, ""), "CURLOPT_ACCEPT_ENCODING");
441#else
442 handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_ENCODING, ""), "CURLOPT_ENCODING");
443#endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 21, 6) */
444
350 /* initialize buffer for body of the answer */ 445 /* initialize buffer for body of the answer */
351 if (curlhelp_initwritebuffer(&body_buf) < 0) 446 if (curlhelp_initwritebuffer(&body_buf) < 0)
352 die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for body\n"); 447 die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for body\n");
@@ -368,9 +463,12 @@ check_http (void)
368 463
369 // fill dns resolve cache to make curl connect to the given server_address instead of the host_name, only required for ssl, because we use the host_name later on to make SNI happy 464 // fill dns resolve cache to make curl connect to the given server_address instead of the host_name, only required for ssl, because we use the host_name later on to make SNI happy
370 if(use_ssl && host_name != NULL) { 465 if(use_ssl && host_name != NULL) {
371 struct curl_slist *host = NULL; 466 if ( (res=lookup_host (server_address, addrstr, 100)) != 0) {
372 char dnscache[DEFAULT_BUFFER_SIZE]; 467 snprintf (msg, DEFAULT_BUFFER_SIZE, _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"),
373 snprintf (dnscache, DEFAULT_BUFFER_SIZE, "%s:%d:%s", host_name, server_port, server_address); 468 server_address, res, gai_strerror (res));
469 die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg);
470 }
471 snprintf (dnscache, DEFAULT_BUFFER_SIZE, "%s:%d:%s", host_name, server_port, addrstr);
374 host = curl_slist_append(NULL, dnscache); 472 host = curl_slist_append(NULL, dnscache);
375 curl_easy_setopt(curl, CURLOPT_RESOLVE, host); 473 curl_easy_setopt(curl, CURLOPT_RESOLVE, host);
376 if (verbose>=1) 474 if (verbose>=1)
@@ -467,9 +565,11 @@ check_http (void)
467 if (client_privkey) 565 if (client_privkey)
468 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_SSLKEY, client_privkey), "CURLOPT_SSLKEY"); 566 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_SSLKEY, client_privkey), "CURLOPT_SSLKEY");
469 if (ca_cert) { 567 if (ca_cert) {
568 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CAINFO, ca_cert), "CURLOPT_CAINFO");
569 }
570 if (ca_cert || verify_peer_and_host) {
470 /* per default if we have a CA verify both the peer and the 571 /* per default if we have a CA verify both the peer and the
471 * hostname in the certificate, can be switched off later */ 572 * hostname in the certificate, can be switched off later */
472 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CAINFO, ca_cert), "CURLOPT_CAINFO");
473 handle_curl_option_return_code (curl_easy_setopt( curl, CURLOPT_SSL_VERIFYPEER, 1), "CURLOPT_SSL_VERIFYPEER"); 573 handle_curl_option_return_code (curl_easy_setopt( curl, CURLOPT_SSL_VERIFYPEER, 1), "CURLOPT_SSL_VERIFYPEER");
474 handle_curl_option_return_code (curl_easy_setopt( curl, CURLOPT_SSL_VERIFYHOST, 2), "CURLOPT_SSL_VERIFYHOST"); 574 handle_curl_option_return_code (curl_easy_setopt( curl, CURLOPT_SSL_VERIFYHOST, 2), "CURLOPT_SSL_VERIFYHOST");
475 } else { 575 } else {
@@ -640,7 +740,7 @@ check_http (void)
640 /* Curl errors, result in critical Nagios state */ 740 /* Curl errors, result in critical Nagios state */
641 if (res != CURLE_OK) { 741 if (res != CURLE_OK) {
642 snprintf (msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: cURL returned %d - %s"), 742 snprintf (msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: cURL returned %d - %s"),
643 server_port, res, curl_easy_strerror(res)); 743 server_port, res, errbuf[0] ? errbuf : curl_easy_strerror(res));
644 die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); 744 die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg);
645 } 745 }
646 746
@@ -746,7 +846,8 @@ GOT_FIRST_CERT:
746 if (curlhelp_parse_statusline (header_buf.buf, &status_line) < 0) { 846 if (curlhelp_parse_statusline (header_buf.buf, &status_line) < 0) {
747 snprintf (msg, DEFAULT_BUFFER_SIZE, "Unparsable status line in %.3g seconds response time|%s\n", 847 snprintf (msg, DEFAULT_BUFFER_SIZE, "Unparsable status line in %.3g seconds response time|%s\n",
748 total_time, perfstring); 848 total_time, perfstring);
749 die (STATE_CRITICAL, "HTTP CRITICAL HTTP/1.x %ld unknown - %s", code, msg); 849 /* we cannot know the major/minor version here for sure as we cannot parse the first line */
850 die (STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg);
750 } 851 }
751 852
752 /* get result code from cURL */ 853 /* get result code from cURL */
@@ -766,7 +867,9 @@ GOT_FIRST_CERT:
766 snprintf(msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host: %s\n"), status_line.first_line); 867 snprintf(msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host: %s\n"), status_line.first_line);
767 else 868 else
768 snprintf(msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: %s\n"), server_port, status_line.first_line); 869 snprintf(msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: %s\n"), server_port, status_line.first_line);
769 die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg); 870 die (STATE_CRITICAL, "HTTP CRITICAL - %s%s%s", msg,
871 show_body ? "\n" : "",
872 show_body ? body_buf.buf : "");
770 } 873 }
771 874
772 if( server_expect_yn ) { 875 if( server_expect_yn ) {
@@ -823,8 +926,8 @@ GOT_FIRST_CERT:
823 926
824 /* check status codes, set exit status accordingly */ 927 /* check status codes, set exit status accordingly */
825 if( status_line.http_code != code ) { 928 if( status_line.http_code != code ) {
826 die (STATE_CRITICAL, _("HTTP CRITICAL HTTP/%d.%d %d %s - different HTTP codes (cUrl has %ld)\n"), 929 die (STATE_CRITICAL, _("HTTP CRITICAL %s %d %s - different HTTP codes (cUrl has %ld)\n"),
827 status_line.http_major, status_line.http_minor, 930 string_statuscode (status_line.http_major, status_line.http_minor),
828 status_line.http_code, status_line.msg, code); 931 status_line.http_code, status_line.msg, code);
829 } 932 }
830 933
@@ -895,13 +998,15 @@ GOT_FIRST_CERT:
895 msg[strlen(msg)-3] = '\0'; 998 msg[strlen(msg)-3] = '\0';
896 999
897 /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */ 1000 /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */
898 die (result, "HTTP %s: HTTP/%d.%d %d %s%s%s - %d bytes in %.3f second response time %s|%s\n", 1001 die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n%s%s",
899 state_text(result), status_line.http_major, status_line.http_minor, 1002 state_text(result), string_statuscode (status_line.http_major, status_line.http_minor),
900 status_line.http_code, status_line.msg, 1003 status_line.http_code, status_line.msg,
901 strlen(msg) > 0 ? " - " : "", 1004 strlen(msg) > 0 ? " - " : "",
902 msg, page_len, total_time, 1005 msg, page_len, total_time,
903 (display_html ? "</A>" : ""), 1006 (display_html ? "</A>" : ""),
904 perfstring); 1007 perfstring,
1008 (show_body ? body_buf.buf : ""),
1009 (show_body ? "\n" : "") );
905 1010
906 /* proper cleanup after die? */ 1011 /* proper cleanup after die? */
907 curlhelp_free_statusline(&status_line); 1012 curlhelp_free_statusline(&status_line);
@@ -928,8 +1033,8 @@ char*
928uri_string (const UriTextRangeA range, char* buf, size_t buflen) 1033uri_string (const UriTextRangeA range, char* buf, size_t buflen)
929{ 1034{
930 if (!range.first) return "(null)"; 1035 if (!range.first) return "(null)";
931 strncpy (buf, range.first, max (buflen, range.afterLast - range.first)); 1036 strncpy (buf, range.first, max (buflen-1, range.afterLast - range.first));
932 buf[max (buflen, range.afterLast - range.first)] = '\0'; 1037 buf[max (buflen-1, range.afterLast - range.first)] = '\0';
933 buf[range.afterLast - range.first] = '\0'; 1038 buf[range.afterLast - range.first] = '\0';
934 return buf; 1039 return buf;
935} 1040}
@@ -1041,7 +1146,7 @@ redir (curlhelp_write_curlbuf* header_buf)
1041 const UriPathSegmentA* p = uri.pathHead; 1146 const UriPathSegmentA* p = uri.pathHead;
1042 for (; p; p = p->next) { 1147 for (; p; p = p->next) {
1043 strncat (new_url, "/", DEFAULT_BUFFER_SIZE); 1148 strncat (new_url, "/", DEFAULT_BUFFER_SIZE);
1044 strncat (new_url, uri_string (p->text, buf, DEFAULT_BUFFER_SIZE), DEFAULT_BUFFER_SIZE); 1149 strncat (new_url, uri_string (p->text, buf, DEFAULT_BUFFER_SIZE), DEFAULT_BUFFER_SIZE-1);
1045 } 1150 }
1046 } 1151 }
1047 1152
@@ -1049,8 +1154,8 @@ redir (curlhelp_write_curlbuf* header_buf)
1049 !strncmp(server_address, new_host, MAX_IPV4_HOSTLENGTH) && 1154 !strncmp(server_address, new_host, MAX_IPV4_HOSTLENGTH) &&
1050 (host_name && !strncmp(host_name, new_host, MAX_IPV4_HOSTLENGTH)) && 1155 (host_name && !strncmp(host_name, new_host, MAX_IPV4_HOSTLENGTH)) &&
1051 !strcmp(server_url, new_url)) 1156 !strcmp(server_url, new_url))
1052 die (STATE_WARNING, 1157 die (STATE_CRITICAL,
1053 _("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"), 1158 _("HTTP CRITICAL - redirection creates an infinite loop - %s://%s:%d%s%s\n"),
1054 use_ssl ? "https" : "http", new_host, new_port, new_url, (display_html ? "</A>" : "")); 1159 use_ssl ? "https" : "http", new_host, new_port, new_url, (display_html ? "</A>" : ""));
1055 1160
1056 /* set new values for redirected request */ 1161 /* set new values for redirected request */
@@ -1106,7 +1211,8 @@ process_arguments (int argc, char **argv)
1106 INVERT_REGEX = CHAR_MAX + 1, 1211 INVERT_REGEX = CHAR_MAX + 1,
1107 SNI_OPTION, 1212 SNI_OPTION,
1108 CA_CERT_OPTION, 1213 CA_CERT_OPTION,
1109 HTTP_VERSION_OPTION 1214 HTTP_VERSION_OPTION,
1215 AUTOMATIC_DECOMPRESSION
1110 }; 1216 };
1111 1217
1112 int option = 0; 1218 int option = 0;
@@ -1136,6 +1242,7 @@ process_arguments (int argc, char **argv)
1136 {"client-cert", required_argument, 0, 'J'}, 1242 {"client-cert", required_argument, 0, 'J'},
1137 {"private-key", required_argument, 0, 'K'}, 1243 {"private-key", required_argument, 0, 'K'},
1138 {"ca-cert", required_argument, 0, CA_CERT_OPTION}, 1244 {"ca-cert", required_argument, 0, CA_CERT_OPTION},
1245 {"verify-cert", no_argument, 0, 'D'},
1139 {"useragent", required_argument, 0, 'A'}, 1246 {"useragent", required_argument, 0, 'A'},
1140 {"header", required_argument, 0, 'k'}, 1247 {"header", required_argument, 0, 'k'},
1141 {"no-body", no_argument, 0, 'N'}, 1248 {"no-body", no_argument, 0, 'N'},
@@ -1146,7 +1253,9 @@ process_arguments (int argc, char **argv)
1146 {"use-ipv4", no_argument, 0, '4'}, 1253 {"use-ipv4", no_argument, 0, '4'},
1147 {"use-ipv6", no_argument, 0, '6'}, 1254 {"use-ipv6", no_argument, 0, '6'},
1148 {"extended-perfdata", no_argument, 0, 'E'}, 1255 {"extended-perfdata", no_argument, 0, 'E'},
1256 {"show-body", no_argument, 0, 'B'},
1149 {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, 1257 {"http-version", required_argument, 0, HTTP_VERSION_OPTION},
1258 {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION},
1150 {0, 0, 0, 0} 1259 {0, 0, 0, 0}
1151 }; 1260 };
1152 1261
@@ -1170,7 +1279,7 @@ process_arguments (int argc, char **argv)
1170 server_url = strdup(DEFAULT_SERVER_URL); 1279 server_url = strdup(DEFAULT_SERVER_URL);
1171 1280
1172 while (1) { 1281 while (1) {
1173 c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:nlLS::m:M:NE", longopts, &option); 1282 c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:DnlLS::m:M:NEB", longopts, &option);
1174 if (c == -1 || c == EOF || c == 1) 1283 if (c == -1 || c == EOF || c == 1)
1175 break; 1284 break;
1176 1285
@@ -1310,6 +1419,11 @@ process_arguments (int argc, char **argv)
1310 ca_cert = optarg; 1419 ca_cert = optarg;
1311 goto enable_ssl; 1420 goto enable_ssl;
1312#endif 1421#endif
1422#ifdef LIBCURL_FEATURE_SSL
1423 case 'D': /* verify peer certificate & host */
1424 verify_peer_and_host = TRUE;
1425 break;
1426#endif
1313 case 'S': /* use SSL */ 1427 case 'S': /* use SSL */
1314#ifdef LIBCURL_FEATURE_SSL 1428#ifdef LIBCURL_FEATURE_SSL
1315 enable_ssl: 1429 enable_ssl:
@@ -1354,7 +1468,7 @@ process_arguments (int argc, char **argv)
1354 ssl_version = CURL_SSLVERSION_DEFAULT; 1468 ssl_version = CURL_SSLVERSION_DEFAULT;
1355#endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 52, 0) */ 1469#endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 52, 0) */
1356 else 1470 else
1357 usage4 (_("Invalid option - Valid SSL/TLS versions: 2, 3, 1, 1.1, 1.2 (with optional '+' suffix)")); 1471 usage4 (_("Invalid option - Valid SSL/TLS versions: 2, 3, 1, 1.1, 1.2, 1.3 (with optional '+' suffix)"));
1358 } 1472 }
1359#if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 54, 0) 1473#if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 54, 0)
1360 if (got_plus) { 1474 if (got_plus) {
@@ -1513,6 +1627,9 @@ process_arguments (int argc, char **argv)
1513 case 'E': /* show extended perfdata */ 1627 case 'E': /* show extended perfdata */
1514 show_extended_perfdata = TRUE; 1628 show_extended_perfdata = TRUE;
1515 break; 1629 break;
1630 case 'B': /* print body content after status line */
1631 show_body = TRUE;
1632 break;
1516 case HTTP_VERSION_OPTION: 1633 case HTTP_VERSION_OPTION:
1517 curl_http_version = CURL_HTTP_VERSION_NONE; 1634 curl_http_version = CURL_HTTP_VERSION_NONE;
1518 if (strcmp (optarg, "1.0") == 0) { 1635 if (strcmp (optarg, "1.0") == 0) {
@@ -1530,6 +1647,9 @@ process_arguments (int argc, char **argv)
1530 exit (STATE_WARNING); 1647 exit (STATE_WARNING);
1531 } 1648 }
1532 break; 1649 break;
1650 case AUTOMATIC_DECOMPRESSION:
1651 automatic_decompression = TRUE;
1652 break;
1533 case '?': 1653 case '?':
1534 /* print short usage statement if args not parsable */ 1654 /* print short usage statement if args not parsable */
1535 usage5 (); 1655 usage5 ();
@@ -1659,7 +1779,7 @@ print_help (void)
1659 printf (" %s\n", "-S, --ssl=VERSION[+]"); 1779 printf (" %s\n", "-S, --ssl=VERSION[+]");
1660 printf (" %s\n", _("Connect via SSL. Port defaults to 443. VERSION is optional, and prevents")); 1780 printf (" %s\n", _("Connect via SSL. Port defaults to 443. VERSION is optional, and prevents"));
1661 printf (" %s\n", _("auto-negotiation (2 = SSLv2, 3 = SSLv3, 1 = TLSv1, 1.1 = TLSv1.1,")); 1781 printf (" %s\n", _("auto-negotiation (2 = SSLv2, 3 = SSLv3, 1 = TLSv1, 1.1 = TLSv1.1,"));
1662 printf (" %s\n", _("1.2 = TLSv1.2). With a '+' suffix, newer versions are also accepted.")); 1782 printf (" %s\n", _("1.2 = TLSv1.2, 1.3 = TLSv1.3). With a '+' suffix, newer versions are also accepted."));
1663 printf (" %s\n", _("Note: SSLv2 and SSLv3 are deprecated and are usually disabled in libcurl")); 1783 printf (" %s\n", _("Note: SSLv2 and SSLv3 are deprecated and are usually disabled in libcurl"));
1664 printf (" %s\n", "--sni"); 1784 printf (" %s\n", "--sni");
1665 printf (" %s\n", _("Enable SSL/TLS hostname extension support (SNI)")); 1785 printf (" %s\n", _("Enable SSL/TLS hostname extension support (SNI)"));
@@ -1680,6 +1800,8 @@ print_help (void)
1680 printf (" %s\n", _("matching the client certificate")); 1800 printf (" %s\n", _("matching the client certificate"));
1681 printf (" %s\n", "--ca-cert=FILE"); 1801 printf (" %s\n", "--ca-cert=FILE");
1682 printf (" %s\n", _("CA certificate file to verify peer against")); 1802 printf (" %s\n", _("CA certificate file to verify peer against"));
1803 printf (" %s\n", "-D, --verify-cert");
1804 printf (" %s\n", _("Verify the peer's SSL certificate and hostname"));
1683#endif 1805#endif
1684 1806
1685 printf (" %s\n", "-e, --expect=STRING"); 1807 printf (" %s\n", "-e, --expect=STRING");
@@ -1723,6 +1845,8 @@ print_help (void)
1723 printf (" %s\n", _("Any other tags to be sent in http header. Use multiple times for additional headers")); 1845 printf (" %s\n", _("Any other tags to be sent in http header. Use multiple times for additional headers"));
1724 printf (" %s\n", "-E, --extended-perfdata"); 1846 printf (" %s\n", "-E, --extended-perfdata");
1725 printf (" %s\n", _("Print additional performance data")); 1847 printf (" %s\n", _("Print additional performance data"));
1848 printf (" %s\n", "-B, --show-body");
1849 printf (" %s\n", _("Print body content below status line"));
1726 printf (" %s\n", "-L, --link"); 1850 printf (" %s\n", "-L, --link");
1727 printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)")); 1851 printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)"));
1728 printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport|curl>"); 1852 printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport|curl>");
@@ -1736,6 +1860,8 @@ print_help (void)
1736 printf (" %s\n", "--http-version=VERSION"); 1860 printf (" %s\n", "--http-version=VERSION");
1737 printf (" %s\n", _("Connect via specific HTTP protocol.")); 1861 printf (" %s\n", _("Connect via specific HTTP protocol."));
1738 printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)")); 1862 printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)"));
1863 printf (" %s\n", "--enable-automatic-decompression");
1864 printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING)."));
1739 printf ("\n"); 1865 printf ("\n");
1740 1866
1741 printf (UT_WARN_CRIT); 1867 printf (UT_WARN_CRIT);
@@ -1813,15 +1939,21 @@ print_usage (void)
1813{ 1939{
1814 printf ("%s\n", _("Usage:")); 1940 printf ("%s\n", _("Usage:"));
1815 printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname); 1941 printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname);
1816 printf (" [-J <client certificate file>] [-K <private key>] [--ca-cert <CA certificate file>]\n"); 1942 printf (" [-J <client certificate file>] [-K <private key>] [--ca-cert <CA certificate file>] [-D]\n");
1817 printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-E] [-a auth]\n"); 1943 printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-E] [-a auth]\n");
1818 printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport|curl>]\n"); 1944 printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport|curl>]\n");
1819 printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); 1945 printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n");
1820 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); 1946 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n");
1821 printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n"); 1947 printf (" [-A string] [-k string] [-S <version>] [--sni]\n");
1822 printf (" [-T <content-type>] [-j method]\n"); 1948 printf (" [-T <content-type>] [-j method]\n");
1823 printf (" [--http-version=<version>]\n"); 1949 printf (" [--http-version=<version>]\n");
1950 printf (" %s -H <vhost> | -I <IP-address> -C <warn_age>[,<crit_age>]\n",progname);
1951 printf (" [-p <port>] [-t <timeout>] [-4|-6] [--sni]\n");
1824 printf ("\n"); 1952 printf ("\n");
1953#ifdef LIBCURL_FEATURE_SSL
1954 printf ("%s\n", _("In the first form, make an HTTP request."));
1955 printf ("%s\n\n", _("In the second form, connect to the server and check the TLS certificate."));
1956#endif
1825 printf ("%s\n", _("WARNING: check_curl is experimental. Please use")); 1957 printf ("%s\n", _("WARNING: check_curl is experimental. Please use"));
1826 printf ("%s\n\n", _("check_http if you need a stable version.")); 1958 printf ("%s\n\n", _("check_http if you need a stable version."));
1827} 1959}
@@ -1944,7 +2076,7 @@ curlhelp_parse_statusline (const char *buf, curlhelp_statusline *status_line)
1944 char *first_line_buf; 2076 char *first_line_buf;
1945 2077
1946 /* find last start of a new header */ 2078 /* find last start of a new header */
1947 start = strrstr2 (buf, "\r\nHTTP"); 2079 start = strrstr2 (buf, "\r\nHTTP/");
1948 if (start != NULL) { 2080 if (start != NULL) {
1949 start += 2; 2081 start += 2;
1950 buf = start; 2082 buf = start;
@@ -2037,7 +2169,7 @@ get_header_value (const struct phr_header* headers, const size_t nof_headers, co
2037{ 2169{
2038 int i; 2170 int i;
2039 for( i = 0; i < nof_headers; i++ ) { 2171 for( i = 0; i < nof_headers; i++ ) {
2040 if( strncasecmp( header, headers[i].name, max( headers[i].name_len, 4 ) ) == 0 ) { 2172 if(headers[i].name != NULL && strncasecmp( header, headers[i].name, max( headers[i].name_len, 4 ) ) == 0 ) {
2041 return strndup( headers[i].value, headers[i].value_len ); 2173 return strndup( headers[i].value, headers[i].value_len );
2042 } 2174 }
2043 } 2175 }
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 844e625..c526d05 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -1,29 +1,29 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Monitoring check_disk plugin 3* Monitoring check_disk plugin
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 1999-2008 Monitoring Plugins Development Team 6* Copyright (c) 1999-2008 Monitoring Plugins Development Team
7* 7*
8* Description: 8* Description:
9* 9*
10* This file contains the check_disk plugin 10* This file contains the check_disk 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
29const char *progname = "check_disk"; 29const char *progname = "check_disk";
@@ -46,7 +46,7 @@ const char *email = "devel@monitoring-plugins.org";
46#include <stdarg.h> 46#include <stdarg.h>
47#include "fsusage.h" 47#include "fsusage.h"
48#include "mountlist.h" 48#include "mountlist.h"
49#include "intprops.h" /* necessary for TYPE_MAXIMUM */ 49#include "intprops.h" /* necessary for TYPE_MAXIMUM */
50#if HAVE_LIMITS_H 50#if HAVE_LIMITS_H
51# include <limits.h> 51# include <limits.h>
52#endif 52#endif
@@ -172,8 +172,6 @@ main (int argc, char **argv)
172 char *preamble; 172 char *preamble;
173 char *flag_header; 173 char *flag_header;
174 double inode_space_pct; 174 double inode_space_pct;
175 double warning_high_tide;
176 double critical_high_tide;
177 int temp_result; 175 int temp_result;
178 176
179 struct mount_entry *me; 177 struct mount_entry *me;
@@ -245,17 +243,17 @@ main (int argc, char **argv)
245 243
246#ifdef __CYGWIN__ 244#ifdef __CYGWIN__
247 if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11) 245 if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11)
248 continue; 246 continue;
249 snprintf(mountdir, sizeof(mountdir), "%s:\\", me->me_mountdir + 10); 247 snprintf(mountdir, sizeof(mountdir), "%s:\\", me->me_mountdir + 10);
250 if (GetDriveType(mountdir) != DRIVE_FIXED) 248 if (GetDriveType(mountdir) != DRIVE_FIXED)
251 me->me_remote = 1; 249 me->me_remote = 1;
252#endif 250#endif
253 /* Filters */ 251 /* Filters */
254 252
255 /* Remove filesystems already seen */ 253 /* Remove filesystems already seen */
256 if (np_seen_name(seen, me->me_mountdir)) { 254 if (np_seen_name(seen, me->me_mountdir)) {
257 continue; 255 continue;
258 } 256 }
259 np_add_name(&seen, me->me_mountdir); 257 np_add_name(&seen, me->me_mountdir);
260 258
261 if (path->group == NULL) { 259 if (path->group == NULL) {
@@ -288,8 +286,17 @@ main (int argc, char **argv)
288 get_stats (path, &fsp); 286 get_stats (path, &fsp);
289 287
290 if (verbose >= 3) { 288 if (verbose >= 3) {
291 printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n", 289 printf ("For %s, used_pct=%g free_pct=%g used_units=%llu free_units=%llu total_units=%llu used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n",
292 me->me_mountdir, path->dused_pct, path->dfree_pct, path->dused_units, path->dfree_units, path->dtotal_units, path->dused_inodes_percent, path->dfree_inodes_percent, fsp.fsu_blocksize, mult); 290 me->me_mountdir,
291 path->dused_pct,
292 path->dfree_pct,
293 path->dused_units,
294 path->dfree_units,
295 path->dtotal_units,
296 path->dused_inodes_percent,
297 path->dfree_inodes_percent,
298 fsp.fsu_blocksize,
299 mult);
293 } 300 }
294 301
295 /* Threshold comparisons */ 302 /* Threshold comparisons */
@@ -326,77 +333,79 @@ main (int argc, char **argv)
326 */ 333 */
327 334
328 /* *_high_tide must be reinitialized at each run */ 335 /* *_high_tide must be reinitialized at each run */
329 warning_high_tide = UINT_MAX; 336 uint64_t warning_high_tide = UINT64_MAX;
330 critical_high_tide = UINT_MAX;
331 337
332 if (path->freespace_units->warning != NULL) { 338 if (path->freespace_units->warning != NULL) {
333 warning_high_tide = path->dtotal_units - path->freespace_units->warning->end; 339 warning_high_tide = (path->dtotal_units - path->freespace_units->warning->end) * mult;
334 } 340 }
335 if (path->freespace_percent->warning != NULL) { 341 if (path->freespace_percent->warning != NULL) {
336 warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freespace_percent->warning->end/100)*path->dtotal_units )); 342 warning_high_tide = min( warning_high_tide, (uint64_t)((1.0 - path->freespace_percent->warning->end/100) * (path->dtotal_units * mult)) );
337 } 343 }
344
345 uint64_t critical_high_tide = UINT64_MAX;
346
338 if (path->freespace_units->critical != NULL) { 347 if (path->freespace_units->critical != NULL) {
339 critical_high_tide = path->dtotal_units - path->freespace_units->critical->end; 348 critical_high_tide = (path->dtotal_units - path->freespace_units->critical->end) * mult;
340 } 349 }
341 if (path->freespace_percent->critical != NULL) { 350 if (path->freespace_percent->critical != NULL) {
342 critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freespace_percent->critical->end/100)*path->dtotal_units )); 351 critical_high_tide = min( critical_high_tide, (uint64_t)((1.0 - path->freespace_percent->critical->end/100) * (path->dtotal_units * mult)) );
343 } 352 }
344 353
345 /* Nb: *_high_tide are unset when == UINT_MAX */ 354 /* Nb: *_high_tide are unset when == UINT64_MAX */
346 xasprintf (&perf, "%s %s", perf, 355 xasprintf (&perf, "%s %s", perf,
347 perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 356 perfdata_uint64 (
348 path->dused_units, units, 357 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
349 (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, 358 path->dused_units * mult, "B",
350 (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide, 359 (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide,
351 TRUE, 0, 360 (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide,
352 TRUE, path->dtotal_units)); 361 TRUE, 0,
362 TRUE, path->dtotal_units * mult));
353 363
354 if (display_inodes_perfdata) { 364 if (display_inodes_perfdata) {
355 /* *_high_tide must be reinitialized at each run */ 365 /* *_high_tide must be reinitialized at each run */
356 warning_high_tide = UINT_MAX; 366 warning_high_tide = UINT64_MAX;
357 critical_high_tide = UINT_MAX; 367 critical_high_tide = UINT64_MAX;
358 368
359 if (path->freeinodes_percent->warning != NULL) { 369 if (path->freeinodes_percent->warning != NULL) {
360 warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total )); 370 warning_high_tide = llabs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total ));
361 } 371 }
362 if (path->freeinodes_percent->critical != NULL) { 372 if (path->freeinodes_percent->critical != NULL) {
363 critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total )); 373 critical_high_tide = llabs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total ));
364 } 374 }
365 375
366 xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir); 376 xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir);
367 /* Nb: *_high_tide are unset when == UINT_MAX */ 377 /* Nb: *_high_tide are unset when == UINT64_MAX */
368 xasprintf (&perf, "%s %s", perf, 378 xasprintf (&perf, "%s %s", perf,
369 perfdata (perf_ilabel, 379 perfdata_uint64 (perf_ilabel,
370 path->inodes_used, "", 380 path->inodes_used, "",
371 (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, 381 (warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide,
372 (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide, 382 (critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide,
373 TRUE, 0, 383 TRUE, 0,
374 TRUE, path->inodes_total)); 384 TRUE, path->inodes_total));
375 } 385 }
376 386
377 if (disk_result==STATE_OK && erronly && !verbose) 387 if (disk_result==STATE_OK && erronly && !verbose)
378 continue; 388 continue;
379 389
380 if(disk_result && verbose >= 1) { 390 if(disk_result && verbose >= 1) {
381 xasprintf(&flag_header, " %s [", state_text (disk_result)); 391 xasprintf(&flag_header, " %s [", state_text (disk_result));
382 } else { 392 } else {
383 xasprintf(&flag_header, ""); 393 xasprintf(&flag_header, "");
384 } 394 }
385 xasprintf (&output, "%s%s %s %.0f %s (%.0f%%", 395 xasprintf (&output, "%s%s %s %llu%s (%.0f%%",
386 output, flag_header, 396 output, flag_header,
387 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 397 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
388 path->dfree_units, 398 path->dfree_units,
389 units, 399 units,
390 path->dfree_pct); 400 path->dfree_pct);
391 if (path->dused_inodes_percent < 0) { 401 if (path->dused_inodes_percent < 0) {
392 xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : "")); 402 xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : ""));
393 } else { 403 } else {
394 xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : "")); 404 xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : ""));
395 } 405 }
396 free(flag_header); 406 free(flag_header);
397 /* TODO: Need to do a similar debug line 407 /* TODO: Need to do a similar debug line
398 xasprintf (&details, _("%s\n\ 408 xasprintf (&details, _("%s\n\%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
399%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
400 details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct, 409 details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct,
401 me->me_devname, me->me_type, me->me_mountdir, 410 me->me_devname, me->me_type, me->me_mountdir,
402 (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); 411 (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp);
@@ -557,14 +566,14 @@ process_arguments (int argc, char **argv)
557 } 566 }
558 break; 567 break;
559 568
560 case 'W': /* warning inode threshold */ 569 case 'W': /* warning inode threshold */
561 if (*optarg == '@') { 570 if (*optarg == '@') {
562 warn_freeinodes_percent = optarg; 571 warn_freeinodes_percent = optarg;
563 } else { 572 } else {
564 xasprintf(&warn_freeinodes_percent, "@%s", optarg); 573 xasprintf(&warn_freeinodes_percent, "@%s", optarg);
565 } 574 }
566 break; 575 break;
567 case 'K': /* critical inode threshold */ 576 case 'K': /* critical inode threshold */
568 if (*optarg == '@') { 577 if (*optarg == '@') {
569 crit_freeinodes_percent = optarg; 578 crit_freeinodes_percent = optarg;
570 } else { 579 } else {
@@ -574,21 +583,24 @@ process_arguments (int argc, char **argv)
574 case 'u': 583 case 'u':
575 if (units) 584 if (units)
576 free(units); 585 free(units);
577 if (! strcmp (optarg, "bytes")) { 586 if (! strcasecmp (optarg, "bytes")) {
578 mult = (uintmax_t)1; 587 mult = (uintmax_t)1;
579 units = strdup ("B"); 588 units = strdup ("B");
580 } else if (! strcmp (optarg, "kB")) { 589 } else if ( (! strcmp (optarg, "kB")) || (!strcmp(optarg, "KiB")) ) {
581 mult = (uintmax_t)1024; 590 mult = (uintmax_t)1024;
582 units = strdup ("kB"); 591 units = strdup ("kiB");
583 } else if (! strcmp (optarg, "MB")) { 592 } else if ( (! strcmp (optarg, "MB")) || (!strcmp(optarg, "MiB")) ) {
584 mult = (uintmax_t)1024 * 1024; 593 mult = (uintmax_t)1024 * 1024;
585 units = strdup ("MB"); 594 units = strdup ("MiB");
586 } else if (! strcmp (optarg, "GB")) { 595 } else if ( (! strcmp (optarg, "GB")) || (!strcmp(optarg, "GiB")) ) {
587 mult = (uintmax_t)1024 * 1024 * 1024; 596 mult = (uintmax_t)1024 * 1024 * 1024;
588 units = strdup ("GB"); 597 units = strdup ("GiB");
589 } else if (! strcmp (optarg, "TB")) { 598 } else if ( (! strcmp (optarg, "TB")) || (!strcmp(optarg, "TiB")) ) {
590 mult = (uintmax_t)1024 * 1024 * 1024 * 1024; 599 mult = (uintmax_t)1024 * 1024 * 1024 * 1024;
591 units = strdup ("TB"); 600 units = strdup ("TiB");
601 } else if ( (! strcmp (optarg, "PB")) || (!strcmp(optarg, "PiB")) ) {
602 mult = (uintmax_t)1024 * 1024 * 1024 * 1024 * 1024;
603 units = strdup ("PiB");
592 } else { 604 } else {
593 die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); 605 die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg);
594 } 606 }
@@ -599,13 +611,13 @@ process_arguments (int argc, char **argv)
599 mult = 1024; 611 mult = 1024;
600 if (units) 612 if (units)
601 free(units); 613 free(units);
602 units = strdup ("kB"); 614 units = strdup ("kiB");
603 break; 615 break;
604 case 'm': /* display mountpoint */ 616 case 'm': /* display mountpoint */
605 mult = 1024 * 1024; 617 mult = 1024 * 1024;
606 if (units) 618 if (units)
607 free(units); 619 free(units);
608 units = strdup ("MB"); 620 units = strdup ("MiB");
609 break; 621 break;
610 case 'L': 622 case 'L':
611 stat_remote_fs = 1; 623 stat_remote_fs = 1;
@@ -812,7 +824,7 @@ process_arguments (int argc, char **argv)
812 } 824 }
813 825
814 if (units == NULL) { 826 if (units == NULL) {
815 units = strdup ("MB"); 827 units = strdup ("MiB");
816 mult = (uintmax_t)1024 * 1024; 828 mult = (uintmax_t)1024 * 1024;
817 } 829 }
818 830
@@ -1026,20 +1038,20 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
1026 if (p_list->group && ! (strcmp(p_list->group, p->group))) { 1038 if (p_list->group && ! (strcmp(p_list->group, p->group))) {
1027 stat_path(p_list); 1039 stat_path(p_list);
1028 get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp); 1040 get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp);
1029 get_path_stats(p_list, &tmpfsp); 1041 get_path_stats(p_list, &tmpfsp);
1030 if (verbose >= 3) 1042 if (verbose >= 3)
1031 printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", 1043 printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n",
1032 p_list->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p_list->best_match->me_mountdir, p_list->dused_units, p_list->dfree_units, 1044 p_list->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p_list->best_match->me_mountdir, p_list->dused_units, p_list->dfree_units,
1033 p_list->dtotal_units, mult); 1045 p_list->dtotal_units, mult);
1034 1046
1035 /* prevent counting the first FS of a group twice since its parameter_list entry 1047 /* prevent counting the first FS of a group twice since its parameter_list entry
1036 * is used to carry the information of all file systems of the entire group */ 1048 * is used to carry the information of all file systems of the entire group */
1037 if (! first) { 1049 if (! first) {
1038 p->total += p_list->total; 1050 p->total += p_list->total;
1039 p->available += p_list->available; 1051 p->available += p_list->available;
1040 p->available_to_root += p_list->available_to_root; 1052 p->available_to_root += p_list->available_to_root;
1041 p->used += p_list->used; 1053 p->used += p_list->used;
1042 1054
1043 p->dused_units += p_list->dused_units; 1055 p->dused_units += p_list->dused_units;
1044 p->dfree_units += p_list->dfree_units; 1056 p->dfree_units += p_list->dfree_units;
1045 p->dtotal_units += p_list->dtotal_units; 1057 p->dtotal_units += p_list->dtotal_units;
@@ -1050,28 +1062,31 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
1050 } 1062 }
1051 first = 0; 1063 first = 0;
1052 } 1064 }
1053 if (verbose >= 3) 1065 if (verbose >= 3)
1054 printf("Group %s now has: used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", 1066 printf("Group %s now has: used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n",
1055 p->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p->best_match->me_mountdir, p->dused_units, 1067 p->group,
1056 p->dfree_units, p->dtotal_units, mult); 1068 tmpfsp.fsu_bavail,
1069 tmpfsp.fsu_blocksize,
1070 p->best_match->me_mountdir,
1071 p->dused_units,
1072 p->dfree_units,
1073 p->dtotal_units,
1074 mult);
1057 } 1075 }
1058 /* modify devname and mountdir for output */ 1076 /* modify devname and mountdir for output */
1059 p->best_match->me_mountdir = p->best_match->me_devname = p->group; 1077 p->best_match->me_mountdir = p->best_match->me_devname = p->group;
1060 } 1078 }
1061 /* finally calculate percentages for either plain FS or summed up group */ 1079 /* finally calculate percentages for either plain FS or summed up group */
1062 p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */ 1080 p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */
1063 p->dfree_pct = 100 - p->dused_pct; 1081 p->dfree_pct = 100 - p->dused_pct;
1064 p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total); 1082 p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total);
1065 p->dfree_inodes_percent = 100 - p->dused_inodes_percent; 1083 p->dfree_inodes_percent = 100 - p->dused_inodes_percent;
1066 1084
1067} 1085}
1068 1086
1069void 1087void
1070get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { 1088get_path_stats (struct parameter_list *p, struct fs_usage *fsp) {
1071 /* 2007-12-08 - Workaround for Gnulib reporting insanely high available 1089 p->available = fsp->fsu_bavail;
1072 * space on BSD (the actual value should be negative but fsp->fsu_bavail
1073 * is unsigned) */
1074 p->available = fsp->fsu_bavail > fsp->fsu_bfree ? 0 : fsp->fsu_bavail;
1075 p->available_to_root = fsp->fsu_bfree; 1090 p->available_to_root = fsp->fsu_bfree;
1076 p->used = fsp->fsu_blocks - fsp->fsu_bfree; 1091 p->used = fsp->fsu_blocks - fsp->fsu_bfree;
1077 if (freespace_ignore_reserved) { 1092 if (freespace_ignore_reserved) {
@@ -1081,7 +1096,7 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) {
1081 /* default behaviour : take all the blocks into account */ 1096 /* default behaviour : take all the blocks into account */
1082 p->total = fsp->fsu_blocks; 1097 p->total = fsp->fsu_blocks;
1083 } 1098 }
1084 1099
1085 p->dused_units = p->used*fsp->fsu_blocksize/mult; 1100 p->dused_units = p->used*fsp->fsu_blocksize/mult;
1086 p->dfree_units = p->available*fsp->fsu_blocksize/mult; 1101 p->dfree_units = p->available*fsp->fsu_blocksize/mult;
1087 p->dtotal_units = p->total*fsp->fsu_blocksize/mult; 1102 p->dtotal_units = p->total*fsp->fsu_blocksize/mult;
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index b90f50e..9de6caf 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -41,7 +41,7 @@ const char *email = "devel@monitoring-plugins.org";
41 41
42int process_arguments (int, char **); 42int process_arguments (int, char **);
43int validate_arguments (void); 43int validate_arguments (void);
44int error_scan (char *); 44int error_scan (char *, int *);
45int ip_match_cidr(const char *, const char *); 45int ip_match_cidr(const char *, const char *);
46unsigned long ip2long(const char *); 46unsigned long ip2long(const char *);
47void print_help (void); 47void print_help (void);
@@ -54,6 +54,7 @@ char ptr_server[ADDRESS_LENGTH] = "";
54int verbose = FALSE; 54int verbose = FALSE;
55char **expected_address = NULL; 55char **expected_address = NULL;
56int expected_address_cnt = 0; 56int expected_address_cnt = 0;
57int expect_nxdomain = FALSE;
57 58
58int expect_authority = FALSE; 59int expect_authority = FALSE;
59int all_match = FALSE; 60int all_match = FALSE;
@@ -87,6 +88,7 @@ main (int argc, char **argv)
87 int parse_address = FALSE; /* This flag scans for Address: but only after Name: */ 88 int parse_address = FALSE; /* This flag scans for Address: but only after Name: */
88 output chld_out, chld_err; 89 output chld_out, chld_err;
89 size_t i; 90 size_t i;
91 int is_nxdomain = FALSE;
90 92
91 setlocale (LC_ALL, ""); 93 setlocale (LC_ALL, "");
92 bindtextdomain (PACKAGE, LOCALEDIR); 94 bindtextdomain (PACKAGE, LOCALEDIR);
@@ -186,7 +188,7 @@ main (int argc, char **argv)
186 } 188 }
187 189
188 190
189 result = error_scan (chld_out.line[i]); 191 result = error_scan (chld_out.line[i], &is_nxdomain);
190 if (result != STATE_OK) { 192 if (result != STATE_OK) {
191 msg = strchr (chld_out.line[i], ':'); 193 msg = strchr (chld_out.line[i], ':');
192 if(msg) msg++; 194 if(msg) msg++;
@@ -199,8 +201,8 @@ main (int argc, char **argv)
199 if (verbose) 201 if (verbose)
200 puts(chld_err.line[i]); 202 puts(chld_err.line[i]);
201 203
202 if (error_scan (chld_err.line[i]) != STATE_OK) { 204 if (error_scan (chld_err.line[i], &is_nxdomain) != STATE_OK) {
203 result = max_state (result, error_scan (chld_err.line[i])); 205 result = max_state (result, error_scan (chld_err.line[i], &is_nxdomain));
204 msg = strchr(input_buffer, ':'); 206 msg = strchr(input_buffer, ':');
205 if(msg) 207 if(msg)
206 msg++; 208 msg++;
@@ -209,6 +211,10 @@ main (int argc, char **argv)
209 } 211 }
210 } 212 }
211 213
214 if (is_nxdomain && !expect_nxdomain) {
215 die (STATE_CRITICAL, _("Domain '%s' was not found by the server\n"), query_address);
216 }
217
212 if (addresses) { 218 if (addresses) {
213 int i,slen; 219 int i,slen;
214 char *adrp; 220 char *adrp;
@@ -260,6 +266,16 @@ main (int argc, char **argv)
260 } 266 }
261 } 267 }
262 268
269 if (expect_nxdomain) {
270 if (!is_nxdomain) {
271 result = STATE_CRITICAL;
272 xasprintf(&msg, _("Domain '%s' was found by the server: '%s'\n"), query_address, address);
273 } else {
274 if (address != NULL) free(address);
275 address = "NXDOMAIN";
276 }
277 }
278
263 /* check if authoritative */ 279 /* check if authoritative */
264 if (result == STATE_OK && expect_authority && non_authoritative) { 280 if (result == STATE_OK && expect_authority && non_authoritative) {
265 result = STATE_CRITICAL; 281 result = STATE_CRITICAL;
@@ -339,9 +355,15 @@ ip2long(const char* src) {
339} 355}
340 356
341int 357int
342error_scan (char *input_buffer) 358error_scan (char *input_buffer, int *is_nxdomain)
343{ 359{
344 360
361 const int nxdomain = strstr (input_buffer, "Non-existent") ||
362 strstr (input_buffer, "** server can't find") ||
363 strstr (input_buffer, "** Can't find") ||
364 strstr (input_buffer, "NXDOMAIN");
365 if (nxdomain) *is_nxdomain = TRUE;
366
345 /* the DNS lookup timed out */ 367 /* the DNS lookup timed out */
346 if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) || 368 if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) ||
347 strstr (input_buffer, _("Consider using the `dig' or `host' programs instead. Run nslookup with")) || 369 strstr (input_buffer, _("Consider using the `dig' or `host' programs instead. Run nslookup with")) ||
@@ -360,7 +382,7 @@ error_scan (char *input_buffer)
360 382
361 /* Connection was refused */ 383 /* Connection was refused */
362 else if (strstr (input_buffer, "Connection refused") || 384 else if (strstr (input_buffer, "Connection refused") ||
363 strstr (input_buffer, "Couldn't find server") || 385 strstr (input_buffer, "Couldn't find server") ||
364 strstr (input_buffer, "Refused") || 386 strstr (input_buffer, "Refused") ||
365 (strstr (input_buffer, "** server can't find") && 387 (strstr (input_buffer, "** server can't find") &&
366 strstr (input_buffer, ": REFUSED"))) 388 strstr (input_buffer, ": REFUSED")))
@@ -374,13 +396,6 @@ error_scan (char *input_buffer)
374 else if (strstr (input_buffer, "No information")) 396 else if (strstr (input_buffer, "No information"))
375 die (STATE_CRITICAL, _("No information returned by DNS server at %s\n"), dns_server); 397 die (STATE_CRITICAL, _("No information returned by DNS server at %s\n"), dns_server);
376 398
377 /* Host or domain name does not exist */
378 else if (strstr (input_buffer, "Non-existent") ||
379 strstr (input_buffer, "** server can't find") ||
380 strstr (input_buffer, "** Can't find") ||
381 strstr (input_buffer,"NXDOMAIN"))
382 die (STATE_CRITICAL, _("Domain %s was not found by the server\n"), query_address);
383
384 /* Network is unreachable */ 399 /* Network is unreachable */
385 else if (strstr (input_buffer, "Network is unreachable")) 400 else if (strstr (input_buffer, "Network is unreachable"))
386 die (STATE_CRITICAL, _("Network is unreachable\n")); 401 die (STATE_CRITICAL, _("Network is unreachable\n"));
@@ -417,6 +432,7 @@ process_arguments (int argc, char **argv)
417 {"server", required_argument, 0, 's'}, 432 {"server", required_argument, 0, 's'},
418 {"reverse-server", required_argument, 0, 'r'}, 433 {"reverse-server", required_argument, 0, 'r'},
419 {"expected-address", required_argument, 0, 'a'}, 434 {"expected-address", required_argument, 0, 'a'},
435 {"expect-nxdomain", no_argument, 0, 'n'},
420 {"expect-authority", no_argument, 0, 'A'}, 436 {"expect-authority", no_argument, 0, 'A'},
421 {"all", no_argument, 0, 'L'}, 437 {"all", no_argument, 0, 'L'},
422 {"warning", required_argument, 0, 'w'}, 438 {"warning", required_argument, 0, 'w'},
@@ -432,7 +448,7 @@ process_arguments (int argc, char **argv)
432 strcpy (argv[c], "-t"); 448 strcpy (argv[c], "-t");
433 449
434 while (1) { 450 while (1) {
435 c = getopt_long (argc, argv, "hVvALt:H:s:r:a:w:c:", long_opts, &opt_index); 451 c = getopt_long (argc, argv, "hVvALnt:H:s:r:a:w:c:", long_opts, &opt_index);
436 452
437 if (c == -1 || c == EOF) 453 if (c == -1 || c == EOF)
438 break; 454 break;
@@ -473,9 +489,26 @@ process_arguments (int argc, char **argv)
473 case 'a': /* expected address */ 489 case 'a': /* expected address */
474 if (strlen (optarg) >= ADDRESS_LENGTH) 490 if (strlen (optarg) >= ADDRESS_LENGTH)
475 die (STATE_UNKNOWN, _("Input buffer overflow\n")); 491 die (STATE_UNKNOWN, _("Input buffer overflow\n"));
476 expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**)); 492 if (strchr(optarg, ',') != NULL) {
477 expected_address[expected_address_cnt] = strdup(optarg); 493 char *comma = strchr(optarg, ',');
478 expected_address_cnt++; 494 while (comma != NULL) {
495 expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**));
496 expected_address[expected_address_cnt] = strndup(optarg, comma - optarg);
497 expected_address_cnt++;
498 optarg = comma + 1;
499 comma = strchr(optarg, ',');
500 }
501 expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**));
502 expected_address[expected_address_cnt] = strdup(optarg);
503 expected_address_cnt++;
504 } else {
505 expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**));
506 expected_address[expected_address_cnt] = strdup(optarg);
507 expected_address_cnt++;
508 }
509 break;
510 case 'n': /* expect NXDOMAIN */
511 expect_nxdomain = TRUE;
479 break; 512 break;
480 case 'A': /* expect authority */ 513 case 'A': /* expect authority */
481 expect_authority = TRUE; 514 expect_authority = TRUE;
@@ -518,8 +551,15 @@ process_arguments (int argc, char **argv)
518int 551int
519validate_arguments () 552validate_arguments ()
520{ 553{
521 if (query_address[0] == 0) 554 if (query_address[0] == 0) {
555 printf ("missing --host argument\n");
522 return ERROR; 556 return ERROR;
557 }
558
559 if (expected_address_cnt > 0 && expect_nxdomain) {
560 printf ("--expected-address and --expect-nxdomain cannot be combined\n");
561 return ERROR;
562 }
523 563
524 return OK; 564 return OK;
525} 565}
@@ -552,6 +592,9 @@ print_help (void)
552 printf (" %s\n", _("Optional IP-ADDRESS/CIDR you expect the DNS server to return. HOST must end")); 592 printf (" %s\n", _("Optional IP-ADDRESS/CIDR you expect the DNS server to return. HOST must end"));
553 printf (" %s\n", _("with a dot (.). This option can be repeated multiple times (Returns OK if any")); 593 printf (" %s\n", _("with a dot (.). This option can be repeated multiple times (Returns OK if any"));
554 printf (" %s\n", _("value matches).")); 594 printf (" %s\n", _("value matches)."));
595 printf (" -n, --expect-nxdomain\n");
596 printf (" %s\n", _("Expect the DNS server to return NXDOMAIN (i.e. the domain was not found)"));
597 printf (" %s\n", _("Cannot be used together with -a"));
555 printf (" -A, --expect-authority\n"); 598 printf (" -A, --expect-authority\n");
556 printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup")); 599 printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup"));
557 printf (" -w, --warning=seconds\n"); 600 printf (" -w, --warning=seconds\n");
@@ -572,5 +615,5 @@ void
572print_usage (void) 615print_usage (void)
573{ 616{
574 printf ("%s\n", _("Usage:")); 617 printf ("%s\n", _("Usage:"));
575 printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit] [-L]\n", progname); 618 printf ("%s -H host [-s server] [-a expected-address] [-n] [-A] [-t timeout] [-w warn] [-c crit] [-L]\n", progname);
576} 619}
diff --git a/plugins/check_http.c b/plugins/check_http.c
index e2298b1..34fb4f0 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -72,7 +72,7 @@ int maximum_age = -1;
72 72
73enum { 73enum {
74 REGS = 2, 74 REGS = 2,
75 MAX_RE_SIZE = 256 75 MAX_RE_SIZE = 1024
76}; 76};
77#include "regex.h" 77#include "regex.h"
78regex_t preg; 78regex_t preg;
@@ -1453,8 +1453,8 @@ redir (char *pos, char *status_line)
1453 !strncmp(server_address, addr, MAX_IPV4_HOSTLENGTH) && 1453 !strncmp(server_address, addr, MAX_IPV4_HOSTLENGTH) &&
1454 (host_name && !strncmp(host_name, addr, MAX_IPV4_HOSTLENGTH)) && 1454 (host_name && !strncmp(host_name, addr, MAX_IPV4_HOSTLENGTH)) &&
1455 !strcmp(server_url, url)) 1455 !strcmp(server_url, url))
1456 die (STATE_WARNING, 1456 die (STATE_CRITICAL,
1457 _("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"), 1457 _("HTTP CRITICAL - redirection creates an infinite loop - %s://%s:%d%s%s\n"),
1458 type, addr, i, url, (display_html ? "</A>" : "")); 1458 type, addr, i, url, (display_html ? "</A>" : ""));
1459 1459
1460 strcpy (server_type, type); 1460 strcpy (server_type, type);
@@ -1567,6 +1567,10 @@ print_help (void)
1567 1567
1568 print_usage (); 1568 print_usage ();
1569 1569
1570#ifdef HAVE_SSL
1571 printf (_("In the first form, make an HTTP request."));
1572 printf (_("In the second form, connect to the server and check the TLS certificate."));
1573#endif
1570 printf (_("NOTE: One or both of -H and -I must be specified")); 1574 printf (_("NOTE: One or both of -H and -I must be specified"));
1571 1575
1572 printf ("\n"); 1576 printf ("\n");
@@ -1726,6 +1730,8 @@ print_usage (void)
1726 printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n"); 1730 printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n");
1727 printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); 1731 printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n");
1728 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); 1732 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n");
1729 printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n"); 1733 printf (" [-A string] [-k string] [-S <version>] [--sni]\n");
1730 printf (" [-T <content-type>] [-j method]\n"); 1734 printf (" [-T <content-type>] [-j method]\n");
1735 printf (" %s -H <vhost> | -I <IP-address> -C <warn_age>[,<crit_age>]\n",progname);
1736 printf (" [-p <port>] [-t <timeout>] [-4|-6] [--sni]\n");
1731} 1737}
diff --git a/plugins/check_load.c b/plugins/check_load.c
index bf7b94b..0e4de54 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -209,7 +209,7 @@ main (int argc, char **argv)
209 else if(la[i] > wload[i]) result = STATE_WARNING; 209 else if(la[i] > wload[i]) result = STATE_WARNING;
210 } 210 }
211 211
212 printf("%s - %s|", state_text(result), status_line); 212 printf("LOAD %s - %s|", state_text(result), status_line);
213 for(i = 0; i < 3; i++) 213 for(i = 0; i < 3; i++)
214 printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]); 214 printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]);
215 215
diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c
index 49a14dd..ac2fb15 100644
--- a/plugins/check_mysql_query.c
+++ b/plugins/check_mysql_query.c
@@ -136,18 +136,18 @@ main (int argc, char **argv)
136 die (STATE_CRITICAL, "QUERY %s: Fetch row error - %s\n", _("CRITICAL"), error); 136 die (STATE_CRITICAL, "QUERY %s: Fetch row error - %s\n", _("CRITICAL"), error);
137 } 137 }
138 138
139 /* free the result */
140 mysql_free_result (res);
141
142 /* close the connection */
143 mysql_close (&mysql);
144
145 if (! is_numeric(row[0])) { 139 if (! is_numeric(row[0])) {
146 die (STATE_CRITICAL, "QUERY %s: %s - '%s'\n", _("CRITICAL"), _("Is not a numeric"), row[0]); 140 die (STATE_CRITICAL, "QUERY %s: %s - '%s'\n", _("CRITICAL"), _("Is not a numeric"), row[0]);
147 } 141 }
148 142
149 value = strtod(row[0], NULL); 143 value = strtod(row[0], NULL);
150 144
145 /* free the result */
146 mysql_free_result (res);
147
148 /* close the connection */
149 mysql_close (&mysql);
150
151 if (verbose >= 3) 151 if (verbose >= 3)
152 printf("mysql result: %f\n", value); 152 printf("mysql result: %f\n", value);
153 153
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c
index 11ce691..b8fc5f1 100644
--- a/plugins/check_pgsql.c
+++ b/plugins/check_pgsql.c
@@ -347,7 +347,7 @@ process_arguments (int argc, char **argv)
347 if (!is_pg_dbname (optarg)) /* checks length and valid chars */ 347 if (!is_pg_dbname (optarg)) /* checks length and valid chars */
348 usage2 (_("Database name is not valid"), optarg); 348 usage2 (_("Database name is not valid"), optarg);
349 else /* we know length, and know optarg is terminated, so us strcpy */ 349 else /* we know length, and know optarg is terminated, so us strcpy */
350 strcpy (dbName, optarg); 350 snprintf(dbName, NAMEDATALEN, "%s", optarg);
351 break; 351 break;
352 case 'l': /* login name */ 352 case 'l': /* login name */
353 if (!is_pg_logname (optarg)) 353 if (!is_pg_logname (optarg))
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 0de6be9..4872340 100644
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
@@ -1,34 +1,34 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Monitoring check_procs plugin 3* Monitoring check_procs 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_procs plugin 10* This file contains the check_procs plugin
11* 11*
12* Checks all processes and generates WARNING or CRITICAL states if the 12* Checks all processes and generates WARNING or CRITICAL states if the
13* specified metric is outside the required threshold ranges. The metric 13* specified metric is outside the required threshold ranges. The metric
14* defaults to number of processes. Search filters can be applied to limit 14* defaults to number of processes. Search filters can be applied to limit
15* the processes to check. 15* the processes to check.
16* 16*
17* 17*
18* This program is free software: you can redistribute it and/or modify 18* This program is free software: you can redistribute it and/or modify
19* it under the terms of the GNU General Public License as published by 19* it under the terms of the GNU General Public License as published by
20* the Free Software Foundation, either version 3 of the License, or 20* the Free Software Foundation, either version 3 of the License, or
21* (at your option) any later version. 21* (at your option) any later version.
22* 22*
23* This program is distributed in the hope that it will be useful, 23* This program is distributed in the hope that it will be useful,
24* but WITHOUT ANY WARRANTY; without even the implied warranty of 24* but WITHOUT ANY WARRANTY; without even the implied warranty of
25* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26* GNU General Public License for more details. 26* GNU General Public License for more details.
27* 27*
28* You should have received a copy of the GNU General Public License 28* You should have received a copy of the GNU General Public License
29* along with this program. If not, see <http://www.gnu.org/licenses/>. 29* along with this program. If not, see <http://www.gnu.org/licenses/>.
30* 30*
31* 31*
32*****************************************************************************/ 32*****************************************************************************/
33 33
34const char *progname = "check_procs"; 34const char *progname = "check_procs";
@@ -50,7 +50,7 @@ const char *email = "devel@monitoring-plugins.org";
50 50
51int process_arguments (int, char **); 51int process_arguments (int, char **);
52int validate_arguments (void); 52int validate_arguments (void);
53int convert_to_seconds (char *); 53int convert_to_seconds (char *);
54void print_help (void); 54void print_help (void);
55void print_usage (void); 55void print_usage (void);
56 56
@@ -230,9 +230,9 @@ main (int argc, char **argv)
230 procseconds = convert_to_seconds(procetime); 230 procseconds = convert_to_seconds(procetime);
231 231
232 if (verbose >= 3) 232 if (verbose >= 3)
233 printf ("proc#=%d uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n", 233 printf ("proc#=%d uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n",
234 procs, procuid, procvsz, procrss, 234 procs, procuid, procvsz, procrss,
235 procpid, procppid, procpcpu, procstat, 235 procpid, procppid, procpcpu, procstat,
236 procetime, procprog, procargs); 236 procetime, procprog, procargs);
237 237
238 /* Ignore self */ 238 /* Ignore self */
@@ -292,9 +292,9 @@ main (int argc, char **argv)
292 292
293 procs++; 293 procs++;
294 if (verbose >= 2) { 294 if (verbose >= 2) {
295 printf ("Matched: uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n", 295 printf ("Matched: uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n",
296 procuid, procvsz, procrss, 296 procuid, procvsz, procrss,
297 procpid, procppid, procpcpu, procstat, 297 procpid, procppid, procpcpu, procstat,
298 procetime, procprog, procargs); 298 procetime, procprog, procargs);
299 } 299 }
300 300
@@ -320,7 +320,7 @@ main (int argc, char **argv)
320 result = max_state (result, i); 320 result = max_state (result, i);
321 } 321 }
322 } 322 }
323 } 323 }
324 /* This should not happen */ 324 /* This should not happen */
325 else if (verbose) { 325 else if (verbose) {
326 printf(_("Not parseable: %s"), input_buffer); 326 printf(_("Not parseable: %s"), input_buffer);
@@ -332,7 +332,7 @@ main (int argc, char **argv)
332 return STATE_UNKNOWN; 332 return STATE_UNKNOWN;
333 } 333 }
334 334
335 if ( result == STATE_UNKNOWN ) 335 if ( result == STATE_UNKNOWN )
336 result = STATE_OK; 336 result = STATE_OK;
337 337
338 /* Needed if procs found, but none match filter */ 338 /* Needed if procs found, but none match filter */
@@ -352,9 +352,9 @@ main (int argc, char **argv)
352 if (metric != METRIC_PROCS) { 352 if (metric != METRIC_PROCS) {
353 printf (_("%d crit, %d warn out of "), crit, warn); 353 printf (_("%d crit, %d warn out of "), crit, warn);
354 } 354 }
355 } 355 }
356 printf (ngettext ("%d process", "%d processes", (unsigned long) procs), procs); 356 printf (ngettext ("%d process", "%d processes", (unsigned long) procs), procs);
357 357
358 if (strcmp(fmt,"") != 0) { 358 if (strcmp(fmt,"") != 0) {
359 printf (_(" with %s"), fmt); 359 printf (_(" with %s"), fmt);
360 } 360 }
@@ -440,7 +440,7 @@ process_arguments (int argc, char **argv)
440 break; 440 break;
441 case 'c': /* critical threshold */ 441 case 'c': /* critical threshold */
442 critical_range = optarg; 442 critical_range = optarg;
443 break; 443 break;
444 case 'w': /* warning threshold */ 444 case 'w': /* warning threshold */
445 warning_range = optarg; 445 warning_range = optarg;
446 break; 446 break;
@@ -542,11 +542,11 @@ process_arguments (int argc, char **argv)
542 if ( strcmp(optarg, "PROCS") == 0) { 542 if ( strcmp(optarg, "PROCS") == 0) {
543 metric = METRIC_PROCS; 543 metric = METRIC_PROCS;
544 break; 544 break;
545 } 545 }
546 else if ( strcmp(optarg, "VSZ") == 0) { 546 else if ( strcmp(optarg, "VSZ") == 0) {
547 metric = METRIC_VSZ; 547 metric = METRIC_VSZ;
548 break; 548 break;
549 } 549 }
550 else if ( strcmp(optarg, "RSS") == 0 ) { 550 else if ( strcmp(optarg, "RSS") == 0 ) {
551 metric = METRIC_RSS; 551 metric = METRIC_RSS;
552 break; 552 break;
@@ -559,7 +559,7 @@ process_arguments (int argc, char **argv)
559 metric = METRIC_ELAPSED; 559 metric = METRIC_ELAPSED;
560 break; 560 break;
561 } 561 }
562 562
563 usage4 (_("Metric must be one of PROCS, VSZ, RSS, CPU, ELAPSED!")); 563 usage4 (_("Metric must be one of PROCS, VSZ, RSS, CPU, ELAPSED!"));
564 case 'k': /* linux kernel thread filter */ 564 case 'k': /* linux kernel thread filter */
565 kthread_filter = 1; 565 kthread_filter = 1;
@@ -642,7 +642,7 @@ convert_to_seconds(char *etime) {
642 seconds = 0; 642 seconds = 0;
643 643
644 for (ptr = etime; *ptr != '\0'; ptr++) { 644 for (ptr = etime; *ptr != '\0'; ptr++) {
645 645
646 if (*ptr == '-') { 646 if (*ptr == '-') {
647 hyphcnt++; 647 hyphcnt++;
648 continue; 648 continue;
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index d37c57c..c1e92df 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -55,6 +55,7 @@ enum {
55#define SMTP_EXPECT "220" 55#define SMTP_EXPECT "220"
56#define SMTP_HELO "HELO " 56#define SMTP_HELO "HELO "
57#define SMTP_EHLO "EHLO " 57#define SMTP_EHLO "EHLO "
58#define SMTP_LHLO "LHLO "
58#define SMTP_QUIT "QUIT\r\n" 59#define SMTP_QUIT "QUIT\r\n"
59#define SMTP_STARTTLS "STARTTLS\r\n" 60#define SMTP_STARTTLS "STARTTLS\r\n"
60#define SMTP_AUTH_LOGIN "AUTH LOGIN\r\n" 61#define SMTP_AUTH_LOGIN "AUTH LOGIN\r\n"
@@ -102,6 +103,7 @@ int check_critical_time = FALSE;
102int verbose = 0; 103int verbose = 0;
103int use_ssl = FALSE; 104int use_ssl = FALSE;
104short use_ehlo = FALSE; 105short use_ehlo = FALSE;
106short use_lhlo = FALSE;
105short ssl_established = 0; 107short ssl_established = 0;
106char *localhostname = NULL; 108char *localhostname = NULL;
107int sd; 109int sd;
@@ -152,7 +154,9 @@ main (int argc, char **argv)
152 return STATE_CRITICAL; 154 return STATE_CRITICAL;
153 } 155 }
154 } 156 }
155 if(use_ehlo) 157 if(use_lhlo)
158 xasprintf (&helocmd, "%s%s%s", SMTP_LHLO, localhostname, "\r\n");
159 else if(use_ehlo)
156 xasprintf (&helocmd, "%s%s%s", SMTP_EHLO, localhostname, "\r\n"); 160 xasprintf (&helocmd, "%s%s%s", SMTP_EHLO, localhostname, "\r\n");
157 else 161 else
158 xasprintf (&helocmd, "%s%s%s", SMTP_HELO, localhostname, "\r\n"); 162 xasprintf (&helocmd, "%s%s%s", SMTP_HELO, localhostname, "\r\n");
@@ -197,7 +201,7 @@ main (int argc, char **argv)
197 if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) { 201 if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) {
198 printf (_("recv() failed\n")); 202 printf (_("recv() failed\n"));
199 return STATE_WARNING; 203 return STATE_WARNING;
200 } else if(use_ehlo){ 204 } else if(use_ehlo || use_lhlo){
201 if(strstr(buffer, "250 STARTTLS") != NULL || 205 if(strstr(buffer, "250 STARTTLS") != NULL ||
202 strstr(buffer, "250-STARTTLS") != NULL){ 206 strstr(buffer, "250-STARTTLS") != NULL){
203 supports_tls=TRUE; 207 supports_tls=TRUE;
@@ -470,6 +474,7 @@ process_arguments (int argc, char **argv)
470 {"use-ipv4", no_argument, 0, '4'}, 474 {"use-ipv4", no_argument, 0, '4'},
471 {"use-ipv6", no_argument, 0, '6'}, 475 {"use-ipv6", no_argument, 0, '6'},
472 {"help", no_argument, 0, 'h'}, 476 {"help", no_argument, 0, 'h'},
477 {"lmtp", no_argument, 0, 'L'},
473 {"starttls",no_argument,0,'S'}, 478 {"starttls",no_argument,0,'S'},
474 {"certificate",required_argument,0,'D'}, 479 {"certificate",required_argument,0,'D'},
475 {"ignore-quit-failure",no_argument,0,'q'}, 480 {"ignore-quit-failure",no_argument,0,'q'},
@@ -489,7 +494,7 @@ process_arguments (int argc, char **argv)
489 } 494 }
490 495
491 while (1) { 496 while (1) {
492 c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:R:SD:F:A:U:P:q", 497 c = getopt_long (argc, argv, "+hVv46Lt:p:f:e:c:w:H:C:R:SD:F:A:U:P:q",
493 longopts, &option); 498 longopts, &option);
494 499
495 if (c == -1 || c == EOF) 500 if (c == -1 || c == EOF)
@@ -616,6 +621,9 @@ process_arguments (int argc, char **argv)
616 use_ssl = TRUE; 621 use_ssl = TRUE;
617 use_ehlo = TRUE; 622 use_ehlo = TRUE;
618 break; 623 break;
624 case 'L':
625 use_lhlo = TRUE;
626 break;
619 case '4': 627 case '4':
620 address_family = AF_INET; 628 address_family = AF_INET;
621 break; 629 break;
@@ -824,6 +832,8 @@ print_help (void)
824 printf (" %s\n", _("SMTP AUTH username")); 832 printf (" %s\n", _("SMTP AUTH username"));
825 printf (" %s\n", "-P, --authpass=STRING"); 833 printf (" %s\n", "-P, --authpass=STRING");
826 printf (" %s\n", _("SMTP AUTH password")); 834 printf (" %s\n", _("SMTP AUTH password"));
835 printf (" %s\n", "-L, --lmtp");
836 printf (" %s\n", _("Send LHLO instead of HELO/EHLO"));
827 printf (" %s\n", "-q, --ignore-quit-failure"); 837 printf (" %s\n", "-q, --ignore-quit-failure");
828 printf (" %s\n", _("Ignore failure when sending QUIT command to server")); 838 printf (" %s\n", _("Ignore failure when sending QUIT command to server"));
829 839
@@ -850,6 +860,6 @@ print_usage (void)
850 printf ("%s\n", _("Usage:")); 860 printf ("%s\n", _("Usage:"));
851 printf ("%s -H host [-p port] [-4|-6] [-e expect] [-C command] [-R response] [-f from addr]\n", progname); 861 printf ("%s -H host [-p port] [-4|-6] [-e expect] [-C command] [-R response] [-f from addr]\n", progname);
852 printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout] [-q]\n"); 862 printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout] [-q]\n");
853 printf ("[-F fqdn] [-S] [-D warn days cert expire[,crit days cert expire]] [-v] \n"); 863 printf ("[-F fqdn] [-S] [-L] [-D warn days cert expire[,crit days cert expire]] [-v] \n");
854} 864}
855 865
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index e8a21a4..58d46b1 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -468,6 +468,9 @@ main (int argc, char **argv)
468 /* Process this block for numeric comparisons */ 468 /* Process this block for numeric comparisons */
469 /* Make some special values,like Timeticks numeric only if a threshold is defined */ 469 /* Make some special values,like Timeticks numeric only if a threshold is defined */
470 if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { 470 if (thlds[i]->warning || thlds[i]->critical || calculate_rate) {
471 if (verbose > 2) {
472 print_thresholds(" thresholds", thlds[i]);
473 }
471 ptr = strpbrk (show, "-0123456789"); 474 ptr = strpbrk (show, "-0123456789");
472 if (ptr == NULL) 475 if (ptr == NULL)
473 die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); 476 die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show);
@@ -576,20 +579,23 @@ main (int argc, char **argv)
576 len = sizeof(perfstr)-strlen(perfstr)-1; 579 len = sizeof(perfstr)-strlen(perfstr)-1;
577 strncat(perfstr, show, len>ptr-show ? ptr-show : len); 580 strncat(perfstr, show, len>ptr-show ? ptr-show : len);
578 581
582 if (type)
583 strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);
584
579 if (warning_thresholds) { 585 if (warning_thresholds) {
580 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); 586 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1);
581 strncat(perfstr, warning_thresholds, sizeof(perfstr)-strlen(perfstr)-1); 587 if(thlds[i]->warning && thlds[i]->warning->text)
588 strncat(perfstr, thlds[i]->warning->text, sizeof(perfstr)-strlen(perfstr)-1);
582 } 589 }
583 590
584 if (critical_thresholds) { 591 if (critical_thresholds) {
585 if (!warning_thresholds) 592 if (!warning_thresholds)
586 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); 593 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1);
587 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); 594 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1);
588 strncat(perfstr, critical_thresholds, sizeof(perfstr)-strlen(perfstr)-1); 595 if(thlds[i]->critical && thlds[i]->critical->text)
596 strncat(perfstr, thlds[i]->critical->text, sizeof(perfstr)-strlen(perfstr)-1);
589 } 597 }
590 598
591 if (type)
592 strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);
593 strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); 599 strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1);
594 } 600 }
595 } 601 }
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 0ff0c77..685c2cc 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -34,6 +34,9 @@ const char *email = "devel@monitoring-plugins.org";
34#include "common.h" 34#include "common.h"
35#include "popen.h" 35#include "popen.h"
36#include "utils.h" 36#include "utils.h"
37#include <string.h>
38#include <math.h>
39#include <libintl.h>
37 40
38#ifdef HAVE_DECL_SWAPCTL 41#ifdef HAVE_DECL_SWAPCTL
39# ifdef HAVE_SYS_PARAM_H 42# ifdef HAVE_SYS_PARAM_H
@@ -51,16 +54,19 @@ const char *email = "devel@monitoring-plugins.org";
51# define SWAP_CONVERSION 1 54# define SWAP_CONVERSION 1
52#endif 55#endif
53 56
54int check_swap (int usp, float free_swap_mb, float total_swap_mb); 57typedef struct {
58 int is_percentage;
59 uint64_t value;
60} threshold_t;
61
62int check_swap (float free_swap_mb, float total_swap_mb);
55int process_arguments (int argc, char **argv); 63int process_arguments (int argc, char **argv);
56int validate_arguments (void); 64int validate_arguments (void);
57void print_usage (void); 65void print_usage (void);
58void print_help (void); 66void print_help (void);
59 67
60int warn_percent = 0; 68threshold_t warn;
61int crit_percent = 0; 69threshold_t crit;
62float warn_size_bytes = 0;
63float crit_size_bytes = 0;
64int verbose; 70int verbose;
65int allswaps; 71int allswaps;
66int no_swap_state = STATE_CRITICAL; 72int no_swap_state = STATE_CRITICAL;
@@ -68,9 +74,10 @@ int no_swap_state = STATE_CRITICAL;
68int 74int
69main (int argc, char **argv) 75main (int argc, char **argv)
70{ 76{
71 int percent_used, percent; 77 unsigned int percent_used, percent;
72 float total_swap_mb = 0, used_swap_mb = 0, free_swap_mb = 0; 78 uint64_t total_swap_mb = 0, used_swap_mb = 0, free_swap_mb = 0;
73 float dsktotal_mb = 0, dskused_mb = 0, dskfree_mb = 0, tmp_mb = 0; 79 uint64_t dsktotal_mb = 0, dskused_mb = 0, dskfree_mb = 0;
80 uint64_t tmp_KB = 0;
74 int result = STATE_UNKNOWN; 81 int result = STATE_UNKNOWN;
75 char input_buffer[MAX_INPUT_BUFFER]; 82 char input_buffer[MAX_INPUT_BUFFER];
76#ifdef HAVE_PROC_MEMINFO 83#ifdef HAVE_PROC_MEMINFO
@@ -116,10 +123,15 @@ main (int argc, char **argv)
116 } 123 }
117 fp = fopen (PROC_MEMINFO, "r"); 124 fp = fopen (PROC_MEMINFO, "r");
118 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { 125 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
119 if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %f %f %f", &dsktotal_mb, &dskused_mb, &dskfree_mb) == 3) { 126 /*
120 dsktotal_mb = dsktotal_mb / 1048576; /* Apply conversion */ 127 * The following sscanf call looks for a line looking like: "Swap: 123 123 123"
121 dskused_mb = dskused_mb / 1048576; 128 * On which kind of system this format exists, I can not say, but I wanted to
122 dskfree_mb = dskfree_mb / 1048576; 129 * document this for people who are not adapt with sscanf anymore, like me
130 */
131 if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %lu %lu %lu", &dsktotal_mb, &dskused_mb, &dskfree_mb) == 3) {
132 dsktotal_mb = dsktotal_mb / (1024 * 1024); /* Apply conversion */
133 dskused_mb = dskused_mb / (1024 * 1024);
134 dskfree_mb = dskfree_mb / (1024 * 1024);
123 total_swap_mb += dsktotal_mb; 135 total_swap_mb += dsktotal_mb;
124 used_swap_mb += dskused_mb; 136 used_swap_mb += dskused_mb;
125 free_swap_mb += dskfree_mb; 137 free_swap_mb += dskfree_mb;
@@ -128,21 +140,25 @@ main (int argc, char **argv)
128 percent=100.0; 140 percent=100.0;
129 else 141 else
130 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); 142 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
131 result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb)); 143 result = max_state (result, check_swap (dskfree_mb, dsktotal_mb));
132 if (verbose) 144 if (verbose)
133 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); 145 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
134 } 146 }
135 } 147 }
136 else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFre]%*[:] %f %*[k]%*[B]", str, &tmp_mb)) { 148 /*
149 * The following sscanf call looks for lines looking like: "SwapTotal: 123" and "SwapFree: 123"
150 * This format exists at least on Debian Linux with a 5.* kernel
151 */
152 else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFre]%*[:] %lu %*[k]%*[B]", str, &tmp_KB)) {
137 if (verbose >= 3) { 153 if (verbose >= 3) {
138 printf("Got %s with %f\n", str, tmp_mb); 154 printf("Got %s with %lu\n", str, tmp_KB);
139 } 155 }
140 /* I think this part is always in Kb, so convert to mb */ 156 /* I think this part is always in Kb, so convert to mb */
141 if (strcmp ("Total", str) == 0) { 157 if (strcmp ("Total", str) == 0) {
142 dsktotal_mb = tmp_mb / 1024; 158 dsktotal_mb = tmp_KB / 1024;
143 } 159 }
144 else if (strcmp ("Free", str) == 0) { 160 else if (strcmp ("Free", str) == 0) {
145 dskfree_mb = tmp_mb / 1024; 161 dskfree_mb = tmp_KB / 1024;
146 } 162 }
147 } 163 }
148 } 164 }
@@ -227,7 +243,7 @@ main (int argc, char **argv)
227 free_swap_mb += dskfree_mb; 243 free_swap_mb += dskfree_mb;
228 if (allswaps) { 244 if (allswaps) {
229 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); 245 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
230 result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb)); 246 result = max_state (result, check_swap (dskfree_mb, dsktotal_mb));
231 if (verbose) 247 if (verbose)
232 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); 248 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
233 } 249 }
@@ -289,7 +305,7 @@ main (int argc, char **argv)
289 305
290 if(allswaps && dsktotal_mb > 0){ 306 if(allswaps && dsktotal_mb > 0){
291 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); 307 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
292 result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb)); 308 result = max_state (result, check_swap (dskfree_mb, dsktotal_mb));
293 if (verbose) { 309 if (verbose) {
294 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); 310 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
295 } 311 }
@@ -328,7 +344,7 @@ main (int argc, char **argv)
328 344
329 if(allswaps && dsktotal_mb > 0){ 345 if(allswaps && dsktotal_mb > 0){
330 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); 346 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
331 result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb)); 347 result = max_state (result, check_swap(dskfree_mb, dsktotal_mb));
332 if (verbose) { 348 if (verbose) {
333 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); 349 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
334 } 350 }
@@ -355,14 +371,19 @@ main (int argc, char **argv)
355 status = "- Swap is either disabled, not present, or of zero size. "; 371 status = "- Swap is either disabled, not present, or of zero size. ";
356 } 372 }
357 373
358 result = max_state (result, check_swap (percent_used, free_swap_mb, total_swap_mb)); 374 result = max_state (result, check_swap(free_swap_mb, total_swap_mb));
359 printf (_("SWAP %s - %d%% free (%d MB out of %d MB) %s|"), 375 printf (_("SWAP %s - %d%% free (%dMB out of %dMB) %s|"),
360 state_text (result), 376 state_text (result),
361 (100 - percent_used), (int) free_swap_mb, (int) total_swap_mb, status); 377 (100 - percent_used), (int) free_swap_mb, (int) total_swap_mb, status);
362 378
363 puts (perfdata ("swap", (long) free_swap_mb, "MB", 379 uint64_t warn_print = warn.value;
364 TRUE, (long) max (warn_size_bytes/(1024 * 1024), warn_percent/100.0*total_swap_mb), 380 if (warn.is_percentage) warn_print = warn.value * (total_swap_mb *1024 *1024/100);
365 TRUE, (long) max (crit_size_bytes/(1024 * 1024), crit_percent/100.0*total_swap_mb), 381 uint64_t crit_print = crit.value;
382 if (crit.is_percentage) crit_print = crit.value * (total_swap_mb *1024 *1024/100);
383
384 puts (perfdata_uint64 ("swap", free_swap_mb *1024 *1024, "B",
385 TRUE, warn_print,
386 TRUE, crit_print,
366 TRUE, 0, 387 TRUE, 0,
367 TRUE, (long) total_swap_mb)); 388 TRUE, (long) total_swap_mb));
368 389
@@ -370,26 +391,37 @@ main (int argc, char **argv)
370} 391}
371 392
372 393
373
374int 394int
375check_swap (int usp, float free_swap_mb, float total_swap_mb) 395check_swap(float free_swap_mb, float total_swap_mb)
376{ 396{
377 397
378 if (!total_swap_mb) return no_swap_state; 398 if (!total_swap_mb) return no_swap_state;
379 399
380 int result = STATE_UNKNOWN; 400 uint64_t free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */
381 float free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ 401
382 if (usp >= 0 && crit_percent != 0 && usp >= (100.0 - crit_percent)) 402 if (!crit.is_percentage && crit.value >= free_swap) return STATE_CRITICAL;
383 result = STATE_CRITICAL; 403 if (!warn.is_percentage && warn.value >= free_swap) return STATE_WARNING;
384 else if (crit_size_bytes > 0 && free_swap <= crit_size_bytes) 404
385 result = STATE_CRITICAL; 405
386 else if (usp >= 0 && warn_percent != 0 && usp >= (100.0 - warn_percent)) 406 uint64_t usage_percentage = ((total_swap_mb - free_swap_mb) / total_swap_mb) * 100;
387 result = STATE_WARNING; 407
388 else if (warn_size_bytes > 0 && free_swap <= warn_size_bytes) 408 if (crit.is_percentage &&
389 result = STATE_WARNING; 409 usage_percentage >= 0 &&
390 else if (usp >= 0.0) 410 crit.value != 0 &&
391 result = STATE_OK; 411 usage_percentage >= (100 - crit.value))
392 return result; 412 {
413 return STATE_CRITICAL;
414 }
415
416 if (warn.is_percentage &&
417 usage_percentage >= 0 &&
418 warn.value != 0 &&
419 usage_percentage >= (100 - warn.value))
420 {
421 return STATE_WARNING;
422 }
423
424 return STATE_OK;
393} 425}
394 426
395 427
@@ -422,42 +454,68 @@ process_arguments (int argc, char **argv)
422 break; 454 break;
423 455
424 switch (c) { 456 switch (c) {
425 case 'w': /* warning size threshold */ 457 case 'w': /* warning size threshold */
426 if (is_intnonneg (optarg)) { 458 {
427 warn_size_bytes = (float) atoi (optarg); 459 /*
428 break; 460 * We expect either a positive integer value without a unit, which means
429 } 461 * the unit is Bytes or a positive integer value and a percentage sign (%),
430 else if (strstr (optarg, ",") && 462 * which means the value must be with 0 and 100 and is relative to the total swap
431 strstr (optarg, "%") && 463 */
432 sscanf (optarg, "%f,%d%%", &warn_size_bytes, &warn_percent) == 2) { 464 size_t length;
433 warn_size_bytes = floorf(warn_size_bytes); 465 length = strlen(optarg);
434 break; 466
435 } 467 if (optarg[length - 1] == '%') {
436 else if (strstr (optarg, "%") && 468 /* It's percentage */
437 sscanf (optarg, "%d%%", &warn_percent) == 1) { 469 warn.is_percentage = 1;
438 break; 470 optarg[length - 1] = '\0';
439 } 471 if (is_uint64(optarg, &warn.value)) {
440 else { 472 if (warn.value > 100) {
441 usage4 (_("Warning threshold must be integer or percentage!")); 473 usage4 (_("Warning threshold percentage must be <= 100!"));
442 } 474 } else {
443 case 'c': /* critical size threshold */ 475 break;
444 if (is_intnonneg (optarg)) { 476 }
445 crit_size_bytes = (float) atoi (optarg); 477 }
446 break; 478 } else {
447 } 479 /* It's Bytes */
448 else if (strstr (optarg, ",") && 480 warn.is_percentage = 0;
449 strstr (optarg, "%") && 481 if (is_uint64(optarg, &warn.value)) {
450 sscanf (optarg, "%f,%d%%", &crit_size_bytes, &crit_percent) == 2) { 482 break;
451 crit_size_bytes = floorf(crit_size_bytes); 483 } else {
452 break; 484 usage4 (_("Warning threshold be positive integer or percentage!"));
453 } 485 }
454 else if (strstr (optarg, "%") && 486 }
455 sscanf (optarg, "%d%%", &crit_percent) == 1) {
456 break;
457 }
458 else {
459 usage4 (_("Critical threshold must be integer or percentage!"));
460 } 487 }
488 case 'c': /* critical size threshold */
489 {
490 /*
491 * We expect either a positive integer value without a unit, which means
492 * the unit is Bytes or a positive integer value and a percentage sign (%),
493 * which means the value must be with 0 and 100 and is relative to the total swap
494 */
495 size_t length;
496 length = strlen(optarg);
497
498 if (optarg[length - 1] == '%') {
499 /* It's percentage */
500 crit.is_percentage = 1;
501 optarg[length - 1] = '\0';
502 if (is_uint64(optarg, &crit.value)) {
503 if (crit.value> 100) {
504 usage4 (_("Critical threshold percentage must be <= 100!"));
505 } else {
506 break;
507 }
508 }
509 } else {
510 /* It's Bytes */
511 crit.is_percentage = 0;
512 if (is_uint64(optarg, &crit.value)) {
513 break;
514 } else {
515 usage4 (_("Critical threshold be positive integer or percentage!"));
516 }
517 }
518 }
461 case 'a': /* all swap */ 519 case 'a': /* all swap */
462 allswaps = TRUE; 520 allswaps = TRUE;
463 break; 521 break;
@@ -482,23 +540,6 @@ process_arguments (int argc, char **argv)
482 c = optind; 540 c = optind;
483 if (c == argc) 541 if (c == argc)
484 return validate_arguments (); 542 return validate_arguments ();
485 if (warn_percent == 0 && is_intnonneg (argv[c]))
486 warn_percent = atoi (argv[c++]);
487
488 if (c == argc)
489 return validate_arguments ();
490 if (crit_percent == 0 && is_intnonneg (argv[c]))
491 crit_percent = atoi (argv[c++]);
492
493 if (c == argc)
494 return validate_arguments ();
495 if (warn_size_bytes == 0 && is_intnonneg (argv[c]))
496 warn_size_bytes = (float) atoi (argv[c++]);
497
498 if (c == argc)
499 return validate_arguments ();
500 if (crit_size_bytes == 0 && is_intnonneg (argv[c]))
501 crit_size_bytes = (float) atoi (argv[c++]);
502 543
503 return validate_arguments (); 544 return validate_arguments ();
504} 545}
@@ -508,17 +549,12 @@ process_arguments (int argc, char **argv)
508int 549int
509validate_arguments (void) 550validate_arguments (void)
510{ 551{
511 if (warn_percent == 0 && crit_percent == 0 && warn_size_bytes == 0 552 if (warn.value == 0 && crit.value == 0) {
512 && crit_size_bytes == 0) {
513 return ERROR; 553 return ERROR;
514 } 554 }
515 else if (warn_percent < crit_percent) { 555 else if (warn.value < crit.value) {
516 usage4
517 (_("Warning percentage should be more than critical percentage"));
518 }
519 else if (warn_size_bytes < crit_size_bytes) {
520 usage4 556 usage4
521 (_("Warning free space should be more than critical free space")); 557 (_("Warning should be more than critical"));
522 } 558 }
523 return OK; 559 return OK;
524} 560}
@@ -564,7 +600,6 @@ print_help (void)
564} 600}
565 601
566 602
567
568void 603void
569print_usage (void) 604print_usage (void)
570{ 605{
diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t
index 4bff538..ada6a04 100644
--- a/plugins/t/check_curl.t
+++ b/plugins/t/check_curl.t
@@ -9,7 +9,7 @@ use Test::More;
9use POSIX qw/mktime strftime/; 9use POSIX qw/mktime strftime/;
10use NPTest; 10use NPTest;
11 11
12plan tests => 57; 12plan tests => 58;
13 13
14my $successOutput = '/OK.*HTTP.*second/'; 14my $successOutput = '/OK.*HTTP.*second/';
15 15
@@ -46,7 +46,7 @@ $res = NPTest->testCmd(
46 ); 46 );
47cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); 47cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" );
48# was CRITICAL only, but both check_curl and check_http print HTTP CRITICAL (puzzle?!) 48# was CRITICAL only, but both check_curl and check_http print HTTP CRITICAL (puzzle?!)
49cmp_ok( $res->output, 'eq', "HTTP CRITICAL - Invalid HTTP response received from host on port 80: cURL returned 28 - Timeout was reached", "Output OK"); 49like( $res->output, "/HTTP CRITICAL - Invalid HTTP response received from host on port 80: cURL returned 28 - Connection timed out after/", "Output OK");
50 50
51$res = NPTest->testCmd( 51$res = NPTest->testCmd(
52 "./$plugin $hostname_invalid -wt 1 -ct 2" 52 "./$plugin $hostname_invalid -wt 1 -ct 2"
@@ -56,7 +56,7 @@ cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" );
56# On Debian, it is Name or service not known, on Darwin, it is No address associated with nodename 56# On Debian, it is Name or service not known, on Darwin, it is No address associated with nodename
57# Is also possible to get a socket timeout if DNS is not responding fast enough 57# Is also possible to get a socket timeout if DNS is not responding fast enough
58# cURL gives us consistent strings from it's own 'lib/strerror.c' 58# cURL gives us consistent strings from it's own 'lib/strerror.c'
59like( $res->output, "/cURL returned 6 - Couldn't resolve host name/", "Output OK"); 59like( $res->output, "/cURL returned 6 - Could not resolve host:/", "Output OK");
60 60
61# host header checks 61# host header checks
62$res = NPTest->testCmd("./$plugin -v -H $host_tcp_http"); 62$res = NPTest->testCmd("./$plugin -v -H $host_tcp_http");
@@ -84,7 +84,7 @@ like( $res->output, '/^Host: testhost:8001\s*$/ms', "Host Header OK" );
84like( $res->output, '/CURLOPT_URL: http:\/\/'.$host_tcp_http.':80\//ms', "Url OK" ); 84like( $res->output, '/CURLOPT_URL: http:\/\/'.$host_tcp_http.':80\//ms', "Url OK" );
85 85
86SKIP: { 86SKIP: {
87 skip "No internet access", 3 if $internet_access eq "no"; 87 skip "No internet access", 4 if $internet_access eq "no";
88 88
89 $res = NPTest->testCmd("./$plugin -v -H $host_tls_http -S"); 89 $res = NPTest->testCmd("./$plugin -v -H $host_tls_http -S");
90 like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); 90 like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" );
@@ -94,6 +94,9 @@ SKIP: {
94 94
95 $res = NPTest->testCmd("./$plugin -v -H $host_tls_http:443 -S -p 443"); 95 $res = NPTest->testCmd("./$plugin -v -H $host_tls_http:443 -S -p 443");
96 like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); 96 like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" );
97
98 $res = NPTest->testCmd("./$plugin -v -H $host_tls_http -D -S -p 443");
99 like( $res->output, '/(^Host: '.$host_tls_http.'\s*$)|(cURL returned 60)/ms', "Host Header OK" );
97}; 100};
98 101
99SKIP: { 102SKIP: {
@@ -117,7 +120,7 @@ SKIP: {
117 cmp_ok( $res->return_code, "==", 0, "And also when not found"); 120 cmp_ok( $res->return_code, "==", 0, "And also when not found");
118} 121}
119SKIP: { 122SKIP: {
120 skip "No internet access", 16 if $internet_access eq "no"; 123 skip "No internet access", 28 if $internet_access eq "no";
121 124
122 $res = NPTest->testCmd( 125 $res = NPTest->testCmd(
123 "./$plugin --ssl $host_tls_http" 126 "./$plugin --ssl $host_tls_http"
@@ -190,8 +193,7 @@ SKIP: {
190 ); 193 );
191 cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" ); 194 cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" );
192 195
193 196 $res = NPTest->testCmd( "./$plugin -H www.mozilla.com -u /firefox -f curl" );
194 $res = NPTest->testCmd( "./$plugin -H www.mozilla.com -u /firefox -f follow" );
195 is( $res->return_code, 0, "Redirection based on location is okay"); 197 is( $res->return_code, 0, "Redirection based on location is okay");
196 198
197 $res = NPTest->testCmd( "./$plugin -H www.mozilla.com --extended-perfdata" ); 199 $res = NPTest->testCmd( "./$plugin -H www.mozilla.com --extended-perfdata" );
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index fdd8769..ec527e7 100644
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
@@ -88,8 +88,9 @@ $result = NPTest->testCmd(
88 ); 88 );
89$_ = $result->perf_output; 89$_ = $result->perf_output;
90my ($warn_absth_data, $crit_absth_data, $total_absth_data) = (m/=.[^;]*;(\d+);(\d+);\d+;(\d+)/); 90my ($warn_absth_data, $crit_absth_data, $total_absth_data) = (m/=.[^;]*;(\d+);(\d+);\d+;(\d+)/);
91is ($warn_absth_data, $total_absth_data - 20, "Wrong warning in perf data using absolute thresholds"); 91# default unit is MiB, but perfdata is always bytes
92is ($crit_absth_data, $total_absth_data - 10, "Wrong critical in perf data using absolute thresholds"); 92is ($warn_absth_data, $total_absth_data - (20 * (2 ** 20)), "Wrong warning in perf data using absolute thresholds");
93is ($crit_absth_data, $total_absth_data - (10 * (2 ** 20)), "Wrong critical in perf data using absolute thresholds");
93 94
94# Then check percent thresholds. 95# Then check percent thresholds.
95$result = NPTest->testCmd( 96$result = NPTest->testCmd(
@@ -119,7 +120,7 @@ like ( $result->only_output, qr/$more_free/, "Have disk name in text");
119$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" ); 120$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" );
120cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free"); 121cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free");
121$_ = $result->output; 122$_ = $result->output;
122my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+) MB .* (\d+) MB /g); 123my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+)MiB .* (\d+)MiB /g);
123my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; 124my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2;
124 125
125 126
diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t
index cdfbe60..afb2062 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 => 19; 13plan tests => 23;
14 14
15my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/'; 15my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/';
16 16
@@ -105,3 +105,11 @@ cmp_ok( $res->return_code, '==', 0, "Got expected address");
105$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_invalid_cidr -t 5"); 105$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_invalid_cidr -t 5");
106cmp_ok( $res->return_code, '==', 2, "Got wrong address"); 106cmp_ok( $res->return_code, '==', 2, "Got wrong address");
107like ( $res->output, "/^DNS CRITICAL.*expected '$hostname_invalid_cidr' but got '$hostname_valid_ip'".'$/', "Output OK"); 107like ( $res->output, "/^DNS CRITICAL.*expected '$hostname_invalid_cidr' but got '$hostname_valid_ip'".'$/', "Output OK");
108
109$res = NPTest->testCmd("./check_dns -H $hostname_valid -n");
110cmp_ok( $res->return_code, '==', 2, "Found $hostname_valid");
111like ( $res->output, "/^DNS CRITICAL.*Domain '$hostname_valid' was found by the server:/", "Output OK");
112
113$res = NPTest->testCmd("./check_dns -H $hostname_invalid -n");
114cmp_ok( $res->return_code, '==', 0, "Did not find $hostname_invalid");
115like ( $res->output, $successOutput, "Output OK" );
diff --git a/plugins/t/check_fping.t b/plugins/t/check_fping.t
index 342b0a7..67b357b 100644
--- a/plugins/t/check_fping.t
+++ b/plugins/t/check_fping.t
@@ -5,34 +5,30 @@
5# 5#
6 6
7use strict; 7use strict;
8use Test; 8use Test::More;
9use NPTest; 9use NPTest;
10 10
11use vars qw($tests);
12
13BEGIN {$tests = 4; plan tests => $tests}
14
15my $successOutput = '/^FPING OK - /';
16my $failureOutput = '/^FPING CRITICAL - /';
17
18my $host_responsive = getTestParameter("NP_HOST_RESPONSIVE", "The hostname of system responsive to network requests", "localhost"); 11my $host_responsive = getTestParameter("NP_HOST_RESPONSIVE", "The hostname of system responsive to network requests", "localhost");
19my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); 12my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1");
20my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); 13my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost");
21 14
22my $t; 15my $res;
23 16
24my $fping = qx(which fping 2> /dev/null); 17my $fping = qx(which fping 2> /dev/null);
25chomp($fping); 18chomp($fping);
26if( ! -x "./check_fping") { 19if( ! -x "./check_fping") {
27 $t += skipMissingCmd( "./check_fping", $tests ); 20 plan skip_all => "check_fping not found, skipping tests";
28} 21}
29elsif ( $> != 0 && (!$fping || ! -u $fping)) { 22elsif ( !$fping || !-x $fping ) {
30 $t += skipMsg( "./check_fping", $tests ); 23 plan skip_all => "fping not found or cannot be executed, skipping tests";
31} else { 24} else {
32 $t += checkCmd( "./check_fping $host_responsive", 0, $successOutput ); 25 plan tests => 3;
33 $t += checkCmd( "./check_fping $host_nonresponsive", [ 1, 2 ] ); 26 $res = NPTest->testCmd( "./check_fping $host_responsive" );
34 $t += checkCmd( "./check_fping $hostname_invalid", [ 1, 2 ] ); 27 cmp_ok( $res->return_code, '==', 0, "Responsive host returns OK");
35} 28
29 $res = NPTest->testCmd( "./check_fping $host_nonresponsive" );
30 cmp_ok( $res->return_code, '==', 2, "Non-Responsive host returns Critical");
36 31
37exit(0) if defined($Test::Harness::VERSION); 32 $res = NPTest->testCmd( "./check_fping $hostname_invalid" );
38exit($tests - $t); 33 cmp_ok( $res->return_code, '==', 3, "Invalid host returns Unknown");
34}
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index e92681e..c137f7b 100644
--- a/plugins/t/check_http.t
+++ b/plugins/t/check_http.t
@@ -103,7 +103,7 @@ SKIP: {
103 cmp_ok( $res->return_code, "==", 0, "And also when not found"); 103 cmp_ok( $res->return_code, "==", 0, "And also when not found");
104} 104}
105SKIP: { 105SKIP: {
106 skip "No internet access", 16 if $internet_access eq "no"; 106 skip "No internet access", 23 if $internet_access eq "no";
107 107
108 $res = NPTest->testCmd( 108 $res = NPTest->testCmd(
109 "./$plugin --ssl $host_tls_http" 109 "./$plugin --ssl $host_tls_http"
@@ -135,7 +135,7 @@ SKIP: {
135 135
136 # run some certificate checks with faketime 136 # run some certificate checks with faketime
137 SKIP: { 137 SKIP: {
138 skip "No faketime binary found", 12 if !$faketime; 138 skip "No faketime binary found", 7 if !$faketime;
139 $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./$plugin -C 1 $host_tls_http"); 139 $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./$plugin -C 1 $host_tls_http");
140 like($res->output, qr/OK - Certificate '$host_tls_cert' will expire on/, "Catch cert output"); 140 like($res->output, qr/OK - Certificate '$host_tls_cert' will expire on/, "Catch cert output");
141 is( $res->return_code, 0, "Catch cert output exit code" ); 141 is( $res->return_code, 0, "Catch cert output exit code" );
diff --git a/plugins/t/check_load.t b/plugins/t/check_load.t
index 55f6f75..60837ef 100644
--- a/plugins/t/check_load.t
+++ b/plugins/t/check_load.t
@@ -11,8 +11,8 @@ use NPTest;
11my $res; 11my $res;
12 12
13my $loadValue = "[0-9]+\.?[0-9]+"; 13my $loadValue = "[0-9]+\.?[0-9]+";
14my $successOutput = "/^OK - load average: $loadValue, $loadValue, $loadValue/"; 14my $successOutput = "/^LOAD OK - load average: $loadValue, $loadValue, $loadValue/";
15my $failureOutput = "/^CRITICAL - load average: $loadValue, $loadValue, $loadValue/"; 15my $failureOutput = "/^LOAD CRITICAL - load average: $loadValue, $loadValue, $loadValue/";
16 16
17plan tests => 11; 17plan tests => 11;
18 18
diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t
index e44adc9..de9e0f0 100644
--- a/plugins/t/check_swap.t
+++ b/plugins/t/check_swap.t
@@ -8,9 +8,9 @@ use strict;
8use Test::More tests => 8; 8use Test::More tests => 8;
9use NPTest; 9use NPTest;
10 10
11my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; 11my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/';
12my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; 12my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/';
13my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; 13my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/';
14 14
15my $result; 15my $result;
16 16
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t
index 1afbe4b..29cb03f 100755
--- a/plugins/tests/check_curl.t
+++ b/plugins/tests/check_curl.t
@@ -21,7 +21,7 @@ use FindBin qw($Bin);
21 21
22$ENV{'LC_TIME'} = "C"; 22$ENV{'LC_TIME'} = "C";
23 23
24my $common_tests = 70; 24my $common_tests = 72;
25my $ssl_only_tests = 8; 25my $ssl_only_tests = 8;
26# Check that all dependent modules are available 26# Check that all dependent modules are available
27eval "use HTTP::Daemon 6.01;"; 27eval "use HTTP::Daemon 6.01;";
@@ -126,8 +126,6 @@ if ($pid) {
126 exit; 126 exit;
127 } 127 }
128 } 128 }
129 # give our webservers some time to startup
130 sleep(1);
131} else { 129} else {
132 # Child 130 # Child
133 #print "child\n"; 131 #print "child\n";
@@ -140,6 +138,9 @@ if ($pid) {
140 exit; 138 exit;
141} 139}
142 140
141# give our webservers some time to startup
142sleep(3);
143
143# Run the same server on http and https 144# Run the same server on http and https
144sub run_server { 145sub run_server {
145 my $d = shift; 146 my $d = shift;
@@ -188,6 +189,12 @@ sub run_server {
188 $c->send_basic_header; 189 $c->send_basic_header;
189 $c->send_header('foo'); 190 $c->send_header('foo');
190 $c->send_crlf; 191 $c->send_crlf;
192 } elsif ($r->url->path eq "/header_broken_check") {
193 $c->send_basic_header;
194 $c->send_header('foo');
195 print $c "Test1:: broken\n";
196 print $c " Test2: leading whitespace\n";
197 $c->send_crlf;
191 } elsif ($r->url->path eq "/virtual_port") { 198 } elsif ($r->url->path eq "/virtual_port") {
192 # return sent Host header 199 # return sent Host header
193 $c->send_basic_header; 200 $c->send_basic_header;
@@ -247,7 +254,7 @@ my $cmd;
247# advanced checks with virtual hostname and virtual port 254# advanced checks with virtual hostname and virtual port
248SKIP: { 255SKIP: {
249 skip "libcurl version is smaller than $required_version", 6 unless $use_advanced_checks; 256 skip "libcurl version is smaller than $required_version", 6 unless $use_advanced_checks;
250 257
251 # http without virtual port 258 # http without virtual port
252 $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$port_http\$"; 259 $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$port_http\$";
253 $result = NPTest->testCmd( $cmd ); 260 $result = NPTest->testCmd( $cmd );
@@ -259,7 +266,7 @@ SKIP: {
259 $result = NPTest->testCmd( $cmd ); 266 $result = NPTest->testCmd( $cmd );
260 is( $result->return_code, 0, $cmd); 267 is( $result->return_code, 0, $cmd);
261 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); 268 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
262 269
263 # http with virtual port (80) 270 # http with virtual port (80)
264 $cmd = "./$plugin -H $virtual_host:80 -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host\$"; 271 $cmd = "./$plugin -H $virtual_host:80 -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host\$";
265 $result = NPTest->testCmd( $cmd ); 272 $result = NPTest->testCmd( $cmd );
@@ -321,6 +328,10 @@ sub run_common_tests {
321 is( $result->return_code, 2, "Missing header string check"); 328 is( $result->return_code, 2, "Missing header string check");
322 like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - header 'bar' not found on 'https?://127\.0\.0\.1:\d+/header_check'%, "Shows search string and location"); 329 like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - header 'bar' not found on 'https?://127\.0\.0\.1:\d+/header_check'%, "Shows search string and location");
323 330
331 $result = NPTest->testCmd( "$command -u /header_broken_check" );
332 is( $result->return_code, 0, "header_check search for string");
333 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 138 bytes in [\d\.]+ second/', "Output correct" );
334
324 my $cmd; 335 my $cmd;
325 $cmd = "$command -u /slow"; 336 $cmd = "$command -u /slow";
326 $result = NPTest->testCmd( $cmd ); 337 $result = NPTest->testCmd( $cmd );
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index 2f051fa..188f5e7 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -91,6 +91,8 @@ if ($pid) {
91 exit; 91 exit;
92 } 92 }
93 } else { 93 } else {
94 # closing the connection after -C cert checks make the daemon exit with a sigpipe otherwise
95 local $SIG{'PIPE'} = 'IGNORE';
94 my $d = HTTP::Daemon::SSL->new( 96 my $d = HTTP::Daemon::SSL->new(
95 LocalPort => $port_https, 97 LocalPort => $port_https,
96 LocalAddr => "127.0.0.1", 98 LocalAddr => "127.0.0.1",
@@ -102,8 +104,6 @@ if ($pid) {
102 exit; 104 exit;
103 } 105 }
104 } 106 }
105 # give our webservers some time to startup
106 sleep(1);
107} else { 107} else {
108 # Child 108 # Child
109 #print "child\n"; 109 #print "child\n";
@@ -116,6 +116,9 @@ if ($pid) {
116 exit; 116 exit;
117} 117}
118 118
119# give our webservers some time to startup
120sleep(3);
121
119# Run the same server on http and https 122# Run the same server on http and https
120sub run_server { 123sub run_server {
121 my $d = shift; 124 my $d = shift;
@@ -414,22 +417,24 @@ sub run_common_tests {
414 417
415 # stickyport - on full urlS port is set back to 80 otherwise 418 # stickyport - on full urlS port is set back to 80 otherwise
416 $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; 419 $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected";
420 alarm(2);
417 eval { 421 eval {
418 local $SIG{ALRM} = sub { die "alarm\n" }; 422 local $SIG{ALRM} = sub { die "alarm\n" };
419 alarm(2);
420 $result = NPTest->testCmd( $cmd ); 423 $result = NPTest->testCmd( $cmd );
421 alarm(0); }; 424 };
422 isnt( $@, "alarm\n", $cmd ); 425 isnt( $@, "alarm\n", $cmd );
426 alarm(0);
423 is( $result->return_code, 0, $cmd ); 427 is( $result->return_code, 0, $cmd );
424 428
425 # Let's hope there won't be any web server on :80 returning "redirected"! 429 # Let's hope there won't be any web server on :80 returning "redirected"!
426 $cmd = "$command -f sticky -u /redir_external -t 5 -s redirected"; 430 $cmd = "$command -f sticky -u /redir_external -t 5 -s redirected";
431 alarm(2);
427 eval { 432 eval {
428 local $SIG{ALRM} = sub { die "alarm\n" }; 433 local $SIG{ALRM} = sub { die "alarm\n" };
429 alarm(2);
430 $result = NPTest->testCmd( $cmd ); 434 $result = NPTest->testCmd( $cmd );
431 alarm(0); }; 435 };
432 isnt( $@, "alarm\n", $cmd ); 436 isnt( $@, "alarm\n", $cmd );
437 alarm(0);
433 isnt( $result->return_code, 0, $cmd ); 438 isnt( $result->return_code, 0, $cmd );
434 439
435 # Test an external address - timeout 440 # Test an external address - timeout
diff --git a/plugins/tests/check_procs.t b/plugins/tests/check_procs.t
index 6d71015..3af218f 100755
--- a/plugins/tests/check_procs.t
+++ b/plugins/tests/check_procs.t
@@ -8,13 +8,14 @@ use Test::More;
8use NPTest; 8use NPTest;
9 9
10if (-x "./check_procs") { 10if (-x "./check_procs") {
11 plan tests => 50; 11 plan tests => 52;
12} else { 12} else {
13 plan skip_all => "No check_procs compiled"; 13 plan skip_all => "No check_procs compiled";
14} 14}
15 15
16my $result; 16my $result;
17my $command = "./check_procs --input-file=tests/var/ps-axwo.darwin"; 17my $command = "./check_procs --input-file=tests/var/ps-axwo.darwin";
18my $cmd_etime = "./check_procs --input-file=tests/var/ps-axwo.debian";
18 19
19$result = NPTest->testCmd( "$command" ); 20$result = NPTest->testCmd( "$command" );
20is( $result->return_code, 0, "Run with no options" ); 21is( $result->return_code, 0, "Run with no options" );
@@ -69,9 +70,21 @@ SKIP: {
69 like( $result->output, '/^PROCS OK: 0 processes with UID = -2 \(nobody\), args \'UsB\'/', "Output correct" ); 70 like( $result->output, '/^PROCS OK: 0 processes with UID = -2 \(nobody\), args \'UsB\'/', "Output correct" );
70}; 71};
71 72
72$result = NPTest->testCmd( "$command --ereg-argument-array='mdworker.*501'" ); 73SKIP: {
73is( $result->return_code, 0, "Checking regexp search of arguments" ); 74 skip 'check_procs is compiled with etime format support', 2 if `$command -vvv` =~ m/etime/mx;
74is( $result->output, "PROCS OK: 1 process with regex args 'mdworker.*501' | procs=1;;;0;", "Output correct" ); 75
76 $result = NPTest->testCmd( "$command --ereg-argument-array='mdworker.*501'" );
77 is( $result->return_code, 0, "Checking regexp search of arguments" );
78 is( $result->output, "PROCS OK: 1 process with regex args 'mdworker.*501' | procs=1;;;0;", "Output correct" );
79}
80
81SKIP: {
82 skip 'check_procs is compiled without etime format support', 2 if `$cmd_etime -vvv` !~ m/etime/mx;
83
84 $result = NPTest->testCmd( "$cmd_etime -m ELAPSED -C apache2 -w 1000 -c 2000" );
85 is( $result->return_code, 2, "Checking elapsed time threshold" );
86 is( $result->output, "ELAPSED CRITICAL: 10 crit, 0 warn out of 10 processes with command name 'apache2' | procs=10;;;0; procs_warn=0;;;0; procs_crit=10;;;0;", "Output correct" );
87}
75 88
76$result = NPTest->testCmd( "$command --vsz 1000000" ); 89$result = NPTest->testCmd( "$command --vsz 1000000" );
77is( $result->return_code, 0, "Checking filter by VSZ" ); 90is( $result->return_code, 0, "Checking filter by VSZ" );
@@ -129,4 +142,3 @@ is( $result->output, 'RSS CRITICAL: 5 crit, 0 warn out of 95 processes [WindowSe
129$result = NPTest->testCmd( "$command --ereg-argument-array='(nosuchname|nosuch2name)'" ); 142$result = NPTest->testCmd( "$command --ereg-argument-array='(nosuchname|nosuch2name)'" );
130is( $result->return_code, 0, "Checking no pipe symbol in output" ); 143is( $result->return_code, 0, "Checking no pipe symbol in output" );
131is( $result->output, "PROCS OK: 0 processes with regex args '(nosuchname,nosuch2name)' | procs=0;;;0;", "Output correct" ); 144is( $result->output, "PROCS OK: 0 processes with regex args '(nosuchname,nosuch2name)' | procs=0;;;0;", "Output correct" );
132
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t
index 85d6bf5..0a77fa8 100755
--- a/plugins/tests/check_snmp.t
+++ b/plugins/tests/check_snmp.t
@@ -9,7 +9,7 @@ use NPTest;
9use FindBin qw($Bin); 9use FindBin qw($Bin);
10use POSIX qw/strftime/; 10use POSIX qw/strftime/;
11 11
12my $tests = 67; 12my $tests = 73;
13# Check that all dependent modules are available 13# Check that all dependent modules are available
14eval { 14eval {
15 require NetSNMP::OID; 15 require NetSNMP::OID;
@@ -251,9 +251,20 @@ is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4;-2:;-3:
251 251
252$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'" ); 252$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'" );
253is($res->return_code, 0, "Negative float OK" ); 253is($res->return_code, 0, "Negative float OK" );
254is($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" ); 254is($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" );
255 255
256$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'" ); 256$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'" );
257is($res->return_code, 1, "Negative float WARNING" ); 257is($res->return_code, 1, "Negative float WARNING" );
258is($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" ); 258is($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" );
259 259
260$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,.1.3.6.1.4.1.8072.3.2.67.17 -w '1:100000,-10:20' -c '2:200000,-20:30'" );
261is($res->return_code, 0, "Multiple OIDs with thresholds" );
262like($res->output, '/SNMP OK - \d+ -4 | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1:100000;2:200000 iso.3.6.1.4.1.8072.3.2.67.17=-4;-10:20;-20:30/', "Multiple OIDs with thresholds output" );
263
264$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,.1.3.6.1.4.1.8072.3.2.67.17 -w '1:100000,-1:2' -c '2:200000,-20:30'" );
265is($res->return_code, 1, "Multiple OIDs with thresholds" );
266like($res->output, '/SNMP WARNING - \d+ \*-4\* | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1:100000;2:200000 iso.3.6.1.4.1.8072.3.2.67.17=-4;-10:20;-20:30/', "Multiple OIDs with thresholds output" );
267
268$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,.1.3.6.1.4.1.8072.3.2.67.17 -w 1,2 -c 1" );
269is($res->return_code, 2, "Multiple OIDs with some thresholds" );
270like($res->output, '/SNMP CRITICAL - \*\d+\* \*-4\* | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1;2 iso.3.6.1.4.1.8072.3.2.67.17=-4;;/', "Multiple OIDs with thresholds output" );
diff --git a/plugins/tests/var/ps-axwo.debian b/plugins/tests/var/ps-axwo.debian
new file mode 100644
index 0000000..5889e9a
--- /dev/null
+++ b/plugins/tests/var/ps-axwo.debian
@@ -0,0 +1,219 @@
1STAT UID PID PPID VSZ RSS %CPU ELAPSED COMMAND COMMAND
2Ss 0 1 0 167244 7144 0.1 26-03:07:26 systemd /lib/systemd/systemd --system --deserialize 17
3S 0 2 0 0 0 0.0 26-03:07:26 kthreadd [kthreadd]
4I< 0 3 2 0 0 0.0 26-03:07:26 rcu_gp [rcu_gp]
5I< 0 4 2 0 0 0.0 26-03:07:26 rcu_par_gp [rcu_par_gp]
6I< 0 6 2 0 0 0.0 26-03:07:26 kworker/0:0H-ev [kworker/0:0H-events_highpri]
7I< 0 9 2 0 0 0.0 26-03:07:26 mm_percpu_wq [mm_percpu_wq]
8S 0 10 2 0 0 0.0 26-03:07:26 rcu_tasks_rude_ [rcu_tasks_rude_]
9S 0 11 2 0 0 0.0 26-03:07:26 rcu_tasks_trace [rcu_tasks_trace]
10S 0 12 2 0 0 0.0 26-03:07:26 ksoftirqd/0 [ksoftirqd/0]
11I 0 13 2 0 0 0.0 26-03:07:26 rcu_sched [rcu_sched]
12S 0 14 2 0 0 0.0 26-03:07:26 migration/0 [migration/0]
13S 0 15 2 0 0 0.0 26-03:07:26 cpuhp/0 [cpuhp/0]
14S 0 16 2 0 0 0.0 26-03:07:26 cpuhp/1 [cpuhp/1]
15S 0 17 2 0 0 0.0 26-03:07:26 migration/1 [migration/1]
16S 0 18 2 0 0 0.0 26-03:07:26 ksoftirqd/1 [ksoftirqd/1]
17I< 0 20 2 0 0 0.0 26-03:07:26 kworker/1:0H-ev [kworker/1:0H-events_highpri]
18S 0 21 2 0 0 0.0 26-03:07:26 cpuhp/2 [cpuhp/2]
19S 0 22 2 0 0 0.0 26-03:07:26 migration/2 [migration/2]
20S 0 23 2 0 0 0.0 26-03:07:26 ksoftirqd/2 [ksoftirqd/2]
21I< 0 25 2 0 0 0.0 26-03:07:26 kworker/2:0H-ev [kworker/2:0H-events_highpri]
22S 0 26 2 0 0 0.0 26-03:07:26 cpuhp/3 [cpuhp/3]
23S 0 27 2 0 0 0.0 26-03:07:26 migration/3 [migration/3]
24S 0 28 2 0 0 0.0 26-03:07:26 ksoftirqd/3 [ksoftirqd/3]
25I< 0 30 2 0 0 0.0 26-03:07:26 kworker/3:0H-ev [kworker/3:0H-events_highpri]
26S 0 35 2 0 0 0.0 26-03:07:26 kdevtmpfs [kdevtmpfs]
27I< 0 36 2 0 0 0.0 26-03:07:26 netns [netns]
28S 0 37 2 0 0 0.0 26-03:07:26 kauditd [kauditd]
29S 0 38 2 0 0 0.0 26-03:07:26 khungtaskd [khungtaskd]
30S 0 39 2 0 0 0.0 26-03:07:26 oom_reaper [oom_reaper]
31I< 0 40 2 0 0 0.0 26-03:07:26 writeback [writeback]
32S 0 41 2 0 0 0.0 26-03:07:26 kcompactd0 [kcompactd0]
33SN 0 42 2 0 0 0.0 26-03:07:26 ksmd [ksmd]
34SN 0 43 2 0 0 0.0 26-03:07:26 khugepaged [khugepaged]
35I< 0 62 2 0 0 0.0 26-03:07:26 kintegrityd [kintegrityd]
36I< 0 63 2 0 0 0.0 26-03:07:26 kblockd [kblockd]
37I< 0 64 2 0 0 0.0 26-03:07:26 blkcg_punt_bio [blkcg_punt_bio]
38I< 0 65 2 0 0 0.0 26-03:07:26 edac-poller [edac-poller]
39I< 0 66 2 0 0 0.0 26-03:07:26 devfreq_wq [devfreq_wq]
40I< 0 67 2 0 0 0.0 26-03:07:26 kworker/2:1H-ev [kworker/2:1H-events_highpri]
41S 0 70 2 0 0 0.3 26-03:07:25 kswapd0 [kswapd0]
42I< 0 71 2 0 0 0.0 26-03:07:25 kthrotld [kthrotld]
43I< 0 72 2 0 0 0.0 26-03:07:25 acpi_thermal_pm [acpi_thermal_pm]
44I< 0 74 2 0 0 0.0 26-03:07:25 ipv6_addrconf [ipv6_addrconf]
45I< 0 80 2 0 0 0.0 26-03:07:25 kworker/3:1H-ev [kworker/3:1H-events_highpri]
46I< 0 84 2 0 0 0.0 26-03:07:25 kstrp [kstrp]
47I< 0 87 2 0 0 0.0 26-03:07:25 zswap-shrink [zswap-shrink]
48I< 0 110 2 0 0 0.0 26-03:07:25 kworker/0:1H-ev [kworker/0:1H-events_highpri]
49I< 0 141 2 0 0 0.0 26-03:07:25 ata_sff [ata_sff]
50S 0 143 2 0 0 0.0 26-03:07:25 scsi_eh_0 [scsi_eh_0]
51I< 0 144 2 0 0 0.0 26-03:07:25 scsi_tmf_0 [scsi_tmf_0]
52S 0 145 2 0 0 0.0 26-03:07:25 scsi_eh_1 [scsi_eh_1]
53I< 0 146 2 0 0 0.0 26-03:07:25 scsi_tmf_1 [scsi_tmf_1]
54S 0 147 2 0 0 0.0 26-03:07:25 scsi_eh_2 [scsi_eh_2]
55I< 0 148 2 0 0 0.0 26-03:07:25 scsi_tmf_2 [scsi_tmf_2]
56S 0 149 2 0 0 0.0 26-03:07:25 scsi_eh_3 [scsi_eh_3]
57I< 0 150 2 0 0 0.0 26-03:07:25 scsi_tmf_3 [scsi_tmf_3]
58S 0 151 2 0 0 0.0 26-03:07:25 scsi_eh_4 [scsi_eh_4]
59I< 0 152 2 0 0 0.0 26-03:07:25 scsi_tmf_4 [scsi_tmf_4]
60S 0 153 2 0 0 0.0 26-03:07:25 scsi_eh_5 [scsi_eh_5]
61I< 0 154 2 0 0 0.0 26-03:07:25 scsi_tmf_5 [scsi_tmf_5]
62S 0 158 2 0 0 0.0 26-03:07:25 card0-crtc0 [card0-crtc0]
63S 0 159 2 0 0 0.0 26-03:07:25 card0-crtc1 [card0-crtc1]
64S 0 160 2 0 0 0.0 26-03:07:25 card0-crtc2 [card0-crtc2]
65I< 0 162 2 0 0 0.0 26-03:07:25 kworker/1:1H-ev [kworker/1:1H-events_highpri]
66S 0 163 2 0 0 0.0 26-03:07:25 scsi_eh_6 [scsi_eh_6]
67I< 0 164 2 0 0 0.0 26-03:07:25 scsi_tmf_6 [scsi_tmf_6]
68S 0 165 2 0 0 0.0 26-03:07:25 usb-storage [usb-storage]
69I< 0 167 2 0 0 0.0 26-03:07:25 uas [uas]
70I< 0 176 2 0 0 0.0 26-03:07:25 kdmflush [kdmflush]
71I< 0 177 2 0 0 0.0 26-03:07:25 kdmflush [kdmflush]
72S 0 202 2 0 0 0.0 26-03:07:24 scsi_eh_7 [scsi_eh_7]
73I< 0 203 2 0 0 0.0 26-03:07:24 scsi_tmf_7 [scsi_tmf_7]
74S 0 204 2 0 0 0.0 26-03:07:24 usb-storage [usb-storage]
75I< 0 232 2 0 0 0.0 26-03:07:23 btrfs-worker [btrfs-worker]
76I< 0 233 2 0 0 0.0 26-03:07:23 btrfs-worker-hi [btrfs-worker-hi]
77I< 0 234 2 0 0 0.0 26-03:07:23 btrfs-delalloc [btrfs-delalloc]
78I< 0 235 2 0 0 0.0 26-03:07:23 btrfs-flush_del [btrfs-flush_del]
79I< 0 236 2 0 0 0.0 26-03:07:23 btrfs-cache [btrfs-cache]
80I< 0 237 2 0 0 0.0 26-03:07:23 btrfs-fixup [btrfs-fixup]
81I< 0 238 2 0 0 0.0 26-03:07:23 btrfs-endio [btrfs-endio]
82I< 0 239 2 0 0 0.0 26-03:07:23 btrfs-endio-met [btrfs-endio-met]
83I< 0 240 2 0 0 0.0 26-03:07:23 btrfs-endio-met [btrfs-endio-met]
84I< 0 241 2 0 0 0.0 26-03:07:23 btrfs-endio-rai [btrfs-endio-rai]
85I< 0 242 2 0 0 0.0 26-03:07:23 btrfs-rmw [btrfs-rmw]
86I< 0 243 2 0 0 0.0 26-03:07:23 btrfs-endio-wri [btrfs-endio-wri]
87I< 0 244 2 0 0 0.0 26-03:07:23 btrfs-freespace [btrfs-freespace]
88I< 0 245 2 0 0 0.0 26-03:07:23 btrfs-delayed-m [btrfs-delayed-m]
89I< 0 246 2 0 0 0.0 26-03:07:23 btrfs-readahead [btrfs-readahead]
90I< 0 247 2 0 0 0.0 26-03:07:23 btrfs-qgroup-re [btrfs-qgroup-re]
91S 0 248 2 0 0 0.0 26-03:07:23 btrfs-cleaner [btrfs-cleaner]
92S 0 249 2 0 0 0.2 26-03:07:23 btrfs-transacti [btrfs-transacti]
93I< 0 317 2 0 0 0.0 26-03:07:22 rpciod [rpciod]
94I< 0 322 2 0 0 0.0 26-03:07:22 xprtiod [xprtiod]
95S 0 381 2 0 0 0.0 26-03:07:22 irq/133-mei_me [irq/133-mei_me]
96S 0 422 2 0 0 0.0 26-03:07:22 watchdogd [watchdogd]
97I< 0 523 2 0 0 0.0 26-03:07:22 led_workqueue [led_workqueue]
98I< 0 583 2 0 0 0.0 26-03:07:22 cryptd [cryptd]
99I< 0 590 2 0 0 0.0 26-03:07:22 ext4-rsv-conver [ext4-rsv-conver]
100Ss 104 693 1 12324 4292 0.5 26-03:07:21 dbus-daemon /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
101Ss 0 731 1 575120 1368 0.0 26-03:07:21 systemd-logind /lib/systemd/systemd-logind
102Ssl 0 1111 1 121248 732 0.0 26-03:07:18 unattended-upgr /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
103S 0 1141 2 0 0 0.0 26-03:07:18 lockd [lockd]
104I< 0 1459 2 0 0 0.0 26-03:07:16 nfsiod [nfsiod]
105S 0 1621 2 0 0 0.0 26-03:07:15 NFSv4 callback [NFSv4 callback]
106Ssl 0 1771 1 1548340 676 0.0 26-03:07:13 libvirtd /usr/sbin/libvirtd
107I< 0 24315 2 0 0 0.0 26-02:49:02 cifsiod [cifsiod]
108I< 0 24316 2 0 0 0.0 26-02:49:02 smb3decryptd [smb3decryptd]
109I< 0 24317 2 0 0 0.0 26-02:49:02 cifsfileinfoput [cifsfileinfoput]
110I< 0 24318 2 0 0 0.0 26-02:49:02 cifsoplockd [cifsoplockd]
111I< 0 24319 2 0 0 0.0 26-02:49:02 cifs-dfscache [cifs-dfscache]
112S 0 24322 2 0 0 0.0 26-02:49:02 cifsd [cifsd]
113I< 0 24413 2 0 0 0.0 26-02:48:57 btrfs-worker [btrfs-worker]
114I< 0 24414 2 0 0 0.0 26-02:48:57 btrfs-worker-hi [btrfs-worker-hi]
115I< 0 24415 2 0 0 0.0 26-02:48:57 btrfs-delalloc [btrfs-delalloc]
116I< 0 24416 2 0 0 0.0 26-02:48:57 btrfs-flush_del [btrfs-flush_del]
117I< 0 24418 2 0 0 0.0 26-02:48:57 btrfs-cache [btrfs-cache]
118I< 0 24419 2 0 0 0.0 26-02:48:57 btrfs-fixup [btrfs-fixup]
119I< 0 24420 2 0 0 0.0 26-02:48:57 btrfs-endio [btrfs-endio]
120I< 0 24421 2 0 0 0.0 26-02:48:57 btrfs-endio-met [btrfs-endio-met]
121I< 0 24422 2 0 0 0.0 26-02:48:57 btrfs-endio-met [btrfs-endio-met]
122I< 0 24423 2 0 0 0.0 26-02:48:57 btrfs-endio-rai [btrfs-endio-rai]
123I< 0 24424 2 0 0 0.0 26-02:48:57 btrfs-rmw [btrfs-rmw]
124I< 0 24425 2 0 0 0.0 26-02:48:57 btrfs-endio-wri [btrfs-endio-wri]
125I< 0 24426 2 0 0 0.0 26-02:48:57 btrfs-freespace [btrfs-freespace]
126I< 0 24427 2 0 0 0.0 26-02:48:57 btrfs-delayed-m [btrfs-delayed-m]
127I< 0 24428 2 0 0 0.0 26-02:48:57 btrfs-readahead [btrfs-readahead]
128I< 0 24429 2 0 0 0.0 26-02:48:57 btrfs-qgroup-re [btrfs-qgroup-re]
129S 0 24450 2 0 0 0.0 26-02:48:53 btrfs-cleaner [btrfs-cleaner]
130S 0 24451 2 0 0 0.0 26-02:48:53 btrfs-transacti [btrfs-transacti]
131I< 0 747708 2 0 0 0.0 16-21:06:20 xfsalloc [xfsalloc]
132I< 0 747709 2 0 0 0.0 16-21:06:20 xfs_mru_cache [xfs_mru_cache]
133S 0 747713 2 0 0 0.0 16-21:06:20 jfsIO [jfsIO]
134S 0 747714 2 0 0 0.0 16-21:06:20 jfsCommit [jfsCommit]
135S 0 747715 2 0 0 0.0 16-21:06:20 jfsCommit [jfsCommit]
136S 0 747716 2 0 0 0.0 16-21:06:20 jfsCommit [jfsCommit]
137S 0 747717 2 0 0 0.0 16-21:06:20 jfsCommit [jfsCommit]
138S 0 747718 2 0 0 0.0 16-21:06:20 jfsSync [jfsSync]
139Ss 0 1071687 1 105976 28304 0.0 3-03:12:31 systemd-journal /lib/systemd/systemd-journald
140Ss 0 1934146 1 25672 4704 0.0 11:19:31 cupsd /usr/sbin/cupsd -l
141Ssl 0 1934148 1 182868 8540 0.0 11:19:31 cups-browsed /usr/sbin/cups-browsed
142S 13 1934155 3392655 5752 88 0.0 11:19:31 pinger (pinger)
143S< 33 1934166 3393034 57996 5460 0.0 11:19:31 apache2 /usr/sbin/apache2 -k start
144S< 33 1934167 3393034 216944 13892 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start
145S< 33 1934168 3393034 216944 13756 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start
146S< 33 1934169 3393034 216936 13732 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start
147S< 33 1934170 3393034 216944 13888 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start
148S< 33 1934172 3393034 216944 15388 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start
149S< 33 1934701 3393034 216936 13736 0.0 11:19:29 apache2 /usr/sbin/apache2 -k start
150S< 33 1935056 3393034 216920 13724 0.0 11:19:28 apache2 /usr/sbin/apache2 -k start
151S 7 1936834 1934146 16652 832 0.0 11:18:12 dbus /usr/lib/cups/notifier/dbus dbus://
152S< 33 1955909 3393034 216928 13792 0.0 11:00:25 apache2 /usr/sbin/apache2 -k start
153I< 0 2531464 2 0 0 0.0 06:35:47 kworker/u9:0-i9 [kworker/u9:0-i915_flip]
154I 0 2570506 2 0 0 0.0 06:27:41 kworker/1:0-cgr [kworker/1:0-cgroup_destroy]
155I 0 2596195 2 0 0 0.0 06:21:52 kworker/1:1-eve [kworker/1:1-events]
156I 0 2785341 2 0 0 0.0 03:34:16 kworker/u8:8-bt [kworker/u8:8-btrfs-endio-write]
157I 0 2785520 2 0 0 0.0 03:33:50 kworker/3:0-eve [kworker/3:0-events]
158I 0 2798669 2 0 0 0.0 03:21:09 kworker/u8:5-bt [kworker/u8:5-btrfs-endio-write]
159Ss 0 2803015 1 5616 3108 0.0 03:17:54 cron /usr/sbin/cron -f
160I 0 2845483 2 0 0 0.0 02:38:11 kworker/0:3-eve [kworker/0:3-events]
161I 0 2939490 2 0 0 0.1 01:10:32 kworker/0:0-eve [kworker/0:0-events]
162I 0 2939754 2 0 0 0.0 01:10:26 kworker/u8:1-i9 [kworker/u8:1-i915]
163I 0 2942040 2 0 0 0.0 01:08:02 kworker/u8:7-bt [kworker/u8:7-btrfs-endio-meta]
164S 117 2954268 3392551 40044 5772 0.0 56:37 pickup pickup -l -t unix -u -c
165I 0 2965195 2 0 0 0.0 46:00 kworker/u8:0-bt [kworker/u8:0-btrfs-worker]
166I 0 2977972 2 0 0 0.0 33:54 kworker/u8:2-bt [kworker/u8:2-btrfs-endio-write]
167I 0 2985488 2 0 0 0.0 27:02 kworker/u8:3-bl [kworker/u8:3-blkcg_punt_bio]
168I 0 2987519 2 0 0 1.0 25:15 kworker/2:1-eve [kworker/2:1-events]
169I 0 2987601 2 0 0 0.0 25:03 kworker/u8:9-i9 [kworker/u8:9-i915]
170I< 0 2995218 2 0 0 0.0 18:41 kworker/u9:2-xp [kworker/u9:2-xprtiod]
171I 0 2997170 2 0 0 0.0 16:41 kworker/3:1-rcu [kworker/3:1-rcu_gp]
172I 0 3001264 2 0 0 0.0 13:01 kworker/u8:4-bt [kworker/u8:4-btrfs-endio-write]
173I 0 3004697 2 0 0 0.7 09:41 kworker/2:0-eve [kworker/2:0-events]
174I 0 3010619 2 0 0 1.0 04:29 kworker/2:2-eve [kworker/2:2-events]
175I 0 3014612 2 0 0 0.0 00:41 kworker/3:2-eve [kworker/3:2-events]
176S 0 3015082 2803015 6716 3028 0.0 00:30 cron /usr/sbin/CRON -f
177I 0 3015382 2 0 0 0.0 00:00 kworker/u8:6-bt [kworker/u8:6-btrfs-endio-meta]
178Ss 1 3392068 1 5592 504 0.0 15-02:34:39 atd /usr/sbin/atd -f
179Ssl 0 3392072 1 235796 1740 0.0 15-02:34:39 accounts-daemon /usr/libexec/accounts-daemon
180Ssl 106 3392076 1 315708 6128 0.0 15-02:34:39 colord /usr/libexec/colord
181Ss 0 3392083 1 8120 720 0.0 15-02:34:39 haveged /usr/sbin/haveged --Foreground --verbose=1
182Ss 0 3392090 1 5168 132 0.0 15-02:34:39 blkmapd /usr/sbin/blkmapd
183SNsl 111 3392094 1 155648 440 0.0 15-02:34:39 rtkit-daemon /usr/libexec/rtkit-daemon
184Ssl 0 3392097 1 290168 1352 0.0 15-02:34:39 packagekitd /usr/libexec/packagekitd
185Ss 128 3392100 1 7960 448 0.0 15-02:34:39 rpcbind /sbin/rpcbind -f -w
186Ss 0 3392114 1 13432 616 0.0 15-02:34:39 systemd-machine /lib/systemd/systemd-machined
187Ss 0 3392118 1 13316 848 0.0 15-02:34:39 sshd sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
188Ssl 0 3392124 1 244072 2456 0.0 15-02:34:39 upowerd /usr/libexec/upowerd
189Ssl 0 3392138 1 1634748 10684 0.0 15-02:34:39 containerd /usr/bin/containerd
190Ssl 0 3392139 1 222768 1784 0.0 15-02:34:39 rsyslogd /usr/sbin/rsyslogd -n -iNONE
191Ss 13 3392140 1 3344 152 0.0 15-02:34:39 polipo /usr/bin/polipo -c /etc/polipo/config pidFile=/var/run/polipo/polipo.pid daemonise=true
192Ssl 119 3392156 1 76472 1688 0.0 15-02:34:39 ntpd /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 119:126
193Ss 120 3392168 1 4656 276 0.0 15-02:34:39 rpc.statd /sbin/rpc.statd --no-notify
194Ss 0 3392171 1 5072 432 0.0 15-02:34:39 rpc.mountd /usr/sbin/rpc.mountd --manage-gids
195Ss 0 3392176 1 5008 288 0.0 15-02:34:39 rpc.idmapd /usr/sbin/rpc.idmapd
196Ss 105 3392184 1 15544 6816 3.5 15-02:34:39 avahi-daemon avahi-daemon: running [tsui.local]
197Ss 0 3392186 1 25288 3860 0.0 15-02:34:39 systemd-udevd /lib/systemd/systemd-udevd
198S 105 3392190 3392184 8788 52 0.0 15-02:34:39 avahi-daemon avahi-daemon: chroot helper
199Ssl 0 3392197 1 396120 4188 0.0 15-02:34:39 udisksd /usr/libexec/udisks2/udisksd
200Ssl 0 3392214 1 237504 6632 0.0 15-02:34:39 polkitd /usr/libexec/polkitd --no-debug
201Ss 0 3392284 1 9684 560 0.0 15-02:34:38 xinetd /usr/sbin/xinetd -pidfile /run/xinetd.pid -stayalive -inetd_compat -inetd_ipv6
202Ssl 0 3392285 1 314840 1352 0.0 15-02:34:38 ModemManager /usr/sbin/ModemManager
203Ss 0 3392317 1 2352 140 0.0 15-02:34:38 acpid /usr/sbin/acpid
204S 0 3392400 2 0 0 0.0 15-02:34:38 nfsd [nfsd]
205S 0 3392401 2 0 0 0.0 15-02:34:38 nfsd [nfsd]
206S 0 3392402 2 0 0 0.0 15-02:34:38 nfsd [nfsd]
207S 0 3392403 2 0 0 0.0 15-02:34:38 nfsd [nfsd]
208S 0 3392404 2 0 0 0.0 15-02:34:38 nfsd [nfsd]
209S 0 3392405 2 0 0 0.0 15-02:34:38 nfsd [nfsd]
210S 0 3392407 2 0 0 0.0 15-02:34:38 nfsd [nfsd]
211S 0 3392410 2 0 0 0.0 15-02:34:38 nfsd [nfsd]
212Ss 0 3392551 1 40092 1304 0.0 15-02:34:37 master /usr/lib/postfix/sbin/master -w
213S 117 3392553 3392551 40156 568 0.0 15-02:34:37 qmgr qmgr -l -t unix -u
214Ss 0 3392650 1 63652 4 0.0 15-02:34:36 squid /usr/sbin/squid --foreground -sYC
215Ssl 116 3392652 1 1675196 93848 0.0 15-02:34:36 mariadbd /usr/sbin/mariadbd
216S 13 3392655 3392650 81776 21232 0.0 15-02:34:36 squid (squid-1) --kid squid-1 --foreground -sYC
217S 13 3392657 3392655 5572 68 0.0 15-02:34:36 log_file_daemon (logfile-daemon) /var/log/squid/access.log
218S<s 0 3393034 1 216648 7560 0.0 15-02:34:34 apache2 /usr/sbin/apache2 -k start
219Ss 33 3393037 1 3432 180 0.0 15-02:34:34 htcacheclean /usr/bin/htcacheclean -d 120 -p /var/cache/apache2/mod_cache_disk -l 300M -n
diff --git a/plugins/tests/var/ps_axwo.debian b/plugins/tests/var/ps_axwo.debian
deleted file mode 100644
index 37a2d35..0000000
--- a/plugins/tests/var/ps_axwo.debian
+++ /dev/null
@@ -1,84 +0,0 @@
1STAT UID PID PPID VSZ RSS %CPU COMMAND COMMAND
2S 0 1 0 1504 428 0.0 init init [2]
3SN 0 2 1 0 0 0.0 ksoftirqd/0 [ksoftirqd/0]
4S< 0 3 1 0 0 0.0 events/0 [events/0]
5S< 0 4 3 0 0 0.0 khelper [khelper]
6S< 0 5 3 0 0 0.0 kacpid [kacpid]
7S< 0 38 3 0 0 0.0 kblockd/0 [kblockd/0]
8S 0 48 3 0 0 0.0 pdflush [pdflush]
9S< 0 51 3 0 0 0.0 aio/0 [aio/0]
10S 0 50 1 0 0 0.0 kswapd0 [kswapd0]
11S 0 193 1 0 0 0.0 kseriod [kseriod]
12S 0 214 1 0 0 0.0 scsi_eh_0 [scsi_eh_0]
13S 0 221 1 0 0 0.0 khubd [khubd]
14S 0 299 1 0 0 0.3 kjournald [kjournald]
15S 0 1148 1 0 0 0.0 pciehpd_event [pciehpd_event]
16S 0 1168 1 0 0 0.0 shpchpd_event [shpchpd_event]
17Ss 1 1795 1 1612 276 0.0 portmap /sbin/portmap
18Ss 0 2200 1 1652 568 0.0 vmware-guestd /usr/sbin/vmware-guestd --background /var/run/vmware-guestd.pid
19Ss 0 2209 1 2240 532 0.0 inetd /usr/sbin/inetd
20Ss 0 2319 1 3468 792 0.0 sshd /usr/sbin/sshd
21Ss 0 2323 1 2468 676 0.0 rpc.statd /sbin/rpc.statd
22Ss 1 2332 1 1684 488 0.0 atd /usr/sbin/atd
23Ss 0 2335 1 1764 636 0.0 cron /usr/sbin/cron
24Ss+ 0 2350 1 1500 348 0.0 getty /sbin/getty 38400 tty1
25Ss+ 0 2351 1 1500 348 0.0 getty /sbin/getty 38400 tty2
26Ss+ 0 2352 1 1500 348 0.0 getty /sbin/getty 38400 tty3
27Ss+ 0 2353 1 1500 348 0.0 getty /sbin/getty 38400 tty4
28Ss+ 0 2354 1 1500 348 0.0 getty /sbin/getty 38400 tty5
29Ss+ 0 2355 1 1500 348 0.0 getty /sbin/getty 38400 tty6
30S 0 6907 1 2308 892 0.0 mysqld_safe /bin/sh /usr/bin/mysqld_safe
31S 103 6944 6907 123220 27724 0.0 mysqld /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock
32S 0 6945 6907 1488 420 0.0 logger logger -p daemon.err -t mysqld_safe -i -t mysqld
33S 1001 17778 1 6436 1588 0.0 snmpd /usr/sbin/snmpd -u nagios -Lsd -Lf /dev/null -p/var/run/snmpd.pid
34Ss 0 17789 1 9496 5556 0.0 snmptrapd /usr/sbin/snmptrapd -t -m ALL -M /usr/share/snmp/mibs:/usr/local/monitoring/snmp/load -p /var/run/snmptrapd.pid
35Ss 0 847 2319 14452 1752 0.0 sshd sshd: tonvoon [priv]
36S 1000 857 847 14616 1832 0.0 sshd sshd: tonvoon@pts/3
37Ss 1000 860 857 2984 1620 0.0 bash -bash
38S 0 868 860 2588 1428 0.0 bash -su
39S+ 1001 877 868 2652 1568 0.0 bash -su
40S 0 6086 3 0 0 0.0 pdflush [pdflush]
41Ss 0 17832 2319 14452 1752 0.0 sshd sshd: tonvoon [priv]
42S 1000 18155 17832 14620 1840 0.0 sshd sshd: tonvoon@pts/0
43Ss 1000 18156 18155 2984 1620 0.0 bash -bash
44S 0 18518 18156 2588 1428 0.0 bash -su
45S 1001 18955 18518 2672 1600 0.0 bash -su
46Ss 0 21683 2319 14452 1756 0.0 sshd sshd: tonvoon [priv]
47S 1000 21742 21683 14620 1896 0.0 sshd sshd: tonvoon@pts/1
48Ss 1000 21743 21742 2984 1620 0.0 bash -bash
49S 0 21748 21743 2592 1432 0.0 bash -su
50S 1001 21757 21748 2620 1540 0.0 bash -su
51Ss 0 2334 2319 14452 1756 0.0 sshd sshd: tonvoon [priv]
52S 1000 2343 2334 14620 1840 0.0 sshd sshd: tonvoon@pts/2
53Ss 1000 2344 2343 2984 1620 0.0 bash -bash
54S 0 2349 2344 2592 1432 0.0 bash -su
55S+ 1001 2364 2349 2620 1520 0.0 bash -su
56T 1001 2454 2364 2096 1032 0.0 vi vi configure.in.rej
57S+ 1001 8500 21757 69604 52576 0.0 opsview_web_ser /usr/bin/perl -w ./script/opsview_web_server.pl -f -d
58Ss 0 7609 2319 14452 1756 0.0 sshd sshd: tonvoon [priv]
59S 1000 7617 7609 14460 1828 0.0 sshd sshd: tonvoon@pts/4
60Ss 1000 7618 7617 2984 1620 0.0 bash -bash
61S 0 7623 7618 2592 1432 0.0 bash -su
62S+ 1001 7632 7623 2620 1528 0.0 bash -su
63Ss 1001 12678 1 20784 17728 0.0 opsviewd opsviewd
64Ss 0 832 1 14512 6360 0.0 apache2 /usr/sbin/apache2 -k start -DSSL
65S 33 842 832 14648 6596 0.0 apache2 /usr/sbin/apache2 -k start -DSSL
66S 33 843 832 14512 6504 0.0 apache2 /usr/sbin/apache2 -k start -DSSL
67S 33 844 832 14512 6476 0.0 apache2 /usr/sbin/apache2 -k start -DSSL
68S 33 845 832 14512 6476 0.0 apache2 /usr/sbin/apache2 -k start -DSSL
69S 33 846 832 14512 6476 0.0 apache2 /usr/sbin/apache2 -k start -DSSL
70Ss 7 4081 1 2464 884 0.0 lpd /usr/sbin/lpd -s
71S 33 26484 832 14512 6476 0.0 apache2 /usr/sbin/apache2 -k start -DSSL
72Ss 1001 22324 1 20252 1612 0.1 nagios ../../bin/nagios -d /usr/local/nagios/etc/nagios.cfg
73Ss 0 23336 2319 14452 1756 0.0 sshd sshd: tonvoon [priv]
74S 1000 23339 23336 14620 1840 0.0 sshd sshd: tonvoon@pts/5
75Ss 1000 23340 23339 2996 1636 0.0 bash -bash
76S 0 23367 23340 3020 1628 0.0 bash bash
77S 1001 23370 23367 3064 1748 0.0 bash bash
78Ss 1001 23783 1 3220 764 0.0 ndo2db /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg
79Ss 1001 23784 1 6428 4948 0.0 import_ndologsd import_ndologsd
80S+ 1001 9803 18955 4132 1936 0.0 ssh ssh altinity@cube02.lei.altinity
81S 1001 22505 22324 20256 1616 0.0 nagios ../../bin/nagios -d /usr/local/nagios/etc/nagios.cfg
82S 1001 22506 22505 1676 608 0.0 check_ping /usr/local/libexec/check_ping -H 192.168.10.23 -w 3000.0,80% -c 5000.0,100% -p 1
83S 1001 22507 22506 1660 492 0.0 ping /bin/ping -n -U -w 10 -c 1 192.168.10.23
84R+ 1001 22508 23370 2308 680 0.0 ps ps axwo stat uid pid ppid vsz rss pcpu comm args
diff --git a/plugins/utils.c b/plugins/utils.c
index 348ec02..ebdae2e 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -27,6 +27,8 @@
27#include "utils_base.h" 27#include "utils_base.h"
28#include <stdarg.h> 28#include <stdarg.h>
29#include <limits.h> 29#include <limits.h>
30#include <string.h>
31#include <errno.h>
30 32
31#include <arpa/inet.h> 33#include <arpa/inet.h>
32 34
@@ -239,6 +241,46 @@ is_intnonneg (char *number)
239 return FALSE; 241 return FALSE;
240} 242}
241 243
244/*
245 * Checks whether the number in the string _number_ can be put inside a int64_t
246 * On success the number will be written to the _target_ address, if _target_ is not set
247 * to NULL.
248 */
249int is_int64(char *number, int64_t *target) {
250 errno = 0;
251 uint64_t tmp = strtoll(number, NULL, 10);
252 if (errno != 0) {
253 return 0;
254 }
255 if (tmp < INT64_MIN || tmp > INT64_MAX) {
256 return 0;
257 }
258 if (target != NULL) {
259 *target = tmp;
260 }
261 return 1;
262}
263
264/*
265 * Checks whether the number in the string _number_ can be put inside a uint64_t
266 * On success the number will be written to the _target_ address, if _target_ is not set
267 * to NULL.
268 */
269int is_uint64(char *number, uint64_t *target) {
270 errno = 0;
271 uint64_t tmp = strtoll(number, NULL, 10);
272 if (errno != 0) {
273 return 0;
274 }
275 if (tmp < 0 || tmp > UINT64_MAX) {
276 return 0;
277 }
278 if (target != NULL) {
279 *target = tmp;
280 }
281 return 1;
282}
283
242int 284int
243is_intpercent (char *number) 285is_intpercent (char *number)
244{ 286{
@@ -556,6 +598,88 @@ char *perfdata (const char *label,
556} 598}
557 599
558 600
601char *perfdata_uint64 (const char *label,
602 uint64_t val,
603 const char *uom,
604 int warnp, /* Warning present */
605 uint64_t warn,
606 int critp, /* Critical present */
607 uint64_t crit,
608 int minp, /* Minimum present */
609 uint64_t minv,
610 int maxp, /* Maximum present */
611 uint64_t maxv)
612{
613 char *data = NULL;
614
615 if (strpbrk (label, "'= "))
616 xasprintf (&data, "'%s'=%ld%s;", label, val, uom);
617 else
618 xasprintf (&data, "%s=%ld%s;", label, val, uom);
619
620 if (warnp)
621 xasprintf (&data, "%s%lu;", data, warn);
622 else
623 xasprintf (&data, "%s;", data);
624
625 if (critp)
626 xasprintf (&data, "%s%lu;", data, crit);
627 else
628 xasprintf (&data, "%s;", data);
629
630 if (minp)
631 xasprintf (&data, "%s%lu;", data, minv);
632 else
633 xasprintf (&data, "%s;", data);
634
635 if (maxp)
636 xasprintf (&data, "%s%lu", data, maxv);
637
638 return data;
639}
640
641
642char *perfdata_int64 (const char *label,
643 int64_t val,
644 const char *uom,
645 int warnp, /* Warning present */
646 int64_t warn,
647 int critp, /* Critical present */
648 int64_t crit,
649 int minp, /* Minimum present */
650 int64_t minv,
651 int maxp, /* Maximum present */
652 int64_t maxv)
653{
654 char *data = NULL;
655
656 if (strpbrk (label, "'= "))
657 xasprintf (&data, "'%s'=%ld%s;", label, val, uom);
658 else
659 xasprintf (&data, "%s=%ld%s;", label, val, uom);
660
661 if (warnp)
662 xasprintf (&data, "%s%ld;", data, warn);
663 else
664 xasprintf (&data, "%s;", data);
665
666 if (critp)
667 xasprintf (&data, "%s%ld;", data, crit);
668 else
669 xasprintf (&data, "%s;", data);
670
671 if (minp)
672 xasprintf (&data, "%s%ld;", data, minv);
673 else
674 xasprintf (&data, "%s;", data);
675
676 if (maxp)
677 xasprintf (&data, "%s%ld", data, maxv);
678
679 return data;
680}
681
682
559char *fperfdata (const char *label, 683char *fperfdata (const char *label,
560 double val, 684 double val,
561 const char *uom, 685 const char *uom,
diff --git a/plugins/utils.h b/plugins/utils.h
index 33a2054..5b54da3 100644
--- a/plugins/utils.h
+++ b/plugins/utils.h
@@ -16,6 +16,7 @@ suite of plugins. */
16/* now some functions etc are being defined in ../lib/utils_base.c */ 16/* now some functions etc are being defined in ../lib/utils_base.c */
17#include "utils_base.h" 17#include "utils_base.h"
18 18
19
19#ifdef NP_EXTRA_OPTS 20#ifdef NP_EXTRA_OPTS
20/* Include extra-opts functions if compiled in */ 21/* Include extra-opts functions if compiled in */
21#include "extra_opts.h" 22#include "extra_opts.h"
@@ -38,6 +39,8 @@ int is_intpos (char *);
38int is_intneg (char *); 39int is_intneg (char *);
39int is_intnonneg (char *); 40int is_intnonneg (char *);
40int is_intpercent (char *); 41int is_intpercent (char *);
42int is_uint64(char *number, uint64_t *target);
43int is_int64(char *number, int64_t *target);
41 44
42int is_numeric (char *); 45int is_numeric (char *);
43int is_positive (char *); 46int is_positive (char *);
@@ -88,6 +91,12 @@ void usage_va(const char *fmt, ...) __attribute__((noreturn));
88char *perfdata (const char *, long int, const char *, int, long int, 91char *perfdata (const char *, long int, const char *, int, long int,
89 int, long int, int, long int, int, long int); 92 int, long int, int, long int, int, long int);
90 93
94char *perfdata_uint64 (const char *, uint64_t , const char *, int, uint64_t,
95 int, uint64_t, int, uint64_t, int, uint64_t);
96
97char *perfdata_int64 (const char *, int64_t, const char *, int, int64_t,
98 int, int64_t, int, int64_t, int, int64_t);
99
91char *fperfdata (const char *, double, const char *, int, double, 100char *fperfdata (const char *, double, const char *, int, double,
92 int, double, int, double, int, double); 101 int, double, int, double, int, double);
93 102