aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_cluster.c10
-rw-r--r--plugins/check_hpjd.c12
-rw-r--r--plugins/check_http.c29
-rw-r--r--plugins/check_smtp.c1
-rw-r--r--plugins/common.h5
-rw-r--r--plugins/t/NPTest.cache.travis44
-rw-r--r--plugins/t/check_by_ssh.t14
-rw-r--r--plugins/t/check_fping.t12
-rw-r--r--plugins/t/check_ftp.t11
-rw-r--r--plugins/t/check_http.t60
-rw-r--r--plugins/t/check_imap.t15
-rw-r--r--plugins/t/check_jabber.t20
-rw-r--r--plugins/t/check_ldap.t17
-rw-r--r--plugins/t/check_mysql.t29
-rw-r--r--plugins/t/check_mysql_query.t11
-rw-r--r--plugins/t/check_snmp.t16
-rw-r--r--plugins/t/check_ssh.t14
-rw-r--r--plugins/t/check_tcp.t20
-rw-r--r--plugins/t/check_time.t11
-rwxr-xr-xplugins/tests/check_snmp.t110
20 files changed, 196 insertions, 265 deletions
diff --git a/plugins/check_cluster.c b/plugins/check_cluster.c
index b86e501d..e1ede9f7 100644
--- a/plugins/check_cluster.c
+++ b/plugins/check_cluster.c
@@ -143,6 +143,7 @@ int main(int argc, char **argv){
int process_arguments(int argc, char **argv){
int c;
+ char *ptr;
int option=0;
static struct option longopts[]={
{"data", required_argument,0,'d'},
@@ -188,6 +189,15 @@ int process_arguments(int argc, char **argv){
case 'd': /* data values */
data_vals=(char *)strdup(optarg);
+ /* validate data */
+ for (ptr=data_vals;ptr!=NULL;ptr+=2){
+ if (ptr[0]<'0' || ptr[0]>'3')
+ return ERROR;
+ if (ptr[1]=='\0')
+ break;
+ if (ptr[1]!=',')
+ return ERROR;
+ }
break;
case 'l': /* text label */
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c
index f159f5a2..65465567 100644
--- a/plugins/check_hpjd.c
+++ b/plugins/check_hpjd.c
@@ -67,6 +67,7 @@ void print_usage (void);
char *community = NULL;
char *address = NULL;
char *port = NULL;
+int check_paper_out = 1;
int
main (int argc, char **argv)
@@ -240,7 +241,8 @@ main (int argc, char **argv)
strcpy (errmsg, _("Paper Jam"));
}
else if (paper_out) {
- result = STATE_WARNING;
+ if (check_paper_out)
+ result = STATE_WARNING;
strcpy (errmsg, _("Out of Paper"));
}
else if (line_status == OFFLINE) {
@@ -325,7 +327,7 @@ process_arguments (int argc, char **argv)
while (1) {
- c = getopt_long (argc, argv, "+hVH:C:p:", longopts, &option);
+ c = getopt_long (argc, argv, "+hVH:C:p:D", longopts, &option);
if (c == -1 || c == EOF || c == 1)
break;
@@ -347,6 +349,8 @@ process_arguments (int argc, char **argv)
usage2 (_("Port must be a positive short integer"), optarg);
else
port = atoi(optarg);
+ case 'D': /* disable paper out check*/
+ check_paper_out = 0;
break;
case 'V': /* version */
print_revision (progname, NP_VERSION);
@@ -420,6 +424,8 @@ print_help (void)
printf (" %s", _("Specify the port to check "));
printf (_("(default=%s)"), DEFAULT_PORT);
printf ("\n");
+ printf (" %s\n", "-D");
+ printf (" %s", _("Disable paper check "));
printf (UT_SUPPORT);
}
@@ -430,5 +436,5 @@ void
print_usage (void)
{
printf ("%s\n", _("Usage:"));
- printf ("%s -H host [-C community] [-p port]\n", progname);
+ printf ("%s -H host [-C community] [-p port] [-D]\n", progname);
}
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 86a36c20..856e1e90 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -120,12 +120,14 @@ int use_ssl = FALSE;
int use_sni = FALSE;
int verbose = FALSE;
int show_extended_perfdata = FALSE;
+int show_body = FALSE;
int sd;
int min_page_len = 0;
int max_page_len = 0;
int redir_depth = 0;
int max_depth = 15;
char *http_method;
+char *http_method_proxy;
char *http_post_data;
char *http_content_type;
char buffer[MAX_INPUT_BUFFER];
@@ -239,6 +241,7 @@ process_arguments (int argc, char **argv)
{"use-ipv4", no_argument, 0, '4'},
{"use-ipv6", no_argument, 0, '6'},
{"extended-perfdata", no_argument, 0, 'E'},
+ {"show-body", no_argument, 0, 'B'},
{0, 0, 0, 0}
};
@@ -259,7 +262,7 @@ process_arguments (int argc, char **argv)
}
while (1) {
- c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:nlLS::m:M:NE", longopts, &option);
+ c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:nlLS::m:M:NEB", longopts, &option);
if (c == -1 || c == EOF)
break;
@@ -446,6 +449,12 @@ process_arguments (int argc, char **argv)
if (http_method)
free(http_method);
http_method = strdup (optarg);
+ char *tmp;
+ if ((tmp = strstr(http_method, ":")) > 0) {
+ tmp[0] = '\0';
+ http_method = http_method;
+ http_method_proxy = ++tmp;
+ }
break;
case 'd': /* string or substring */
strncpy (header_expect, optarg, MAX_INPUT_BUFFER - 1);
@@ -540,6 +549,9 @@ process_arguments (int argc, char **argv)
case 'E': /* show extended perfdata */
show_extended_perfdata = TRUE;
break;
+ case 'B': /* print body content after status line */
+ show_body = TRUE;
+ break;
}
}
@@ -566,6 +578,9 @@ process_arguments (int argc, char **argv)
if (http_method == NULL)
http_method = strdup ("GET");
+ if (http_method_proxy == NULL)
+ http_method_proxy = strdup ("GET");
+
if (client_cert && !client_privkey)
usage4 (_("If you use a client certificate you must also specify a private key file"));
@@ -950,7 +965,7 @@ check_http (void)
if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0
&& host_name != NULL && use_ssl == TRUE)
- asprintf (&buf, "%s %s %s\r\n%s\r\n", "GET", server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent);
+ asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method_proxy, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent);
else
asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent);
@@ -1290,6 +1305,9 @@ check_http (void)
perfd_time (elapsed_time),
perfd_size (page_len));
+ if (show_body)
+ xasprintf (&msg, _("%s\n%s"), msg, page);
+
result = max_state_alt(get_status(elapsed_time, thlds), result);
die (result, "HTTP %s: %s\n", state_text(result), msg);
@@ -1581,7 +1599,7 @@ print_help (void)
printf (" %s\n", _("URL to GET or POST (default: /)"));
printf (" %s\n", "-P, --post=STRING");
printf (" %s\n", _("URL encoded http POST data"));
- printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT)");
+ printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT, CONNECT:POST)");
printf (" %s\n", _("Set HTTP method."));
printf (" %s\n", "-N, --no-body");
printf (" %s\n", _("Don't wait for document body: stop reading after headers."));
@@ -1611,6 +1629,8 @@ print_help (void)
printf (" %s\n", _("Any other tags to be sent in http header. Use multiple times for additional headers"));
printf (" %s\n", "-E, --extended-perfdata");
printf (" %s\n", _("Print additional performance data"));
+ printf (" %s\n", "-B, --show-body");
+ printf (" %s\n", _("Print body content below status line"));
printf (" %s\n", "-L, --link");
printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)"));
printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport>");
@@ -1668,7 +1688,8 @@ print_help (void)
printf (" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> -S(sl) -j CONNECT -H <webserver>"));
printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds"));
printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,"));
- printf (" %s\n", _("a STATE_CRITICAL will be returned."));
+ printf (" %s\n", _("a STATE_CRITICAL will be returned. By adding a colon to the method you can set the method used"));
+ printf (" %s\n", _("inside the proxied connection: -j CONNECT:POST"));
#endif
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index 0fcf4c68..d37c57c8 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -293,6 +293,7 @@ main (int argc, char **argv)
printf("%s", buffer);
}
+ n = 0;
while (n < ncommands) {
xasprintf (&cmd_str, "%s%s", commands[n], "\r\n");
my_send(cmd_str, strlen(cmd_str));
diff --git a/plugins/common.h b/plugins/common.h
index 8719b502..6bf4fca4 100644
--- a/plugins/common.h
+++ b/plugins/common.h
@@ -174,6 +174,11 @@
*
*/
+/* MariaDB 10.2 client does not set MYSQL_PORT */
+#ifndef MYSQL_PORT
+# define MYSQL_PORT 3306
+#endif
+
enum {
OK = 0,
ERROR = -1
diff --git a/plugins/t/NPTest.cache.travis b/plugins/t/NPTest.cache.travis
index e9705f3b..9b9f8059 100644
--- a/plugins/t/NPTest.cache.travis
+++ b/plugins/t/NPTest.cache.travis
@@ -1,62 +1,54 @@
{
- 'MYSQL_LOGIN_DETAILS' => '-u root -d test',
'NP_ALLOW_SUDO' => 'yes',
'NP_DNS_SERVER' => '8.8.8.8',
'NP_GOOD_NTP_SERVICE' => '',
+ 'NP_HOST_DHCP_RESPONSIVE' => '',
+ 'NP_HOST_HPJD_PORT_INVALID' => '161',
+ 'NP_HOST_HPJD_PORT_VALID' => '',
+ 'NP_HOSTNAME_INVALID_CIDR' => '130.133.8.39/30',
'NP_HOSTNAME_INVALID' => 'nosuchhost',
- 'NP_HOSTNAME_VALID' => 'monitoring-plugins.org',
- 'NP_HOSTNAME_VALID_IP' => '130.133.8.40',
'NP_HOSTNAME_VALID_CIDR' => '130.133.8.41/30',
- 'NP_HOSTNAME_INVALID_CIDR' => '130.133.8.39/30',
+ 'NP_HOSTNAME_VALID_IP' => '130.133.8.40',
+ 'NP_HOSTNAME_VALID' => 'monitoring-plugins.org',
'NP_HOSTNAME_VALID_REVERSE' => 'orwell.monitoring-plugins.org.',
- 'NP_HOST_DHCP_RESPONSIVE' => '',
'NP_HOST_NONRESPONSIVE' => '10.0.0.1',
'NP_HOST_RESPONSIVE' => 'localhost',
'NP_HOST_SMB' => '',
- 'NP_HOST_SNMP' => 'localhost',
+ 'NP_HOST_SNMP' => '',
'NP_HOST_TCP_FTP' => '',
'NP_HOST_TCP_HPJD' => '',
- 'NP_HOST_HPJD_PORT_INVALID' => '161',
- 'NP_HOST_HPJD_PORT_VALID' => '',
- 'NP_HOST_TCP_HTTP' => 'localhost',
'NP_HOST_TCP_HTTP2' => 'test.monitoring-plugins.org',
+ 'NP_HOST_TCP_HTTP' => 'localhost',
'NP_HOST_TCP_IMAP' => 'imap.web.de',
+ 'NP_HOST_TCP_JABBER' => 'jabber.org',
'NP_HOST_TCP_LDAP' => 'localhost',
'NP_HOST_TCP_POP' => 'pop.web.de',
+ 'NP_HOST_TCP_PROXY' => 'localhost',
'NP_HOST_TCP_SMTP' => 'localhost',
'NP_HOST_TCP_SMTP_NOTLS' => '',
'NP_HOST_TCP_SMTP_TLS' => '',
+ 'NP_HOST_TLS_CERT' => 'localhost,
+ 'NP_HOST_TLS_HTTP' => 'localhost',
+ 'NP_HOST_UDP_TIME' => 'none',
'NP_INTERNET_ACCESS' => 'yes',
'NP_LDAP_BASE_DN' => 'cn=admin,dc=nodomain',
'NP_MOUNTPOINT2_VALID' => '/media/ramdisk',
'NP_MOUNTPOINT_VALID' => '/',
+ 'NP_MYSQL_LOGIN_DETAILS' => '-u root -d test',
'NP_MYSQL_SERVER' => 'localhost',
- 'NP_HOST_UDP_TIME' => 'localhost',
'NP_MYSQL_SOCKET' => '/var/run/mysqld/mysqld.sock',
'NP_MYSQL_WITH_SLAVE' => '',
'NP_MYSQL_WITH_SLAVE_LOGIN' => '',
'NP_NO_NTP_SERVICE' => 'localhost',
+ 'NP_PORT_TCP_PROXY' => '3128',
'NP_SMB_SHARE' => '',
'NP_SMB_SHARE_DENY' => '',
'NP_SMB_SHARE_SPC' => '',
'NP_SMB_VALID_USER' => '',
'NP_SMB_VALID_USER_PASS' => '',
- 'NP_SNMP_COMMUNITY' => 'public',
+ 'NP_SNMP_COMMUNITY' => '',
+ 'NP_SNMP_USER' => '',
'NP_SSH_CONFIGFILE' => '~/.ssh/config',
'NP_SSH_HOST' => 'localhost',
- 'NP_SSH_IDENTITY' => '~/.ssh/id_dsa',
- 'NP_HOST_TCP_JABBER' => 'jabber.org',
- 'host_nonresponsive' => '10.0.0.1',
- 'host_responsive' => 'localhost',
- 'host_snmp' => '',
- 'host_tcp_ftp' => '',
- 'host_tcp_http' => 'localhost',
- 'host_tcp_imap' => 'imap.nierlein.de',
- 'host_tcp_smtp' => 'localhost',
- 'hostname_invalid' => 'nosuchhost',
- 'snmp_community' => '',
- 'user_snmp' => '',
- 'host_udp_time' => 'none',
- 'host_tls_http' => 'localhost',
- 'host_tls_cert' => 'localhost',
+ 'NP_SSH_IDENTITY' => '~/.ssh/id_rsa'
}
diff --git a/plugins/t/check_by_ssh.t b/plugins/t/check_by_ssh.t
index 4797390d..1d2939e9 100644
--- a/plugins/t/check_by_ssh.t
+++ b/plugins/t/check_by_ssh.t
@@ -9,17 +9,9 @@ use Test::More;
use NPTest;
# Required parameters
-my $ssh_service = getTestParameter( "NP_SSH_HOST",
- "A host providing SSH service",
- "localhost");
-
-my $ssh_key = getTestParameter( "NP_SSH_IDENTITY",
- "A key allowing access to NP_SSH_HOST",
- "~/.ssh/id_dsa");
-
-my $ssh_conf = getTestParameter( "NP_SSH_CONFIGFILE",
- "A config file with ssh settings",
- "~/.ssh/config");
+my $ssh_service = getTestParameter("NP_SSH_HOST", "A host providing SSH service", "localhost");
+my $ssh_key = getTestParameter("NP_SSH_IDENTITY", "A key allowing access to NP_SSH_HOST", "~/.ssh/id_dsa");
+my $ssh_conf = getTestParameter( "NP_SSH_CONFIGFILE", "A config file with ssh settings", "~/.ssh/config");
plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_service && $ssh_key);
diff --git a/plugins/t/check_fping.t b/plugins/t/check_fping.t
index 08692e46..342b0a7e 100644
--- a/plugins/t/check_fping.t
+++ b/plugins/t/check_fping.t
@@ -15,15 +15,9 @@ BEGIN {$tests = 4; plan tests => $tests}
my $successOutput = '/^FPING OK - /';
my $failureOutput = '/^FPING CRITICAL - /';
-my $host_responsive = getTestParameter( "host_responsive", "NP_HOST_RESPONSIVE", "localhost",
- "The hostname of system responsive to network requests" );
-
-my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
- "The hostname of system not responsive to network requests" );
-
-my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
- "An invalid (not known to DNS) hostname" );
-
+my $host_responsive = getTestParameter("NP_HOST_RESPONSIVE", "The hostname of system responsive to network requests", "localhost");
+my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1");
+my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost");
my $t;
diff --git a/plugins/t/check_ftp.t b/plugins/t/check_ftp.t
index de6831ba..93a7d7c3 100644
--- a/plugins/t/check_ftp.t
+++ b/plugins/t/check_ftp.t
@@ -11,14 +11,9 @@ use NPTest;
use vars qw($tests);
BEGIN {$tests = 4; plan tests => $tests}
-my $host_tcp_ftp = getTestParameter( "host_tcp_ftp", "NP_HOST_TCP_FTP", "localhost",
- "A host providing the FTP Service (an FTP server)");
-
-my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
- "The hostname of system not responsive to network requests" );
-
-my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
- "An invalid (not known to DNS) hostname" );
+my $host_tcp_ftp = getTestParameter("NP_HOST_TCP_FTP", "A host providing the FTP Service (an FTP server)", "localhost");
+my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1");
+my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost");
my $successOutput = '/FTP OK -\s+[0-9]?\.?[0-9]+ second response time/';
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index 8bd484a0..b3760ebe 100644
--- a/plugins/t/check_http.t
+++ b/plugins/t/check_http.t
@@ -9,38 +9,21 @@ use Test::More;
use POSIX qw/mktime strftime/;
use NPTest;
-plan tests => 49;
+plan tests => 50;
my $successOutput = '/OK.*HTTP.*second/';
my $res;
-my $host_tcp_http = getTestParameter( "NP_HOST_TCP_HTTP",
- "A host providing the HTTP Service (a web server)",
- "localhost" );
-
-my $host_tls_http = getTestParameter( "host_tls_http", "NP_HOST_TLS_HTTP", "localhost",
- "A host providing the HTTPS Service (a tls web server)" );
-
-my $host_tls_cert = getTestParameter( "host_tls_cert", "NP_HOST_TLS_CERT", "localhost",
- "the common name of the certificate." );
-
-
-my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
- "The hostname of system not responsive to network requests",
- "10.0.0.1" );
-
-my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
- "An invalid (not known to DNS) hostname",
- "nosuchhost");
-
-my $internet_access = getTestParameter( "NP_INTERNET_ACCESS",
- "Is this system directly connected to the internet?",
- "yes");
-
-my $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2",
- "A host providing an index page containing the string 'monitoring'",
- "test.monitoring-plugins.org" );
+my $host_tcp_http = getTestParameter("NP_HOST_TCP_HTTP", "A host providing the HTTP Service (a web server)", "localhost");
+my $host_tls_http = getTestParameter("NP_HOST_TLS_HTTP", "A host providing the HTTPS Service (a tls web server)", "localhost");
+my $host_tls_cert = getTestParameter("NP_HOST_TLS_CERT", "the common name of the certificate.", "localhost");
+my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1");
+my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost");
+my $internet_access = getTestParameter("NP_INTERNET_ACCESS", "Is this system directly connected to the internet?", "yes");
+my $host_tcp_http2 = getTestParameter("NP_HOST_TCP_HTTP2", "A host providing an index page containing the string 'monitoring'", "test.monitoring-plugins.org");
+my $host_tcp_proxy = getTestParameter("NP_HOST_TCP_PROXY", "A host providing a HTTP proxy with CONNECT support", "localhost");
+my $port_tcp_proxy = getTestParameter("NP_PORT_TCP_PROXY", "Port of the proxy with HTTP and CONNECT support", "3128");
my $faketime = -x '/usr/bin/faketime' ? 1 : 0;
@@ -150,7 +133,7 @@ SKIP: {
# run some certificate checks with faketime
SKIP: {
- skip "No faketime binary found", 12 if !$faketime;
+ skip "No faketime binary found", 7 if !$faketime;
$res = NPTest->testCmd("LC_TIME=C TZ=UTC ./check_http -C 1 $host_tls_http");
like($res->output, qr/OK - Certificate '$host_tls_cert' will expire on/, "Catch cert output");
is( $res->return_code, 0, "Catch cert output exit code" );
@@ -163,23 +146,18 @@ SKIP: {
my $time = strftime("%Y-%m-%d %H:%M:%S", localtime($ts));
$res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_http -C 1 $host_tls_http");
like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' just expired/, "Output on expire date");
- is( $res->return_code, 2, "Output on expire date" );
$res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-1))."' ./check_http -C 1 $host_tls_http");
like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 0 minutes/, "cert expires in 1 second output");
- is( $res->return_code, 2, "cert expires in 1 second exit code" );
$res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-120))."' ./check_http -C 1 $host_tls_http");
like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 minutes/, "cert expires in 2 minutes output");
- is( $res->return_code, 2, "cert expires in 2 minutes exit code" );
$res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-7200))."' ./check_http -C 1 $host_tls_http");
like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 hours/, "cert expires in 2 hours output");
- is( $res->return_code, 2, "cert expires in 2 hours exit code" );
$res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_http -C 1 $host_tls_http");
like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expired on/, "Certificate expired output");
- is( $res->return_code, 2, "Certificate expired exit code" );
};
$res = NPTest->testCmd( "./check_http --ssl $host_tls_http -E" );
@@ -198,3 +176,19 @@ SKIP: {
$res = NPTest->testCmd( "./check_http -H www.mozilla.com --extended-perfdata" );
like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
}
+
+SKIP: {
+ skip "No internet access or proxy configured", 6 if $internet_access eq "no" or ! $host_tcp_proxy;
+
+ $res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -u http://$host_tcp_http -e 200,301,302");
+ is( $res->return_code, 0, "Proxy HTTP works");
+ like($res->output, qr/OK: Status line output matched/, "Proxy HTTP Output is sufficent");
+
+ $res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT");
+ is( $res->return_code, 0, "Proxy HTTP CONNECT works");
+ like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent");
+
+ $res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT:HEAD");
+ is( $res->return_code, 0, "Proxy HTTP CONNECT works with override method");
+ like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent");
+}
diff --git a/plugins/t/check_imap.t b/plugins/t/check_imap.t
index 9c6eae1f..7c74e564 100644
--- a/plugins/t/check_imap.t
+++ b/plugins/t/check_imap.t
@@ -8,17 +8,10 @@ use strict;
use Test::More tests => 7;
use NPTest;
-my $host_tcp_smtp = getTestParameter( "host_tcp_smtp", "NP_HOST_TCP_SMTP", "mailhost",
- "A host providing an STMP Service (a mail server)");
-
-my $host_tcp_imap = getTestParameter( "host_tcp_imap", "NP_HOST_TCP_IMAP", $host_tcp_smtp,
- "A host providing an IMAP Service (a mail server)");
-
-my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
- "The hostname of system not responsive to network requests" );
-
-my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
- "An invalid (not known to DNS) hostname" );
+my $host_tcp_smtp = getTestParameter("NP_HOST_TCP_SMTP", "A host providing an STMP Service (a mail server)", "mailhost");
+my $host_tcp_imap = getTestParameter("NP_HOST_TCP_IMAP", "A host providing an IMAP Service (a mail server)", $host_tcp_smtp);
+my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1");
+my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost");
my $t;
diff --git a/plugins/t/check_jabber.t b/plugins/t/check_jabber.t
index 7a708d5b..fcdae179 100644
--- a/plugins/t/check_jabber.t
+++ b/plugins/t/check_jabber.t
@@ -10,23 +10,9 @@ use NPTest;
plan tests => 10;
-my $host_tcp_jabber = getTestParameter(
- "NP_HOST_TCP_JABBER",
- "A host providing the Jabber Service",
- "jabber.org"
- );
-
-my $host_nonresponsive = getTestParameter(
- "NP_HOST_NONRESPONSIVE",
- "The hostname of system not responsive to network requests",
- "10.0.0.1",
- );
-
-my $hostname_invalid = getTestParameter(
- "NP_HOSTNAME_INVALID",
- "An invalid (not known to DNS) hostname",
- "nosuchhost",
- );
+my $host_tcp_jabber = getTestParameter("NP_HOST_TCP_JABBER", "A host providing the Jabber Service", "jabber.de");
+my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1");
+my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost");
my $jabberOK = '/JABBER OK\s-\s\d+\.\d+\ssecond response time on '.$host_tcp_jabber.' port 5222/';
diff --git a/plugins/t/check_ldap.t b/plugins/t/check_ldap.t
index b8944d4b..b8a4a766 100644
--- a/plugins/t/check_ldap.t
+++ b/plugins/t/check_ldap.t
@@ -9,19 +9,10 @@ use warnings;
use Test::More;
use NPTest;
-my $host_tcp_ldap = getTestParameter("NP_HOST_TCP_LDAP",
- "A host providing the LDAP Service",
- "localhost" );
-
-my $ldap_base_dn = getTestParameter("NP_LDAP_BASE_DN",
- "A base dn for the LDAP Service",
- "cn=admin" );
-
-my $host_nonresponsive = getTestParameter("host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
- "The hostname of system not responsive to network requests" );
-
-my $hostname_invalid = getTestParameter("hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
- "An invalid (not known to DNS) hostname" );
+my $host_tcp_ldap = getTestParameter("NP_HOST_TCP_LDAP", "A host providing the LDAP Service", "localhost");
+my $ldap_base_dn = getTestParameter("NP_LDAP_BASE_DN", "A base dn for the LDAP Service", "cn=admin");
+my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1");
+my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost");
my($result, $cmd);
my $command = './check_ldap';
diff --git a/plugins/t/check_mysql.t b/plugins/t/check_mysql.t
index 28cd4cd0..e426bf59 100644
--- a/plugins/t/check_mysql.t
+++ b/plugins/t/check_mysql.t
@@ -21,30 +21,11 @@ plan skip_all => "check_mysql not compiled" unless (-x "check_mysql");
plan tests => 15;
my $bad_login_output = '/Access denied for user /';
-my $mysqlserver = getTestParameter(
- "NP_MYSQL_SERVER",
- "A MySQL Server hostname or IP with no slaves setup"
- );
-my $mysqlsocket = getTestParameter(
- "NP_MYSQL_SOCKET",
- "Full path to a MySQL Server socket with no slaves setup"
- );
-my $mysql_login_details = getTestParameter(
- "MYSQL_LOGIN_DETAILS",
- "Command line parameters to specify login access (requires " .
- "REPLICATION CLIENT privleges)",
- "-u test -ptest",
- );
-my $with_slave = getTestParameter(
- "NP_MYSQL_WITH_SLAVE",
- "MySQL server with slaves setup"
- );
-my $with_slave_login = getTestParameter(
- "NP_MYSQL_WITH_SLAVE_LOGIN",
- "Login details for server with slave (requires REPLICATION CLIENT " .
- "privleges)",
- $mysql_login_details || "-u test -ptest"
- );
+my $mysqlserver = getTestParameter("NP_MYSQL_SERVER", "A MySQL Server hostname or IP with no slaves setup");
+my $mysqlsocket = getTestParameter("NP_MYSQL_SOCKET", "Full path to a MySQL Server socket with no slaves setup");
+my $mysql_login_details = getTestParameter("NP_MYSQL_LOGIN_DETAILS", "Command line parameters to specify login access (requires REPLICATION CLIENT privleges)", "-u test -ptest");
+my $with_slave = getTestParameter("NP_MYSQL_WITH_SLAVE", "MySQL server with slaves setup");
+my $with_slave_login = getTestParameter("NP_MYSQL_WITH_SLAVE_LOGIN", "Login details for server with slave (requires REPLICATION CLIENT privleges)", $mysql_login_details || "-u test -ptest");
my $result;
diff --git a/plugins/t/check_mysql_query.t b/plugins/t/check_mysql_query.t
index 407af881..96899ac6 100644
--- a/plugins/t/check_mysql_query.t
+++ b/plugins/t/check_mysql_query.t
@@ -17,15 +17,8 @@ use vars qw($tests);
plan skip_all => "check_mysql_query not compiled" unless (-x "check_mysql_query");
-my $mysqlserver = getTestParameter(
- "NP_MYSQL_SERVER",
- "A MySQL Server with no slaves setup"
- );
-my $mysql_login_details = getTestParameter(
- "MYSQL_LOGIN_DETAILS",
- "Command line parameters to specify login access",
- "-u user -ppw -d db",
- );
+my $mysqlserver = getTestParameter("NP_MYSQL_SERVER", "A MySQL Server with no slaves setup");
+my $mysql_login_details = getTestParameter("NP_MYSQL_LOGIN_DETAILS", "Command line parameters to specify login access", "-u user -ppw -d db");
my $result;
if (! $mysqlserver) {
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t
index 9a6cd2bb..f2f218fd 100644
--- a/plugins/t/check_snmp.t
+++ b/plugins/t/check_snmp.t
@@ -15,18 +15,12 @@ BEGIN {
my $res;
-my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost",
- "A host providing an SNMP Service");
+my $host_snmp = getTestParameter("NP_HOST_SNMP", "A host providing an SNMP Service", "localhost");
+my $snmp_community = getTestParameter("NP_SNMP_COMMUNITY", "The SNMP Community string for SNMP Testing (assumes snmp v1)", "public");
+my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1");
+my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost");
+my $user_snmp = getTestParameter("NP_SNMP_USER", "An SNMP user", "auth_md5");
-my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public",
- "The SNMP Community string for SNMP Testing (assumes snmp v1)" );
-
-my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
- "The hostname of system not responsive to network requests" );
-
-my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
- "An invalid (not known to DNS) hostname" );
-my $user_snmp = getTestParameter( "user_snmp", "NP_SNMP_USER", "auth_md5", "An SNMP user");
$res = NPTest->testCmd( "./check_snmp -t 1" );
is( $res->return_code, 3, "No host name" );
diff --git a/plugins/t/check_ssh.t b/plugins/t/check_ssh.t
index 80083492..a5cd23ce 100644
--- a/plugins/t/check_ssh.t
+++ b/plugins/t/check_ssh.t
@@ -9,17 +9,9 @@ use Test::More;
use NPTest;
# Required parameters
-my $ssh_host = getTestParameter("NP_SSH_HOST",
- "A host providing SSH service",
- "localhost");
-
-my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE",
- "The hostname of system not responsive to network requests",
- "10.0.0.1" );
-
-my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID",
- "An invalid (not known to DNS) hostname",
- "nosuchhost" );
+my $ssh_host = getTestParameter("NP_SSH_HOST", "A host providing SSH service", "localhost");
+my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1" );
+my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost" );
plan skip_all => "SSH_HOST must be defined" unless $ssh_host;
diff --git a/plugins/t/check_tcp.t b/plugins/t/check_tcp.t
index 121b0cb3..cb4de53d 100644
--- a/plugins/t/check_tcp.t
+++ b/plugins/t/check_tcp.t
@@ -15,21 +15,11 @@ BEGIN {
}
-my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost",
- "A host providing the HTTP Service (a web server)" );
-
-my $host_tls_http = getTestParameter( "host_tls_http", "NP_HOST_TLS_HTTP", "localhost",
- "A host providing the HTTPS Service (a tls web server)" );
-
-my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
- "The hostname of system not responsive to network requests" );
-
-my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
- "An invalid (not known to DNS) hostname" );
-
-my $internet_access = getTestParameter( "NP_INTERNET_ACCESS",
- "Is this system directly connected to the internet?",
- "yes");
+my $host_tcp_http = getTestParameter("NP_HOST_TCP_HTTP", "A host providing the HTTP Service (a web server)", "localhost");
+my $host_tls_http = getTestParameter("NP_HOST_TLS_HTTP", "A host providing the HTTPS Service (a tls web server)", "localhost");
+my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1");
+my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost");
+my $internet_access = getTestParameter("NP_INTERNET_ACCESS", "Is this system directly connected to the internet?", "yes");
my $successOutput = '/^TCP OK\s-\s+[0-9]?\.?[0-9]+ second response time on port [0-9]+/';
diff --git a/plugins/t/check_time.t b/plugins/t/check_time.t
index 961f56e6..92c2f891 100644
--- a/plugins/t/check_time.t
+++ b/plugins/t/check_time.t
@@ -11,14 +11,9 @@ use NPTest;
use vars qw($tests);
BEGIN {$tests = 8; plan tests => $tests}
-my $host_udp_time = getTestParameter( "host_udp_time", "NP_HOST_UDP_TIME", "localhost",
- "A host providing the UDP Time Service" );
-
-my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
- "The hostname of system not responsive to network requests" );
-
-my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
- "An invalid (not known to DNS) hostname" );
+my $host_udp_time = getTestParameter("NP_HOST_UDP_TIME", "A host providing the UDP Time Service", "localhost");
+my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1");
+my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost");
my $successOutput = '/^TIME OK - [0-9]+ second time difference/';
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t
index 73a68b20..85d6bf55 100755
--- a/plugins/tests/check_snmp.t
+++ b/plugins/tests/check_snmp.t
@@ -7,6 +7,7 @@ use strict;
use Test::More;
use NPTest;
use FindBin qw($Bin);
+use POSIX qw/strftime/;
my $tests = 67;
# Check that all dependent modules are available
@@ -37,6 +38,7 @@ if ($@) {
my $port_snmp = 16100 + int(rand(100));
+my $faketime = -x '/usr/bin/faketime' ? 1 : 0;
# Start up server
my @pids;
@@ -118,77 +120,81 @@ like($res->output, '/'.quotemeta('SNMP OK - And now have fun with with this: \"C
"And now have fun with with this: \"C:\\\\\"
because we\'re not done yet!"').'/m', "Attempt to confuse parser No.3");
-system("rm -f ".$ENV{'MP_STATE_PATH'}."/check_snmp/*");
-$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" );
-is($res->return_code, 0, "Returns OK");
-is($res->output, "No previous data to calculate rate - assume okay");
+system("rm -f ".$ENV{'MP_STATE_PATH'}."/*/check_snmp/*");
-# Need to sleep, otherwise duration=0
-sleep 1;
+# run rate checks with faketime. rate checks depend on the exact amount of time spend between the
+# plugin runs which may fail on busy machines.
+# using faketime removes this race condition and also saves all the sleeps in between.
+SKIP: {
+ skip "No faketime binary found", 28 if !$faketime;
-$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" );
-is($res->return_code, 1, "WARNING - due to going above rate calculation" );
-is($res->output, "SNMP RATE WARNING - *666* | iso.3.6.1.4.1.8072.3.2.67.10=666;600 ");
+ my $ts = time();
+ $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./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" );
+ is($res->return_code, 0, "Returns OK");
+ is($res->output, "No previous data to calculate rate - assume okay");
-$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" );
-is($res->return_code, 3, "UNKNOWN - basically the divide by zero error" );
-is($res->output, "Time duration between plugin calls is invalid");
+ # test rate 1 second later
+ $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./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" );
+ is($res->return_code, 1, "WARNING - due to going above rate calculation" );
+ is($res->output, "SNMP RATE WARNING - *666* | iso.3.6.1.4.1.8072.3.2.67.10=666;600 ");
+ # test rate with same time
+ $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./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" );
+ is($res->return_code, 3, "UNKNOWN - basically the divide by zero error" );
+ is($res->output, "Time duration between plugin calls is invalid");
-$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 -l inoctets" );
-is($res->return_code, 0, "OK for first call" );
-is($res->output, "No previous data to calculate rate - assume okay" );
-# Need to sleep, otherwise duration=0
-sleep 1;
+ $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./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 -l inoctets" );
+ is($res->return_code, 0, "OK for first call" );
+ is($res->output, "No previous data to calculate rate - assume okay" );
-$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 -l inoctets" );
-is($res->return_code, 0, "OK as no thresholds" );
-is($res->output, "SNMP RATE OK - inoctets 666 | inoctets=666 ", "Check label");
+ # test rate 1 second later
+ $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./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 -l inoctets" );
+ is($res->return_code, 0, "OK as no thresholds" );
+ is($res->output, "SNMP RATE OK - inoctets 666 | inoctets=666 ", "Check label");
-sleep 2;
+ # test rate 3 seconds later
+ $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+3))."' ./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 -l inoctets" );
+ is($res->return_code, 0, "OK as no thresholds" );
+ is($res->output, "SNMP RATE OK - inoctets 333 | inoctets=333 ", "Check rate decreases due to longer interval");
-$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 -l inoctets" );
-is($res->return_code, 0, "OK as no thresholds" );
-is($res->output, "SNMP RATE OK - inoctets 333 | inoctets=333 ", "Check rate decreases due to longer interval");
+ # label performance data check
+ $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 -l test" );
+ is($res->return_code, 0, "OK as no thresholds" );
+ is($res->output, "SNMP OK - test 67996 | test=67996c ", "Check label");
-# label performance data check
-$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 -l test" );
-is($res->return_code, 0, "OK as no thresholds" );
-is($res->output, "SNMP OK - test 67996 | test=67996c ", "Check label");
+ $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 -l \"test'test\"" );
+ is($res->return_code, 0, "OK as no thresholds" );
+ is($res->output, "SNMP OK - test'test 68662 | \"test'test\"=68662c ", "Check label");
-$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 -l \"test'test\"" );
-is($res->return_code, 0, "OK as no thresholds" );
-is($res->output, "SNMP OK - test'test 68662 | \"test'test\"=68662c ", "Check label");
+ $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 -l 'test\"test'" );
+ is($res->return_code, 0, "OK as no thresholds" );
+ is($res->output, "SNMP OK - test\"test 69328 | 'test\"test'=69328c ", "Check label");
-$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 -l 'test\"test'" );
-is($res->return_code, 0, "OK as no thresholds" );
-is($res->output, "SNMP OK - test\"test 69328 | 'test\"test'=69328c ", "Check label");
+ $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 -l test -O" );
+ is($res->return_code, 0, "OK as no thresholds" );
+ is($res->output, "SNMP OK - test 69994 | iso.3.6.1.4.1.8072.3.2.67.10=69994c ", "Check label");
-$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 -l test -O" );
-is($res->return_code, 0, "OK as no thresholds" );
-is($res->output, "SNMP OK - test 69994 | iso.3.6.1.4.1.8072.3.2.67.10=69994c ", "Check label");
+ $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" );
+ is($res->return_code, 0, "OK as no thresholds" );
+ is($res->output, "SNMP OK - 70660 | iso.3.6.1.4.1.8072.3.2.67.10=70660c ", "Check label");
-$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" );
-is($res->return_code, 0, "OK as no thresholds" );
-is($res->output, "SNMP OK - 70660 | iso.3.6.1.4.1.8072.3.2.67.10=70660c ", "Check label");
+ $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 -l 'test test'" );
+ is($res->return_code, 0, "OK as no thresholds" );
+ is($res->output, "SNMP OK - test test 71326 | 'test test'=71326c ", "Check label");
-$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 -l 'test test'" );
-is($res->return_code, 0, "OK as no thresholds" );
-is($res->output, "SNMP OK - test test 71326 | 'test test'=71326c ", "Check label");
+ $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./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 -l inoctets_per_minute --rate-multiplier=60" );
+ is($res->return_code, 0, "OK for first call" );
+ is($res->output, "No previous data to calculate rate - assume okay" );
-$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 -l inoctets_per_minute --rate-multiplier=60" );
-is($res->return_code, 0, "OK for first call" );
-is($res->output, "No previous data to calculate rate - assume okay" );
-
-# Need to sleep, otherwise duration=0
-sleep 1;
+ # test 1 second later
+ $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./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 -l inoctets_per_minute --rate-multiplier=60" );
+ is($res->return_code, 0, "OK as no thresholds" );
+ is($res->output, "SNMP RATE OK - inoctets_per_minute 39960 | inoctets_per_minute=39960 ", "Checking multiplier");
+};
-$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 -l inoctets_per_minute --rate-multiplier=60" );
-is($res->return_code, 0, "OK as no thresholds" );
-is($res->output, "SNMP RATE OK - inoctets_per_minute 39960 | inoctets_per_minute=39960 ", "Checking multiplier");
$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.11 -s '\"stringtests\"'" );