summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Makefile.am2
-rw-r--r--plugins/check_apt.c2
-rw-r--r--plugins/check_by_ssh.c3
-rw-r--r--plugins/check_dig.c9
-rw-r--r--plugins/check_disk.c59
-rw-r--r--plugins/check_dns.c22
-rw-r--r--plugins/check_fping.c2
-rw-r--r--plugins/check_http.c45
-rw-r--r--plugins/check_ldap.c95
-rw-r--r--plugins/check_mrtgtraf.c14
-rw-r--r--plugins/check_nt.c51
-rw-r--r--plugins/check_ntp.c25
-rw-r--r--plugins/check_ntp_peer.c9
-rw-r--r--plugins/check_real.c10
-rw-r--r--plugins/check_snmp.c57
-rw-r--r--plugins/check_ssh.c12
-rw-r--r--plugins/check_swap.c3
-rw-r--r--plugins/check_tcp.c7
-rw-r--r--plugins/sslutils.c33
-rw-r--r--plugins/t/NPTest.cache.travis4
-rw-r--r--plugins/t/check_dns.t12
-rw-r--r--plugins/t/check_http.t43
-rw-r--r--plugins/t/check_ldap.t80
-rw-r--r--plugins/t/negate.t5
-rwxr-xr-xplugins/tests/check_http.t8
-rwxr-xr-xplugins/tests/check_snmp.t33
-rw-r--r--plugins/utils.c42
27 files changed, 557 insertions, 130 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 0ddf9bd..41906c5 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -71,7 +71,7 @@ check_apt_LDADD = $(BASEOBJS)
71check_cluster_LDADD = $(BASEOBJS) 71check_cluster_LDADD = $(BASEOBJS)
72check_dbi_LDADD = $(NETLIBS) $(DBILIBS) 72check_dbi_LDADD = $(NETLIBS) $(DBILIBS)
73check_dig_LDADD = $(NETLIBS) 73check_dig_LDADD = $(NETLIBS)
74check_disk_LDADD = $(BASEOBJS) 74check_disk_LDADD = $(BASEOBJS) $(THREADLIBS)
75check_dns_LDADD = $(NETLIBS) 75check_dns_LDADD = $(NETLIBS)
76check_dummy_LDADD = $(BASEOBJS) 76check_dummy_LDADD = $(BASEOBJS)
77check_fping_LDADD = $(NETLIBS) 77check_fping_LDADD = $(NETLIBS)
diff --git a/plugins/check_apt.c b/plugins/check_apt.c
index 07622c2..8747f90 100644
--- a/plugins/check_apt.c
+++ b/plugins/check_apt.c
@@ -224,7 +224,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
224 char *cmdline=NULL, rerrbuf[64]; 224 char *cmdline=NULL, rerrbuf[64];
225 225
226 /* initialize ereg as it is possible it is printed while uninitialized */ 226 /* initialize ereg as it is possible it is printed while uninitialized */
227 memset(&ereg, "\0", sizeof(ereg.buffer)); 227 memset(&ereg, '\0', sizeof(ereg.buffer));
228 228
229 if(upgrade==NO_UPGRADE) return STATE_OK; 229 if(upgrade==NO_UPGRADE) return STATE_OK;
230 230
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 58f333d..a877f88 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -169,7 +169,8 @@ process_arguments (int argc, char **argv)
169 {"verbose", no_argument, 0, 'v'}, 169 {"verbose", no_argument, 0, 'v'},
170 {"fork", no_argument, 0, 'f'}, 170 {"fork", no_argument, 0, 'f'},
171 {"timeout", required_argument, 0, 't'}, 171 {"timeout", required_argument, 0, 't'},
172 {"host", required_argument, 0, 'H'}, 172 {"host", required_argument, 0, 'H'}, /* backward compatibility */
173 {"hostname", required_argument, 0, 'H'},
173 {"port", required_argument,0,'p'}, 174 {"port", required_argument,0,'p'},
174 {"output", required_argument, 0, 'O'}, 175 {"output", required_argument, 0, 'O'},
175 {"name", required_argument, 0, 'n'}, 176 {"name", required_argument, 0, 'n'},
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index d9481f2..d899b11 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -94,8 +94,8 @@ main (int argc, char **argv)
94 timeout_interval_dig = timeout_interval / number_tries + number_tries; 94 timeout_interval_dig = timeout_interval / number_tries + number_tries;
95 95
96 /* get the command to run */ 96 /* get the command to run */
97 xasprintf (&command_line, "%s @%s -p %d %s -t %s %s %s +tries=%d +time=%d", 97 xasprintf (&command_line, "%s %s %s -p %d @%s %s %s +tries=%d +time=%d",
98 PATH_TO_DIG, dns_server, server_port, query_address, record_type, dig_args, query_transport, number_tries, timeout_interval_dig); 98 PATH_TO_DIG, dig_args, query_transport, server_port, dns_server, query_address, record_type, number_tries, timeout_interval_dig);
99 99
100 alarm (timeout_interval); 100 alarm (timeout_interval);
101 gettimeofday (&tv, NULL); 101 gettimeofday (&tv, NULL);
@@ -296,7 +296,10 @@ process_arguments (int argc, char **argv)
296 dns_server = argv[c]; 296 dns_server = argv[c];
297 } 297 }
298 else { 298 else {
299 dns_server = strdup ("127.0.0.1"); 299 if (strcmp(query_transport,"-6") == 0)
300 dns_server = strdup("::1");
301 else
302 dns_server = strdup ("127.0.0.1");
300 } 303 }
301 } 304 }
302 305
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 925dfa8..eb573f5 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -51,6 +51,9 @@ const char *email = "devel@monitoring-plugins.org";
51# include <limits.h> 51# include <limits.h>
52#endif 52#endif
53#include "regex.h" 53#include "regex.h"
54#if HAVE_PTHREAD_H
55# include <pthread.h>
56#endif
54 57
55#ifdef __CYGWIN__ 58#ifdef __CYGWIN__
56# include <windows.h> 59# include <windows.h>
@@ -130,6 +133,7 @@ void print_help (void);
130void print_usage (void); 133void print_usage (void);
131double calculate_percent(uintmax_t, uintmax_t); 134double calculate_percent(uintmax_t, uintmax_t);
132void stat_path (struct parameter_list *p); 135void stat_path (struct parameter_list *p);
136void *do_stat_path (void *p);
133void get_stats (struct parameter_list *p, struct fs_usage *fsp); 137void get_stats (struct parameter_list *p, struct fs_usage *fsp);
134void get_path_stats (struct parameter_list *p, struct fs_usage *fsp); 138void get_path_stats (struct parameter_list *p, struct fs_usage *fsp);
135 139
@@ -171,6 +175,7 @@ main (int argc, char **argv)
171 char *details; 175 char *details;
172 char *perf; 176 char *perf;
173 char *preamble; 177 char *preamble;
178 char *flag_header;
174 double inode_space_pct; 179 double inode_space_pct;
175 double warning_high_tide; 180 double warning_high_tide;
176 double critical_high_tide; 181 double critical_high_tide;
@@ -353,18 +358,23 @@ main (int argc, char **argv)
353 if (disk_result==STATE_OK && erronly && !verbose) 358 if (disk_result==STATE_OK && erronly && !verbose)
354 continue; 359 continue;
355 360
356 xasprintf (&output, "%s %s %.0f %s (%.0f%%", 361 if(disk_result && verbose >= 1) {
357 output, 362 xasprintf(&flag_header, " %s [", state_text (disk_result));
363 } else {
364 xasprintf(&flag_header, "");
365 }
366 xasprintf (&output, "%s%s %s %.0f %s (%.0f%%",
367 output, flag_header,
358 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 368 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
359 path->dfree_units, 369 path->dfree_units,
360 units, 370 units,
361 path->dfree_pct); 371 path->dfree_pct);
362 if (path->dused_inodes_percent < 0) { 372 if (path->dused_inodes_percent < 0) {
363 xasprintf(&output, "%s inode=-);", output); 373 xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : ""));
364 } else { 374 } else {
365 xasprintf(&output, "%s inode=%.0f%%);", output, path->dfree_inodes_percent ); 375 xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : ""));
366 } 376 }
367 377 free(flag_header);
368 /* TODO: Need to do a similar debug line 378 /* TODO: Need to do a similar debug line
369 xasprintf (&details, _("%s\n\ 379 xasprintf (&details, _("%s\n\
370%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), 380%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
@@ -962,6 +972,44 @@ print_usage (void)
962void 972void
963stat_path (struct parameter_list *p) 973stat_path (struct parameter_list *p)
964{ 974{
975#ifdef HAVE_PTHREAD_H
976 pthread_t stat_thread;
977 int statdone = 0;
978 int timer = timeout_interval;
979 struct timespec req, rem;
980
981 req.tv_sec = 0;
982 pthread_create(&stat_thread, NULL, do_stat_path, p);
983 while (timer-- > 0) {
984 req.tv_nsec = 10000000;
985 nanosleep(&req, &rem);
986 if (pthread_kill(stat_thread, 0)) {
987 statdone = 1;
988 break;
989 } else {
990 req.tv_nsec = 990000000;
991 nanosleep(&req, &rem);
992 }
993 }
994 if (statdone == 1) {
995 pthread_join(stat_thread, NULL);
996 } else {
997 pthread_detach(stat_thread);
998 if (verbose >= 3)
999 printf("stat did not return within %ds on %s\n", timeout_interval, p->name);
1000 printf("DISK %s - ", _("CRITICAL"));
1001 die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("hangs"), _("Timeout"));
1002 }
1003#else
1004 do_stat_path(p);
1005#endif
1006}
1007
1008void *
1009do_stat_path (void *in)
1010{
1011 struct parameter_list *p = in;
1012
965 /* Stat entry to check that dir exists and is accessible */ 1013 /* Stat entry to check that dir exists and is accessible */
966 if (verbose >= 3) 1014 if (verbose >= 3)
967 printf("calling stat on %s\n", p->name); 1015 printf("calling stat on %s\n", p->name);
@@ -971,6 +1019,7 @@ stat_path (struct parameter_list *p)
971 printf("DISK %s - ", _("CRITICAL")); 1019 printf("DISK %s - ", _("CRITICAL"));
972 die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno)); 1020 die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno));
973 } 1021 }
1022 return NULL;
974} 1023}
975 1024
976 1025
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 31a953d..2212122 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -136,6 +136,28 @@ main (int argc, char **argv)
136 } 136 }
137 } 137 }
138 138
139 /* bug ID: 2946553 - Older versions of bind will use all available dns
140 servers, we have to match the one specified */
141 if (strstr (chld_out.line[i], "Server:") && strlen(dns_server) > 0) {
142 temp_buffer = strchr (chld_out.line[i], ':');
143 temp_buffer++;
144
145 /* Strip leading tabs */
146 for (; *temp_buffer != '\0' && *temp_buffer == '\t'; temp_buffer++)
147 /* NOOP */;
148
149 strip(temp_buffer);
150 if (temp_buffer==NULL || strlen(temp_buffer)==0) {
151 die (STATE_CRITICAL,
152 _("DNS CRITICAL - '%s' returned empty server string\n"),
153 NSLOOKUP_COMMAND);
154 }
155
156 if (strcmp(temp_buffer, dns_server) != 0) {
157 die (STATE_CRITICAL, _("DNS CRITICAL - No response from DNS %s\n"), dns_server);
158 }
159 }
160
139 /* the server is responding, we just got the host name... */ 161 /* the server is responding, we just got the host name... */
140 if (strstr (chld_out.line[i], "Name:")) 162 if (strstr (chld_out.line[i], "Name:"))
141 parse_address = TRUE; 163 parse_address = TRUE;
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index 46046b4..274dd75 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -105,7 +105,7 @@ main (int argc, char **argv)
105 xasprintf(&option_string, "%s-I %s ", option_string, sourceif); 105 xasprintf(&option_string, "%s-I %s ", option_string, sourceif);
106 106
107#ifdef PATH_TO_FPING6 107#ifdef PATH_TO_FPING6
108 if (address_family == AF_INET6) 108 if (address_family != AF_INET && is_inet6_addr(server))
109 fping_prog = strdup(PATH_TO_FPING6); 109 fping_prog = strdup(PATH_TO_FPING6);
110 else 110 else
111 fping_prog = strdup(PATH_TO_FPING); 111 fping_prog = strdup(PATH_TO_FPING);
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 5167997..2437406 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -875,11 +875,35 @@ check_http (void)
875 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) 875 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK)
876 die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n")); 876 die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n"));
877 microsec_connect = deltime (tv_temp); 877 microsec_connect = deltime (tv_temp);
878
879 /* if we are called with the -I option, the -j method is CONNECT and */
880 /* we received -S for SSL, then we tunnel the request through a proxy*/
881 /* @20100414, public[at]frank4dd.com, http://www.frank4dd.com/howto */
882
883 if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0
884 && host_name != NULL && use_ssl == TRUE) {
885
886 if (verbose) printf ("Entering CONNECT tunnel mode with proxy %s:%d to dst %s:%d\n", server_address, server_port, host_name, HTTPS_PORT);
887 asprintf (&buf, "%s %s:%d HTTP/1.1\r\n%s\r\n", http_method, host_name, HTTPS_PORT, user_agent);
888 asprintf (&buf, "%sProxy-Connection: keep-alive\r\n", buf);
889 asprintf (&buf, "%sHost: %s\r\n", buf, host_name);
890 /* we finished our request, send empty line with CRLF */
891 asprintf (&buf, "%s%s", buf, CRLF);
892 if (verbose) printf ("%s\n", buf);
893 send(sd, buf, strlen (buf), 0);
894 buf[0]='\0';
895
896 if (verbose) printf ("Receive response from proxy\n");
897 read (sd, buffer, MAX_INPUT_BUFFER-1);
898 if (verbose) printf ("%s", buffer);
899 /* Here we should check if we got HTTP/1.1 200 Connection established */
900 }
878#ifdef HAVE_SSL 901#ifdef HAVE_SSL
879 elapsed_time_connect = (double)microsec_connect / 1.0e6; 902 elapsed_time_connect = (double)microsec_connect / 1.0e6;
880 if (use_ssl == TRUE) { 903 if (use_ssl == TRUE) {
881 gettimeofday (&tv_temp, NULL); 904 gettimeofday (&tv_temp, NULL);
882 result = np_net_ssl_init_with_hostname_version_and_cert(sd, (use_sni ? host_name : NULL), ssl_version, client_cert, client_privkey); 905 result = np_net_ssl_init_with_hostname_version_and_cert(sd, (use_sni ? host_name : NULL), ssl_version, client_cert, client_privkey);
906 if (verbose) printf ("SSL initialized\n");
883 if (result != STATE_OK) 907 if (result != STATE_OK)
884 die (STATE_CRITICAL, NULL); 908 die (STATE_CRITICAL, NULL);
885 microsec_ssl = deltime (tv_temp); 909 microsec_ssl = deltime (tv_temp);
@@ -893,7 +917,11 @@ check_http (void)
893 } 917 }
894#endif /* HAVE_SSL */ 918#endif /* HAVE_SSL */
895 919
896 xasprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); 920 if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0
921 && host_name != NULL && use_ssl == TRUE)
922 asprintf (&buf, "%s %s %s\r\n%s\r\n", "GET", server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent);
923 else
924 asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent);
897 925
898 /* tell HTTP/1.1 servers not to keep the connection alive */ 926 /* tell HTTP/1.1 servers not to keep the connection alive */
899 xasprintf (&buf, "%sConnection: close\r\n", buf); 927 xasprintf (&buf, "%sConnection: close\r\n", buf);
@@ -906,7 +934,9 @@ check_http (void)
906 * (default) port is explicitly specified in the "Host:" header line. 934 * (default) port is explicitly specified in the "Host:" header line.
907 */ 935 */
908 if ((use_ssl == FALSE && server_port == HTTP_PORT) || 936 if ((use_ssl == FALSE && server_port == HTTP_PORT) ||
909 (use_ssl == TRUE && server_port == HTTPS_PORT)) 937 (use_ssl == TRUE && server_port == HTTPS_PORT) ||
938 ( server_address != NULL && strcmp(http_method, "CONNECT") == 0
939 && host_name != NULL && use_ssl == TRUE))
910 xasprintf (&buf, "%sHost: %s\r\n", buf, host_name); 940 xasprintf (&buf, "%sHost: %s\r\n", buf, host_name);
911 else 941 else
912 xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port); 942 xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port);
@@ -1496,7 +1526,7 @@ print_help (void)
1496 printf (" %s\n", _("URL to GET or POST (default: /)")); 1526 printf (" %s\n", _("URL to GET or POST (default: /)"));
1497 printf (" %s\n", "-P, --post=STRING"); 1527 printf (" %s\n", "-P, --post=STRING");
1498 printf (" %s\n", _("URL encoded http POST data")); 1528 printf (" %s\n", _("URL encoded http POST data"));
1499 printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE)"); 1529 printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT)");
1500 printf (" %s\n", _("Set HTTP method.")); 1530 printf (" %s\n", _("Set HTTP method."));
1501 printf (" %s\n", "-N, --no-body"); 1531 printf (" %s\n", "-N, --no-body");
1502 printf (" %s\n", _("Don't wait for document body: stop reading after headers.")); 1532 printf (" %s\n", _("Don't wait for document body: stop reading after headers."));
@@ -1570,7 +1600,7 @@ print_help (void)
1570 printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 14 days,")); 1600 printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 14 days,"));
1571 printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than")); 1601 printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than"));
1572 printf (" %s\n", _("14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when")); 1602 printf (" %s\n", _("14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when"));
1573 printf (" %s\n", _("the certificate is expired.")); 1603 printf (" %s\n\n", _("the certificate is expired."));
1574 printf ("\n"); 1604 printf ("\n");
1575 printf (" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 30,14"); 1605 printf (" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 30,14");
1576 printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 30 days,")); 1606 printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 30 days,"));
@@ -1578,6 +1608,13 @@ print_help (void)
1578 printf (" %s\n", _("30 days, but more than 14 days, a STATE_WARNING is returned.")); 1608 printf (" %s\n", _("30 days, but more than 14 days, a STATE_WARNING is returned."));
1579 printf (" %s\n", _("A STATE_CRITICAL will be returned when certificate expires in less than 14 days")); 1609 printf (" %s\n", _("A STATE_CRITICAL will be returned when certificate expires in less than 14 days"));
1580 1610
1611 printf (" %s\n\n", "CHECK SSL WEBSERVER CONTENT VIA PROXY USING HTTP 1.1 CONNECT: ");
1612 printf (" %s\n", _("check_http -I 192.168.100.35 -p 80 -u https://www.verisign.com/ -S -j CONNECT -H www.verisign.com "));
1613 printf (" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> -S(sl) -j CONNECT -H <webserver>"));
1614 printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds"));
1615 printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,"));
1616 printf (" %s\n", _("a STATE_CRITICAL will be returned."));
1617
1581#endif 1618#endif
1582 1619
1583 printf (UT_SUPPORT); 1620 printf (UT_SUPPORT);
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c
index c371be9..cfc8222 100644
--- a/plugins/check_ldap.c
+++ b/plugins/check_ldap.c
@@ -1,29 +1,29 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Monitoring check_ldap plugin 3* Monitoring check_ldap plugin
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 2000-2008 Monitoring Plugins Development Team 6* Copyright (c) 2000-2008 Monitoring Plugins Development Team
7* 7*
8* Description: 8* Description:
9* 9*
10* This file contains the check_ldap plugin 10* This file contains the check_ldap plugin
11* 11*
12* 12*
13* This program is free software: you can redistribute it and/or modify 13* This program is free software: you can redistribute it and/or modify
14* it under the terms of the GNU General Public License as published by 14* it under the terms of the GNU General Public License as published by
15* the Free Software Foundation, either version 3 of the License, or 15* the Free Software Foundation, either version 3 of the License, or
16* (at your option) any later version. 16* (at your option) any later version.
17* 17*
18* This program is distributed in the hope that it will be useful, 18* This program is distributed in the hope that it will be useful,
19* but WITHOUT ANY WARRANTY; without even the implied warranty of 19* but WITHOUT ANY WARRANTY; without even the implied warranty of
20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21* GNU General Public License for more details. 21* GNU General Public License for more details.
22* 22*
23* You should have received a copy of the GNU General Public License 23* You should have received a copy of the GNU General Public License
24* along with this program. If not, see <http://www.gnu.org/licenses/>. 24* along with this program. If not, see <http://www.gnu.org/licenses/>.
25* 25*
26* 26*
27*****************************************************************************/ 27*****************************************************************************/
28 28
29/* progname may be check_ldaps */ 29/* progname may be check_ldaps */
@@ -67,7 +67,10 @@ int ld_protocol = DEFAULT_PROTOCOL;
67#endif 67#endif
68double warn_time = UNDEFINED; 68double warn_time = UNDEFINED;
69double crit_time = UNDEFINED; 69double crit_time = UNDEFINED;
70thresholds *entries_thresholds = NULL;
70struct timeval tv; 71struct timeval tv;
72char* warn_entries = NULL;
73char* crit_entries = NULL;
71int starttls = FALSE; 74int starttls = FALSE;
72int ssl_on_connect = FALSE; 75int ssl_on_connect = FALSE;
73int verbose = 0; 76int verbose = 0;
@@ -94,6 +97,12 @@ main (int argc, char *argv[])
94 int tls; 97 int tls;
95 int version=3; 98 int version=3;
96 99
100 /* for entry counting */
101
102 LDAPMessage *next_entry;
103 int status_entries = STATE_OK;
104 int num_entries = 0;
105
97 setlocale (LC_ALL, ""); 106 setlocale (LC_ALL, "");
98 bindtextdomain (PACKAGE, LOCALEDIR); 107 bindtextdomain (PACKAGE, LOCALEDIR);
99 textdomain (PACKAGE); 108 textdomain (PACKAGE);
@@ -197,12 +206,14 @@ main (int argc, char *argv[])
197 } 206 }
198 207
199 /* do a search of all objectclasses in the base dn */ 208 /* do a search of all objectclasses in the base dn */
200 if (ldap_search_s (ld, ld_base, LDAP_SCOPE_BASE, ld_attr, NULL, 0, &result) 209 if (ldap_search_s (ld, ld_base, (crit_entries!=NULL || warn_entries!=NULL) ? LDAP_SCOPE_SUBTREE : LDAP_SCOPE_BASE, ld_attr, NULL, 0, &result)
201 != LDAP_SUCCESS) { 210 != LDAP_SUCCESS) {
202 if (verbose) 211 if (verbose)
203 ldap_perror(ld, "ldap_search"); 212 ldap_perror(ld, "ldap_search");
204 printf (_("Could not search/find objectclasses in %s\n"), ld_base); 213 printf (_("Could not search/find objectclasses in %s\n"), ld_base);
205 return STATE_CRITICAL; 214 return STATE_CRITICAL;
215 } else if (crit_entries!=NULL || warn_entries!=NULL) {
216 num_entries = ldap_count_entries(ld, result);
206 } 217 }
207 218
208 /* unbind from the ldap server */ 219 /* unbind from the ldap server */
@@ -223,14 +234,42 @@ main (int argc, char *argv[])
223 else 234 else
224 status = STATE_OK; 235 status = STATE_OK;
225 236
237 if(entries_thresholds != NULL) {
238 if (verbose) {
239 printf ("entries found: %d\n", num_entries);
240 print_thresholds("entry threasholds", entries_thresholds);
241 }
242 status_entries = get_status(num_entries, entries_thresholds);
243 if (status_entries == STATE_CRITICAL) {
244 status = STATE_CRITICAL;
245 } else if (status != STATE_CRITICAL) {
246 status = status_entries;
247 }
248 }
249
226 /* print out the result */ 250 /* print out the result */
227 printf (_("LDAP %s - %.3f seconds response time|%s\n"), 251 if (crit_entries!=NULL || warn_entries!=NULL) {
228 state_text (status), 252 printf (_("LDAP %s - found %d entries in %.3f seconds|%s %s\n"),
229 elapsed_time, 253 state_text (status),
230 fperfdata ("time", elapsed_time, "s", 254 num_entries,
231 (int)warn_time, warn_time, 255 elapsed_time,
232 (int)crit_time, crit_time, 256 fperfdata ("time", elapsed_time, "s",
233 TRUE, 0, FALSE, 0)); 257 (int)warn_time, warn_time,
258 (int)crit_time, crit_time,
259 TRUE, 0, FALSE, 0),
260 sperfdata ("entries", (double)num_entries, "",
261 warn_entries,
262 crit_entries,
263 TRUE, 0.0, FALSE, 0.0));
264 } else {
265 printf (_("LDAP %s - %.3f seconds response time|%s\n"),
266 state_text (status),
267 elapsed_time,
268 fperfdata ("time", elapsed_time, "s",
269 (int)warn_time, warn_time,
270 (int)crit_time, crit_time,
271 TRUE, 0, FALSE, 0));
272 }
234 273
235 return status; 274 return status;
236} 275}
@@ -263,6 +302,8 @@ process_arguments (int argc, char **argv)
263 {"port", required_argument, 0, 'p'}, 302 {"port", required_argument, 0, 'p'},
264 {"warn", required_argument, 0, 'w'}, 303 {"warn", required_argument, 0, 'w'},
265 {"crit", required_argument, 0, 'c'}, 304 {"crit", required_argument, 0, 'c'},
305 {"warn-entries", required_argument, 0, 'W'},
306 {"crit-entries", required_argument, 0, 'C'},
266 {"verbose", no_argument, 0, 'v'}, 307 {"verbose", no_argument, 0, 'v'},
267 {0, 0, 0, 0} 308 {0, 0, 0, 0}
268 }; 309 };
@@ -276,7 +317,7 @@ process_arguments (int argc, char **argv)
276 } 317 }
277 318
278 while (1) { 319 while (1) {
279 c = getopt_long (argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:", longopts, &option); 320 c = getopt_long (argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:C:W:", longopts, &option);
280 321
281 if (c == -1 || c == EOF) 322 if (c == -1 || c == EOF)
282 break; 323 break;
@@ -318,6 +359,12 @@ process_arguments (int argc, char **argv)
318 case 'c': 359 case 'c':
319 crit_time = strtod (optarg, NULL); 360 crit_time = strtod (optarg, NULL);
320 break; 361 break;
362 case 'W':
363 warn_entries = optarg;
364 break;
365 case 'C':
366 crit_entries = optarg;
367 break;
321#ifdef HAVE_LDAP_SET_OPTION 368#ifdef HAVE_LDAP_SET_OPTION
322 case '2': 369 case '2':
323 ld_protocol = 2; 370 ld_protocol = 2;
@@ -381,6 +428,10 @@ validate_arguments ()
381 if (ld_base==NULL) 428 if (ld_base==NULL)
382 usage4 (_("Please specify the LDAP base\n")); 429 usage4 (_("Please specify the LDAP base\n"));
383 430
431 if (crit_entries!=NULL || warn_entries!=NULL) {
432 set_thresholds(&entries_thresholds,
433 warn_entries, crit_entries);
434 }
384 return OK; 435 return OK;
385} 436}
386 437
@@ -430,6 +481,11 @@ print_help (void)
430 481
431 printf (UT_WARN_CRIT); 482 printf (UT_WARN_CRIT);
432 483
484 printf (" %s\n", "-W [--warn-entries]");
485 printf (" %s\n", _("Number of found entries to result in warning status"));
486 printf (" %s\n", "-W [--crit-entries]");
487 printf (" %s\n", _("Number of found entries to result in critical status"));
488
433 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 489 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
434 490
435 printf (UT_VERBOSE); 491 printf (UT_VERBOSE);
@@ -441,6 +497,7 @@ print_help (void)
441 printf (" %s\n", _("'SSL on connect' will be used no matter how the plugin was called.")); 497 printf (" %s\n", _("'SSL on connect' will be used no matter how the plugin was called."));
442 printf (" %s\n", _("This detection is deprecated, please use 'check_ldap' with the '--starttls' or '--ssl' flags")); 498 printf (" %s\n", _("This detection is deprecated, please use 'check_ldap' with the '--starttls' or '--ssl' flags"));
443 printf (" %s\n", _("to define the behaviour explicitly instead.")); 499 printf (" %s\n", _("to define the behaviour explicitly instead."));
500 printf (" %s\n", _("The parameters --warn-entries and --crit-entries are optional."));
444 501
445 printf (UT_SUPPORT); 502 printf (UT_SUPPORT);
446} 503}
diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c
index 32ba050..3b038cf 100644
--- a/plugins/check_mrtgtraf.c
+++ b/plugins/check_mrtgtraf.c
@@ -148,37 +148,37 @@ main (int argc, char **argv)
148 148
149 /* report incoming traffic in Bytes/sec */ 149 /* report incoming traffic in Bytes/sec */
150 if (incoming_rate < 1024) { 150 if (incoming_rate < 1024) {
151 strcpy (incoming_speed_rating, "B/s"); 151 strcpy (incoming_speed_rating, "B");
152 adjusted_incoming_rate = (double) incoming_rate; 152 adjusted_incoming_rate = (double) incoming_rate;
153 } 153 }
154 154
155 /* report incoming traffic in KBytes/sec */ 155 /* report incoming traffic in KBytes/sec */
156 else if (incoming_rate < (1024 * 1024)) { 156 else if (incoming_rate < (1024 * 1024)) {
157 strcpy (incoming_speed_rating, "KB/s"); 157 strcpy (incoming_speed_rating, "KB");
158 adjusted_incoming_rate = (double) (incoming_rate / 1024.0); 158 adjusted_incoming_rate = (double) (incoming_rate / 1024.0);
159 } 159 }
160 160
161 /* report incoming traffic in MBytes/sec */ 161 /* report incoming traffic in MBytes/sec */
162 else { 162 else {
163 strcpy (incoming_speed_rating, "MB/s"); 163 strcpy (incoming_speed_rating, "MB");
164 adjusted_incoming_rate = (double) (incoming_rate / 1024.0 / 1024.0); 164 adjusted_incoming_rate = (double) (incoming_rate / 1024.0 / 1024.0);
165 } 165 }
166 166
167 /* report outgoing traffic in Bytes/sec */ 167 /* report outgoing traffic in Bytes/sec */
168 if (outgoing_rate < 1024) { 168 if (outgoing_rate < 1024) {
169 strcpy (outgoing_speed_rating, "B/s"); 169 strcpy (outgoing_speed_rating, "B");
170 adjusted_outgoing_rate = (double) outgoing_rate; 170 adjusted_outgoing_rate = (double) outgoing_rate;
171 } 171 }
172 172
173 /* report outgoing traffic in KBytes/sec */ 173 /* report outgoing traffic in KBytes/sec */
174 else if (outgoing_rate < (1024 * 1024)) { 174 else if (outgoing_rate < (1024 * 1024)) {
175 strcpy (outgoing_speed_rating, "KB/s"); 175 strcpy (outgoing_speed_rating, "KB");
176 adjusted_outgoing_rate = (double) (outgoing_rate / 1024.0); 176 adjusted_outgoing_rate = (double) (outgoing_rate / 1024.0);
177 } 177 }
178 178
179 /* report outgoing traffic in MBytes/sec */ 179 /* report outgoing traffic in MBytes/sec */
180 else { 180 else {
181 strcpy (outgoing_speed_rating, "MB/s"); 181 strcpy (outgoing_speed_rating, "MB");
182 adjusted_outgoing_rate = (double) (outgoing_rate / 1024.0 / 1024.0); 182 adjusted_outgoing_rate = (double) (outgoing_rate / 1024.0 / 1024.0);
183 } 183 }
184 184
@@ -191,7 +191,7 @@ main (int argc, char **argv)
191 result = STATE_WARNING; 191 result = STATE_WARNING;
192 } 192 }
193 193
194 xasprintf (&error_message, _("%s. In = %0.1f %s, %s. Out = %0.1f %s|%s %s\n"), 194 xasprintf (&error_message, _("%s. In = %0.1f %s/s, %s. Out = %0.1f %s/s|%s %s\n"),
195 (use_average == TRUE) ? _("Avg") : _("Max"), adjusted_incoming_rate, 195 (use_average == TRUE) ? _("Avg") : _("Max"), adjusted_incoming_rate,
196 incoming_speed_rating, (use_average == TRUE) ? _("Avg") : _("Max"), 196 incoming_speed_rating, (use_average == TRUE) ? _("Avg") : _("Max"),
197 adjusted_outgoing_rate, outgoing_speed_rating, 197 adjusted_outgoing_rate, outgoing_speed_rating,
diff --git a/plugins/check_nt.c b/plugins/check_nt.c
index fefbfb7..f621b0a 100644
--- a/plugins/check_nt.c
+++ b/plugins/check_nt.c
@@ -197,19 +197,40 @@ int main(int argc, char **argv){
197 197
198 case CHECK_UPTIME: 198 case CHECK_UPTIME:
199 199
200 xasprintf(&send_buffer, "%s&3", req_password); 200 if (value_list == NULL) {
201 fetch_data (server_address, server_port, send_buffer); 201 value_list = "minutes";
202 uptime=strtoul(recv_buffer,NULL,10); 202 }
203 updays = uptime / 86400; 203 if (strncmp(value_list, "seconds", strlen("seconds") + 1 ) &&
204 uphours = (uptime % 86400) / 3600; 204 strncmp(value_list, "minutes", strlen("minutes") + 1) &&
205 upminutes = ((uptime % 86400) % 3600) / 60; 205 strncmp(value_list, "hours", strlen("hours") + 1) &&
206 xasprintf(&output_message,_("System Uptime - %u day(s) %u hour(s) %u minute(s)|uptime=%lu"), updays, uphours, upminutes, uptime); 206 strncmp(value_list, "days", strlen("days") + 1)) {
207 if (check_critical_value==TRUE && uptime <= critical_value) 207
208 return_code=STATE_CRITICAL; 208 output_message = strdup (_("wrong -l argument"));
209 else if (check_warning_value==TRUE && uptime <= warning_value) 209 } else {
210 return_code=STATE_WARNING; 210 xasprintf(&send_buffer, "%s&3", req_password);
211 else 211 fetch_data (server_address, server_port, send_buffer);
212 return_code=STATE_OK; 212 uptime=strtoul(recv_buffer,NULL,10);
213 updays = uptime / 86400;
214 uphours = (uptime % 86400) / 3600;
215 upminutes = ((uptime % 86400) % 3600) / 60;
216
217 if (!strncmp(value_list, "minutes", strlen("minutes")))
218 uptime = uptime / 60;
219 else if (!strncmp(value_list, "hours", strlen("hours")))
220 uptime = uptime / 3600;
221 else if (!strncmp(value_list, "days", strlen("days")))
222 uptime = uptime / 86400;
223 /* else uptime in seconds, nothing to do */
224
225 xasprintf(&output_message,_("System Uptime - %u day(s) %u hour(s) %u minute(s) |uptime=%lu"),updays, uphours, upminutes, uptime);
226
227 if (check_critical_value==TRUE && uptime <= critical_value)
228 return_code=STATE_CRITICAL;
229 else if (check_warning_value==TRUE && uptime <= warning_value)
230 return_code=STATE_WARNING;
231 else
232 return_code=STATE_OK;
233 }
213 break; 234 break;
214 235
215 case CHECK_USEDDISKSPACE: 236 case CHECK_USEDDISKSPACE:
@@ -713,7 +734,9 @@ void print_help(void)
713 printf (" %s\n", "ie: -l 60,90,95,120,90,95"); 734 printf (" %s\n", "ie: -l 60,90,95,120,90,95");
714 printf (" %s\n", "UPTIME ="); 735 printf (" %s\n", "UPTIME =");
715 printf (" %s\n", _("Get the uptime of the machine.")); 736 printf (" %s\n", _("Get the uptime of the machine."));
716 printf (" %s\n", _("No specific parameters. No warning or critical threshold")); 737 printf (" %s\n", _("-l <unit> "));
738 printf (" %s\n", _("<unit> = seconds, minutes, hours, or days. (default: minutes)"));
739 printf (" %s\n", _("Thresholds will use the unit specified above."));
717 printf (" %s\n", "USEDDISKSPACE ="); 740 printf (" %s\n", "USEDDISKSPACE =");
718 printf (" %s\n", _("Size and percentage of disk use.")); 741 printf (" %s\n", _("Size and percentage of disk use."));
719 printf (" %s\n", _("Request a -l parameter containing the drive letter only.")); 742 printf (" %s\n", _("Request a -l parameter containing the drive letter only."));
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c
index 09a923e..a7d278d 100644
--- a/plugins/check_ntp.c
+++ b/plugins/check_ntp.c
@@ -517,14 +517,13 @@ setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){
517double jitter_request(const char *host, int *status){ 517double jitter_request(const char *host, int *status){
518 int conn=-1, i, npeers=0, num_candidates=0, syncsource_found=0; 518 int conn=-1, i, npeers=0, num_candidates=0, syncsource_found=0;
519 int run=0, min_peer_sel=PEER_INCLUDED, num_selected=0, num_valid=0; 519 int run=0, min_peer_sel=PEER_INCLUDED, num_selected=0, num_valid=0;
520 int peers_size=0, peer_offset=0, bytes_read=0; 520 int peers_size=0, peer_offset=0;
521 ntp_assoc_status_pair *peers=NULL; 521 ntp_assoc_status_pair *peers=NULL;
522 ntp_control_message req; 522 ntp_control_message req;
523 const char *getvar = "jitter"; 523 const char *getvar = "jitter";
524 double rval = 0.0, jitter = -1.0; 524 double rval = 0.0, jitter = -1.0;
525 char *startofvalue=NULL, *nptr=NULL; 525 char *startofvalue=NULL, *nptr=NULL;
526 void *tmp; 526 void *tmp;
527 int ntp_cm_ints = sizeof(uint16_t) * 5 + sizeof(uint8_t) * 2;
528 527
529 /* Long-winded explanation: 528 /* Long-winded explanation:
530 * Getting the jitter requires a number of steps: 529 * Getting the jitter requires a number of steps:
@@ -591,6 +590,9 @@ double jitter_request(const char *host, int *status){
591 for (i = 0; i < npeers; i++){ 590 for (i = 0; i < npeers; i++){
592 /* Only query this server if it is the current sync source */ 591 /* Only query this server if it is the current sync source */
593 if (PEER_SEL(peers[i].status) >= min_peer_sel){ 592 if (PEER_SEL(peers[i].status) >= min_peer_sel){
593 char jitter_data[MAX_CM_SIZE+1];
594 size_t jitter_data_count;
595
594 num_selected++; 596 num_selected++;
595 setup_control_request(&req, OP_READVAR, 2); 597 setup_control_request(&req, OP_READVAR, 2);
596 req.assoc = peers[i].assoc; 598 req.assoc = peers[i].assoc;
@@ -609,15 +611,7 @@ double jitter_request(const char *host, int *status){
609 611
610 req.count = htons(MAX_CM_SIZE); 612 req.count = htons(MAX_CM_SIZE);
611 DBG(printf("recieving READVAR response...\n")); 613 DBG(printf("recieving READVAR response...\n"));
612 614 read(conn, &req, SIZEOF_NTPCM(req));
613 /* cov-66524 - req.data not null terminated before usage. Also covers verifying struct was returned correctly*/
614 if ((bytes_read = read(conn, &req, SIZEOF_NTPCM(req))) == -1)
615 die(STATE_UNKNOWN, _("Cannot read from socket: %s"), strerror(errno));
616 if (bytes_read != ntp_cm_ints + req.count)
617 die(STATE_UNKNOWN, _("Invalid NTP response: %d bytes read does not equal %d plus %d data segment"), bytes_read, ntp_cm_ints, req.count);
618 /* else null terminate */
619 strncpy(req.data[req.count], "\0", 1);
620
621 DBG(print_ntp_control_message(&req)); 615 DBG(print_ntp_control_message(&req));
622 616
623 if(req.op&REM_ERROR && strstr(getvar, "jitter")) { 617 if(req.op&REM_ERROR && strstr(getvar, "jitter")) {
@@ -632,7 +626,14 @@ double jitter_request(const char *host, int *status){
632 if(verbose) { 626 if(verbose) {
633 printf("parsing jitter from peer %.2x: ", ntohs(peers[i].assoc)); 627 printf("parsing jitter from peer %.2x: ", ntohs(peers[i].assoc));
634 } 628 }
635 startofvalue = strchr(req.data, '='); 629 if((jitter_data_count = ntohs(req.count)) >= sizeof(jitter_data)){
630 die(STATE_UNKNOWN,
631 _("jitter response too large (%lu bytes)\n"),
632 (unsigned long)jitter_data_count);
633 }
634 memcpy(jitter_data, req.data, jitter_data_count);
635 jitter_data[jitter_data_count] = '\0';
636 startofvalue = strchr(jitter_data, '=');
636 if(startofvalue != NULL) { 637 if(startofvalue != NULL) {
637 startofvalue++; 638 startofvalue++;
638 jitter = strtod(startofvalue, &nptr); 639 jitter = strtod(startofvalue, &nptr);
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c
index d3ae599..44424af 100644
--- a/plugins/check_ntp_peer.c
+++ b/plugins/check_ntp_peer.c
@@ -599,17 +599,20 @@ int main(int argc, char *argv[]){
599 } 599 }
600 oresult = result; 600 oresult = result;
601 601
602 if(do_truechimers) 602 if(do_truechimers) {
603 tresult = get_status(num_truechimers, truechimer_thresholds); 603 tresult = get_status(num_truechimers, truechimer_thresholds);
604 result = max_state_alt(result, tresult); 604 result = max_state_alt(result, tresult);
605 }
605 606
606 if(do_stratum) 607 if(do_stratum) {
607 sresult = get_status(stratum, stratum_thresholds); 608 sresult = get_status(stratum, stratum_thresholds);
608 result = max_state_alt(result, sresult); 609 result = max_state_alt(result, sresult);
610 }
609 611
610 if(do_jitter) 612 if(do_jitter) {
611 jresult = get_status(jitter, jitter_thresholds); 613 jresult = get_status(jitter, jitter_thresholds);
612 result = max_state_alt(result, jresult); 614 result = max_state_alt(result, jresult);
615 }
613 616
614 switch (result) { 617 switch (result) {
615 case STATE_CRITICAL : 618 case STATE_CRITICAL :
diff --git a/plugins/check_real.c b/plugins/check_real.c
index 36f6413..00bd4d2 100644
--- a/plugins/check_real.c
+++ b/plugins/check_real.c
@@ -163,22 +163,22 @@ main (int argc, char **argv)
163 163
164 /* Part I - Server Check */ 164 /* Part I - Server Check */
165 165
166 /* send the OPTIONS request */ 166 /* send the DESCRIBE request */
167 sprintf (buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\n", host_name, 167 sprintf (buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\r\n", host_name,
168 server_port, server_url); 168 server_port, server_url);
169 result = send (sd, buffer, strlen (buffer), 0); 169 result = send (sd, buffer, strlen (buffer), 0);
170 170
171 /* send the header sync */ 171 /* send the header sync */
172 sprintf (buffer, "CSeq: 2\n"); 172 sprintf (buffer, "CSeq: 2\r\n");
173 result = send (sd, buffer, strlen (buffer), 0); 173 result = send (sd, buffer, strlen (buffer), 0);
174 174
175 /* send a newline so the server knows we're done with the request */ 175 /* send a newline so the server knows we're done with the request */
176 sprintf (buffer, "\n"); 176 sprintf (buffer, "\r\n");
177 result = send (sd, buffer, strlen (buffer), 0); 177 result = send (sd, buffer, strlen (buffer), 0);
178 178
179 /* watch for the REAL connection string */ 179 /* watch for the REAL connection string */
180 result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); 180 result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0);
181 buffer[result] = "\0"; /* null terminate recieved buffer */ 181 buffer[result] = '\0'; /* null terminate recieved buffer */
182 182
183 /* return a CRITICAL status if we couldn't read any data */ 183 /* return a CRITICAL status if we couldn't read any data */
184 if (result == -1) { 184 if (result == -1) {
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 2c62a23..62e6b8b 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -104,6 +104,8 @@ int errcode, excode;
104 104
105char *server_address = NULL; 105char *server_address = NULL;
106char *community = NULL; 106char *community = NULL;
107char **contextargs = NULL;
108char *context = NULL;
107char **authpriv = NULL; 109char **authpriv = NULL;
108char *proto = NULL; 110char *proto = NULL;
109char *seclevel = NULL; 111char *seclevel = NULL;
@@ -128,6 +130,7 @@ size_t nunits = 0;
128size_t unitv_size = OID_COUNT_STEP; 130size_t unitv_size = OID_COUNT_STEP;
129int numoids = 0; 131int numoids = 0;
130int numauthpriv = 0; 132int numauthpriv = 0;
133int numcontext = 0;
131int verbose = 0; 134int verbose = 0;
132int usesnmpgetnext = FALSE; 135int usesnmpgetnext = FALSE;
133char *warning_thresholds = NULL; 136char *warning_thresholds = NULL;
@@ -297,8 +300,8 @@ main (int argc, char **argv)
297 snmpcmd = strdup (PATH_TO_SNMPGET); 300 snmpcmd = strdup (PATH_TO_SNMPGET);
298 } 301 }
299 302
300 /* 10 arguments to pass before authpriv options + 1 for host and numoids. Add one for terminating NULL */ 303 /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */
301 command_line = calloc (10 + numauthpriv + 1 + numoids + 1, sizeof (char *)); 304 command_line = calloc (10 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *));
302 command_line[0] = snmpcmd; 305 command_line[0] = snmpcmd;
303 command_line[1] = strdup ("-Le"); 306 command_line[1] = strdup ("-Le");
304 command_line[2] = strdup ("-t"); 307 command_line[2] = strdup ("-t");
@@ -310,23 +313,27 @@ main (int argc, char **argv)
310 command_line[8] = "-v"; 313 command_line[8] = "-v";
311 command_line[9] = strdup (proto); 314 command_line[9] = strdup (proto);
312 315
316 for (i = 0; i < numcontext; i++) {
317 command_line[10 + i] = contextargs[i];
318 }
319
313 for (i = 0; i < numauthpriv; i++) { 320 for (i = 0; i < numauthpriv; i++) {
314 command_line[10 + i] = authpriv[i]; 321 command_line[10 + numcontext + i] = authpriv[i];
315 } 322 }
316 323
317 xasprintf (&command_line[10 + numauthpriv], "%s:%s", server_address, port); 324 xasprintf (&command_line[10 + numcontext + numauthpriv], "%s:%s", server_address, port);
318 325
319 /* This is just for display purposes, so it can remain a string */ 326 /* This is just for display purposes, so it can remain a string */
320 xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s:%s", 327 xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s %s:%s",
321 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]", 328 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[context]", "[authpriv]",
322 server_address, port); 329 server_address, port);
323 330
324 for (i = 0; i < numoids; i++) { 331 for (i = 0; i < numoids; i++) {
325 command_line[10 + numauthpriv + 1 + i] = oids[i]; 332 command_line[10 + numcontext + numauthpriv + 1 + i] = oids[i];
326 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); 333 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
327 } 334 }
328 335
329 command_line[10 + numauthpriv + 1 + numoids] = NULL; 336 command_line[10 + numcontext + numauthpriv + 1 + numoids] = NULL;
330 337
331 if (verbose) 338 if (verbose)
332 printf ("%s\n", cl_hidden_auth); 339 printf ("%s\n", cl_hidden_auth);
@@ -411,6 +418,9 @@ main (int argc, char **argv)
411 else if (strstr (response, "INTEGER: ")) { 418 else if (strstr (response, "INTEGER: ")) {
412 show = strstr (response, "INTEGER: ") + 9; 419 show = strstr (response, "INTEGER: ") + 9;
413 } 420 }
421 else if (strstr (response, "OID: ")) {
422 show = strstr (response, "OID: ") + 5;
423 }
414 else if (strstr (response, "STRING: ")) { 424 else if (strstr (response, "STRING: ")) {
415 show = strstr (response, "STRING: ") + 8; 425 show = strstr (response, "STRING: ") + 8;
416 conv = "%.10g"; 426 conv = "%.10g";
@@ -567,6 +577,18 @@ main (int argc, char **argv)
567 len = sizeof(perfstr)-strlen(perfstr)-1; 577 len = sizeof(perfstr)-strlen(perfstr)-1;
568 strncat(perfstr, show, len>ptr-show ? ptr-show : len); 578 strncat(perfstr, show, len>ptr-show ? ptr-show : len);
569 579
580 if (warning_thresholds) {
581 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1);
582 strncat(perfstr, warning_thresholds, sizeof(perfstr)-strlen(perfstr)-1);
583 }
584
585 if (critical_thresholds) {
586 if (!warning_thresholds)
587 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1);
588 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1);
589 strncat(perfstr, critical_thresholds, sizeof(perfstr)-strlen(perfstr)-1);
590 }
591
570 if (type) 592 if (type)
571 strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); 593 strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);
572 strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); 594 strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1);
@@ -646,6 +668,7 @@ process_arguments (int argc, char **argv)
646 {"retries", required_argument, 0, 'e'}, 668 {"retries", required_argument, 0, 'e'},
647 {"miblist", required_argument, 0, 'm'}, 669 {"miblist", required_argument, 0, 'm'},
648 {"protocol", required_argument, 0, 'P'}, 670 {"protocol", required_argument, 0, 'P'},
671 {"context", required_argument, 0, 'N'},
649 {"seclevel", required_argument, 0, 'L'}, 672 {"seclevel", required_argument, 0, 'L'},
650 {"secname", required_argument, 0, 'U'}, 673 {"secname", required_argument, 0, 'U'},
651 {"authproto", required_argument, 0, 'a'}, 674 {"authproto", required_argument, 0, 'a'},
@@ -675,7 +698,7 @@ process_arguments (int argc, char **argv)
675 } 698 }
676 699
677 while (1) { 700 while (1) {
678 c = getopt_long (argc, argv, "nhvVOt:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:L:U:a:x:A:X:", 701 c = getopt_long (argc, argv, "nhvVOt:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:N:L:U:a:x:A:X:",
679 longopts, &option); 702 longopts, &option);
680 703
681 if (c == -1 || c == EOF) 704 if (c == -1 || c == EOF)
@@ -713,6 +736,9 @@ process_arguments (int argc, char **argv)
713 case 'P': /* SNMP protocol version */ 736 case 'P': /* SNMP protocol version */
714 proto = optarg; 737 proto = optarg;
715 break; 738 break;
739 case 'N': /* SNMPv3 context */
740 context = optarg;
741 break;
716 case 'L': /* security level */ 742 case 'L': /* security level */
717 seclevel = optarg; 743 seclevel = optarg;
718 break; 744 break;
@@ -960,6 +986,13 @@ validate_arguments ()
960 authpriv[1] = strdup (community); 986 authpriv[1] = strdup (community);
961 } 987 }
962 else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */ 988 else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */
989 if (!(context == NULL)) {
990 numcontext = 2;
991 contextargs = calloc (numcontext, sizeof (char *));
992 contextargs[0] = strdup ("-n");
993 contextargs[1] = strdup (context);
994 }
995
963 if (seclevel == NULL) 996 if (seclevel == NULL)
964 xasprintf(&seclevel, "noAuthNoPriv"); 997 xasprintf(&seclevel, "noAuthNoPriv");
965 998
@@ -1103,6 +1136,8 @@ print_help (void)
1103 printf (" %s\n", _("Use SNMP GETNEXT instead of SNMP GET")); 1136 printf (" %s\n", _("Use SNMP GETNEXT instead of SNMP GET"));
1104 printf (" %s\n", "-P, --protocol=[1|2c|3]"); 1137 printf (" %s\n", "-P, --protocol=[1|2c|3]");
1105 printf (" %s\n", _("SNMP protocol version")); 1138 printf (" %s\n", _("SNMP protocol version"));
1139 printf (" %s\n", "-N, --context=CONTEXT");
1140 printf (" %s\n", _("SNMPv3 context"));
1106 printf (" %s\n", "-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]"); 1141 printf (" %s\n", "-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]");
1107 printf (" %s\n", _("SNMPv3 securityLevel")); 1142 printf (" %s\n", _("SNMPv3 securityLevel"));
1108 printf (" %s\n", "-a, --authproto=[MD5|SHA]"); 1143 printf (" %s\n", "-a, --authproto=[MD5|SHA]");
@@ -1210,6 +1245,6 @@ print_usage (void)
1210 printf ("%s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range]\n",progname); 1245 printf ("%s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range]\n",progname);
1211 printf ("[-C community] [-s string] [-r regex] [-R regexi] [-t timeout] [-e retries]\n"); 1246 printf ("[-C community] [-s string] [-r regex] [-R regexi] [-t timeout] [-e retries]\n");
1212 printf ("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n"); 1247 printf ("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n");
1213 printf ("[-m miblist] [-P snmp version] [-L seclevel] [-U secname] [-a authproto]\n"); 1248 printf ("[-m miblist] [-P snmp version] [-N context] [-L seclevel] [-U secname]\n");
1214 printf ("[-A authpasswd] [-x privproto] [-X privpasswd]\n"); 1249 printf ("[-a authproto] [-A authpasswd] [-x privproto] [-X privpasswd]\n");
1215} 1250}
diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c
index b6187d6..3658965 100644
--- a/plugins/check_ssh.c
+++ b/plugins/check_ssh.c
@@ -253,18 +253,18 @@ ssh_connect (char *haddr, int hport, char *remote_version, char *remote_protocol
253 253
254 if (remote_version && strcmp(remote_version, ssh_server)) { 254 if (remote_version && strcmp(remote_version, ssh_server)) {
255 printf 255 printf
256 (_("SSH WARNING - %s (protocol %s) version mismatch, expected '%s'\n"), 256 (_("SSH CRITICAL - %s (protocol %s) version mismatch, expected '%s'\n"),
257 ssh_server, ssh_proto, remote_version); 257 ssh_server, ssh_proto, remote_version);
258 close(sd); 258 close(sd);
259 exit (STATE_WARNING); 259 exit (STATE_CRITICAL);
260 } 260 }
261 261
262 if (remote_protocol && strcmp(remote_protocol, ssh_proto)) { 262 if (remote_protocol && strcmp(remote_protocol, ssh_proto)) {
263 printf 263 printf
264 (_("SSH WARNING - %s (protocol %s) protocol version mismatch, expected '%s'\n"), 264 (_("SSH CRITICAL - %s (protocol %s) protocol version mismatch, expected '%s'\n"),
265 ssh_server, ssh_proto, remote_protocol); 265 ssh_server, ssh_proto, remote_protocol);
266 close(sd); 266 close(sd);
267 exit (STATE_WARNING); 267 exit (STATE_CRITICAL);
268 } 268 }
269 269
270 elapsed_time = (double)deltime(tv) / 1.0e6; 270 elapsed_time = (double)deltime(tv) / 1.0e6;
@@ -307,10 +307,10 @@ print_help (void)
307 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 307 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
308 308
309 printf (" %s\n", "-r, --remote-version=STRING"); 309 printf (" %s\n", "-r, --remote-version=STRING");
310 printf (" %s\n", _("Warn if string doesn't match expected server version (ex: OpenSSH_3.9p1)")); 310 printf (" %s\n", _("Alert if string doesn't match expected server version (ex: OpenSSH_3.9p1)"));
311 311
312 printf (" %s\n", "-P, --remote-protocol=STRING"); 312 printf (" %s\n", "-P, --remote-protocol=STRING");
313 printf (" %s\n", _("Warn if protocol doesn't match expected protocol version (ex: 2.0)")); 313 printf (" %s\n", _("Alert if protocol doesn't match expected protocol version (ex: 2.0)"));
314 314
315 printf (UT_VERBOSE); 315 printf (UT_VERBOSE);
316 316
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 88a2a2a..25e0bac 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -1,6 +1,6 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Monitoring check_disk plugin 3* Monitoring check_swap plugin
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net) 6* Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net)
@@ -352,6 +352,7 @@ main (int argc, char **argv)
352 percent_used = 100 * ((double) used_swap_mb) / ((double) total_swap_mb); 352 percent_used = 100 * ((double) used_swap_mb) / ((double) total_swap_mb);
353 } else { 353 } else {
354 percent_used = 100; 354 percent_used = 100;
355 status = "- Swap is either disabled, not present, or of zero size. ";
355 } 356 }
356 357
357 result = max_state (result, check_swap (percent_used, free_swap_mb)); 358 result = max_state (result, check_swap (percent_used, free_swap_mb));
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index f75c523..5c563d8 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -172,7 +172,7 @@ main (int argc, char **argv)
172 } 172 }
173 else if (!strncmp(SERVICE, "JABBER", 6)) { 173 else if (!strncmp(SERVICE, "JABBER", 6)) {
174 SEND = "<stream:stream to=\'host\' xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'>\n"; 174 SEND = "<stream:stream to=\'host\' xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'>\n";
175 EXPECT = "<?xml version=\'1.0\'?><stream:stream xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'"; 175 EXPECT = "<?xml version=\'1.0\'";
176 QUIT = "</stream:stream>\n"; 176 QUIT = "</stream:stream>\n";
177 flags |= FLAG_HIDE_OUTPUT; 177 flags |= FLAG_HIDE_OUTPUT;
178 PORT = 5222; 178 PORT = 5222;
@@ -577,7 +577,8 @@ process_arguments (int argc, char **argv)
577 if ((temp=strchr(optarg,','))!=NULL) { 577 if ((temp=strchr(optarg,','))!=NULL) {
578 *temp='\0'; 578 *temp='\0';
579 if (!is_intnonneg (optarg)) 579 if (!is_intnonneg (optarg))
580 usage2 (_("Invalid certificate expiration period"), optarg); days_till_exp_warn = atoi(optarg); 580 usage2 (_("Invalid certificate expiration period"), optarg);
581 days_till_exp_warn = atoi (optarg);
581 *temp=','; 582 *temp=',';
582 temp++; 583 temp++;
583 if (!is_intnonneg (temp)) 584 if (!is_intnonneg (temp))
@@ -643,7 +644,7 @@ print_help (void)
643 printf (UT_IPv46); 644 printf (UT_IPv46);
644 645
645 printf (" %s\n", "-E, --escape"); 646 printf (" %s\n", "-E, --escape");
646 printf (" %s\n", _("Can use \\n, \\r, \\t or \\ in send or quit string. Must come before send or quit option")); 647 printf (" %s\n", _("Can use \\n, \\r, \\t or \\\\ in send or quit string. Must come before send or quit option"));
647 printf (" %s\n", _("Default: nothing added to send, \\r\\n added to end of quit")); 648 printf (" %s\n", _("Default: nothing added to send, \\r\\n added to end of quit"));
648 printf (" %s\n", "-s, --send=STRING"); 649 printf (" %s\n", "-s, --send=STRING");
649 printf (" %s\n", _("String to send to the server")); 650 printf (" %s\n", _("String to send to the server"));
diff --git a/plugins/sslutils.c b/plugins/sslutils.c
index d0ae474..c9882c6 100644
--- a/plugins/sslutils.c
+++ b/plugins/sslutils.c
@@ -144,7 +144,9 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
144# ifdef USE_OPENSSL 144# ifdef USE_OPENSSL
145 X509 *certificate=NULL; 145 X509 *certificate=NULL;
146 X509_NAME *subj=NULL; 146 X509_NAME *subj=NULL;
147 char timestamp[50] = "";
147 char cn[MAX_CN_LENGTH]= ""; 148 char cn[MAX_CN_LENGTH]= "";
149
148 int cnlen =-1; 150 int cnlen =-1;
149 int status=STATE_UNKNOWN; 151 int status=STATE_UNKNOWN;
150 152
@@ -153,7 +155,7 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
153 struct tm stamp; 155 struct tm stamp;
154 float time_left; 156 float time_left;
155 int days_left; 157 int days_left;
156 char timestamp[50] = ""; 158 int time_remaining;
157 time_t tm_t; 159 time_t tm_t;
158 160
159 certificate=SSL_get_peer_certificate(s); 161 certificate=SSL_get_peer_certificate(s);
@@ -207,7 +209,8 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
207 (tm->data[6 + offset] - '0') * 10 + (tm->data[7 + offset] - '0'); 209 (tm->data[6 + offset] - '0') * 10 + (tm->data[7 + offset] - '0');
208 stamp.tm_min = 210 stamp.tm_min =
209 (tm->data[8 + offset] - '0') * 10 + (tm->data[9 + offset] - '0'); 211 (tm->data[8 + offset] - '0') * 10 + (tm->data[9 + offset] - '0');
210 stamp.tm_sec = 0; 212 stamp.tm_sec =
213 (tm->data[10 + offset] - '0') * 10 + (tm->data[11 + offset] - '0');
211 stamp.tm_isdst = -1; 214 stamp.tm_isdst = -1;
212 215
213 time_left = difftime(timegm(&stamp), time(NULL)); 216 time_left = difftime(timegm(&stamp), time(NULL));
@@ -218,21 +221,35 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
218 if (days_left > 0 && days_left <= days_till_exp_warn) { 221 if (days_left > 0 && days_left <= days_till_exp_warn) {
219 printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, days_left, timestamp); 222 printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, days_left, timestamp);
220 if (days_left > days_till_exp_crit) 223 if (days_left > days_till_exp_crit)
221 return STATE_WARNING; 224 status = STATE_WARNING;
222 else 225 else
223 return STATE_CRITICAL; 226 status = STATE_CRITICAL;
227 } else if (days_left == 0 && time_left > 0) {
228 if (time_left >= 3600)
229 time_remaining = (int) time_left / 3600;
230 else
231 time_remaining = (int) time_left / 60;
232
233 printf (_("%s - Certificate '%s' expires in %u %s (%s)\n"),
234 (days_left>days_till_exp_crit) ? "WARNING" : "CRITICAL", cn, time_remaining,
235 time_left >= 3600 ? "hours" : "minutes", timestamp);
236
237 if ( days_left > days_till_exp_crit)
238 status = STATE_WARNING;
239 else
240 status = STATE_CRITICAL;
224 } else if (time_left < 0) { 241 } else if (time_left < 0) {
225 printf(_("CRITICAL - Certificate '%s' expired on %s.\n"), cn, timestamp); 242 printf(_("CRITICAL - Certificate '%s' expired on %s.\n"), cn, timestamp);
226 status=STATE_CRITICAL; 243 status=STATE_CRITICAL;
227 } else if (days_left == 0) { 244 } else if (days_left == 0) {
228 printf (_("%s - Certificate '%s' expires today (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, timestamp); 245 printf (_("%s - Certificate '%s' just expired (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, timestamp);
229 if (days_left > days_till_exp_crit) 246 if (days_left > days_till_exp_crit)
230 return STATE_WARNING; 247 status = STATE_WARNING;
231 else 248 else
232 return STATE_CRITICAL; 249 status = STATE_CRITICAL;
233 } else { 250 } else {
234 printf(_("OK - Certificate '%s' will expire on %s.\n"), cn, timestamp); 251 printf(_("OK - Certificate '%s' will expire on %s.\n"), cn, timestamp);
235 status=STATE_OK; 252 status = STATE_OK;
236 } 253 }
237 X509_free(certificate); 254 X509_free(certificate);
238 return status; 255 return status;
diff --git a/plugins/t/NPTest.cache.travis b/plugins/t/NPTest.cache.travis
index 4ebfb90..fe8aabd 100644
--- a/plugins/t/NPTest.cache.travis
+++ b/plugins/t/NPTest.cache.travis
@@ -17,13 +17,15 @@
17 'NP_HOST_HPJD_PORT_INVALID' => '161', 17 'NP_HOST_HPJD_PORT_INVALID' => '161',
18 'NP_HOST_HPJD_PORT_VALID' => '', 18 'NP_HOST_HPJD_PORT_VALID' => '',
19 'NP_HOST_TCP_HTTP' => 'localhost', 19 'NP_HOST_TCP_HTTP' => 'localhost',
20 'NP_HOST_TCP_HTTP2' => 'labs.consol.de', 20 'NP_HOST_TCP_HTTP2' => 'test.monitoring-plugins.org',
21 'NP_HOST_TCP_IMAP' => 'imap.web.de', 21 'NP_HOST_TCP_IMAP' => 'imap.web.de',
22 'NP_HOST_TCP_LDAP' => 'localhost',
22 'NP_HOST_TCP_POP' => 'pop.web.de', 23 'NP_HOST_TCP_POP' => 'pop.web.de',
23 'NP_HOST_TCP_SMTP' => 'localhost', 24 'NP_HOST_TCP_SMTP' => 'localhost',
24 'NP_HOST_TCP_SMTP_NOTLS' => '', 25 'NP_HOST_TCP_SMTP_NOTLS' => '',
25 'NP_HOST_TCP_SMTP_TLS' => '', 26 'NP_HOST_TCP_SMTP_TLS' => '',
26 'NP_INTERNET_ACCESS' => 'yes', 27 'NP_INTERNET_ACCESS' => 'yes',
28 'NP_LDAP_BASE_DN' => 'cn=admin,dc=nodomain',
27 'NP_MOUNTPOINT2_VALID' => '', 29 'NP_MOUNTPOINT2_VALID' => '',
28 'NP_MOUNTPOINT_VALID' => '/', 30 'NP_MOUNTPOINT_VALID' => '/',
29 'NP_MYSQL_SERVER' => 'localhost', 31 'NP_MYSQL_SERVER' => 'localhost',
diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t
index b885880..035e768 100644
--- a/plugins/t/check_dns.t
+++ b/plugins/t/check_dns.t
@@ -10,7 +10,7 @@ use NPTest;
10 10
11plan skip_all => "check_dns not compiled" unless (-x "check_dns"); 11plan skip_all => "check_dns not compiled" unless (-x "check_dns");
12 12
13plan tests => 14; 13plan tests => 16;
14 14
15my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/'; 15my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/';
16 16
@@ -43,6 +43,12 @@ my $dns_server = getTestParameter(
43 "A non default (remote) DNS server", 43 "A non default (remote) DNS server",
44 ); 44 );
45 45
46my $host_nonresponsive = getTestParameter(
47 "NP_HOST_NONRESPONSIVE",
48 "The hostname of system not responsive to network requests",
49 "10.0.0.1",
50 );
51
46my $res; 52my $res;
47 53
48$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5"); 54$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5");
@@ -66,6 +72,10 @@ like ( $res->output, $successOutput, "Output OK" );
66$res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1"); 72$res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1");
67cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server"); 73cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server");
68 74
75$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -s $host_nonresponsive -t 2");
76cmp_ok( $res->return_code, '==', 2, "Got no answer from unresponsive server");
77like ( $res->output, "/CRITICAL - /", "Output OK");
78
69$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5"); 79$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5");
70cmp_ok( $res->return_code, '==', 0, "Got expected address"); 80cmp_ok( $res->return_code, '==', 0, "Got expected address");
71 81
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index 2539a28..c2caec6 100644
--- a/plugins/t/check_http.t
+++ b/plugins/t/check_http.t
@@ -6,9 +6,10 @@
6 6
7use strict; 7use strict;
8use Test::More; 8use Test::More;
9use POSIX qw/mktime strftime/;
9use NPTest; 10use NPTest;
10 11
11plan tests => 30; 12plan tests => 42;
12 13
13my $successOutput = '/OK.*HTTP.*second/'; 14my $successOutput = '/OK.*HTTP.*second/';
14 15
@@ -34,6 +35,8 @@ my $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2",
34 "A host providing an index page containing the string 'monitoring'", 35 "A host providing an index page containing the string 'monitoring'",
35 "test.monitoring-plugins.org" ); 36 "test.monitoring-plugins.org" );
36 37
38my $faketime = -x '/usr/bin/faketime' ? 1 : 0;
39
37 40
38$res = NPTest->testCmd( 41$res = NPTest->testCmd(
39 "./check_http $host_tcp_http -wt 300 -ct 600" 42 "./check_http $host_tcp_http -wt 300 -ct 600"
@@ -47,10 +50,10 @@ $res = NPTest->testCmd(
47like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); 50like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" );
48 51
49$res = NPTest->testCmd( 52$res = NPTest->testCmd(
50 "./check_http $host_nonresponsive -wt 1 -ct 2" 53 "./check_http $host_nonresponsive -wt 1 -ct 2 -t 3"
51 ); 54 );
52cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); 55cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" );
53cmp_ok( $res->output, 'eq', "CRITICAL - Socket timeout after 10 seconds", "Output OK"); 56cmp_ok( $res->output, 'eq', "CRITICAL - Socket timeout after 3 seconds", "Output OK");
54 57
55$res = NPTest->testCmd( 58$res = NPTest->testCmd(
56 "./check_http $hostname_invalid -wt 1 -ct 2" 59 "./check_http $hostname_invalid -wt 1 -ct 2"
@@ -112,6 +115,40 @@ SKIP: {
112 $res = NPTest->testCmd( "./check_http www.verisign.com -C 1" ); 115 $res = NPTest->testCmd( "./check_http www.verisign.com -C 1" );
113 cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works"); 116 cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works");
114 117
118 # run some certificate checks with faketime
119 SKIP: {
120 skip "No faketime binary found", 12 if !$faketime;
121 $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./check_http -C 1 www.verisign.com");
122 like($res->output, qr/OK - Certificate 'www.verisign.com' will expire on/, "Catch cert output");
123 is( $res->return_code, 0, "Catch cert output exit code" );
124 my($mon,$day,$hour,$min,$sec,$year) = ($res->output =~ /(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)\./);
125 if(!defined $year) {
126 die("parsing date failed from: ".$res);
127 }
128 my $months = {'Jan' => 0, 'Feb' => 1, 'Mar' => 2, 'Apr' => 3, 'May' => 4, 'Jun' => 5, 'Jul' => 6, 'Aug' => 7, 'Sep' => 8, 'Oct' => 9, 'Nov' => 10, 'Dec' => 11};
129 my $ts = mktime($sec, $min, $hour, $day, $months->{$mon}, $year-1900);
130 my $time = strftime("%Y-%m-%d %H:%M:%S", localtime($ts));
131 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_http -C 1 www.verisign.com");
132 like($res->output, qr/CRITICAL - Certificate 'www.verisign.com' just expired/, "Output on expire date");
133 is( $res->return_code, 2, "Output on expire date" );
134
135 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-1))."' ./check_http -C 1 www.verisign.com");
136 like($res->output, qr/CRITICAL - Certificate 'www.verisign.com' expires in 0 minutes/, "cert expires in 1 second output");
137 is( $res->return_code, 2, "cert expires in 1 second exit code" );
138
139 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-120))."' ./check_http -C 1 www.verisign.com");
140 like($res->output, qr/CRITICAL - Certificate 'www.verisign.com' expires in 2 minutes/, "cert expires in 2 minutes output");
141 is( $res->return_code, 2, "cert expires in 2 minutes exit code" );
142
143 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-7200))."' ./check_http -C 1 www.verisign.com");
144 like($res->output, qr/CRITICAL - Certificate 'www.verisign.com' expires in 2 hours/, "cert expires in 2 hours output");
145 is( $res->return_code, 2, "cert expires in 2 hours exit code" );
146
147 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_http -C 1 www.verisign.com");
148 like($res->output, qr/CRITICAL - Certificate 'www.verisign.com' expired on/, "Certificate expired output");
149 is( $res->return_code, 2, "Certificate expired exit code" );
150 };
151
115 $res = NPTest->testCmd( "./check_http --ssl www.verisign.com -E" ); 152 $res = NPTest->testCmd( "./check_http --ssl www.verisign.com -E" );
116 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); 153 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
117 like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); 154 like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' );
diff --git a/plugins/t/check_ldap.t b/plugins/t/check_ldap.t
new file mode 100644
index 0000000..b8944d4
--- /dev/null
+++ b/plugins/t/check_ldap.t
@@ -0,0 +1,80 @@
1#!/usr/bin/env perl -I ..
2#
3# Lightweight Directory Access Protocol (LDAP) Test via check_ldap
4#
5#
6
7use strict;
8use warnings;
9use Test::More;
10use NPTest;
11
12my $host_tcp_ldap = getTestParameter("NP_HOST_TCP_LDAP",
13 "A host providing the LDAP Service",
14 "localhost" );
15
16my $ldap_base_dn = getTestParameter("NP_LDAP_BASE_DN",
17 "A base dn for the LDAP Service",
18 "cn=admin" );
19
20my $host_nonresponsive = getTestParameter("host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
21 "The hostname of system not responsive to network requests" );
22
23my $hostname_invalid = getTestParameter("hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
24 "An invalid (not known to DNS) hostname" );
25
26my($result, $cmd);
27my $command = './check_ldap';
28
29plan tests => 16;
30
31SKIP: {
32 skip "NP_HOST_NONRESPONSIVE not set", 2 if ! $host_nonresponsive;
33
34 $result = NPTest->testCmd("$command -H $host_nonresponsive -b ou=blah -t 2 -w 1 -c 1");
35 is( $result->return_code, 2, "$command -H $host_nonresponsive -b ou=blah -t 5 -w 2 -c 3" );
36 is( $result->output, 'CRITICAL - Socket timeout after 2 seconds', "output ok" );
37};
38
39SKIP: {
40 skip "NP_HOSTNAME_INVALID not set", 2 if ! $hostname_invalid;
41
42 $result = NPTest->testCmd("$command -H $hostname_invalid -b ou=blah -t 5");
43 is( $result->return_code, 2, "$command -H $hostname_invalid -b ou=blah -t 5" );
44 is( $result->output, 'Could not bind to the LDAP server', "output ok" );
45};
46
47SKIP: {
48 skip "NP_HOST_TCP_LDAP not set", 12 if ! $host_tcp_ldap;
49 skip "NP_LDAP_BASE_DN not set", 12 if ! $ldap_base_dn;
50
51 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3";
52 $result = NPTest->testCmd($cmd);
53 is( $result->return_code, 0, $cmd );
54 like( $result->output, '/^LDAP OK - \d+.\d+ seconds response time\|time=\d+\.\d+s;2\.0+;3\.0+;0\.0+$/', "output ok" );
55
56 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000 -C 10000001";
57 $result = NPTest->testCmd($cmd);
58 is( $result->return_code, 0, $cmd );
59 like( $result->output, '/^LDAP OK - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000;10000001;0\.0+$/', "output ok" );
60
61 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000: -C 10000001:";
62 $result = NPTest->testCmd($cmd);
63 is( $result->return_code, 2, $cmd );
64 like( $result->output, '/^LDAP CRITICAL - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000:;10000001:;0\.0+$/', "output ok" );
65
66 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 0 -C 0";
67 $result = NPTest->testCmd($cmd);
68 is( $result->return_code, 2, $cmd );
69 like( $result->output, '/^LDAP CRITICAL - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;0;0;0\.0+$/', "output ok" );
70
71 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000: -C 10000001";
72 $result = NPTest->testCmd($cmd);
73 is( $result->return_code, 1, $cmd );
74 like( $result->output, '/^LDAP WARNING - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000:;10000001;0\.0+$/', "output ok" );
75
76 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -C 10000001";
77 $result = NPTest->testCmd($cmd);
78 is( $result->return_code, 0, $cmd );
79 like( $result->output, '/^LDAP OK - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;;10000001;0\.0+$/', "output ok" );
80};
diff --git a/plugins/t/negate.t b/plugins/t/negate.t
index f18acc3..d96a109 100644
--- a/plugins/t/negate.t
+++ b/plugins/t/negate.t
@@ -6,6 +6,7 @@
6 6
7use strict; 7use strict;
8use Test::More; 8use Test::More;
9use Cwd;
9use NPTest; 10use NPTest;
10 11
11# 15 tests in the first part, 9 in timeout tests and 2 * 32 in the last loops 12# 15 tests in the first part, 9 in timeout tests and 2 * 32 in the last loops
@@ -13,7 +14,7 @@ plan tests => 88;
13 14
14my $res; 15my $res;
15 16
16my $PWD = $ENV{PWD}; 17my $PWD = getcwd();
17 18
18$res = NPTest->testCmd( "./negate" ); 19$res = NPTest->testCmd( "./negate" );
19is( $res->return_code, 3, "Not enough parameters"); 20is( $res->return_code, 3, "Not enough parameters");
@@ -50,7 +51,7 @@ is( $res->output, "OK: a dummy okay", "The quoted string is passed through to su
50$res = NPTest->testCmd( "./negate '$PWD/check_dummy 0' 'a dummy okay'" ); 51$res = NPTest->testCmd( "./negate '$PWD/check_dummy 0' 'a dummy okay'" );
51is( $res->output, "No data returned from command", "Bad command, as expected (trying to execute './check_dummy 0')"); 52is( $res->output, "No data returned from command", "Bad command, as expected (trying to execute './check_dummy 0')");
52 53
53$res = NPTest->testCmd( './negate $PWD/check_dummy 0 \'$$ a dummy okay\'' ); 54$res = NPTest->testCmd( './negate '.$PWD.'/check_dummy 0 \'$$ a dummy okay\'' );
54is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' ); 55is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' );
55 56
56my %state = ( 57my %state = (
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index d93a0ec..e72d243 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -186,21 +186,21 @@ SKIP: {
186 186
187 $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); 187 $result = NPTest->testCmd( "$command -p $port_https -S -C 14" );
188 is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); 188 is( $result->return_code, 0, "$command -p $port_https -S -C 14" );
189 is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:00 2019.', "output ok" ); 189 is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:28 2019.', "output ok" );
190 190
191 $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); 191 $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" );
192 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); 192 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" );
193 like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:00 2019\)./', "output ok" ); 193 like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019\)./', "output ok" );
194 194
195 # Expired cert tests 195 # Expired cert tests
196 $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); 196 $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" );
197 is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); 197 is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" );
198 like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:00 2019\)./', "output ok" ); 198 like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019\)./', "output ok" );
199 199
200 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); 200 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" );
201 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); 201 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" );
202 is( $result->output, 202 is( $result->output,
203 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:00 2009.', 203 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:16 2009.',
204 "output ok" ); 204 "output ok" );
205 205
206} 206}
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t
index aace9bc..73a68b2 100755
--- a/plugins/tests/check_snmp.t
+++ b/plugins/tests/check_snmp.t
@@ -20,7 +20,16 @@ if ($@) {
20 plan skip_all => "Missing required module for test: $@"; 20 plan skip_all => "Missing required module for test: $@";
21} else { 21} else {
22 if (-x "./check_snmp") { 22 if (-x "./check_snmp") {
23 plan tests => $tests; 23 # check if snmpd has perl support
24 my $test = `snmpd -c tests/conf/snmpd.conf -C -r -H 2>&1`;
25 if(!defined $test) {
26 plan skip_all => "snmpd required";
27 }
28 elsif($test =~ m/Warning: Unknown token: perl/) {
29 plan skip_all => "snmpd has no perl support";
30 } else {
31 plan tests => $tests;
32 }
24 } else { 33 } else {
25 plan skip_all => "No check_snmp compiled"; 34 plan skip_all => "No check_snmp compiled";
26 } 35 }
@@ -119,7 +128,7 @@ sleep 1;
119 128
120$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); 129$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" );
121is($res->return_code, 1, "WARNING - due to going above rate calculation" ); 130is($res->return_code, 1, "WARNING - due to going above rate calculation" );
122is($res->output, "SNMP RATE WARNING - *666* | iso.3.6.1.4.1.8072.3.2.67.10=666 "); 131is($res->output, "SNMP RATE WARNING - *666* | iso.3.6.1.4.1.8072.3.2.67.10=666;600 ");
123 132
124$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); 133$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" );
125is($res->return_code, 3, "UNKNOWN - basically the divide by zero error" ); 134is($res->return_code, 3, "UNKNOWN - basically the divide by zero error" );
@@ -200,7 +209,7 @@ is($res->output, 'SNMP OK - "stringtests" | ', "OK as inverted string no match"
200 209
201$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.12 -w 4:5" ); 210$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.12 -w 4:5" );
202is($res->return_code, 1, "Numeric in string test" ); 211is($res->return_code, 1, "Numeric in string test" );
203is($res->output, 'SNMP WARNING - *3.5* | iso.3.6.1.4.1.8072.3.2.67.12=3.5 ', "WARNING threshold checks for string masquerading as number" ); 212is($res->output, 'SNMP WARNING - *3.5* | iso.3.6.1.4.1.8072.3.2.67.12=3.5;4:5 ', "WARNING threshold checks for string masquerading as number" );
204 213
205$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.13" ); 214$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.13" );
206is($res->return_code, 0, "Not really numeric test" ); 215is($res->return_code, 0, "Not really numeric test" );
@@ -216,29 +225,29 @@ is($res->output, 'SNMP OK - "CUSTOM CHECK OK: foo is 12345" | ', "String check w
216 225
217$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); 226$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" );
218is($res->return_code, 0, "Negative integer check OK" ); 227is($res->return_code, 0, "Negative integer check OK" );
219is($res->output, 'SNMP OK - -2 | iso.3.6.1.4.1.8072.3.2.67.16=-2 ', "Negative integer check OK output" ); 228is($res->output, 'SNMP OK - -2 | iso.3.6.1.4.1.8072.3.2.67.16=-2;-2:;-3: ', "Negative integer check OK output" );
220 229
221$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); 230$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" );
222is($res->return_code, 1, "Negative integer check WARNING" ); 231is($res->return_code, 1, "Negative integer check WARNING" );
223is($res->output, 'SNMP WARNING - *-3* | iso.3.6.1.4.1.8072.3.2.67.16=-3 ', "Negative integer check WARNING output" ); 232is($res->output, 'SNMP WARNING - *-3* | iso.3.6.1.4.1.8072.3.2.67.16=-3;-2:;-3: ', "Negative integer check WARNING output" );
224 233
225$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); 234$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" );
226is($res->return_code, 2, "Negative integer check CRITICAL" ); 235is($res->return_code, 2, "Negative integer check CRITICAL" );
227is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.16=-4 ', "Negative integer check CRITICAL output" ); 236is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.16=-4;-2:;-3: ', "Negative integer check CRITICAL output" );
228 237
229$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.17 -w -3: -c -6:" ); 238$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.17 -w -3: -c -6:" );
230is($res->return_code, 1, "Negative integer as string, WARNING" ); 239is($res->return_code, 1, "Negative integer as string, WARNING" );
231is($res->output, 'SNMP WARNING - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4 ', "Negative integer as string, WARNING output" ); 240is($res->output, 'SNMP WARNING - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4;-3:;-6: ', "Negative integer as string, WARNING output" );
232 241
233$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.17 -w -2: -c -3:" ); 242$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.17 -w -2: -c -3:" );
234is($res->return_code, 2, "Negative integer as string, CRITICAL" ); 243is($res->return_code, 2, "Negative integer as string, CRITICAL" );
235is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4 ', "Negative integer as string, CRITICAL output" ); 244is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4;-2:;-3: ', "Negative integer as string, CRITICAL output" );
236 245
237$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -c ~:-6.5" ); 246$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -c '~:-6.5'" );
238is($res->return_code, 0, "Negative float OK" ); 247is($res->return_code, 0, "Negative float OK" );
239is($res->output, 'SNMP OK - -6.6 | iso.3.6.1.4.1.8072.3.2.67.18=-6.6 ', "Negative float OK output" ); 248is($res->output, 'SNMP OK - -6.6 | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;;~:-6.5 ', "Negative float OK output" );
240 249
241$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -w ~:-6.65 -c ~:-6.55" ); 250$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -w '~:-6.65' -c '~:-6.55'" );
242is($res->return_code, 1, "Negative float WARNING" ); 251is($res->return_code, 1, "Negative float WARNING" );
243is($res->output, 'SNMP WARNING - *-6.6* | iso.3.6.1.4.1.8072.3.2.67.18=-6.6 ', "Negative float WARNING output" ); 252is($res->output, 'SNMP WARNING - *-6.6* | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;~:-6.65;~:-6.55 ', "Negative float WARNING output" );
244 253
diff --git a/plugins/utils.c b/plugins/utils.c
index 58b153d..a864e4a 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -144,8 +144,6 @@ usage5 (void)
144void 144void
145print_revision (const char *command_name, const char *revision) 145print_revision (const char *command_name, const char *revision)
146{ 146{
147 char plugin_revision[STRLEN];
148
149 printf ("%s v%s (%s %s)\n", 147 printf ("%s v%s (%s %s)\n",
150 command_name, revision, PACKAGE, VERSION); 148 command_name, revision, PACKAGE, VERSION);
151} 149}
@@ -630,3 +628,43 @@ char *fperfdata (const char *label,
630 628
631 return data; 629 return data;
632} 630}
631
632char *sperfdata (const char *label,
633 double val,
634 const char *uom,
635 char *warn,
636 char *crit,
637 int minp,
638 double minv,
639 int maxp,
640 double maxv)
641{
642 char *data = NULL;
643 if (strpbrk (label, "'= "))
644 xasprintf (&data, "'%s'=", label);
645 else
646 xasprintf (&data, "%s=", label);
647
648 xasprintf (&data, "%s%f", data, val);
649 xasprintf (&data, "%s%s;", data, uom);
650
651 if (warn!=NULL)
652 xasprintf (&data, "%s%s", data, warn);
653
654 xasprintf (&data, "%s;", data);
655
656 if (crit!=NULL)
657 xasprintf (&data, "%s%s", data, crit);
658
659 xasprintf (&data, "%s;", data);
660
661 if (minp)
662 xasprintf (&data, "%s%f", data, minv);
663
664 if (maxp) {
665 xasprintf (&data, "%s;", data);
666 xasprintf (&data, "%s%f", data, maxv);
667 }
668
669 return data;
670}