aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-x.github/prepare_debian.sh2
-rw-r--r--.github/workflows/test.yml1
-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/check_icmp.c2
-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.c97
-rw-r--r--plugins/check_disk.c189
-rw-r--r--plugins/check_dns.c61
-rw-r--r--plugins/check_http.c4
-rw-r--r--plugins/check_load.c2
-rw-r--r--plugins/check_procs.c50
-rw-r--r--plugins/check_smtp.c18
-rw-r--r--plugins/check_snmp.c9
-rw-r--r--plugins/check_swap.c237
-rw-r--r--plugins/t/check_disk.t7
-rw-r--r--plugins/t/check_dns.t10
-rw-r--r--plugins/t/check_load.t4
-rw-r--r--plugins/t/check_swap.t6
-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
30 files changed, 844 insertions, 356 deletions
diff --git a/.github/prepare_debian.sh b/.github/prepare_debian.sh
index c68b9f5d..4021c104 100755
--- a/.github/prepare_debian.sh
+++ b/.github/prepare_debian.sh
@@ -13,7 +13,7 @@ if [ $(lsb_release -is) = "Debian" ]; then
fi
apt-get -y install perl autotools-dev libdbi-dev libldap2-dev libpq-dev libradcli-dev libnet-snmp-perl procps
apt-get -y install libdbi0-dev libdbd-sqlite3 libssl-dev dnsutils snmp-mibs-downloader libsnmp-perl snmpd
-apt-get -y install fping snmp netcat smbclient vsftpd apache2 ssl-cert postfix libhttp-daemon-ssl-perl
+apt-get -y install fping snmp netcat-openbsd smbclient vsftpd apache2 ssl-cert postfix libhttp-daemon-ssl-perl
apt-get -y install libdbd-sybase-perl libnet-dns-perl
apt-get -y install slapd ldap-utils
apt-get -y install gcc make autoconf automake gettext
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 512d28e6..0f93930a 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -35,6 +35,7 @@ jobs:
-e NPTEST_CACHE="/src/.github/NPTest.cache" \
-w /src -v ${PWD}:/src \
--tmpfs /media/ramdisk1 \
+ -v /var/run/utmp:/var/run/utmp \
--mount source=tmp-vol,destination=/src,target=/media/ramdisk2 \
${{ matrix.distro }} \
/bin/sh -c '${{ matrix.prepare }} && \
diff --git a/NEWS b/NEWS
index 4061c033..3790e8a0 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@ This file documents the major additions and syntax changes between releases.
check_dns: Accept CIDR
check_dns: allow unsorted addresses
check_dns: allow forcing complete match of all addresses
+ check_dns: option to expect NXDOMAIN
check_apt: add --only-critical switch
check_apt: add -l/--list option to print packages
check_file_age: add range checking
diff --git a/configure.ac b/configure.ac
index 7c17dcd1..dfc37b5e 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
dnl ac_cv_ps_cols=8
dnl AC_MSG_RESULT([$ac_cv_ps_command])
+dnl This one is the exact same test as the next one but includes etime
+elif ps axwo 'stat comm vsz rss user uid pid ppid etime args' 2>/dev/null | \
+ egrep -i ["^ *STAT +[UCOMAND]+ +VSZ +RSS +USER +UID +PID +PPID +ELAPSED +COMMAND"] > /dev/null
+then
+ ac_cv_ps_varlist="[procstat,&procuid,&procpid,&procppid,&procvsz,&procrss,&procpcpu,procetime,procprog,&pos]"
+ ac_cv_ps_command="$PATH_TO_PS axwo 'stat uid pid ppid vsz rss pcpu etime comm args'"
+ ac_cv_ps_format="%s %d %d %d %d %d %f %s %s %n"
+ ac_cv_ps_cols=10
+ AC_MSG_RESULT([$ac_cv_ps_command])
+
dnl Some gnu/linux systems (debian for one) don't like -axwo and need axwo.
dnl so test for this first...
elif 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 fd7058da..08fa215c 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -128,6 +128,7 @@ range
temp_range->end = 0;
temp_range->end_infinity = TRUE;
temp_range->alert_on = OUTSIDE;
+ temp_range->text = strdup(str);
if (str[0] == '@') {
temp_range->alert_on = INSIDE;
@@ -706,4 +707,3 @@ void np_state_write_string(time_t data_time, char *data_string) {
np_free(temp_file);
}
-
diff --git a/lib/utils_base.h b/lib/utils_base.h
index d7e7dffa..9482f23b 100644
--- a/lib/utils_base.h
+++ b/lib/utils_base.h
@@ -23,6 +23,7 @@ typedef struct range_struct {
double end;
int end_infinity;
int alert_on; /* OUTSIDE (default) or INSIDE */
+ char* text; /* original unparsed text input */
} range;
typedef struct thresholds_struct {
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index 999270cd..bf52e4ce 100644
--- a/lib/utils_disk.h
+++ b/lib/utils_disk.h
@@ -27,7 +27,7 @@ struct parameter_list
uintmax_t total, available, available_to_root, used,
inodes_free, inodes_free_to_root, inodes_used, inodes_total;
double dfree_pct, dused_pct;
- double dused_units, dfree_units, dtotal_units;
+ uint64_t dused_units, dfree_units, dtotal_units;
double dused_inodes_percent, dfree_inodes_percent;
};
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 31eb4c65..519b93c6 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)
/* if we're in hostcheck mode, exit with limited printouts */
if(mode == MODE_HOSTCHECK) {
printf("OK - %s responds to ICMP. Packet %u, rta %0.3fms|"
- "pkt=%u;;0;%u rta=%0.3f;%0.3f;%0.3f;;\n",
+ "pkt=%u;;;0;%u rta=%0.3f;%0.3f;%0.3f;;\n",
host->name, icmp_recv, (float)tdiff / 1000,
icmp_recv, packets, (float)tdiff / 1000,
(float)warn.rta / 1000, (float)crit.rta / 1000);
diff --git a/plugins-scripts/check_ifoperstatus.pl b/plugins-scripts/check_ifoperstatus.pl
index 9ede1633..c190ce95 100755
--- a/plugins-scripts/check_ifoperstatus.pl
+++ b/plugins-scripts/check_ifoperstatus.pl
@@ -124,10 +124,10 @@ if (!defined($session)) {
## map ifdescr to ifindex - should look at being able to cache this value
if (defined $ifdescr || defined $iftype) {
- # escape "/" in ifdescr - very common in the Cisco world
if (defined $iftype) {
$status=fetch_ifindex($snmpIfType, $iftype);
} else {
+ # escape "/" in ifdescr - very common in the Cisco world
$ifdescr =~ s/\//\\\//g;
$status=fetch_ifindex($snmpIfDescr, $ifdescr); # if using on device with large number of interfaces
# recommend use of SNMP v2 (get-bulk)
diff --git a/plugins-scripts/check_ircd.pl b/plugins-scripts/check_ircd.pl
index 22d21c2e..d869ae7b 100755
--- a/plugins-scripts/check_ircd.pl
+++ b/plugins-scripts/check_ircd.pl
@@ -69,7 +69,9 @@ $ENV{'ENV'}='';
# -----------------------------------------------------------------[ Global ]--
$PROGNAME = "check_ircd";
-my $NICK="ircd$$";
+# nickname shouldn't be longer than 9 chars, this might happen with large PIDs
+# To prevent this, we cut of the part over 10000
+my $NICK="ircd" . $$ % 10000;
my $USER_INFO="monitor localhost localhost : ";
# -------------------------------------------------------------[ connection ]--
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 13d8bc3b..485bf3be 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -230,7 +230,6 @@ process_arguments (int argc, char **argv)
timeout_interval = atoi (optarg);
break;
case 'H': /* host */
- host_or_die(optarg);
hostname = optarg;
break;
case 'p': /* port number */
@@ -329,7 +328,6 @@ process_arguments (int argc, char **argv)
if (c <= argc) {
die (STATE_UNKNOWN, _("%s: You must provide a host name\n"), progname);
}
- host_or_die(argv[c]);
hostname = argv[c++];
}
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index d29db0a6..14cc8463 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -55,6 +55,12 @@ const char *email = "devel@monitoring-plugins.org";
#include <arpa/inet.h>
+#if defined(HAVE_SSL) && defined(USE_OPENSSL)
+#include <openssl/opensslv.h>
+#endif
+
+#include <netdb.h>
+
#define MAKE_LIBCURL_VERSION(major, minor, patch) ((major)*0x10000 + (minor)*0x100 + (patch))
#define DEFAULT_BUFFER_SIZE 2048
@@ -206,6 +212,7 @@ int maximum_age = -1;
int address_family = AF_UNSPEC;
curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN;
int curl_http_version = CURL_HTTP_VERSION_NONE;
+int automatic_decompression = FALSE;
int process_arguments (int, char**);
void handle_curl_option_return_code (CURLcode res, const char* option);
@@ -285,6 +292,20 @@ int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx)
* TODO: is the last certificate always the server certificate?
*/
cert = X509_STORE_CTX_get_current_cert(x509_ctx);
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+ X509_up_ref(cert);
+#endif
+ if (verbose>=2) {
+ puts("* SSL verify callback with certificate:");
+ X509_NAME *subject, *issuer;
+ printf("* issuer:\n");
+ issuer = X509_get_issuer_name( cert );
+ X509_NAME_print_ex_fp(stdout, issuer, 5, XN_FLAG_MULTILINE);
+ printf("* curl verify_callback:\n* subject:\n");
+ subject = X509_get_subject_name( cert );
+ X509_NAME_print_ex_fp(stdout, subject, 5, XN_FLAG_MULTILINE);
+ puts("");
+ }
return 1;
}
@@ -351,12 +372,55 @@ handle_curl_option_return_code (CURLcode res, const char* option)
}
int
+lookup_host (const char *host, char *buf, size_t buflen)
+{
+ struct addrinfo hints, *res, *result;
+ int errcode;
+ void *ptr;
+
+ memset (&hints, 0, sizeof (hints));
+ hints.ai_family = address_family;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags |= AI_CANONNAME;
+
+ errcode = getaddrinfo (host, NULL, &hints, &result);
+ if (errcode != 0)
+ return errcode;
+
+ res = result;
+
+ while (res) {
+ inet_ntop (res->ai_family, res->ai_addr->sa_data, buf, buflen);
+ switch (res->ai_family) {
+ case AF_INET:
+ ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr;
+ break;
+ case AF_INET6:
+ ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
+ break;
+ }
+ inet_ntop (res->ai_family, ptr, buf, buflen);
+ if (verbose >= 1)
+ printf ("* getaddrinfo IPv%d address: %s\n",
+ res->ai_family == PF_INET6 ? 6 : 4, buf);
+ res = res->ai_next;
+ }
+
+ freeaddrinfo(result);
+
+ return 0;
+}
+
+int
check_http (void)
{
int result = STATE_OK;
int page_len = 0;
int i;
char *force_host_header = NULL;
+ struct curl_slist *host = NULL;
+ char addrstr[100];
+ char dnscache[DEFAULT_BUFFER_SIZE];
/* initialize curl */
if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK)
@@ -371,6 +435,13 @@ check_http (void)
/* print everything on stdout like check_http would do */
handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_STDERR, stdout), "CURLOPT_STDERR");
+ if (automatic_decompression)
+#if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 21, 6)
+ handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, ""), "CURLOPT_ACCEPT_ENCODING");
+#else
+ handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_ENCODING, ""), "CURLOPT_ENCODING");
+#endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 21, 6) */
+
/* initialize buffer for body of the answer */
if (curlhelp_initwritebuffer(&body_buf) < 0)
die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for body\n");
@@ -392,9 +463,12 @@ check_http (void)
// 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
if(use_ssl && host_name != NULL) {
- struct curl_slist *host = NULL;
- char dnscache[DEFAULT_BUFFER_SIZE];
- snprintf (dnscache, DEFAULT_BUFFER_SIZE, "%s:%d:%s", host_name, server_port, server_address);
+ if ( (res=lookup_host (server_address, addrstr, 100)) != 0) {
+ snprintf (msg, DEFAULT_BUFFER_SIZE, _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"),
+ server_address, res, gai_strerror (res));
+ die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg);
+ }
+ snprintf (dnscache, DEFAULT_BUFFER_SIZE, "%s:%d:%s", host_name, server_port, addrstr);
host = curl_slist_append(NULL, dnscache);
curl_easy_setopt(curl, CURLOPT_RESOLVE, host);
if (verbose>=1)
@@ -959,8 +1033,8 @@ char*
uri_string (const UriTextRangeA range, char* buf, size_t buflen)
{
if (!range.first) return "(null)";
- strncpy (buf, range.first, max (buflen, range.afterLast - range.first));
- buf[max (buflen, range.afterLast - range.first)] = '\0';
+ strncpy (buf, range.first, max (buflen-1, range.afterLast - range.first));
+ buf[max (buflen-1, range.afterLast - range.first)] = '\0';
buf[range.afterLast - range.first] = '\0';
return buf;
}
@@ -1080,8 +1154,8 @@ redir (curlhelp_write_curlbuf* header_buf)
!strncmp(server_address, new_host, MAX_IPV4_HOSTLENGTH) &&
(host_name && !strncmp(host_name, new_host, MAX_IPV4_HOSTLENGTH)) &&
!strcmp(server_url, new_url))
- die (STATE_WARNING,
- _("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"),
+ die (STATE_CRITICAL,
+ _("HTTP CRITICAL - redirection creates an infinite loop - %s://%s:%d%s%s\n"),
use_ssl ? "https" : "http", new_host, new_port, new_url, (display_html ? "</A>" : ""));
/* set new values for redirected request */
@@ -1137,7 +1211,8 @@ process_arguments (int argc, char **argv)
INVERT_REGEX = CHAR_MAX + 1,
SNI_OPTION,
CA_CERT_OPTION,
- HTTP_VERSION_OPTION
+ HTTP_VERSION_OPTION,
+ AUTOMATIC_DECOMPRESSION
};
int option = 0;
@@ -1180,6 +1255,7 @@ process_arguments (int argc, char **argv)
{"extended-perfdata", no_argument, 0, 'E'},
{"show-body", no_argument, 0, 'B'},
{"http-version", required_argument, 0, HTTP_VERSION_OPTION},
+ {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION},
{0, 0, 0, 0}
};
@@ -1571,6 +1647,9 @@ process_arguments (int argc, char **argv)
exit (STATE_WARNING);
}
break;
+ case AUTOMATIC_DECOMPRESSION:
+ automatic_decompression = TRUE;
+ break;
case '?':
/* print short usage statement if args not parsable */
usage5 ();
@@ -1781,6 +1860,8 @@ print_help (void)
printf (" %s\n", "--http-version=VERSION");
printf (" %s\n", _("Connect via specific HTTP protocol."));
printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)"));
+ printf (" %s\n", "--enable-automatic-decompression");
+ printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING)."));
printf ("\n");
printf (UT_WARN_CRIT);
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 844e625f..c526d056 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -1,29 +1,29 @@
/*****************************************************************************
-*
+*
* Monitoring check_disk plugin
-*
+*
* License: GPL
* Copyright (c) 1999-2008 Monitoring Plugins Development Team
-*
+*
* Description:
-*
+*
* This file contains the check_disk plugin
-*
-*
+*
+*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*
-*
+*
+*
*****************************************************************************/
const char *progname = "check_disk";
@@ -46,7 +46,7 @@ const char *email = "devel@monitoring-plugins.org";
#include <stdarg.h>
#include "fsusage.h"
#include "mountlist.h"
-#include "intprops.h" /* necessary for TYPE_MAXIMUM */
+#include "intprops.h" /* necessary for TYPE_MAXIMUM */
#if HAVE_LIMITS_H
# include <limits.h>
#endif
@@ -172,8 +172,6 @@ main (int argc, char **argv)
char *preamble;
char *flag_header;
double inode_space_pct;
- double warning_high_tide;
- double critical_high_tide;
int temp_result;
struct mount_entry *me;
@@ -245,17 +243,17 @@ main (int argc, char **argv)
#ifdef __CYGWIN__
if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11)
- continue;
+ continue;
snprintf(mountdir, sizeof(mountdir), "%s:\\", me->me_mountdir + 10);
if (GetDriveType(mountdir) != DRIVE_FIXED)
- me->me_remote = 1;
+ me->me_remote = 1;
#endif
/* Filters */
/* Remove filesystems already seen */
if (np_seen_name(seen, me->me_mountdir)) {
continue;
- }
+ }
np_add_name(&seen, me->me_mountdir);
if (path->group == NULL) {
@@ -288,8 +286,17 @@ main (int argc, char **argv)
get_stats (path, &fsp);
if (verbose >= 3) {
- 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",
- 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);
+ 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",
+ 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);
}
/* Threshold comparisons */
@@ -326,77 +333,79 @@ main (int argc, char **argv)
*/
/* *_high_tide must be reinitialized at each run */
- warning_high_tide = UINT_MAX;
- critical_high_tide = UINT_MAX;
+ uint64_t warning_high_tide = UINT64_MAX;
if (path->freespace_units->warning != NULL) {
- warning_high_tide = path->dtotal_units - path->freespace_units->warning->end;
+ warning_high_tide = (path->dtotal_units - path->freespace_units->warning->end) * mult;
}
if (path->freespace_percent->warning != NULL) {
- warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freespace_percent->warning->end/100)*path->dtotal_units ));
+ warning_high_tide = min( warning_high_tide, (uint64_t)((1.0 - path->freespace_percent->warning->end/100) * (path->dtotal_units * mult)) );
}
+
+ uint64_t critical_high_tide = UINT64_MAX;
+
if (path->freespace_units->critical != NULL) {
- critical_high_tide = path->dtotal_units - path->freespace_units->critical->end;
+ critical_high_tide = (path->dtotal_units - path->freespace_units->critical->end) * mult;
}
if (path->freespace_percent->critical != NULL) {
- critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freespace_percent->critical->end/100)*path->dtotal_units ));
+ critical_high_tide = min( critical_high_tide, (uint64_t)((1.0 - path->freespace_percent->critical->end/100) * (path->dtotal_units * mult)) );
}
- /* Nb: *_high_tide are unset when == UINT_MAX */
+ /* Nb: *_high_tide are unset when == UINT64_MAX */
xasprintf (&perf, "%s %s", perf,
- perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
- path->dused_units, units,
- (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide,
- (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide,
- TRUE, 0,
- TRUE, path->dtotal_units));
+ perfdata_uint64 (
+ (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
+ path->dused_units * mult, "B",
+ (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide,
+ (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide,
+ TRUE, 0,
+ TRUE, path->dtotal_units * mult));
if (display_inodes_perfdata) {
/* *_high_tide must be reinitialized at each run */
- warning_high_tide = UINT_MAX;
- critical_high_tide = UINT_MAX;
+ warning_high_tide = UINT64_MAX;
+ critical_high_tide = UINT64_MAX;
if (path->freeinodes_percent->warning != NULL) {
- warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total ));
+ warning_high_tide = llabs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total ));
}
if (path->freeinodes_percent->critical != NULL) {
- critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total ));
+ critical_high_tide = llabs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total ));
}
xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir);
- /* Nb: *_high_tide are unset when == UINT_MAX */
+ /* Nb: *_high_tide are unset when == UINT64_MAX */
xasprintf (&perf, "%s %s", perf,
- perfdata (perf_ilabel,
- path->inodes_used, "",
- (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide,
- (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide,
- TRUE, 0,
- TRUE, path->inodes_total));
+ perfdata_uint64 (perf_ilabel,
+ path->inodes_used, "",
+ (warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide,
+ (critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide,
+ TRUE, 0,
+ TRUE, path->inodes_total));
}
if (disk_result==STATE_OK && erronly && !verbose)
continue;
- if(disk_result && verbose >= 1) {
- xasprintf(&flag_header, " %s [", state_text (disk_result));
- } else {
- xasprintf(&flag_header, "");
- }
- xasprintf (&output, "%s%s %s %.0f %s (%.0f%%",
- output, flag_header,
- (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
- path->dfree_units,
- units,
- path->dfree_pct);
- if (path->dused_inodes_percent < 0) {
- xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : ""));
- } else {
- xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : ""));
- }
+ if(disk_result && verbose >= 1) {
+ xasprintf(&flag_header, " %s [", state_text (disk_result));
+ } else {
+ xasprintf(&flag_header, "");
+ }
+ xasprintf (&output, "%s%s %s %llu%s (%.0f%%",
+ output, flag_header,
+ (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
+ path->dfree_units,
+ units,
+ path->dfree_pct);
+ if (path->dused_inodes_percent < 0) {
+ xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : ""));
+ } else {
+ xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : ""));
+ }
free(flag_header);
/* TODO: Need to do a similar debug line
- 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%%"),
+ 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%%"),
details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct,
me->me_devname, me->me_type, me->me_mountdir,
(unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp);
@@ -557,14 +566,14 @@ process_arguments (int argc, char **argv)
}
break;
- case 'W': /* warning inode threshold */
+ case 'W': /* warning inode threshold */
if (*optarg == '@') {
warn_freeinodes_percent = optarg;
} else {
xasprintf(&warn_freeinodes_percent, "@%s", optarg);
}
break;
- case 'K': /* critical inode threshold */
+ case 'K': /* critical inode threshold */
if (*optarg == '@') {
crit_freeinodes_percent = optarg;
} else {
@@ -574,21 +583,24 @@ process_arguments (int argc, char **argv)
case 'u':
if (units)
free(units);
- if (! strcmp (optarg, "bytes")) {
+ if (! strcasecmp (optarg, "bytes")) {
mult = (uintmax_t)1;
units = strdup ("B");
- } else if (! strcmp (optarg, "kB")) {
+ } else if ( (! strcmp (optarg, "kB")) || (!strcmp(optarg, "KiB")) ) {
mult = (uintmax_t)1024;
- units = strdup ("kB");
- } else if (! strcmp (optarg, "MB")) {
+ units = strdup ("kiB");
+ } else if ( (! strcmp (optarg, "MB")) || (!strcmp(optarg, "MiB")) ) {
mult = (uintmax_t)1024 * 1024;
- units = strdup ("MB");
- } else if (! strcmp (optarg, "GB")) {
+ units = strdup ("MiB");
+ } else if ( (! strcmp (optarg, "GB")) || (!strcmp(optarg, "GiB")) ) {
mult = (uintmax_t)1024 * 1024 * 1024;
- units = strdup ("GB");
- } else if (! strcmp (optarg, "TB")) {
+ units = strdup ("GiB");
+ } else if ( (! strcmp (optarg, "TB")) || (!strcmp(optarg, "TiB")) ) {
mult = (uintmax_t)1024 * 1024 * 1024 * 1024;
- units = strdup ("TB");
+ units = strdup ("TiB");
+ } else if ( (! strcmp (optarg, "PB")) || (!strcmp(optarg, "PiB")) ) {
+ mult = (uintmax_t)1024 * 1024 * 1024 * 1024 * 1024;
+ units = strdup ("PiB");
} else {
die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg);
}
@@ -599,13 +611,13 @@ process_arguments (int argc, char **argv)
mult = 1024;
if (units)
free(units);
- units = strdup ("kB");
+ units = strdup ("kiB");
break;
case 'm': /* display mountpoint */
mult = 1024 * 1024;
if (units)
free(units);
- units = strdup ("MB");
+ units = strdup ("MiB");
break;
case 'L':
stat_remote_fs = 1;
@@ -812,7 +824,7 @@ process_arguments (int argc, char **argv)
}
if (units == NULL) {
- units = strdup ("MB");
+ units = strdup ("MiB");
mult = (uintmax_t)1024 * 1024;
}
@@ -1026,20 +1038,20 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
if (p_list->group && ! (strcmp(p_list->group, p->group))) {
stat_path(p_list);
get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp);
- get_path_stats(p_list, &tmpfsp);
+ get_path_stats(p_list, &tmpfsp);
if (verbose >= 3)
printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n",
p_list->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p_list->best_match->me_mountdir, p_list->dused_units, p_list->dfree_units,
p_list->dtotal_units, mult);
- /* prevent counting the first FS of a group twice since its parameter_list entry
+ /* prevent counting the first FS of a group twice since its parameter_list entry
* is used to carry the information of all file systems of the entire group */
if (! first) {
p->total += p_list->total;
p->available += p_list->available;
p->available_to_root += p_list->available_to_root;
p->used += p_list->used;
-
+
p->dused_units += p_list->dused_units;
p->dfree_units += p_list->dfree_units;
p->dtotal_units += p_list->dtotal_units;
@@ -1050,28 +1062,31 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
}
first = 0;
}
- if (verbose >= 3)
+ if (verbose >= 3)
printf("Group %s now has: used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n",
- p->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p->best_match->me_mountdir, p->dused_units,
- p->dfree_units, p->dtotal_units, mult);
+ p->group,
+ tmpfsp.fsu_bavail,
+ tmpfsp.fsu_blocksize,
+ p->best_match->me_mountdir,
+ p->dused_units,
+ p->dfree_units,
+ p->dtotal_units,
+ mult);
}
/* modify devname and mountdir for output */
p->best_match->me_mountdir = p->best_match->me_devname = p->group;
}
/* finally calculate percentages for either plain FS or summed up group */
- p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */
+ p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */
p->dfree_pct = 100 - p->dused_pct;
p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total);
p->dfree_inodes_percent = 100 - p->dused_inodes_percent;
-
+
}
void
get_path_stats (struct parameter_list *p, struct fs_usage *fsp) {
- /* 2007-12-08 - Workaround for Gnulib reporting insanely high available
- * space on BSD (the actual value should be negative but fsp->fsu_bavail
- * is unsigned) */
- p->available = fsp->fsu_bavail > fsp->fsu_bfree ? 0 : fsp->fsu_bavail;
+ p->available = fsp->fsu_bavail;
p->available_to_root = fsp->fsu_bfree;
p->used = fsp->fsu_blocks - fsp->fsu_bfree;
if (freespace_ignore_reserved) {
@@ -1081,7 +1096,7 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) {
/* default behaviour : take all the blocks into account */
p->total = fsp->fsu_blocks;
}
-
+
p->dused_units = p->used*fsp->fsu_blocksize/mult;
p->dfree_units = p->available*fsp->fsu_blocksize/mult;
p->dtotal_units = p->total*fsp->fsu_blocksize/mult;
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 0f2e6541..9de6caf5 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -41,7 +41,7 @@ const char *email = "devel@monitoring-plugins.org";
int process_arguments (int, char **);
int validate_arguments (void);
-int error_scan (char *);
+int error_scan (char *, int *);
int ip_match_cidr(const char *, const char *);
unsigned long ip2long(const char *);
void print_help (void);
@@ -54,6 +54,7 @@ char ptr_server[ADDRESS_LENGTH] = "";
int verbose = FALSE;
char **expected_address = NULL;
int expected_address_cnt = 0;
+int expect_nxdomain = FALSE;
int expect_authority = FALSE;
int all_match = FALSE;
@@ -87,6 +88,7 @@ main (int argc, char **argv)
int parse_address = FALSE; /* This flag scans for Address: but only after Name: */
output chld_out, chld_err;
size_t i;
+ int is_nxdomain = FALSE;
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
@@ -186,7 +188,7 @@ main (int argc, char **argv)
}
- result = error_scan (chld_out.line[i]);
+ result = error_scan (chld_out.line[i], &is_nxdomain);
if (result != STATE_OK) {
msg = strchr (chld_out.line[i], ':');
if(msg) msg++;
@@ -199,8 +201,8 @@ main (int argc, char **argv)
if (verbose)
puts(chld_err.line[i]);
- if (error_scan (chld_err.line[i]) != STATE_OK) {
- result = max_state (result, error_scan (chld_err.line[i]));
+ if (error_scan (chld_err.line[i], &is_nxdomain) != STATE_OK) {
+ result = max_state (result, error_scan (chld_err.line[i], &is_nxdomain));
msg = strchr(input_buffer, ':');
if(msg)
msg++;
@@ -209,6 +211,10 @@ main (int argc, char **argv)
}
}
+ if (is_nxdomain && !expect_nxdomain) {
+ die (STATE_CRITICAL, _("Domain '%s' was not found by the server\n"), query_address);
+ }
+
if (addresses) {
int i,slen;
char *adrp;
@@ -260,6 +266,16 @@ main (int argc, char **argv)
}
}
+ if (expect_nxdomain) {
+ if (!is_nxdomain) {
+ result = STATE_CRITICAL;
+ xasprintf(&msg, _("Domain '%s' was found by the server: '%s'\n"), query_address, address);
+ } else {
+ if (address != NULL) free(address);
+ address = "NXDOMAIN";
+ }
+ }
+
/* check if authoritative */
if (result == STATE_OK && expect_authority && non_authoritative) {
result = STATE_CRITICAL;
@@ -339,9 +355,15 @@ ip2long(const char* src) {
}
int
-error_scan (char *input_buffer)
+error_scan (char *input_buffer, int *is_nxdomain)
{
+ const int nxdomain = strstr (input_buffer, "Non-existent") ||
+ strstr (input_buffer, "** server can't find") ||
+ strstr (input_buffer, "** Can't find") ||
+ strstr (input_buffer, "NXDOMAIN");
+ if (nxdomain) *is_nxdomain = TRUE;
+
/* the DNS lookup timed out */
if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) ||
strstr (input_buffer, _("Consider using the `dig' or `host' programs instead. Run nslookup with")) ||
@@ -360,7 +382,7 @@ error_scan (char *input_buffer)
/* Connection was refused */
else if (strstr (input_buffer, "Connection refused") ||
- strstr (input_buffer, "Couldn't find server") ||
+ strstr (input_buffer, "Couldn't find server") ||
strstr (input_buffer, "Refused") ||
(strstr (input_buffer, "** server can't find") &&
strstr (input_buffer, ": REFUSED")))
@@ -374,13 +396,6 @@ error_scan (char *input_buffer)
else if (strstr (input_buffer, "No information"))
die (STATE_CRITICAL, _("No information returned by DNS server at %s\n"), dns_server);
- /* Host or domain name does not exist */
- else if (strstr (input_buffer, "Non-existent") ||
- strstr (input_buffer, "** server can't find") ||
- strstr (input_buffer, "** Can't find") ||
- strstr (input_buffer,"NXDOMAIN"))
- die (STATE_CRITICAL, _("Domain %s was not found by the server\n"), query_address);
-
/* Network is unreachable */
else if (strstr (input_buffer, "Network is unreachable"))
die (STATE_CRITICAL, _("Network is unreachable\n"));
@@ -417,6 +432,7 @@ process_arguments (int argc, char **argv)
{"server", required_argument, 0, 's'},
{"reverse-server", required_argument, 0, 'r'},
{"expected-address", required_argument, 0, 'a'},
+ {"expect-nxdomain", no_argument, 0, 'n'},
{"expect-authority", no_argument, 0, 'A'},
{"all", no_argument, 0, 'L'},
{"warning", required_argument, 0, 'w'},
@@ -432,7 +448,7 @@ process_arguments (int argc, char **argv)
strcpy (argv[c], "-t");
while (1) {
- c = getopt_long (argc, argv, "hVvALt:H:s:r:a:w:c:", long_opts, &opt_index);
+ c = getopt_long (argc, argv, "hVvALnt:H:s:r:a:w:c:", long_opts, &opt_index);
if (c == -1 || c == EOF)
break;
@@ -491,6 +507,9 @@ process_arguments (int argc, char **argv)
expected_address_cnt++;
}
break;
+ case 'n': /* expect NXDOMAIN */
+ expect_nxdomain = TRUE;
+ break;
case 'A': /* expect authority */
expect_authority = TRUE;
break;
@@ -532,8 +551,15 @@ process_arguments (int argc, char **argv)
int
validate_arguments ()
{
- if (query_address[0] == 0)
+ if (query_address[0] == 0) {
+ printf ("missing --host argument\n");
+ return ERROR;
+ }
+
+ if (expected_address_cnt > 0 && expect_nxdomain) {
+ printf ("--expected-address and --expect-nxdomain cannot be combined\n");
return ERROR;
+ }
return OK;
}
@@ -566,6 +592,9 @@ print_help (void)
printf (" %s\n", _("Optional IP-ADDRESS/CIDR you expect the DNS server to return. HOST must end"));
printf (" %s\n", _("with a dot (.). This option can be repeated multiple times (Returns OK if any"));
printf (" %s\n", _("value matches)."));
+ printf (" -n, --expect-nxdomain\n");
+ printf (" %s\n", _("Expect the DNS server to return NXDOMAIN (i.e. the domain was not found)"));
+ printf (" %s\n", _("Cannot be used together with -a"));
printf (" -A, --expect-authority\n");
printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup"));
printf (" -w, --warning=seconds\n");
@@ -586,5 +615,5 @@ void
print_usage (void)
{
printf ("%s\n", _("Usage:"));
- printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit] [-L]\n", progname);
+ printf ("%s -H host [-s server] [-a expected-address] [-n] [-A] [-t timeout] [-w warn] [-c crit] [-L]\n", progname);
}
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 0b712665..34fb4f01 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -1453,8 +1453,8 @@ redir (char *pos, char *status_line)
!strncmp(server_address, addr, MAX_IPV4_HOSTLENGTH) &&
(host_name && !strncmp(host_name, addr, MAX_IPV4_HOSTLENGTH)) &&
!strcmp(server_url, url))
- die (STATE_WARNING,
- _("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"),
+ die (STATE_CRITICAL,
+ _("HTTP CRITICAL - redirection creates an infinite loop - %s://%s:%d%s%s\n"),
type, addr, i, url, (display_html ? "</A>" : ""));
strcpy (server_type, type);
diff --git a/plugins/check_load.c b/plugins/check_load.c
index bf7b94b4..0e4de54e 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -209,7 +209,7 @@ main (int argc, char **argv)
else if(la[i] > wload[i]) result = STATE_WARNING;
}
- printf("%s - %s|", state_text(result), status_line);
+ printf("LOAD %s - %s|", state_text(result), status_line);
for(i = 0; i < 3; i++)
printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]);
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index f7917c34..bae429de 100644
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
@@ -1,34 +1,34 @@
/*****************************************************************************
-*
+*
* Monitoring check_procs plugin
-*
+*
* License: GPL
* Copyright (c) 2000-2008 Monitoring Plugins Development Team
-*
+*
* Description:
-*
+*
* This file contains the check_procs plugin
-*
+*
* Checks all processes and generates WARNING or CRITICAL states if the
* specified metric is outside the required threshold ranges. The metric
* defaults to number of processes. Search filters can be applied to limit
* the processes to check.
-*
-*
+*
+*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*
-*
+*
+*
*****************************************************************************/
const char *progname = "check_procs";
@@ -50,7 +50,7 @@ const char *email = "devel@monitoring-plugins.org";
int process_arguments (int, char **);
int validate_arguments (void);
-int convert_to_seconds (char *);
+int convert_to_seconds (char *);
void print_help (void);
void print_usage (void);
@@ -230,9 +230,9 @@ main (int argc, char **argv)
procseconds = convert_to_seconds(procetime);
if (verbose >= 3)
- printf ("proc#=%d uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n",
+ printf ("proc#=%d uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n",
procs, procuid, procvsz, procrss,
- procpid, procppid, procpcpu, procstat,
+ procpid, procppid, procpcpu, procstat,
procetime, procprog, procargs);
/* Ignore self */
@@ -292,9 +292,9 @@ main (int argc, char **argv)
procs++;
if (verbose >= 2) {
- printf ("Matched: uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n",
+ printf ("Matched: uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n",
procuid, procvsz, procrss,
- procpid, procppid, procpcpu, procstat,
+ procpid, procppid, procpcpu, procstat,
procetime, procprog, procargs);
}
@@ -320,7 +320,7 @@ main (int argc, char **argv)
result = max_state (result, i);
}
}
- }
+ }
/* This should not happen */
else if (verbose) {
printf(_("Not parseable: %s"), input_buffer);
@@ -332,7 +332,7 @@ main (int argc, char **argv)
return STATE_UNKNOWN;
}
- if ( result == STATE_UNKNOWN )
+ if ( result == STATE_UNKNOWN )
result = STATE_OK;
/* Needed if procs found, but none match filter */
@@ -352,9 +352,9 @@ main (int argc, char **argv)
if (metric != METRIC_PROCS) {
printf (_("%d crit, %d warn out of "), crit, warn);
}
- }
+ }
printf (ngettext ("%d process", "%d processes", (unsigned long) procs), procs);
-
+
if (strcmp(fmt,"") != 0) {
printf (_(" with %s"), fmt);
}
@@ -440,7 +440,7 @@ process_arguments (int argc, char **argv)
break;
case 'c': /* critical threshold */
critical_range = optarg;
- break;
+ break;
case 'w': /* warning threshold */
warning_range = optarg;
break;
@@ -542,11 +542,11 @@ process_arguments (int argc, char **argv)
if ( strcmp(optarg, "PROCS") == 0) {
metric = METRIC_PROCS;
break;
- }
+ }
else if ( strcmp(optarg, "VSZ") == 0) {
metric = METRIC_VSZ;
break;
- }
+ }
else if ( strcmp(optarg, "RSS") == 0 ) {
metric = METRIC_RSS;
break;
@@ -559,7 +559,7 @@ process_arguments (int argc, char **argv)
metric = METRIC_ELAPSED;
break;
}
-
+
usage4 (_("Metric must be one of PROCS, VSZ, RSS, CPU, ELAPSED!"));
case 'k': /* linux kernel thread filter */
kthread_filter = 1;
@@ -642,7 +642,7 @@ convert_to_seconds(char *etime) {
seconds = 0;
for (ptr = etime; *ptr != '\0'; ptr++) {
-
+
if (*ptr == '-') {
hyphcnt++;
continue;
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index d37c57c8..c1e92dff 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -55,6 +55,7 @@ enum {
#define SMTP_EXPECT "220"
#define SMTP_HELO "HELO "
#define SMTP_EHLO "EHLO "
+#define SMTP_LHLO "LHLO "
#define SMTP_QUIT "QUIT\r\n"
#define SMTP_STARTTLS "STARTTLS\r\n"
#define SMTP_AUTH_LOGIN "AUTH LOGIN\r\n"
@@ -102,6 +103,7 @@ int check_critical_time = FALSE;
int verbose = 0;
int use_ssl = FALSE;
short use_ehlo = FALSE;
+short use_lhlo = FALSE;
short ssl_established = 0;
char *localhostname = NULL;
int sd;
@@ -152,7 +154,9 @@ main (int argc, char **argv)
return STATE_CRITICAL;
}
}
- if(use_ehlo)
+ if(use_lhlo)
+ xasprintf (&helocmd, "%s%s%s", SMTP_LHLO, localhostname, "\r\n");
+ else if(use_ehlo)
xasprintf (&helocmd, "%s%s%s", SMTP_EHLO, localhostname, "\r\n");
else
xasprintf (&helocmd, "%s%s%s", SMTP_HELO, localhostname, "\r\n");
@@ -197,7 +201,7 @@ main (int argc, char **argv)
if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) {
printf (_("recv() failed\n"));
return STATE_WARNING;
- } else if(use_ehlo){
+ } else if(use_ehlo || use_lhlo){
if(strstr(buffer, "250 STARTTLS") != NULL ||
strstr(buffer, "250-STARTTLS") != NULL){
supports_tls=TRUE;
@@ -470,6 +474,7 @@ process_arguments (int argc, char **argv)
{"use-ipv4", no_argument, 0, '4'},
{"use-ipv6", no_argument, 0, '6'},
{"help", no_argument, 0, 'h'},
+ {"lmtp", no_argument, 0, 'L'},
{"starttls",no_argument,0,'S'},
{"certificate",required_argument,0,'D'},
{"ignore-quit-failure",no_argument,0,'q'},
@@ -489,7 +494,7 @@ process_arguments (int argc, char **argv)
}
while (1) {
- c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:R:SD:F:A:U:P:q",
+ c = getopt_long (argc, argv, "+hVv46Lt:p:f:e:c:w:H:C:R:SD:F:A:U:P:q",
longopts, &option);
if (c == -1 || c == EOF)
@@ -616,6 +621,9 @@ process_arguments (int argc, char **argv)
use_ssl = TRUE;
use_ehlo = TRUE;
break;
+ case 'L':
+ use_lhlo = TRUE;
+ break;
case '4':
address_family = AF_INET;
break;
@@ -824,6 +832,8 @@ print_help (void)
printf (" %s\n", _("SMTP AUTH username"));
printf (" %s\n", "-P, --authpass=STRING");
printf (" %s\n", _("SMTP AUTH password"));
+ printf (" %s\n", "-L, --lmtp");
+ printf (" %s\n", _("Send LHLO instead of HELO/EHLO"));
printf (" %s\n", "-q, --ignore-quit-failure");
printf (" %s\n", _("Ignore failure when sending QUIT command to server"));
@@ -850,6 +860,6 @@ print_usage (void)
printf ("%s\n", _("Usage:"));
printf ("%s -H host [-p port] [-4|-6] [-e expect] [-C command] [-R response] [-f from addr]\n", progname);
printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout] [-q]\n");
- printf ("[-F fqdn] [-S] [-D warn days cert expire[,crit days cert expire]] [-v] \n");
+ printf ("[-F fqdn] [-S] [-L] [-D warn days cert expire[,crit days cert expire]] [-v] \n");
}
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index afc568b2..58d46b11 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -468,6 +468,9 @@ main (int argc, char **argv)
/* Process this block for numeric comparisons */
/* Make some special values,like Timeticks numeric only if a threshold is defined */
if (thlds[i]->warning || thlds[i]->critical || calculate_rate) {
+ if (verbose > 2) {
+ print_thresholds(" thresholds", thlds[i]);
+ }
ptr = strpbrk (show, "-0123456789");
if (ptr == NULL)
die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show);
@@ -581,14 +584,16 @@ main (int argc, char **argv)
if (warning_thresholds) {
strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1);
- strncat(perfstr, warning_thresholds, sizeof(perfstr)-strlen(perfstr)-1);
+ if(thlds[i]->warning && thlds[i]->warning->text)
+ strncat(perfstr, thlds[i]->warning->text, sizeof(perfstr)-strlen(perfstr)-1);
}
if (critical_thresholds) {
if (!warning_thresholds)
strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1);
strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1);
- strncat(perfstr, critical_thresholds, sizeof(perfstr)-strlen(perfstr)-1);
+ if(thlds[i]->critical && thlds[i]->critical->text)
+ strncat(perfstr, thlds[i]->critical->text, sizeof(perfstr)-strlen(perfstr)-1);
}
strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1);
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 0ff0c770..685c2cc5 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -34,6 +34,9 @@ const char *email = "devel@monitoring-plugins.org";
#include "common.h"
#include "popen.h"
#include "utils.h"
+#include <string.h>
+#include <math.h>
+#include <libintl.h>
#ifdef HAVE_DECL_SWAPCTL
# ifdef HAVE_SYS_PARAM_H
@@ -51,16 +54,19 @@ const char *email = "devel@monitoring-plugins.org";
# define SWAP_CONVERSION 1
#endif
-int check_swap (int usp, float free_swap_mb, float total_swap_mb);
+typedef struct {
+ int is_percentage;
+ uint64_t value;
+} threshold_t;
+
+int check_swap (float free_swap_mb, float total_swap_mb);
int process_arguments (int argc, char **argv);
int validate_arguments (void);
void print_usage (void);
void print_help (void);
-int warn_percent = 0;
-int crit_percent = 0;
-float warn_size_bytes = 0;
-float crit_size_bytes = 0;
+threshold_t warn;
+threshold_t crit;
int verbose;
int allswaps;
int no_swap_state = STATE_CRITICAL;
@@ -68,9 +74,10 @@ int no_swap_state = STATE_CRITICAL;
int
main (int argc, char **argv)
{
- int percent_used, percent;
- float total_swap_mb = 0, used_swap_mb = 0, free_swap_mb = 0;
- float dsktotal_mb = 0, dskused_mb = 0, dskfree_mb = 0, tmp_mb = 0;
+ unsigned int percent_used, percent;
+ uint64_t total_swap_mb = 0, used_swap_mb = 0, free_swap_mb = 0;
+ uint64_t dsktotal_mb = 0, dskused_mb = 0, dskfree_mb = 0;
+ uint64_t tmp_KB = 0;
int result = STATE_UNKNOWN;
char input_buffer[MAX_INPUT_BUFFER];
#ifdef HAVE_PROC_MEMINFO
@@ -116,10 +123,15 @@ main (int argc, char **argv)
}
fp = fopen (PROC_MEMINFO, "r");
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
- if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %f %f %f", &dsktotal_mb, &dskused_mb, &dskfree_mb) == 3) {
- dsktotal_mb = dsktotal_mb / 1048576; /* Apply conversion */
- dskused_mb = dskused_mb / 1048576;
- dskfree_mb = dskfree_mb / 1048576;
+ /*
+ * The following sscanf call looks for a line looking like: "Swap: 123 123 123"
+ * On which kind of system this format exists, I can not say, but I wanted to
+ * document this for people who are not adapt with sscanf anymore, like me
+ */
+ if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %lu %lu %lu", &dsktotal_mb, &dskused_mb, &dskfree_mb) == 3) {
+ dsktotal_mb = dsktotal_mb / (1024 * 1024); /* Apply conversion */
+ dskused_mb = dskused_mb / (1024 * 1024);
+ dskfree_mb = dskfree_mb / (1024 * 1024);
total_swap_mb += dsktotal_mb;
used_swap_mb += dskused_mb;
free_swap_mb += dskfree_mb;
@@ -128,21 +140,25 @@ main (int argc, char **argv)
percent=100.0;
else
percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
- result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb));
+ result = max_state (result, check_swap (dskfree_mb, dsktotal_mb));
if (verbose)
xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
}
}
- else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFre]%*[:] %f %*[k]%*[B]", str, &tmp_mb)) {
+ /*
+ * The following sscanf call looks for lines looking like: "SwapTotal: 123" and "SwapFree: 123"
+ * This format exists at least on Debian Linux with a 5.* kernel
+ */
+ else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFre]%*[:] %lu %*[k]%*[B]", str, &tmp_KB)) {
if (verbose >= 3) {
- printf("Got %s with %f\n", str, tmp_mb);
+ printf("Got %s with %lu\n", str, tmp_KB);
}
/* I think this part is always in Kb, so convert to mb */
if (strcmp ("Total", str) == 0) {
- dsktotal_mb = tmp_mb / 1024;
+ dsktotal_mb = tmp_KB / 1024;
}
else if (strcmp ("Free", str) == 0) {
- dskfree_mb = tmp_mb / 1024;
+ dskfree_mb = tmp_KB / 1024;
}
}
}
@@ -227,7 +243,7 @@ main (int argc, char **argv)
free_swap_mb += dskfree_mb;
if (allswaps) {
percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
- result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb));
+ result = max_state (result, check_swap (dskfree_mb, dsktotal_mb));
if (verbose)
xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
}
@@ -289,7 +305,7 @@ main (int argc, char **argv)
if(allswaps && dsktotal_mb > 0){
percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
- result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb));
+ result = max_state (result, check_swap (dskfree_mb, dsktotal_mb));
if (verbose) {
xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
}
@@ -328,7 +344,7 @@ main (int argc, char **argv)
if(allswaps && dsktotal_mb > 0){
percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
- result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb));
+ result = max_state (result, check_swap(dskfree_mb, dsktotal_mb));
if (verbose) {
xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
}
@@ -355,14 +371,19 @@ main (int argc, char **argv)
status = "- Swap is either disabled, not present, or of zero size. ";
}
- result = max_state (result, check_swap (percent_used, free_swap_mb, total_swap_mb));
- printf (_("SWAP %s - %d%% free (%d MB out of %d MB) %s|"),
+ result = max_state (result, check_swap(free_swap_mb, total_swap_mb));
+ printf (_("SWAP %s - %d%% free (%dMB out of %dMB) %s|"),
state_text (result),
(100 - percent_used), (int) free_swap_mb, (int) total_swap_mb, status);
- puts (perfdata ("swap", (long) free_swap_mb, "MB",
- TRUE, (long) max (warn_size_bytes/(1024 * 1024), warn_percent/100.0*total_swap_mb),
- TRUE, (long) max (crit_size_bytes/(1024 * 1024), crit_percent/100.0*total_swap_mb),
+ uint64_t warn_print = warn.value;
+ if (warn.is_percentage) warn_print = warn.value * (total_swap_mb *1024 *1024/100);
+ uint64_t crit_print = crit.value;
+ if (crit.is_percentage) crit_print = crit.value * (total_swap_mb *1024 *1024/100);
+
+ puts (perfdata_uint64 ("swap", free_swap_mb *1024 *1024, "B",
+ TRUE, warn_print,
+ TRUE, crit_print,
TRUE, 0,
TRUE, (long) total_swap_mb));
@@ -370,26 +391,37 @@ main (int argc, char **argv)
}
-
int
-check_swap (int usp, float free_swap_mb, float total_swap_mb)
+check_swap(float free_swap_mb, float total_swap_mb)
{
if (!total_swap_mb) return no_swap_state;
- int result = STATE_UNKNOWN;
- float free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */
- if (usp >= 0 && crit_percent != 0 && usp >= (100.0 - crit_percent))
- result = STATE_CRITICAL;
- else if (crit_size_bytes > 0 && free_swap <= crit_size_bytes)
- result = STATE_CRITICAL;
- else if (usp >= 0 && warn_percent != 0 && usp >= (100.0 - warn_percent))
- result = STATE_WARNING;
- else if (warn_size_bytes > 0 && free_swap <= warn_size_bytes)
- result = STATE_WARNING;
- else if (usp >= 0.0)
- result = STATE_OK;
- return result;
+ uint64_t free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */
+
+ if (!crit.is_percentage && crit.value >= free_swap) return STATE_CRITICAL;
+ if (!warn.is_percentage && warn.value >= free_swap) return STATE_WARNING;
+
+
+ uint64_t usage_percentage = ((total_swap_mb - free_swap_mb) / total_swap_mb) * 100;
+
+ if (crit.is_percentage &&
+ usage_percentage >= 0 &&
+ crit.value != 0 &&
+ usage_percentage >= (100 - crit.value))
+ {
+ return STATE_CRITICAL;
+ }
+
+ if (warn.is_percentage &&
+ usage_percentage >= 0 &&
+ warn.value != 0 &&
+ usage_percentage >= (100 - warn.value))
+ {
+ return STATE_WARNING;
+ }
+
+ return STATE_OK;
}
@@ -422,42 +454,68 @@ process_arguments (int argc, char **argv)
break;
switch (c) {
- case 'w': /* warning size threshold */
- if (is_intnonneg (optarg)) {
- warn_size_bytes = (float) atoi (optarg);
- break;
- }
- else if (strstr (optarg, ",") &&
- strstr (optarg, "%") &&
- sscanf (optarg, "%f,%d%%", &warn_size_bytes, &warn_percent) == 2) {
- warn_size_bytes = floorf(warn_size_bytes);
- break;
- }
- else if (strstr (optarg, "%") &&
- sscanf (optarg, "%d%%", &warn_percent) == 1) {
- break;
- }
- else {
- usage4 (_("Warning threshold must be integer or percentage!"));
- }
- case 'c': /* critical size threshold */
- if (is_intnonneg (optarg)) {
- crit_size_bytes = (float) atoi (optarg);
- break;
- }
- else if (strstr (optarg, ",") &&
- strstr (optarg, "%") &&
- sscanf (optarg, "%f,%d%%", &crit_size_bytes, &crit_percent) == 2) {
- crit_size_bytes = floorf(crit_size_bytes);
- break;
- }
- else if (strstr (optarg, "%") &&
- sscanf (optarg, "%d%%", &crit_percent) == 1) {
- break;
- }
- else {
- usage4 (_("Critical threshold must be integer or percentage!"));
+ case 'w': /* warning size threshold */
+ {
+ /*
+ * We expect either a positive integer value without a unit, which means
+ * the unit is Bytes or a positive integer value and a percentage sign (%),
+ * which means the value must be with 0 and 100 and is relative to the total swap
+ */
+ size_t length;
+ length = strlen(optarg);
+
+ if (optarg[length - 1] == '%') {
+ /* It's percentage */
+ warn.is_percentage = 1;
+ optarg[length - 1] = '\0';
+ if (is_uint64(optarg, &warn.value)) {
+ if (warn.value > 100) {
+ usage4 (_("Warning threshold percentage must be <= 100!"));
+ } else {
+ break;
+ }
+ }
+ } else {
+ /* It's Bytes */
+ warn.is_percentage = 0;
+ if (is_uint64(optarg, &warn.value)) {
+ break;
+ } else {
+ usage4 (_("Warning threshold be positive integer or percentage!"));
+ }
+ }
}
+ case 'c': /* critical size threshold */
+ {
+ /*
+ * We expect either a positive integer value without a unit, which means
+ * the unit is Bytes or a positive integer value and a percentage sign (%),
+ * which means the value must be with 0 and 100 and is relative to the total swap
+ */
+ size_t length;
+ length = strlen(optarg);
+
+ if (optarg[length - 1] == '%') {
+ /* It's percentage */
+ crit.is_percentage = 1;
+ optarg[length - 1] = '\0';
+ if (is_uint64(optarg, &crit.value)) {
+ if (crit.value> 100) {
+ usage4 (_("Critical threshold percentage must be <= 100!"));
+ } else {
+ break;
+ }
+ }
+ } else {
+ /* It's Bytes */
+ crit.is_percentage = 0;
+ if (is_uint64(optarg, &crit.value)) {
+ break;
+ } else {
+ usage4 (_("Critical threshold be positive integer or percentage!"));
+ }
+ }
+ }
case 'a': /* all swap */
allswaps = TRUE;
break;
@@ -482,23 +540,6 @@ process_arguments (int argc, char **argv)
c = optind;
if (c == argc)
return validate_arguments ();
- if (warn_percent == 0 && is_intnonneg (argv[c]))
- warn_percent = atoi (argv[c++]);
-
- if (c == argc)
- return validate_arguments ();
- if (crit_percent == 0 && is_intnonneg (argv[c]))
- crit_percent = atoi (argv[c++]);
-
- if (c == argc)
- return validate_arguments ();
- if (warn_size_bytes == 0 && is_intnonneg (argv[c]))
- warn_size_bytes = (float) atoi (argv[c++]);
-
- if (c == argc)
- return validate_arguments ();
- if (crit_size_bytes == 0 && is_intnonneg (argv[c]))
- crit_size_bytes = (float) atoi (argv[c++]);
return validate_arguments ();
}
@@ -508,17 +549,12 @@ process_arguments (int argc, char **argv)
int
validate_arguments (void)
{
- if (warn_percent == 0 && crit_percent == 0 && warn_size_bytes == 0
- && crit_size_bytes == 0) {
+ if (warn.value == 0 && crit.value == 0) {
return ERROR;
}
- else if (warn_percent < crit_percent) {
- usage4
- (_("Warning percentage should be more than critical percentage"));
- }
- else if (warn_size_bytes < crit_size_bytes) {
+ else if (warn.value < crit.value) {
usage4
- (_("Warning free space should be more than critical free space"));
+ (_("Warning should be more than critical"));
}
return OK;
}
@@ -564,7 +600,6 @@ print_help (void)
}
-
void
print_usage (void)
{
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index fdd8769b..ec527e7f 100644
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
@@ -88,8 +88,9 @@ $result = NPTest->testCmd(
);
$_ = $result->perf_output;
my ($warn_absth_data, $crit_absth_data, $total_absth_data) = (m/=.[^;]*;(\d+);(\d+);\d+;(\d+)/);
-is ($warn_absth_data, $total_absth_data - 20, "Wrong warning in perf data using absolute thresholds");
-is ($crit_absth_data, $total_absth_data - 10, "Wrong critical in perf data using absolute thresholds");
+# default unit is MiB, but perfdata is always bytes
+is ($warn_absth_data, $total_absth_data - (20 * (2 ** 20)), "Wrong warning in perf data using absolute thresholds");
+is ($crit_absth_data, $total_absth_data - (10 * (2 ** 20)), "Wrong critical in perf data using absolute thresholds");
# Then check percent thresholds.
$result = NPTest->testCmd(
@@ -119,7 +120,7 @@ like ( $result->only_output, qr/$more_free/, "Have disk name in text");
$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" );
cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free");
$_ = $result->output;
-my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+) MB .* (\d+) MB /g);
+my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+)MiB .* (\d+)MiB /g);
my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2;
diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t
index cdfbe60d..afb2062d 100644
--- a/plugins/t/check_dns.t
+++ b/plugins/t/check_dns.t
@@ -10,7 +10,7 @@ use NPTest;
plan skip_all => "check_dns not compiled" unless (-x "check_dns");
-plan tests => 19;
+plan tests => 23;
my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/';
@@ -105,3 +105,11 @@ cmp_ok( $res->return_code, '==', 0, "Got expected address");
$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_invalid_cidr -t 5");
cmp_ok( $res->return_code, '==', 2, "Got wrong address");
like ( $res->output, "/^DNS CRITICAL.*expected '$hostname_invalid_cidr' but got '$hostname_valid_ip'".'$/', "Output OK");
+
+$res = NPTest->testCmd("./check_dns -H $hostname_valid -n");
+cmp_ok( $res->return_code, '==', 2, "Found $hostname_valid");
+like ( $res->output, "/^DNS CRITICAL.*Domain '$hostname_valid' was found by the server:/", "Output OK");
+
+$res = NPTest->testCmd("./check_dns -H $hostname_invalid -n");
+cmp_ok( $res->return_code, '==', 0, "Did not find $hostname_invalid");
+like ( $res->output, $successOutput, "Output OK" );
diff --git a/plugins/t/check_load.t b/plugins/t/check_load.t
index 55f6f752..60837ef6 100644
--- a/plugins/t/check_load.t
+++ b/plugins/t/check_load.t
@@ -11,8 +11,8 @@ use NPTest;
my $res;
my $loadValue = "[0-9]+\.?[0-9]+";
-my $successOutput = "/^OK - load average: $loadValue, $loadValue, $loadValue/";
-my $failureOutput = "/^CRITICAL - load average: $loadValue, $loadValue, $loadValue/";
+my $successOutput = "/^LOAD OK - load average: $loadValue, $loadValue, $loadValue/";
+my $failureOutput = "/^LOAD CRITICAL - load average: $loadValue, $loadValue, $loadValue/";
plan tests => 11;
diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t
index e44adc90..de9e0f05 100644
--- a/plugins/t/check_swap.t
+++ b/plugins/t/check_swap.t
@@ -8,9 +8,9 @@ use strict;
use Test::More tests => 8;
use NPTest;
-my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/';
-my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/';
-my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/';
+my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/';
+my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/';
+my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/';
my $result;
diff --git a/plugins/tests/check_procs.t b/plugins/tests/check_procs.t
index 54d43d9b..fcea404e 100755
--- a/plugins/tests/check_procs.t
+++ b/plugins/tests/check_procs.t
@@ -8,13 +8,14 @@ use Test::More;
use NPTest;
if (-x "./check_procs") {
- plan tests => 50;
+ plan tests => 52;
} else {
plan skip_all => "No check_procs compiled";
}
my $result;
-my $command = "./check_procs --input-file=tests/var/ps-axwo.darwin";
+my $command = "./check_procs --input-file=tests/var/ps-axwo.darwin";
+my $cmd_etime = "./check_procs --input-file=tests/var/ps-axwo.debian";
$result = NPTest->testCmd( "$command" );
is( $result->return_code, 0, "Run with no options" );
@@ -69,9 +70,21 @@ SKIP: {
like( $result->output, '/^PROCS OK: 0 processes with UID = -2 \(nobody\), args \'UsB\'/', "Output correct" );
};
-$result = NPTest->testCmd( "$command --ereg-argument-array='mdworker.*501'" );
-is( $result->return_code, 0, "Checking regexp search of arguments" );
-is( $result->output, "PROCS OK: 1 process with regex args 'mdworker.*501' | procs=1;;;0;", "Output correct" );
+SKIP: {
+ skip 'check_procs is compiled with etime format support', 2 if `$command -vvv` =~ m/etime/mx;
+
+ $result = NPTest->testCmd( "$command --ereg-argument-array='mdworker.*501'" );
+ is( $result->return_code, 0, "Checking regexp search of arguments" );
+ is( $result->output, "PROCS OK: 1 process with regex args 'mdworker.*501' | procs=1;;;0;", "Output correct" );
+}
+
+SKIP: {
+ skip 'check_procs is compiled without etime format support', 2 if `$cmd_etime -vvv` !~ m/etime/mx;
+
+ $result = NPTest->testCmd( "$cmd_etime -m ELAPSED -C apache2 -w 1000 -c 2000" );
+ is( $result->return_code, 2, "Checking elapsed time threshold" );
+ 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" );
+}
$result = NPTest->testCmd( "$command --vsz 1000000" );
is( $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
$result = NPTest->testCmd( "$command --ereg-argument-array='(nosuchname|nosuch2name)'" );
is( $result->return_code, 0, "Checking no pipe symbol in output" );
is( $result->output, "PROCS OK: 0 processes with regex args '(nosuchname,nosuch2name)' | procs=0;;;0;", "Output correct" );
-
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t
index 85d6bf55..0a77fa8a 100755
--- a/plugins/tests/check_snmp.t
+++ b/plugins/tests/check_snmp.t
@@ -9,7 +9,7 @@ use NPTest;
use FindBin qw($Bin);
use POSIX qw/strftime/;
-my $tests = 67;
+my $tests = 73;
# Check that all dependent modules are available
eval {
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:
$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'" );
is($res->return_code, 0, "Negative float OK" );
-is($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" );
+is($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" );
$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'" );
is($res->return_code, 1, "Negative float WARNING" );
-is($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" );
+is($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" );
+$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'" );
+is($res->return_code, 0, "Multiple OIDs with thresholds" );
+like($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" );
+
+$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'" );
+is($res->return_code, 1, "Multiple OIDs with thresholds" );
+like($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" );
+
+$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" );
+is($res->return_code, 2, "Multiple OIDs with some thresholds" );
+like($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 00000000..5889e9a4
--- /dev/null
+++ b/plugins/tests/var/ps-axwo.debian
@@ -0,0 +1,219 @@
+STAT UID PID PPID VSZ RSS %CPU ELAPSED COMMAND COMMAND
+Ss 0 1 0 167244 7144 0.1 26-03:07:26 systemd /lib/systemd/systemd --system --deserialize 17
+S 0 2 0 0 0 0.0 26-03:07:26 kthreadd [kthreadd]
+I< 0 3 2 0 0 0.0 26-03:07:26 rcu_gp [rcu_gp]
+I< 0 4 2 0 0 0.0 26-03:07:26 rcu_par_gp [rcu_par_gp]
+I< 0 6 2 0 0 0.0 26-03:07:26 kworker/0:0H-ev [kworker/0:0H-events_highpri]
+I< 0 9 2 0 0 0.0 26-03:07:26 mm_percpu_wq [mm_percpu_wq]
+S 0 10 2 0 0 0.0 26-03:07:26 rcu_tasks_rude_ [rcu_tasks_rude_]
+S 0 11 2 0 0 0.0 26-03:07:26 rcu_tasks_trace [rcu_tasks_trace]
+S 0 12 2 0 0 0.0 26-03:07:26 ksoftirqd/0 [ksoftirqd/0]
+I 0 13 2 0 0 0.0 26-03:07:26 rcu_sched [rcu_sched]
+S 0 14 2 0 0 0.0 26-03:07:26 migration/0 [migration/0]
+S 0 15 2 0 0 0.0 26-03:07:26 cpuhp/0 [cpuhp/0]
+S 0 16 2 0 0 0.0 26-03:07:26 cpuhp/1 [cpuhp/1]
+S 0 17 2 0 0 0.0 26-03:07:26 migration/1 [migration/1]
+S 0 18 2 0 0 0.0 26-03:07:26 ksoftirqd/1 [ksoftirqd/1]
+I< 0 20 2 0 0 0.0 26-03:07:26 kworker/1:0H-ev [kworker/1:0H-events_highpri]
+S 0 21 2 0 0 0.0 26-03:07:26 cpuhp/2 [cpuhp/2]
+S 0 22 2 0 0 0.0 26-03:07:26 migration/2 [migration/2]
+S 0 23 2 0 0 0.0 26-03:07:26 ksoftirqd/2 [ksoftirqd/2]
+I< 0 25 2 0 0 0.0 26-03:07:26 kworker/2:0H-ev [kworker/2:0H-events_highpri]
+S 0 26 2 0 0 0.0 26-03:07:26 cpuhp/3 [cpuhp/3]
+S 0 27 2 0 0 0.0 26-03:07:26 migration/3 [migration/3]
+S 0 28 2 0 0 0.0 26-03:07:26 ksoftirqd/3 [ksoftirqd/3]
+I< 0 30 2 0 0 0.0 26-03:07:26 kworker/3:0H-ev [kworker/3:0H-events_highpri]
+S 0 35 2 0 0 0.0 26-03:07:26 kdevtmpfs [kdevtmpfs]
+I< 0 36 2 0 0 0.0 26-03:07:26 netns [netns]
+S 0 37 2 0 0 0.0 26-03:07:26 kauditd [kauditd]
+S 0 38 2 0 0 0.0 26-03:07:26 khungtaskd [khungtaskd]
+S 0 39 2 0 0 0.0 26-03:07:26 oom_reaper [oom_reaper]
+I< 0 40 2 0 0 0.0 26-03:07:26 writeback [writeback]
+S 0 41 2 0 0 0.0 26-03:07:26 kcompactd0 [kcompactd0]
+SN 0 42 2 0 0 0.0 26-03:07:26 ksmd [ksmd]
+SN 0 43 2 0 0 0.0 26-03:07:26 khugepaged [khugepaged]
+I< 0 62 2 0 0 0.0 26-03:07:26 kintegrityd [kintegrityd]
+I< 0 63 2 0 0 0.0 26-03:07:26 kblockd [kblockd]
+I< 0 64 2 0 0 0.0 26-03:07:26 blkcg_punt_bio [blkcg_punt_bio]
+I< 0 65 2 0 0 0.0 26-03:07:26 edac-poller [edac-poller]
+I< 0 66 2 0 0 0.0 26-03:07:26 devfreq_wq [devfreq_wq]
+I< 0 67 2 0 0 0.0 26-03:07:26 kworker/2:1H-ev [kworker/2:1H-events_highpri]
+S 0 70 2 0 0 0.3 26-03:07:25 kswapd0 [kswapd0]
+I< 0 71 2 0 0 0.0 26-03:07:25 kthrotld [kthrotld]
+I< 0 72 2 0 0 0.0 26-03:07:25 acpi_thermal_pm [acpi_thermal_pm]
+I< 0 74 2 0 0 0.0 26-03:07:25 ipv6_addrconf [ipv6_addrconf]
+I< 0 80 2 0 0 0.0 26-03:07:25 kworker/3:1H-ev [kworker/3:1H-events_highpri]
+I< 0 84 2 0 0 0.0 26-03:07:25 kstrp [kstrp]
+I< 0 87 2 0 0 0.0 26-03:07:25 zswap-shrink [zswap-shrink]
+I< 0 110 2 0 0 0.0 26-03:07:25 kworker/0:1H-ev [kworker/0:1H-events_highpri]
+I< 0 141 2 0 0 0.0 26-03:07:25 ata_sff [ata_sff]
+S 0 143 2 0 0 0.0 26-03:07:25 scsi_eh_0 [scsi_eh_0]
+I< 0 144 2 0 0 0.0 26-03:07:25 scsi_tmf_0 [scsi_tmf_0]
+S 0 145 2 0 0 0.0 26-03:07:25 scsi_eh_1 [scsi_eh_1]
+I< 0 146 2 0 0 0.0 26-03:07:25 scsi_tmf_1 [scsi_tmf_1]
+S 0 147 2 0 0 0.0 26-03:07:25 scsi_eh_2 [scsi_eh_2]
+I< 0 148 2 0 0 0.0 26-03:07:25 scsi_tmf_2 [scsi_tmf_2]
+S 0 149 2 0 0 0.0 26-03:07:25 scsi_eh_3 [scsi_eh_3]
+I< 0 150 2 0 0 0.0 26-03:07:25 scsi_tmf_3 [scsi_tmf_3]
+S 0 151 2 0 0 0.0 26-03:07:25 scsi_eh_4 [scsi_eh_4]
+I< 0 152 2 0 0 0.0 26-03:07:25 scsi_tmf_4 [scsi_tmf_4]
+S 0 153 2 0 0 0.0 26-03:07:25 scsi_eh_5 [scsi_eh_5]
+I< 0 154 2 0 0 0.0 26-03:07:25 scsi_tmf_5 [scsi_tmf_5]
+S 0 158 2 0 0 0.0 26-03:07:25 card0-crtc0 [card0-crtc0]
+S 0 159 2 0 0 0.0 26-03:07:25 card0-crtc1 [card0-crtc1]
+S 0 160 2 0 0 0.0 26-03:07:25 card0-crtc2 [card0-crtc2]
+I< 0 162 2 0 0 0.0 26-03:07:25 kworker/1:1H-ev [kworker/1:1H-events_highpri]
+S 0 163 2 0 0 0.0 26-03:07:25 scsi_eh_6 [scsi_eh_6]
+I< 0 164 2 0 0 0.0 26-03:07:25 scsi_tmf_6 [scsi_tmf_6]
+S 0 165 2 0 0 0.0 26-03:07:25 usb-storage [usb-storage]
+I< 0 167 2 0 0 0.0 26-03:07:25 uas [uas]
+I< 0 176 2 0 0 0.0 26-03:07:25 kdmflush [kdmflush]
+I< 0 177 2 0 0 0.0 26-03:07:25 kdmflush [kdmflush]
+S 0 202 2 0 0 0.0 26-03:07:24 scsi_eh_7 [scsi_eh_7]
+I< 0 203 2 0 0 0.0 26-03:07:24 scsi_tmf_7 [scsi_tmf_7]
+S 0 204 2 0 0 0.0 26-03:07:24 usb-storage [usb-storage]
+I< 0 232 2 0 0 0.0 26-03:07:23 btrfs-worker [btrfs-worker]
+I< 0 233 2 0 0 0.0 26-03:07:23 btrfs-worker-hi [btrfs-worker-hi]
+I< 0 234 2 0 0 0.0 26-03:07:23 btrfs-delalloc [btrfs-delalloc]
+I< 0 235 2 0 0 0.0 26-03:07:23 btrfs-flush_del [btrfs-flush_del]
+I< 0 236 2 0 0 0.0 26-03:07:23 btrfs-cache [btrfs-cache]
+I< 0 237 2 0 0 0.0 26-03:07:23 btrfs-fixup [btrfs-fixup]
+I< 0 238 2 0 0 0.0 26-03:07:23 btrfs-endio [btrfs-endio]
+I< 0 239 2 0 0 0.0 26-03:07:23 btrfs-endio-met [btrfs-endio-met]
+I< 0 240 2 0 0 0.0 26-03:07:23 btrfs-endio-met [btrfs-endio-met]
+I< 0 241 2 0 0 0.0 26-03:07:23 btrfs-endio-rai [btrfs-endio-rai]
+I< 0 242 2 0 0 0.0 26-03:07:23 btrfs-rmw [btrfs-rmw]
+I< 0 243 2 0 0 0.0 26-03:07:23 btrfs-endio-wri [btrfs-endio-wri]
+I< 0 244 2 0 0 0.0 26-03:07:23 btrfs-freespace [btrfs-freespace]
+I< 0 245 2 0 0 0.0 26-03:07:23 btrfs-delayed-m [btrfs-delayed-m]
+I< 0 246 2 0 0 0.0 26-03:07:23 btrfs-readahead [btrfs-readahead]
+I< 0 247 2 0 0 0.0 26-03:07:23 btrfs-qgroup-re [btrfs-qgroup-re]
+S 0 248 2 0 0 0.0 26-03:07:23 btrfs-cleaner [btrfs-cleaner]
+S 0 249 2 0 0 0.2 26-03:07:23 btrfs-transacti [btrfs-transacti]
+I< 0 317 2 0 0 0.0 26-03:07:22 rpciod [rpciod]
+I< 0 322 2 0 0 0.0 26-03:07:22 xprtiod [xprtiod]
+S 0 381 2 0 0 0.0 26-03:07:22 irq/133-mei_me [irq/133-mei_me]
+S 0 422 2 0 0 0.0 26-03:07:22 watchdogd [watchdogd]
+I< 0 523 2 0 0 0.0 26-03:07:22 led_workqueue [led_workqueue]
+I< 0 583 2 0 0 0.0 26-03:07:22 cryptd [cryptd]
+I< 0 590 2 0 0 0.0 26-03:07:22 ext4-rsv-conver [ext4-rsv-conver]
+Ss 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
+Ss 0 731 1 575120 1368 0.0 26-03:07:21 systemd-logind /lib/systemd/systemd-logind
+Ssl 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
+S 0 1141 2 0 0 0.0 26-03:07:18 lockd [lockd]
+I< 0 1459 2 0 0 0.0 26-03:07:16 nfsiod [nfsiod]
+S 0 1621 2 0 0 0.0 26-03:07:15 NFSv4 callback [NFSv4 callback]
+Ssl 0 1771 1 1548340 676 0.0 26-03:07:13 libvirtd /usr/sbin/libvirtd
+I< 0 24315 2 0 0 0.0 26-02:49:02 cifsiod [cifsiod]
+I< 0 24316 2 0 0 0.0 26-02:49:02 smb3decryptd [smb3decryptd]
+I< 0 24317 2 0 0 0.0 26-02:49:02 cifsfileinfoput [cifsfileinfoput]
+I< 0 24318 2 0 0 0.0 26-02:49:02 cifsoplockd [cifsoplockd]
+I< 0 24319 2 0 0 0.0 26-02:49:02 cifs-dfscache [cifs-dfscache]
+S 0 24322 2 0 0 0.0 26-02:49:02 cifsd [cifsd]
+I< 0 24413 2 0 0 0.0 26-02:48:57 btrfs-worker [btrfs-worker]
+I< 0 24414 2 0 0 0.0 26-02:48:57 btrfs-worker-hi [btrfs-worker-hi]
+I< 0 24415 2 0 0 0.0 26-02:48:57 btrfs-delalloc [btrfs-delalloc]
+I< 0 24416 2 0 0 0.0 26-02:48:57 btrfs-flush_del [btrfs-flush_del]
+I< 0 24418 2 0 0 0.0 26-02:48:57 btrfs-cache [btrfs-cache]
+I< 0 24419 2 0 0 0.0 26-02:48:57 btrfs-fixup [btrfs-fixup]
+I< 0 24420 2 0 0 0.0 26-02:48:57 btrfs-endio [btrfs-endio]
+I< 0 24421 2 0 0 0.0 26-02:48:57 btrfs-endio-met [btrfs-endio-met]
+I< 0 24422 2 0 0 0.0 26-02:48:57 btrfs-endio-met [btrfs-endio-met]
+I< 0 24423 2 0 0 0.0 26-02:48:57 btrfs-endio-rai [btrfs-endio-rai]
+I< 0 24424 2 0 0 0.0 26-02:48:57 btrfs-rmw [btrfs-rmw]
+I< 0 24425 2 0 0 0.0 26-02:48:57 btrfs-endio-wri [btrfs-endio-wri]
+I< 0 24426 2 0 0 0.0 26-02:48:57 btrfs-freespace [btrfs-freespace]
+I< 0 24427 2 0 0 0.0 26-02:48:57 btrfs-delayed-m [btrfs-delayed-m]
+I< 0 24428 2 0 0 0.0 26-02:48:57 btrfs-readahead [btrfs-readahead]
+I< 0 24429 2 0 0 0.0 26-02:48:57 btrfs-qgroup-re [btrfs-qgroup-re]
+S 0 24450 2 0 0 0.0 26-02:48:53 btrfs-cleaner [btrfs-cleaner]
+S 0 24451 2 0 0 0.0 26-02:48:53 btrfs-transacti [btrfs-transacti]
+I< 0 747708 2 0 0 0.0 16-21:06:20 xfsalloc [xfsalloc]
+I< 0 747709 2 0 0 0.0 16-21:06:20 xfs_mru_cache [xfs_mru_cache]
+S 0 747713 2 0 0 0.0 16-21:06:20 jfsIO [jfsIO]
+S 0 747714 2 0 0 0.0 16-21:06:20 jfsCommit [jfsCommit]
+S 0 747715 2 0 0 0.0 16-21:06:20 jfsCommit [jfsCommit]
+S 0 747716 2 0 0 0.0 16-21:06:20 jfsCommit [jfsCommit]
+S 0 747717 2 0 0 0.0 16-21:06:20 jfsCommit [jfsCommit]
+S 0 747718 2 0 0 0.0 16-21:06:20 jfsSync [jfsSync]
+Ss 0 1071687 1 105976 28304 0.0 3-03:12:31 systemd-journal /lib/systemd/systemd-journald
+Ss 0 1934146 1 25672 4704 0.0 11:19:31 cupsd /usr/sbin/cupsd -l
+Ssl 0 1934148 1 182868 8540 0.0 11:19:31 cups-browsed /usr/sbin/cups-browsed
+S 13 1934155 3392655 5752 88 0.0 11:19:31 pinger (pinger)
+S< 33 1934166 3393034 57996 5460 0.0 11:19:31 apache2 /usr/sbin/apache2 -k start
+S< 33 1934167 3393034 216944 13892 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start
+S< 33 1934168 3393034 216944 13756 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start
+S< 33 1934169 3393034 216936 13732 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start
+S< 33 1934170 3393034 216944 13888 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start
+S< 33 1934172 3393034 216944 15388 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start
+S< 33 1934701 3393034 216936 13736 0.0 11:19:29 apache2 /usr/sbin/apache2 -k start
+S< 33 1935056 3393034 216920 13724 0.0 11:19:28 apache2 /usr/sbin/apache2 -k start
+S 7 1936834 1934146 16652 832 0.0 11:18:12 dbus /usr/lib/cups/notifier/dbus dbus://
+S< 33 1955909 3393034 216928 13792 0.0 11:00:25 apache2 /usr/sbin/apache2 -k start
+I< 0 2531464 2 0 0 0.0 06:35:47 kworker/u9:0-i9 [kworker/u9:0-i915_flip]
+I 0 2570506 2 0 0 0.0 06:27:41 kworker/1:0-cgr [kworker/1:0-cgroup_destroy]
+I 0 2596195 2 0 0 0.0 06:21:52 kworker/1:1-eve [kworker/1:1-events]
+I 0 2785341 2 0 0 0.0 03:34:16 kworker/u8:8-bt [kworker/u8:8-btrfs-endio-write]
+I 0 2785520 2 0 0 0.0 03:33:50 kworker/3:0-eve [kworker/3:0-events]
+I 0 2798669 2 0 0 0.0 03:21:09 kworker/u8:5-bt [kworker/u8:5-btrfs-endio-write]
+Ss 0 2803015 1 5616 3108 0.0 03:17:54 cron /usr/sbin/cron -f
+I 0 2845483 2 0 0 0.0 02:38:11 kworker/0:3-eve [kworker/0:3-events]
+I 0 2939490 2 0 0 0.1 01:10:32 kworker/0:0-eve [kworker/0:0-events]
+I 0 2939754 2 0 0 0.0 01:10:26 kworker/u8:1-i9 [kworker/u8:1-i915]
+I 0 2942040 2 0 0 0.0 01:08:02 kworker/u8:7-bt [kworker/u8:7-btrfs-endio-meta]
+S 117 2954268 3392551 40044 5772 0.0 56:37 pickup pickup -l -t unix -u -c
+I 0 2965195 2 0 0 0.0 46:00 kworker/u8:0-bt [kworker/u8:0-btrfs-worker]
+I 0 2977972 2 0 0 0.0 33:54 kworker/u8:2-bt [kworker/u8:2-btrfs-endio-write]
+I 0 2985488 2 0 0 0.0 27:02 kworker/u8:3-bl [kworker/u8:3-blkcg_punt_bio]
+I 0 2987519 2 0 0 1.0 25:15 kworker/2:1-eve [kworker/2:1-events]
+I 0 2987601 2 0 0 0.0 25:03 kworker/u8:9-i9 [kworker/u8:9-i915]
+I< 0 2995218 2 0 0 0.0 18:41 kworker/u9:2-xp [kworker/u9:2-xprtiod]
+I 0 2997170 2 0 0 0.0 16:41 kworker/3:1-rcu [kworker/3:1-rcu_gp]
+I 0 3001264 2 0 0 0.0 13:01 kworker/u8:4-bt [kworker/u8:4-btrfs-endio-write]
+I 0 3004697 2 0 0 0.7 09:41 kworker/2:0-eve [kworker/2:0-events]
+I 0 3010619 2 0 0 1.0 04:29 kworker/2:2-eve [kworker/2:2-events]
+I 0 3014612 2 0 0 0.0 00:41 kworker/3:2-eve [kworker/3:2-events]
+S 0 3015082 2803015 6716 3028 0.0 00:30 cron /usr/sbin/CRON -f
+I 0 3015382 2 0 0 0.0 00:00 kworker/u8:6-bt [kworker/u8:6-btrfs-endio-meta]
+Ss 1 3392068 1 5592 504 0.0 15-02:34:39 atd /usr/sbin/atd -f
+Ssl 0 3392072 1 235796 1740 0.0 15-02:34:39 accounts-daemon /usr/libexec/accounts-daemon
+Ssl 106 3392076 1 315708 6128 0.0 15-02:34:39 colord /usr/libexec/colord
+Ss 0 3392083 1 8120 720 0.0 15-02:34:39 haveged /usr/sbin/haveged --Foreground --verbose=1
+Ss 0 3392090 1 5168 132 0.0 15-02:34:39 blkmapd /usr/sbin/blkmapd
+SNsl 111 3392094 1 155648 440 0.0 15-02:34:39 rtkit-daemon /usr/libexec/rtkit-daemon
+Ssl 0 3392097 1 290168 1352 0.0 15-02:34:39 packagekitd /usr/libexec/packagekitd
+Ss 128 3392100 1 7960 448 0.0 15-02:34:39 rpcbind /sbin/rpcbind -f -w
+Ss 0 3392114 1 13432 616 0.0 15-02:34:39 systemd-machine /lib/systemd/systemd-machined
+Ss 0 3392118 1 13316 848 0.0 15-02:34:39 sshd sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
+Ssl 0 3392124 1 244072 2456 0.0 15-02:34:39 upowerd /usr/libexec/upowerd
+Ssl 0 3392138 1 1634748 10684 0.0 15-02:34:39 containerd /usr/bin/containerd
+Ssl 0 3392139 1 222768 1784 0.0 15-02:34:39 rsyslogd /usr/sbin/rsyslogd -n -iNONE
+Ss 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
+Ssl 119 3392156 1 76472 1688 0.0 15-02:34:39 ntpd /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 119:126
+Ss 120 3392168 1 4656 276 0.0 15-02:34:39 rpc.statd /sbin/rpc.statd --no-notify
+Ss 0 3392171 1 5072 432 0.0 15-02:34:39 rpc.mountd /usr/sbin/rpc.mountd --manage-gids
+Ss 0 3392176 1 5008 288 0.0 15-02:34:39 rpc.idmapd /usr/sbin/rpc.idmapd
+Ss 105 3392184 1 15544 6816 3.5 15-02:34:39 avahi-daemon avahi-daemon: running [tsui.local]
+Ss 0 3392186 1 25288 3860 0.0 15-02:34:39 systemd-udevd /lib/systemd/systemd-udevd
+S 105 3392190 3392184 8788 52 0.0 15-02:34:39 avahi-daemon avahi-daemon: chroot helper
+Ssl 0 3392197 1 396120 4188 0.0 15-02:34:39 udisksd /usr/libexec/udisks2/udisksd
+Ssl 0 3392214 1 237504 6632 0.0 15-02:34:39 polkitd /usr/libexec/polkitd --no-debug
+Ss 0 3392284 1 9684 560 0.0 15-02:34:38 xinetd /usr/sbin/xinetd -pidfile /run/xinetd.pid -stayalive -inetd_compat -inetd_ipv6
+Ssl 0 3392285 1 314840 1352 0.0 15-02:34:38 ModemManager /usr/sbin/ModemManager
+Ss 0 3392317 1 2352 140 0.0 15-02:34:38 acpid /usr/sbin/acpid
+S 0 3392400 2 0 0 0.0 15-02:34:38 nfsd [nfsd]
+S 0 3392401 2 0 0 0.0 15-02:34:38 nfsd [nfsd]
+S 0 3392402 2 0 0 0.0 15-02:34:38 nfsd [nfsd]
+S 0 3392403 2 0 0 0.0 15-02:34:38 nfsd [nfsd]
+S 0 3392404 2 0 0 0.0 15-02:34:38 nfsd [nfsd]
+S 0 3392405 2 0 0 0.0 15-02:34:38 nfsd [nfsd]
+S 0 3392407 2 0 0 0.0 15-02:34:38 nfsd [nfsd]
+S 0 3392410 2 0 0 0.0 15-02:34:38 nfsd [nfsd]
+Ss 0 3392551 1 40092 1304 0.0 15-02:34:37 master /usr/lib/postfix/sbin/master -w
+S 117 3392553 3392551 40156 568 0.0 15-02:34:37 qmgr qmgr -l -t unix -u
+Ss 0 3392650 1 63652 4 0.0 15-02:34:36 squid /usr/sbin/squid --foreground -sYC
+Ssl 116 3392652 1 1675196 93848 0.0 15-02:34:36 mariadbd /usr/sbin/mariadbd
+S 13 3392655 3392650 81776 21232 0.0 15-02:34:36 squid (squid-1) --kid squid-1 --foreground -sYC
+S 13 3392657 3392655 5572 68 0.0 15-02:34:36 log_file_daemon (logfile-daemon) /var/log/squid/access.log
+S<s 0 3393034 1 216648 7560 0.0 15-02:34:34 apache2 /usr/sbin/apache2 -k start
+Ss 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 37a2d35e..00000000
--- a/plugins/tests/var/ps_axwo.debian
+++ /dev/null
@@ -1,84 +0,0 @@
-STAT UID PID PPID VSZ RSS %CPU COMMAND COMMAND
-S 0 1 0 1504 428 0.0 init init [2]
-SN 0 2 1 0 0 0.0 ksoftirqd/0 [ksoftirqd/0]
-S< 0 3 1 0 0 0.0 events/0 [events/0]
-S< 0 4 3 0 0 0.0 khelper [khelper]
-S< 0 5 3 0 0 0.0 kacpid [kacpid]
-S< 0 38 3 0 0 0.0 kblockd/0 [kblockd/0]
-S 0 48 3 0 0 0.0 pdflush [pdflush]
-S< 0 51 3 0 0 0.0 aio/0 [aio/0]
-S 0 50 1 0 0 0.0 kswapd0 [kswapd0]
-S 0 193 1 0 0 0.0 kseriod [kseriod]
-S 0 214 1 0 0 0.0 scsi_eh_0 [scsi_eh_0]
-S 0 221 1 0 0 0.0 khubd [khubd]
-S 0 299 1 0 0 0.3 kjournald [kjournald]
-S 0 1148 1 0 0 0.0 pciehpd_event [pciehpd_event]
-S 0 1168 1 0 0 0.0 shpchpd_event [shpchpd_event]
-Ss 1 1795 1 1612 276 0.0 portmap /sbin/portmap
-Ss 0 2200 1 1652 568 0.0 vmware-guestd /usr/sbin/vmware-guestd --background /var/run/vmware-guestd.pid
-Ss 0 2209 1 2240 532 0.0 inetd /usr/sbin/inetd
-Ss 0 2319 1 3468 792 0.0 sshd /usr/sbin/sshd
-Ss 0 2323 1 2468 676 0.0 rpc.statd /sbin/rpc.statd
-Ss 1 2332 1 1684 488 0.0 atd /usr/sbin/atd
-Ss 0 2335 1 1764 636 0.0 cron /usr/sbin/cron
-Ss+ 0 2350 1 1500 348 0.0 getty /sbin/getty 38400 tty1
-Ss+ 0 2351 1 1500 348 0.0 getty /sbin/getty 38400 tty2
-Ss+ 0 2352 1 1500 348 0.0 getty /sbin/getty 38400 tty3
-Ss+ 0 2353 1 1500 348 0.0 getty /sbin/getty 38400 tty4
-Ss+ 0 2354 1 1500 348 0.0 getty /sbin/getty 38400 tty5
-Ss+ 0 2355 1 1500 348 0.0 getty /sbin/getty 38400 tty6
-S 0 6907 1 2308 892 0.0 mysqld_safe /bin/sh /usr/bin/mysqld_safe
-S 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
-S 0 6945 6907 1488 420 0.0 logger logger -p daemon.err -t mysqld_safe -i -t mysqld
-S 1001 17778 1 6436 1588 0.0 snmpd /usr/sbin/snmpd -u nagios -Lsd -Lf /dev/null -p/var/run/snmpd.pid
-Ss 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
-Ss 0 847 2319 14452 1752 0.0 sshd sshd: tonvoon [priv]
-S 1000 857 847 14616 1832 0.0 sshd sshd: tonvoon@pts/3
-Ss 1000 860 857 2984 1620 0.0 bash -bash
-S 0 868 860 2588 1428 0.0 bash -su
-S+ 1001 877 868 2652 1568 0.0 bash -su
-S 0 6086 3 0 0 0.0 pdflush [pdflush]
-Ss 0 17832 2319 14452 1752 0.0 sshd sshd: tonvoon [priv]
-S 1000 18155 17832 14620 1840 0.0 sshd sshd: tonvoon@pts/0
-Ss 1000 18156 18155 2984 1620 0.0 bash -bash
-S 0 18518 18156 2588 1428 0.0 bash -su
-S 1001 18955 18518 2672 1600 0.0 bash -su
-Ss 0 21683 2319 14452 1756 0.0 sshd sshd: tonvoon [priv]
-S 1000 21742 21683 14620 1896 0.0 sshd sshd: tonvoon@pts/1
-Ss 1000 21743 21742 2984 1620 0.0 bash -bash
-S 0 21748 21743 2592 1432 0.0 bash -su
-S 1001 21757 21748 2620 1540 0.0 bash -su
-Ss 0 2334 2319 14452 1756 0.0 sshd sshd: tonvoon [priv]
-S 1000 2343 2334 14620 1840 0.0 sshd sshd: tonvoon@pts/2
-Ss 1000 2344 2343 2984 1620 0.0 bash -bash
-S 0 2349 2344 2592 1432 0.0 bash -su
-S+ 1001 2364 2349 2620 1520 0.0 bash -su
-T 1001 2454 2364 2096 1032 0.0 vi vi configure.in.rej
-S+ 1001 8500 21757 69604 52576 0.0 opsview_web_ser /usr/bin/perl -w ./script/opsview_web_server.pl -f -d
-Ss 0 7609 2319 14452 1756 0.0 sshd sshd: tonvoon [priv]
-S 1000 7617 7609 14460 1828 0.0 sshd sshd: tonvoon@pts/4
-Ss 1000 7618 7617 2984 1620 0.0 bash -bash
-S 0 7623 7618 2592 1432 0.0 bash -su
-S+ 1001 7632 7623 2620 1528 0.0 bash -su
-Ss 1001 12678 1 20784 17728 0.0 opsviewd opsviewd
-Ss 0 832 1 14512 6360 0.0 apache2 /usr/sbin/apache2 -k start -DSSL
-S 33 842 832 14648 6596 0.0 apache2 /usr/sbin/apache2 -k start -DSSL
-S 33 843 832 14512 6504 0.0 apache2 /usr/sbin/apache2 -k start -DSSL
-S 33 844 832 14512 6476 0.0 apache2 /usr/sbin/apache2 -k start -DSSL
-S 33 845 832 14512 6476 0.0 apache2 /usr/sbin/apache2 -k start -DSSL
-S 33 846 832 14512 6476 0.0 apache2 /usr/sbin/apache2 -k start -DSSL
-Ss 7 4081 1 2464 884 0.0 lpd /usr/sbin/lpd -s
-S 33 26484 832 14512 6476 0.0 apache2 /usr/sbin/apache2 -k start -DSSL
-Ss 1001 22324 1 20252 1612 0.1 nagios ../../bin/nagios -d /usr/local/nagios/etc/nagios.cfg
-Ss 0 23336 2319 14452 1756 0.0 sshd sshd: tonvoon [priv]
-S 1000 23339 23336 14620 1840 0.0 sshd sshd: tonvoon@pts/5
-Ss 1000 23340 23339 2996 1636 0.0 bash -bash
-S 0 23367 23340 3020 1628 0.0 bash bash
-S 1001 23370 23367 3064 1748 0.0 bash bash
-Ss 1001 23783 1 3220 764 0.0 ndo2db /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg
-Ss 1001 23784 1 6428 4948 0.0 import_ndologsd import_ndologsd
-S+ 1001 9803 18955 4132 1936 0.0 ssh ssh altinity@cube02.lei.altinity
-S 1001 22505 22324 20256 1616 0.0 nagios ../../bin/nagios -d /usr/local/nagios/etc/nagios.cfg
-S 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
-S 1001 22507 22506 1660 492 0.0 ping /bin/ping -n -U -w 10 -c 1 192.168.10.23
-R+ 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 348ec022..ebdae2e1 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -27,6 +27,8 @@
#include "utils_base.h"
#include <stdarg.h>
#include <limits.h>
+#include <string.h>
+#include <errno.h>
#include <arpa/inet.h>
@@ -239,6 +241,46 @@ is_intnonneg (char *number)
return FALSE;
}
+/*
+ * Checks whether the number in the string _number_ can be put inside a int64_t
+ * On success the number will be written to the _target_ address, if _target_ is not set
+ * to NULL.
+ */
+int is_int64(char *number, int64_t *target) {
+ errno = 0;
+ uint64_t tmp = strtoll(number, NULL, 10);
+ if (errno != 0) {
+ return 0;
+ }
+ if (tmp < INT64_MIN || tmp > INT64_MAX) {
+ return 0;
+ }
+ if (target != NULL) {
+ *target = tmp;
+ }
+ return 1;
+}
+
+/*
+ * Checks whether the number in the string _number_ can be put inside a uint64_t
+ * On success the number will be written to the _target_ address, if _target_ is not set
+ * to NULL.
+ */
+int is_uint64(char *number, uint64_t *target) {
+ errno = 0;
+ uint64_t tmp = strtoll(number, NULL, 10);
+ if (errno != 0) {
+ return 0;
+ }
+ if (tmp < 0 || tmp > UINT64_MAX) {
+ return 0;
+ }
+ if (target != NULL) {
+ *target = tmp;
+ }
+ return 1;
+}
+
int
is_intpercent (char *number)
{
@@ -556,6 +598,88 @@ char *perfdata (const char *label,
}
+char *perfdata_uint64 (const char *label,
+ uint64_t val,
+ const char *uom,
+ int warnp, /* Warning present */
+ uint64_t warn,
+ int critp, /* Critical present */
+ uint64_t crit,
+ int minp, /* Minimum present */
+ uint64_t minv,
+ int maxp, /* Maximum present */
+ uint64_t maxv)
+{
+ char *data = NULL;
+
+ if (strpbrk (label, "'= "))
+ xasprintf (&data, "'%s'=%ld%s;", label, val, uom);
+ else
+ xasprintf (&data, "%s=%ld%s;", label, val, uom);
+
+ if (warnp)
+ xasprintf (&data, "%s%lu;", data, warn);
+ else
+ xasprintf (&data, "%s;", data);
+
+ if (critp)
+ xasprintf (&data, "%s%lu;", data, crit);
+ else
+ xasprintf (&data, "%s;", data);
+
+ if (minp)
+ xasprintf (&data, "%s%lu;", data, minv);
+ else
+ xasprintf (&data, "%s;", data);
+
+ if (maxp)
+ xasprintf (&data, "%s%lu", data, maxv);
+
+ return data;
+}
+
+
+char *perfdata_int64 (const char *label,
+ int64_t val,
+ const char *uom,
+ int warnp, /* Warning present */
+ int64_t warn,
+ int critp, /* Critical present */
+ int64_t crit,
+ int minp, /* Minimum present */
+ int64_t minv,
+ int maxp, /* Maximum present */
+ int64_t maxv)
+{
+ char *data = NULL;
+
+ if (strpbrk (label, "'= "))
+ xasprintf (&data, "'%s'=%ld%s;", label, val, uom);
+ else
+ xasprintf (&data, "%s=%ld%s;", label, val, uom);
+
+ if (warnp)
+ xasprintf (&data, "%s%ld;", data, warn);
+ else
+ xasprintf (&data, "%s;", data);
+
+ if (critp)
+ xasprintf (&data, "%s%ld;", data, crit);
+ else
+ xasprintf (&data, "%s;", data);
+
+ if (minp)
+ xasprintf (&data, "%s%ld;", data, minv);
+ else
+ xasprintf (&data, "%s;", data);
+
+ if (maxp)
+ xasprintf (&data, "%s%ld", data, maxv);
+
+ return data;
+}
+
+
char *fperfdata (const char *label,
double val,
const char *uom,
diff --git a/plugins/utils.h b/plugins/utils.h
index 33a20547..5b54da3c 100644
--- a/plugins/utils.h
+++ b/plugins/utils.h
@@ -16,6 +16,7 @@ suite of plugins. */
/* now some functions etc are being defined in ../lib/utils_base.c */
#include "utils_base.h"
+
#ifdef NP_EXTRA_OPTS
/* Include extra-opts functions if compiled in */
#include "extra_opts.h"
@@ -38,6 +39,8 @@ int is_intpos (char *);
int is_intneg (char *);
int is_intnonneg (char *);
int is_intpercent (char *);
+int is_uint64(char *number, uint64_t *target);
+int is_int64(char *number, int64_t *target);
int is_numeric (char *);
int is_positive (char *);
@@ -88,6 +91,12 @@ void usage_va(const char *fmt, ...) __attribute__((noreturn));
char *perfdata (const char *, long int, const char *, int, long int,
int, long int, int, long int, int, long int);
+char *perfdata_uint64 (const char *, uint64_t , const char *, int, uint64_t,
+ int, uint64_t, int, uint64_t, int, uint64_t);
+
+char *perfdata_int64 (const char *, int64_t, const char *, int, int64_t,
+ int, int64_t, int, int64_t, int, int64_t);
+
char *fperfdata (const char *, double, const char *, int, double,
int, double, int, double, int, double);