diff options
Diffstat (limited to 'plugins/tests')
-rw-r--r-- | plugins/tests/certs/expired-cert.pem | 41 | ||||
-rw-r--r-- | plugins/tests/certs/expired-key.pem | 43 | ||||
-rw-r--r-- | plugins/tests/certs/server-cert.pem | 41 | ||||
-rw-r--r-- | plugins/tests/certs/server-key.pem | 43 | ||||
-rwxr-xr-x | plugins/tests/check_curl.t | 509 | ||||
-rwxr-xr-x | plugins/tests/check_http.t | 89 | ||||
-rwxr-xr-x | plugins/tests/check_snmp.t | 110 |
7 files changed, 736 insertions, 140 deletions
diff --git a/plugins/tests/certs/expired-cert.pem b/plugins/tests/certs/expired-cert.pem index 40324cf8..77a9166e 100644 --- a/plugins/tests/certs/expired-cert.pem +++ b/plugins/tests/certs/expired-cert.pem | |||
@@ -1,21 +1,24 @@ | |||
1 | -----BEGIN CERTIFICATE----- | 1 | -----BEGIN CERTIFICATE----- |
2 | MIIDYzCCAsygAwIBAgIJAJISzcX71f5pMA0GCSqGSIb3DQEBBAUAMH8xCzAJBgNV | 2 | MIIEETCCAvmgAwIBAgIUFDsP6WnV/uqeQMpD/DYSqouE13kwDQYJKoZIhvcNAQEL |
3 | BAYTAlVLMRMwEQYDVQQIEwpEZXJieXNoaXJlMQ8wDQYDVQQHEwZCZWxwZXIxFzAV | 3 | BQAwgZcxCzAJBgNVBAYTAkRFMRAwDgYDVQQIDAdCYXZhcmlhMQ8wDQYDVQQHDAZN |
4 | BgNVBAoTDk5hZ2lvcyBQbHVnaW5zMREwDwYDVQQDEwhUb24gVm9vbjEeMBwGCSqG | 4 | dW5pY2gxGzAZBgNVBAoMEk1vbml0b3JpbmcgUGx1Z2luczEbMBkGA1UEAwwSTW9u |
5 | SIb3DQEJARYPdG9udm9vbkBtYWMuY29tMB4XDTA5MDMwNjAwMTMxNVoXDTA5MDMw | 5 | aXRvcmluZyBQbHVnaW5zMSswKQYJKoZIhvcNAQkBFhxkZXZlbEBtb25pdG9yaW5n |
6 | NTAwMTMxNlowfzELMAkGA1UEBhMC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Sf7 | ||
23 | eCaHtO0VKsbLZoiTmpxidjsdYiXyeKYIQNtUpTjyJ5V/cZsq9w== | ||
21 | -----END CERTIFICATE----- | 24 | -----END CERTIFICATE----- |
diff --git a/plugins/tests/certs/expired-key.pem b/plugins/tests/certs/expired-key.pem index af0e24da..c1510b2d 100644 --- a/plugins/tests/certs/expired-key.pem +++ b/plugins/tests/certs/expired-key.pem | |||
@@ -1,15 +1,28 @@ | |||
1 | -----BEGIN RSA PRIVATE KEY----- | 1 | -----BEGIN PRIVATE KEY----- |
2 | MIICXAIBAAKBgQDkBz+CZ8wAouKuqrlwIivoE0n3xussoxFfiosrrUYARdjHRdN1 | 2 | MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDJ4crAoWMlZRdg |
3 | +ZbNMBDcP+X5zE6x8p5eF6BqFf6w+AkdoRk9Ju3b+1btDES5TydUgohXjLkEt9M8 | 3 | cqyKzKlR/10eUg9AAhLIY/UFfpQvbpku8TqQpvHcsVD1bY84ahBaXMWIHWygZ5VY |
4 | yzCa9AOyFvOvakZSkJs8bNSU+lw20qDULhdeeM6McDbCpTI6F7SUhzdmKQIDAQAB | 4 | N3RTQm1Z0IqY5dZ1xem6lCVNJS1EIwNCR+os3wZHlMFN3vet7OnmbPTycx8vC7Sn |
5 | AoGARgI3rHjjuDpKMGg4IMZNBqaNaiZHY9/44IVvrww21rSbFqtIfgsQEpU0R/rS | 5 | lVDX3VSLwkcWCsA5qUCfxTDkN7y+PhWZNeZTk0nZQWgLR11T9OH+XBEJrIdzVycx |
6 | R7xDWPztRGQqmwd/t6OfYNpqHbjO1MWzasVBVnzue5P59Y1xy1h0LZF8+a9GY++0 | 6 | WrYXtz+6ExRRBg0GYnLSnGgdrCn6P00qX/EhiyOBA2BqFDI26zC4YeNoTCE+77sb |
7 | uAGUC24jsXSmypNVzoX+ZKyinA3oYV/etdPYx1W8Ms5XIzUCQQD7xwhMuLok6Kbq | 7 | Tdexbh6G74fXz3wz8yRKWfotABTWzKgnzKk8zy1X7ODHi7CPu52dnaFx433m5bvQ |
8 | UEgiSfBTbx+haP3IiqqMF14z8QoEyD3jchydNaXEYdQxN8jEl2aPrMqTc6x8Jq4/ | 8 | 9aDkNDJTAgMBAAECggEACrLFfNnQmD24NGs/S4e2/VpsA9xTZI/3kNkDNgxULANP |
9 | ai0OkB+fAkEA59pAmN81HylV7+CsVjLOSbJqzau7NDxSs2uutxhHZRwz0e25wVer | 9 | aNZtxRajwI9A/BCXQ2UTgsZhzWnJxOJYXrlpl7PweY78mUesysb3MOUC6QisUm0M |
10 | fA03l08u0ebC/TDHkmHV6ikCryM5HU2FNwJAVZJFzd2S1myEHmr+uTisB49jDrbi | 10 | kimfdktHWOnAKLFFLNleN9DUVjjVkTeslijqhNX80f80py1grG2UuCLKCX4OqYIm |
11 | WkBWypo+mCS6JPnxntXvx7auClq9haTSBY73eqldiFPuMZvr6P2rJqHxPQJBAOTM | 11 | qACE8TMmSZLz42AO96TndNtKplQ8LuGLEmByW95wEfhx3Gm4ckkL7qII/U3DnQXr |
12 | quaxjti7kATy8N73sD9mBKQGju1TgkFxSK+DFCGhnTnToXY9MAtxd6SoDYoyccYu | 12 | 0T+3xLaj+eNJzYDpIFZiw4sNzOuAyCz+4Cc4sPDuMnzquXF+enpkemoycC1RmEpG |
13 | dyPrzJAR/IYc+mYCdC0CQDKlZuMPVXEgvGaQapzMQ++5yJRvMZF4tWvONBs0OCE9 | 13 | KIDTwmFsc8TrbGV0qifC6fsCrDivdYLqL7R/q3IBQQKBgQDmfvO3VYTEKY8NA+AT |
14 | QYarsTi5M20cymMBXHOLZIjqwsni4G/C9kqJSvC75Vg= | 14 | 5s6+7NTxRsXxJUCEhCNBWimSH3EzmBAvrodLY6A0oYg8i81bgNX1I9GPVXJZ/QA7 |
15 | -----END RSA PRIVATE KEY----- | 15 | ukd84HUIQoGS5Usmo4rp+kz4P6KkLXDemZtWPU5GXxicfajHRQlkbW6St6SpV7IS |
16 | ibJcDADeoiaPL1xvue1ToP/LoQKBgQDgOFHjYpep00gabvjXfYW7vhrg1vVwaKUM | ||
17 | rf0+UW8Exk4nbBw0eEC2YjxIwzdktlkdbzGaXYULnhg8GnfxYesMOpCLPw1JdB8o | ||
18 | ixETAFpW5bKrUsjEFRUGhzWnsCSFIQ4smpmtGLTxOQ8AkoDdORY5Z+Wv7JtFF6Do | ||
19 | PSoblckZcwKBgB3TD3YJesRnHDty5OuuUdIikuslXTd2uoJrFqS+JeLibqNeabnB | ||
20 | u3/lxDULMbWj4U6VvRmbKOKDC+jY887Gq7lc0cff0yROxwqY3sCnwo3crg7QUmp7 | ||
21 | Nb5S8G3qoCSfndcq96wm/Me/O28uCbycVJfUdchY8uRUHIHYbP0FOBQBAoGBAMgh | ||
22 | fPX4imaKr1DovDObVkK87EDDnU84GBm5MtDs3qrkVd3aIVK0Aw7HoAdSN58tI12i | ||
23 | YiPmVVqJQhhjh6tsOuAvZdTj8ngdrbICbrsHFZt6an+A5LIgHyQ0iy+hiPdLCdvG | ||
24 | ImTeKKMmyr04Bs1upueWVO0xw2VoMbcY4Py+NUEBAoGASQqedfCSKGLT+5lLZrhP | ||
25 | CbFVMmswEPjBcRb1trcuA09vfExn9FfUNFnnw3i9miprED5kufvAjb+6nduXizKg | ||
26 | 7HQYHCwVvakgtXgbiDMaNgYZcjWm+MdnfiwLJjJTO3DfI1JF2PJ8y9R95DPlAkDm | ||
27 | xH3OV8KV4UiTEVxS7ksmGzY= | ||
28 | -----END PRIVATE KEY----- | ||
diff --git a/plugins/tests/certs/server-cert.pem b/plugins/tests/certs/server-cert.pem index 549e4f7e..b84b91d2 100644 --- a/plugins/tests/certs/server-cert.pem +++ b/plugins/tests/certs/server-cert.pem | |||
@@ -1,21 +1,24 @@ | |||
1 | -----BEGIN CERTIFICATE----- | 1 | -----BEGIN CERTIFICATE----- |
2 | MIIDYzCCAsygAwIBAgIJAL8LkpNwzYdxMA0GCSqGSIb3DQEBBAUAMH8xCzAJBgNV | 2 | MII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MAMBAf8wDQYJKoZIhvcN |
18 | N2NHiNNUunolIZEYR+dW99ezKmHlDiQ/tMgoLVYpl2Ubho2pAkLGQR+W0ZASgWQ1 | 18 | AQELBQADggEBAGwitJPOnlIKLndNf+iCLMIs0dxsl8kAaejFcjoT0n4ja7Y6Zrqz |
19 | NjfV27Rv0y6lYQMTA0lVAU93L1x9reo3FMedmL5+H+lIEpLCxEPtAJNISrJOneZB | 19 | VSIidzz9vQWvy24xKJpAOdj/iLRHCUOG+Pf5fA6+/FiuqXr6gE2/lm0eC58BNONr |
20 | W5jDadwkoQ== | 20 | E5OzjQ/VoQ8RX4hDntgu6FYbaVa/vhwn16igt9qmdNGGZXf2/+DM3JADwyaA4EK8 |
21 | vm7KdofX9zkxXecHPNvf3jiVLPiDDt6tkGpHPEsyP/yc+RUdltUeZvHfliV0cCuC | ||
22 | jJX+Fm9ysjSpHIFFr+jUMuMHibWoOD8iy3eYxfCDoWsH488pCbj8MNuAq6vd6DBk | ||
23 | bOZxDz43vjWuYMkwXJTxJQh7Pne6kK0vE1g= | ||
21 | -----END CERTIFICATE----- | 24 | -----END CERTIFICATE----- |
diff --git a/plugins/tests/certs/server-key.pem b/plugins/tests/certs/server-key.pem index eacaeaa3..11947555 100644 --- a/plugins/tests/certs/server-key.pem +++ b/plugins/tests/certs/server-key.pem | |||
@@ -1,15 +1,28 @@ | |||
1 | -----BEGIN RSA PRIVATE KEY----- | 1 | -----BEGIN PRIVATE KEY----- |
2 | MIICWwIBAAKBgQCnFjAbTbX2PL2V5NEjevxGE1Tfyzr2jknoMqFXS6BsLsI2oJPl | 2 | MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCoFdsqfKULybjf |
3 | 5gs7wqh2UafJZwi2suwDvAECO00jdNooQnEq4BgPTk/h3IiCdZef5BGFALgNT0em | 3 | miRnQHuh3dLY2rrXgj3DSHDPdlizhevUy00mKJ9Vw6J+LR04eGeXeJQ/G37BsxVQ |
4 | Civ0+9d81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o3VF0sctTX0 |
12 | sYP3urg7zzx7c3qUe5gJ0wLuefjR1PSX4ecbfb7DDMdcSdjIuG1QDiZGmd2f1KG7 | 12 | ItP8A9qDmDQN7GIWX0MW6gncojpS1omC2wcFsdjj/xfPyiDal1X4aq/2YqG8351c |
13 | nwSCOtxk5dloW2KGAQJAQh/iBn0QhfKLFAP5eZBVk8E8XlZuw+S2DLy5SnBlIiYJ | 13 | YlM/+6Va0u9WWE/i64gASTAVqpMV4Yg8y0gGycuA0QKBgQDbgI2QeLd3FvMcURiU |
14 | GB5I2OClgtudXMv1labFrcST8O9eFrtsrhU1iUGUOw== | 14 | l3w9qJgw/Jp3jaNC/9LkVGGz4f4lKKB67lPZvI4noMK8GqO/LcXgqP/RY1oJojoA |
15 | -----END RSA PRIVATE KEY----- | 15 | /6JKVvzYGASZ7VgMoG9bk1AneP1PGdibuTUEwimGlcObxnDFIC/yjwPFu3jIdqdS |
16 | zZi1RZzyqAogN5y3SBEypSmn9wKBgQDECKsqqlcizmCl8v5aVk875AzGN+DOHZqx | ||
17 | bkmztlnLO/2e2Fmk3G5Vvnui0FYisf8Eq19tUTQCF6lSfJlGQeFAT119wkFZhLu+ | ||
18 | FfLGqoEMH0ijJg/8PpdpFRK3I94YcISoTNN6yxMvE6xdDGfKCt5a+IX5bwQi9Zdc | ||
19 | B242gEc6tQKBgA6tM8n7KFlAIZU9HuWgk2AUC8kKutFPmSD7tgAqXDYI4FNfugs+ | ||
20 | MEEYyHCB4UNujJBV4Ss6YZCAkh6eyD4U2aca1eElCfm40vBVMdzvpqZdAqLtWXxg | ||
21 | D9l3mgszrFaYGCY2Fr6jLV9lP5g3xsxUjudf9jSLY9HvpfzjRrMaNATVAoGBALTl | ||
22 | /vYfPMucwKlC5B7++J0e4/7iv6vUu9SyHocdZh1anb9AjPDKjXLIlZT4RhQ8R0XK | ||
23 | 0wOw5JpttU2uN08TKkbLNk3/vYhbKVjPLjrQSseh8sjDLgsqw1QwIxYnniLVakVY | ||
24 | p+rvjSNrNyqicQCMKQavwgocvSd5lJRTMwxOMezlAoGBAKWj71BX+0CK00/2S6lC | ||
25 | TcNcuUPG0d8y1czZ4q6tUlG4htwq1FMOpaghATXjkdsOGTLS+H1aA0Kt7Ai9zDhc | ||
26 | /bzOJEJ+jvBXV4Gcs7jl1r/HTKv0tT9ZSI5Vzkida0rfqxDGzcMVlLuCdH0cb8Iu | ||
27 | N0wdmCAqlQwHR13+F1zrAD7V | ||
28 | -----END PRIVATE KEY----- | ||
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t new file mode 100755 index 00000000..29cb03f2 --- /dev/null +++ b/plugins/tests/check_curl.t | |||
@@ -0,0 +1,509 @@ | |||
1 | #! /usr/bin/perl -w -I .. | ||
2 | # | ||
3 | # Test check_http by having an actual HTTP server running | ||
4 | # | ||
5 | # To create the https server certificate: | ||
6 | # openssl req -new -x509 -keyout server-key.pem -out server-cert.pem -days 3650 -nodes | ||
7 | # to create a new expired certificate: | ||
8 | # faketime '2008-01-01 12:00:00' openssl req -new -x509 -keyout expired-key.pem -out expired-cert.pem -days 1 -nodes | ||
9 | # Country Name (2 letter code) [AU]:DE | ||
10 | # State or Province Name (full name) [Some-State]:Bavaria | ||
11 | # Locality Name (eg, city) []:Munich | ||
12 | # Organization Name (eg, company) [Internet Widgits Pty Ltd]:Monitoring Plugins | ||
13 | # Organizational Unit Name (eg, section) []: | ||
14 | # Common Name (e.g. server FQDN or YOUR name) []:Monitoring Plugins | ||
15 | # Email Address []:devel@monitoring-plugins.org | ||
16 | |||
17 | use strict; | ||
18 | use Test::More; | ||
19 | use NPTest; | ||
20 | use FindBin qw($Bin); | ||
21 | |||
22 | $ENV{'LC_TIME'} = "C"; | ||
23 | |||
24 | my $common_tests = 72; | ||
25 | my $ssl_only_tests = 8; | ||
26 | # Check that all dependent modules are available | ||
27 | eval "use HTTP::Daemon 6.01;"; | ||
28 | plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@; | ||
29 | eval { | ||
30 | require HTTP::Status; | ||
31 | require HTTP::Response; | ||
32 | }; | ||
33 | |||
34 | my $plugin = 'check_http'; | ||
35 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; | ||
36 | |||
37 | # look for libcurl version to see if some advanced checks are possible (>= 7.49.0) | ||
38 | my $advanced_checks = 12; | ||
39 | my $use_advanced_checks = 0; | ||
40 | my $required_version = '7.49.0'; | ||
41 | my $virtual_host = 'www.somefunnyhost.com'; | ||
42 | my $virtual_port = 42; | ||
43 | my $curl_version = ''; | ||
44 | open (my $fh, '-|', "./$plugin --version") or die; | ||
45 | while (<$fh>) { | ||
46 | if (m{libcurl/([\d.]+)\s}) { | ||
47 | $curl_version = $1; | ||
48 | last; | ||
49 | } | ||
50 | } | ||
51 | close ($fh); | ||
52 | if ($curl_version) { | ||
53 | my ($major, $minor, $release) = split (/\./, $curl_version); | ||
54 | my ($req_major, $req_minor, $req_release) = split (/\./, $required_version); | ||
55 | my $check = ($major <=> $req_major or $minor <=> $req_minor or $release <=> $req_release); | ||
56 | if ($check >= 0) { | ||
57 | $use_advanced_checks = 1; | ||
58 | print "Found libcurl $major.$minor.$release. Using advanced checks\n"; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | if ($@) { | ||
63 | plan skip_all => "Missing required module for test: $@"; | ||
64 | } else { | ||
65 | if (-x "./$plugin") { | ||
66 | plan tests => $common_tests * 2 + $ssl_only_tests + $advanced_checks; | ||
67 | } else { | ||
68 | plan skip_all => "No $plugin compiled"; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | my $servers = { http => 0 }; # HTTP::Daemon should always be available | ||
73 | eval { require HTTP::Daemon::SSL }; | ||
74 | if ($@) { | ||
75 | diag "Cannot load HTTP::Daemon::SSL: $@"; | ||
76 | } else { | ||
77 | $servers->{https} = 0; | ||
78 | } | ||
79 | |||
80 | # set a fixed version, so the header size doesn't vary | ||
81 | $HTTP::Daemon::VERSION = "1.00"; | ||
82 | |||
83 | my $port_http = 50000 + int(rand(1000)); | ||
84 | my $port_https = $port_http + 1; | ||
85 | my $port_https_expired = $port_http + 2; | ||
86 | |||
87 | # This array keeps sockets around for implementing timeouts | ||
88 | my @persist; | ||
89 | |||
90 | # Start up all servers | ||
91 | my @pids; | ||
92 | my $pid = fork(); | ||
93 | if ($pid) { | ||
94 | # Parent | ||
95 | push @pids, $pid; | ||
96 | if (exists $servers->{https}) { | ||
97 | # Fork a normal HTTPS server | ||
98 | $pid = fork(); | ||
99 | if ($pid) { | ||
100 | # Parent | ||
101 | push @pids, $pid; | ||
102 | # Fork an expired cert server | ||
103 | $pid = fork(); | ||
104 | if ($pid) { | ||
105 | push @pids, $pid; | ||
106 | } else { | ||
107 | my $d = HTTP::Daemon::SSL->new( | ||
108 | LocalPort => $port_https_expired, | ||
109 | LocalAddr => "127.0.0.1", | ||
110 | SSL_cert_file => "$Bin/certs/expired-cert.pem", | ||
111 | SSL_key_file => "$Bin/certs/expired-key.pem", | ||
112 | ) || die; | ||
113 | print "Please contact https expired at: <URL:", $d->url, ">\n"; | ||
114 | run_server( $d ); | ||
115 | exit; | ||
116 | } | ||
117 | } else { | ||
118 | my $d = HTTP::Daemon::SSL->new( | ||
119 | LocalPort => $port_https, | ||
120 | LocalAddr => "127.0.0.1", | ||
121 | SSL_cert_file => "$Bin/certs/server-cert.pem", | ||
122 | SSL_key_file => "$Bin/certs/server-key.pem", | ||
123 | ) || die; | ||
124 | print "Please contact https at: <URL:", $d->url, ">\n"; | ||
125 | run_server( $d ); | ||
126 | exit; | ||
127 | } | ||
128 | } | ||
129 | } else { | ||
130 | # Child | ||
131 | #print "child\n"; | ||
132 | my $d = HTTP::Daemon->new( | ||
133 | LocalPort => $port_http, | ||
134 | LocalAddr => "127.0.0.1", | ||
135 | ) || die; | ||
136 | print "Please contact http at: <URL:", $d->url, ">\n"; | ||
137 | run_server( $d ); | ||
138 | exit; | ||
139 | } | ||
140 | |||
141 | # give our webservers some time to startup | ||
142 | sleep(3); | ||
143 | |||
144 | # Run the same server on http and https | ||
145 | sub run_server { | ||
146 | my $d = shift; | ||
147 | MAINLOOP: while (my $c = $d->accept ) { | ||
148 | while (my $r = $c->get_request) { | ||
149 | if ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) { | ||
150 | $c->send_basic_header($1); | ||
151 | $c->send_crlf; | ||
152 | } elsif ($r->method eq "GET" and $r->url->path =~ m^/file/(.*)^) { | ||
153 | $c->send_basic_header; | ||
154 | $c->send_crlf; | ||
155 | $c->send_file_response("$Bin/var/$1"); | ||
156 | } elsif ($r->method eq "GET" and $r->url->path eq "/slow") { | ||
157 | $c->send_basic_header; | ||
158 | $c->send_crlf; | ||
159 | sleep 1; | ||
160 | $c->send_response("slow"); | ||
161 | } elsif ($r->url->path eq "/method") { | ||
162 | if ($r->method eq "DELETE") { | ||
163 | $c->send_error(HTTP::Status->RC_METHOD_NOT_ALLOWED); | ||
164 | } elsif ($r->method eq "foo") { | ||
165 | $c->send_error(HTTP::Status->RC_NOT_IMPLEMENTED); | ||
166 | } else { | ||
167 | $c->send_status_line(200, $r->method); | ||
168 | } | ||
169 | } elsif ($r->url->path eq "/postdata") { | ||
170 | $c->send_basic_header; | ||
171 | $c->send_crlf; | ||
172 | $c->send_response($r->method.":".$r->content); | ||
173 | } elsif ($r->url->path eq "/redirect") { | ||
174 | $c->send_redirect( "/redirect2" ); | ||
175 | } elsif ($r->url->path eq "/redir_external") { | ||
176 | $c->send_redirect(($d->isa('HTTP::Daemon::SSL') ? "https" : "http") . "://169.254.169.254/redirect2" ); | ||
177 | } elsif ($r->url->path eq "/redirect2") { | ||
178 | $c->send_basic_header; | ||
179 | $c->send_crlf; | ||
180 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' )); | ||
181 | } elsif ($r->url->path eq "/redir_timeout") { | ||
182 | $c->send_redirect( "/timeout" ); | ||
183 | } elsif ($r->url->path eq "/timeout") { | ||
184 | # Keep $c from being destroyed, but prevent severe leaks | ||
185 | unshift @persist, $c; | ||
186 | delete($persist[1000]); | ||
187 | next MAINLOOP; | ||
188 | } elsif ($r->url->path eq "/header_check") { | ||
189 | $c->send_basic_header; | ||
190 | $c->send_header('foo'); | ||
191 | $c->send_crlf; | ||
192 | } elsif ($r->url->path eq "/header_broken_check") { | ||
193 | $c->send_basic_header; | ||
194 | $c->send_header('foo'); | ||
195 | print $c "Test1:: broken\n"; | ||
196 | print $c " Test2: leading whitespace\n"; | ||
197 | $c->send_crlf; | ||
198 | } elsif ($r->url->path eq "/virtual_port") { | ||
199 | # return sent Host header | ||
200 | $c->send_basic_header; | ||
201 | $c->send_crlf; | ||
202 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host'))); | ||
203 | } else { | ||
204 | $c->send_error(HTTP::Status->RC_FORBIDDEN); | ||
205 | } | ||
206 | $c->close; | ||
207 | } | ||
208 | } | ||
209 | } | ||
210 | |||
211 | END { | ||
212 | foreach my $pid (@pids) { | ||
213 | if ($pid) { print "Killing $pid\n"; kill "INT", $pid } | ||
214 | } | ||
215 | }; | ||
216 | |||
217 | if ($ARGV[0] && $ARGV[0] eq "-d") { | ||
218 | while (1) { | ||
219 | sleep 100; | ||
220 | } | ||
221 | } | ||
222 | |||
223 | my $result; | ||
224 | my $command = "./$plugin -H 127.0.0.1"; | ||
225 | |||
226 | run_common_tests( { command => "$command -p $port_http" } ); | ||
227 | SKIP: { | ||
228 | skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https}; | ||
229 | run_common_tests( { command => "$command -p $port_https", ssl => 1 } ); | ||
230 | |||
231 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); | ||
232 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); | ||
233 | is( $result->output, "OK - Certificate 'Monitoring Plugins' will expire on Fri Feb 16 15:31:44 2029 +0000.", "output ok" ); | ||
234 | |||
235 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); | ||
236 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); | ||
237 | like( $result->output, '/WARNING - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" ); | ||
238 | |||
239 | # Expired cert tests | ||
240 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); | ||
241 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); | ||
242 | like( $result->output, '/CRITICAL - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" ); | ||
243 | |||
244 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); | ||
245 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); | ||
246 | is( $result->output, | ||
247 | 'CRITICAL - Certificate \'Monitoring Plugins\' expired on Wed Jan 2 11:00:26 2008 +0000.', | ||
248 | "output ok" ); | ||
249 | |||
250 | } | ||
251 | |||
252 | my $cmd; | ||
253 | |||
254 | # advanced checks with virtual hostname and virtual port | ||
255 | SKIP: { | ||
256 | skip "libcurl version is smaller than $required_version", 6 unless $use_advanced_checks; | ||
257 | |||
258 | # http without virtual port | ||
259 | $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$port_http\$"; | ||
260 | $result = NPTest->testCmd( $cmd ); | ||
261 | is( $result->return_code, 0, $cmd); | ||
262 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
263 | |||
264 | # http with virtual port (!= 80) | ||
265 | $cmd = "./$plugin -H $virtual_host:$virtual_port -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$virtual_port\$"; | ||
266 | $result = NPTest->testCmd( $cmd ); | ||
267 | is( $result->return_code, 0, $cmd); | ||
268 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
269 | |||
270 | # http with virtual port (80) | ||
271 | $cmd = "./$plugin -H $virtual_host:80 -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host\$"; | ||
272 | $result = NPTest->testCmd( $cmd ); | ||
273 | is( $result->return_code, 0, $cmd); | ||
274 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
275 | } | ||
276 | |||
277 | # and the same for SSL | ||
278 | SKIP: { | ||
279 | skip "libcurl version is smaller than $required_version and/or HTTP::Daemon::SSL not installed", 6 if ! exists $servers->{https} or not $use_advanced_checks; | ||
280 | # https without virtual port | ||
281 | $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host:$port_https\$"; | ||
282 | $result = NPTest->testCmd( $cmd ); | ||
283 | is( $result->return_code, 0, $cmd); | ||
284 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
285 | |||
286 | # https with virtual port (!= 443) | ||
287 | $cmd = "./$plugin -H $virtual_host:$virtual_port -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host:$virtual_port\$"; | ||
288 | $result = NPTest->testCmd( $cmd ); | ||
289 | is( $result->return_code, 0, $cmd); | ||
290 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
291 | |||
292 | # https with virtual port (443) | ||
293 | $cmd = "./$plugin -H $virtual_host:443 -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host\$"; | ||
294 | $result = NPTest->testCmd( $cmd ); | ||
295 | is( $result->return_code, 0, $cmd); | ||
296 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
297 | } | ||
298 | |||
299 | |||
300 | sub run_common_tests { | ||
301 | my ($opts) = @_; | ||
302 | my $command = $opts->{command}; | ||
303 | if ($opts->{ssl}) { | ||
304 | $command .= " --ssl"; | ||
305 | } | ||
306 | |||
307 | $result = NPTest->testCmd( "$command -u /file/root" ); | ||
308 | is( $result->return_code, 0, "/file/root"); | ||
309 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second/', "Output correct" ); | ||
310 | |||
311 | $result = NPTest->testCmd( "$command -u /file/root -s Root" ); | ||
312 | is( $result->return_code, 0, "/file/root search for string"); | ||
313 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second/', "Output correct" ); | ||
314 | |||
315 | $result = NPTest->testCmd( "$command -u /file/root -s NonRoot" ); | ||
316 | is( $result->return_code, 2, "Missing string check"); | ||
317 | like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - string 'NonRoot' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location"); | ||
318 | |||
319 | $result = NPTest->testCmd( "$command -u /file/root -s NonRootWithOver30charsAndMoreFunThanAWetFish" ); | ||
320 | is( $result->return_code, 2, "Missing string check"); | ||
321 | like( $result->output, qr%HTTP CRITICAL: HTTP/1\.1 200 OK - string 'NonRootWithOver30charsAndM...' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location"); | ||
322 | |||
323 | $result = NPTest->testCmd( "$command -u /header_check -d foo" ); | ||
324 | is( $result->return_code, 0, "header_check search for string"); | ||
325 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 96 bytes in [\d\.]+ second/', "Output correct" ); | ||
326 | |||
327 | $result = NPTest->testCmd( "$command -u /header_check -d bar" ); | ||
328 | is( $result->return_code, 2, "Missing header string check"); | ||
329 | like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - header 'bar' not found on 'https?://127\.0\.0\.1:\d+/header_check'%, "Shows search string and location"); | ||
330 | |||
331 | $result = NPTest->testCmd( "$command -u /header_broken_check" ); | ||
332 | is( $result->return_code, 0, "header_check search for string"); | ||
333 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 138 bytes in [\d\.]+ second/', "Output correct" ); | ||
334 | |||
335 | my $cmd; | ||
336 | $cmd = "$command -u /slow"; | ||
337 | $result = NPTest->testCmd( $cmd ); | ||
338 | is( $result->return_code, 0, "$cmd"); | ||
339 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
340 | $result->output =~ /in ([\d\.]+) second/; | ||
341 | cmp_ok( $1, ">", 1, "Time is > 1 second" ); | ||
342 | |||
343 | $cmd = "$command -u /statuscode/200"; | ||
344 | $result = NPTest->testCmd( $cmd ); | ||
345 | is( $result->return_code, 0, $cmd); | ||
346 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
347 | |||
348 | $cmd = "$command -u /statuscode/200 -e 200"; | ||
349 | $result = NPTest->testCmd( $cmd ); | ||
350 | is( $result->return_code, 0, $cmd); | ||
351 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - Status line output matched "200" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
352 | |||
353 | $cmd = "$command -u /statuscode/201"; | ||
354 | $result = NPTest->testCmd( $cmd ); | ||
355 | is( $result->return_code, 0, $cmd); | ||
356 | like( $result->output, '/^HTTP OK: HTTP/1.1 201 Created - \d+ bytes in [\d\.]+ second /', "Output correct: ".$result->output ); | ||
357 | |||
358 | $cmd = "$command -u /statuscode/201 -e 201"; | ||
359 | $result = NPTest->testCmd( $cmd ); | ||
360 | is( $result->return_code, 0, $cmd); | ||
361 | like( $result->output, '/^HTTP OK: HTTP/1.1 201 Created - Status line output matched "201" - \d+ bytes in [\d\.]+ second /', "Output correct: ".$result->output ); | ||
362 | |||
363 | $cmd = "$command -u /statuscode/201 -e 200"; | ||
364 | $result = NPTest->testCmd( $cmd ); | ||
365 | is( $result->return_code, 2, $cmd); | ||
366 | like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port \d+: HTTP/1.1 201 Created/', "Output correct: ".$result->output ); | ||
367 | |||
368 | $cmd = "$command -u /statuscode/200 -e 200,201,202"; | ||
369 | $result = NPTest->testCmd( $cmd ); | ||
370 | is( $result->return_code, 0, $cmd); | ||
371 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - Status line output matched "200,201,202" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
372 | |||
373 | $cmd = "$command -u /statuscode/201 -e 200,201,202"; | ||
374 | $result = NPTest->testCmd( $cmd ); | ||
375 | is( $result->return_code, 0, $cmd); | ||
376 | like( $result->output, '/^HTTP OK: HTTP/1.1 201 Created - Status line output matched "200,201,202" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
377 | |||
378 | $cmd = "$command -u /statuscode/203 -e 200,201,202"; | ||
379 | $result = NPTest->testCmd( $cmd ); | ||
380 | is( $result->return_code, 2, $cmd); | ||
381 | like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port (\d+): HTTP/1.1 203 Non-Authoritative Information/', "Output correct: ".$result->output ); | ||
382 | |||
383 | $cmd = "$command -j HEAD -u /method"; | ||
384 | $result = NPTest->testCmd( $cmd ); | ||
385 | is( $result->return_code, 0, $cmd); | ||
386 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 HEAD - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
387 | |||
388 | $cmd = "$command -j POST -u /method"; | ||
389 | $result = NPTest->testCmd( $cmd ); | ||
390 | is( $result->return_code, 0, $cmd); | ||
391 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
392 | |||
393 | $cmd = "$command -j GET -u /method"; | ||
394 | $result = NPTest->testCmd( $cmd ); | ||
395 | is( $result->return_code, 0, $cmd); | ||
396 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
397 | |||
398 | $cmd = "$command -u /method"; | ||
399 | $result = NPTest->testCmd( $cmd ); | ||
400 | is( $result->return_code, 0, $cmd); | ||
401 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
402 | |||
403 | $cmd = "$command -P foo -u /method"; | ||
404 | $result = NPTest->testCmd( $cmd ); | ||
405 | is( $result->return_code, 0, $cmd); | ||
406 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
407 | |||
408 | $cmd = "$command -j DELETE -u /method"; | ||
409 | $result = NPTest->testCmd( $cmd ); | ||
410 | is( $result->return_code, 1, $cmd); | ||
411 | like( $result->output, '/^HTTP WARNING: HTTP/1.1 405 Method Not Allowed/', "Output correct: ".$result->output ); | ||
412 | |||
413 | $cmd = "$command -j foo -u /method"; | ||
414 | $result = NPTest->testCmd( $cmd ); | ||
415 | is( $result->return_code, 2, $cmd); | ||
416 | like( $result->output, '/^HTTP CRITICAL: HTTP/1.1 501 Not Implemented/', "Output correct: ".$result->output ); | ||
417 | |||
418 | $cmd = "$command -P stufftoinclude -u /postdata -s POST:stufftoinclude"; | ||
419 | $result = NPTest->testCmd( $cmd ); | ||
420 | is( $result->return_code, 0, $cmd); | ||
421 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
422 | |||
423 | $cmd = "$command -j PUT -P stufftoinclude -u /postdata -s PUT:stufftoinclude"; | ||
424 | $result = NPTest->testCmd( $cmd ); | ||
425 | is( $result->return_code, 0, $cmd); | ||
426 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
427 | |||
428 | # To confirm that the free doesn't segfault | ||
429 | $cmd = "$command -P stufftoinclude -j PUT -u /postdata -s PUT:stufftoinclude"; | ||
430 | $result = NPTest->testCmd( $cmd ); | ||
431 | is( $result->return_code, 0, $cmd); | ||
432 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
433 | |||
434 | $cmd = "$command -u /redirect"; | ||
435 | $result = NPTest->testCmd( $cmd ); | ||
436 | is( $result->return_code, 0, $cmd); | ||
437 | like( $result->output, '/^HTTP OK: HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
438 | |||
439 | $cmd = "$command -f follow -u /redirect"; | ||
440 | $result = NPTest->testCmd( $cmd ); | ||
441 | is( $result->return_code, 0, $cmd); | ||
442 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
443 | |||
444 | $cmd = "$command -u /redirect -k 'follow: me'"; | ||
445 | $result = NPTest->testCmd( $cmd ); | ||
446 | is( $result->return_code, 0, $cmd); | ||
447 | like( $result->output, '/^HTTP OK: HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
448 | |||
449 | $cmd = "$command -f follow -u /redirect -k 'follow: me'"; | ||
450 | $result = NPTest->testCmd( $cmd ); | ||
451 | is( $result->return_code, 0, $cmd); | ||
452 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
453 | |||
454 | $cmd = "$command -f sticky -u /redirect -k 'follow: me'"; | ||
455 | $result = NPTest->testCmd( $cmd ); | ||
456 | is( $result->return_code, 0, $cmd); | ||
457 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
458 | |||
459 | $cmd = "$command -f stickyport -u /redirect -k 'follow: me'"; | ||
460 | $result = NPTest->testCmd( $cmd ); | ||
461 | is( $result->return_code, 0, $cmd); | ||
462 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
463 | |||
464 | # These tests may block | ||
465 | print "ALRM\n"; | ||
466 | |||
467 | # stickyport - on full urlS port is set back to 80 otherwise | ||
468 | $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; | ||
469 | eval { | ||
470 | local $SIG{ALRM} = sub { die "alarm\n" }; | ||
471 | alarm(2); | ||
472 | $result = NPTest->testCmd( $cmd ); | ||
473 | alarm(0); }; | ||
474 | isnt( $@, "alarm\n", $cmd ); | ||
475 | is( $result->return_code, 0, $cmd ); | ||
476 | |||
477 | # Let's hope there won't be any web server on :80 returning "redirected"! | ||
478 | $cmd = "$command -f sticky -u /redir_external -t 5 -s redirected"; | ||
479 | eval { | ||
480 | local $SIG{ALRM} = sub { die "alarm\n" }; | ||
481 | alarm(2); | ||
482 | $result = NPTest->testCmd( $cmd ); | ||
483 | alarm(0); }; | ||
484 | isnt( $@, "alarm\n", $cmd ); | ||
485 | isnt( $result->return_code, 0, $cmd ); | ||
486 | |||
487 | # Test an external address - timeout | ||
488 | SKIP: { | ||
489 | skip "This doesn't seem to work all the time", 1 unless ($ENV{HTTP_EXTERNAL}); | ||
490 | $cmd = "$command -f follow -u /redir_external -t 5"; | ||
491 | eval { | ||
492 | $result = NPTest->testCmd( $cmd, 2 ); | ||
493 | }; | ||
494 | like( $@, "/timeout in command: $cmd/", $cmd ); | ||
495 | } | ||
496 | |||
497 | $cmd = "$command -u /timeout -t 5"; | ||
498 | eval { | ||
499 | $result = NPTest->testCmd( $cmd, 2 ); | ||
500 | }; | ||
501 | like( $@, "/timeout in command: $cmd/", $cmd ); | ||
502 | |||
503 | $cmd = "$command -f follow -u /redir_timeout -t 2"; | ||
504 | eval { | ||
505 | $result = NPTest->testCmd( $cmd, 5 ); | ||
506 | }; | ||
507 | is( $@, "", $cmd ); | ||
508 | |||
509 | } | ||
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index e72d243a..188f5e75 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t | |||
@@ -4,20 +4,25 @@ | |||
4 | # | 4 | # |
5 | # To create the https server certificate: | 5 | # To create the https server certificate: |
6 | # openssl req -new -x509 -keyout server-key.pem -out server-cert.pem -days 3650 -nodes | 6 | # openssl req -new -x509 -keyout server-key.pem -out server-cert.pem -days 3650 -nodes |
7 | # Country Name (2 letter code) [AU]:UK | 7 | # to create a new expired certificate: |
8 | # State or Province Name (full name) [Some-State]:Derbyshire | 8 | # faketime '2008-01-01 12:00:00' openssl req -new -x509 -keyout expired-key.pem -out expired-cert.pem -days 1 -nodes |
9 | # Locality Name (eg, city) []:Belper | 9 | # Country Name (2 letter code) [AU]:DE |
10 | # State or Province Name (full name) [Some-State]:Bavaria | ||
11 | # Locality Name (eg, city) []:Munich | ||
10 | # Organization Name (eg, company) [Internet Widgits Pty Ltd]:Monitoring Plugins | 12 | # Organization Name (eg, company) [Internet Widgits Pty Ltd]:Monitoring Plugins |
11 | # Organizational Unit Name (eg, section) []: | 13 | # Organizational Unit Name (eg, section) []: |
12 | # Common Name (eg, YOUR name) []:Ton Voon | 14 | # Common Name (e.g. server FQDN or YOUR name) []:Monitoring Plugins |
13 | # Email Address []:tonvoon@mac.com | 15 | # Email Address []:devel@monitoring-plugins.org |
14 | 16 | ||
15 | use strict; | 17 | use strict; |
16 | use Test::More; | 18 | use Test::More; |
17 | use NPTest; | 19 | use NPTest; |
18 | use FindBin qw($Bin); | 20 | use FindBin qw($Bin); |
19 | 21 | ||
22 | $ENV{'LC_TIME'} = "C"; | ||
23 | |||
20 | my $common_tests = 70; | 24 | my $common_tests = 70; |
25 | my $virtual_port_tests = 8; | ||
21 | my $ssl_only_tests = 8; | 26 | my $ssl_only_tests = 8; |
22 | # Check that all dependent modules are available | 27 | # Check that all dependent modules are available |
23 | eval "use HTTP::Daemon 6.01;"; | 28 | eval "use HTTP::Daemon 6.01;"; |
@@ -27,13 +32,16 @@ eval { | |||
27 | require HTTP::Response; | 32 | require HTTP::Response; |
28 | }; | 33 | }; |
29 | 34 | ||
35 | my $plugin = 'check_http'; | ||
36 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; | ||
37 | |||
30 | if ($@) { | 38 | if ($@) { |
31 | plan skip_all => "Missing required module for test: $@"; | 39 | plan skip_all => "Missing required module for test: $@"; |
32 | } else { | 40 | } else { |
33 | if (-x "./check_http") { | 41 | if (-x "./$plugin") { |
34 | plan tests => $common_tests * 2 + $ssl_only_tests; | 42 | plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests; |
35 | } else { | 43 | } else { |
36 | plan skip_all => "No check_http compiled"; | 44 | plan skip_all => "No $plugin compiled"; |
37 | } | 45 | } |
38 | } | 46 | } |
39 | 47 | ||
@@ -83,6 +91,8 @@ if ($pid) { | |||
83 | exit; | 91 | exit; |
84 | } | 92 | } |
85 | } else { | 93 | } else { |
94 | # closing the connection after -C cert checks make the daemon exit with a sigpipe otherwise | ||
95 | local $SIG{'PIPE'} = 'IGNORE'; | ||
86 | my $d = HTTP::Daemon::SSL->new( | 96 | my $d = HTTP::Daemon::SSL->new( |
87 | LocalPort => $port_https, | 97 | LocalPort => $port_https, |
88 | LocalAddr => "127.0.0.1", | 98 | LocalAddr => "127.0.0.1", |
@@ -94,8 +104,6 @@ if ($pid) { | |||
94 | exit; | 104 | exit; |
95 | } | 105 | } |
96 | } | 106 | } |
97 | # give our webservers some time to startup | ||
98 | sleep(1); | ||
99 | } else { | 107 | } else { |
100 | # Child | 108 | # Child |
101 | #print "child\n"; | 109 | #print "child\n"; |
@@ -108,6 +116,9 @@ if ($pid) { | |||
108 | exit; | 116 | exit; |
109 | } | 117 | } |
110 | 118 | ||
119 | # give our webservers some time to startup | ||
120 | sleep(3); | ||
121 | |||
111 | # Run the same server on http and https | 122 | # Run the same server on http and https |
112 | sub run_server { | 123 | sub run_server { |
113 | my $d = shift; | 124 | my $d = shift; |
@@ -156,6 +167,11 @@ sub run_server { | |||
156 | $c->send_basic_header; | 167 | $c->send_basic_header; |
157 | $c->send_header('foo'); | 168 | $c->send_header('foo'); |
158 | $c->send_crlf; | 169 | $c->send_crlf; |
170 | } elsif ($r->url->path eq "/virtual_port") { | ||
171 | # return sent Host header | ||
172 | $c->send_basic_header; | ||
173 | $c->send_crlf; | ||
174 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host'))); | ||
159 | } else { | 175 | } else { |
160 | $c->send_error(HTTP::Status->RC_FORBIDDEN); | 176 | $c->send_error(HTTP::Status->RC_FORBIDDEN); |
161 | } | 177 | } |
@@ -177,7 +193,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") { | |||
177 | } | 193 | } |
178 | 194 | ||
179 | my $result; | 195 | my $result; |
180 | my $command = "./check_http -H 127.0.0.1"; | 196 | my $command = "./$plugin -H 127.0.0.1"; |
181 | 197 | ||
182 | run_common_tests( { command => "$command -p $port_http" } ); | 198 | run_common_tests( { command => "$command -p $port_http" } ); |
183 | SKIP: { | 199 | SKIP: { |
@@ -186,25 +202,56 @@ SKIP: { | |||
186 | 202 | ||
187 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); | 203 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); |
188 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); | 204 | 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:28 2019.', "output ok" ); | 205 | is( $result->output, "OK - Certificate 'Monitoring Plugins' will expire on Fri Feb 16 15:31:44 2029 +0000.", "output ok" ); |
190 | 206 | ||
191 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); | 207 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); |
192 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); | 208 | 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:28 2019\)./', "output ok" ); | 209 | like( $result->output, '/WARNING - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" ); |
194 | 210 | ||
195 | # Expired cert tests | 211 | # Expired cert tests |
196 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); | 212 | $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" ); | 213 | 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:28 2019\)./', "output ok" ); | 214 | like( $result->output, '/CRITICAL - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" ); |
199 | 215 | ||
200 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); | 216 | $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" ); | 217 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); |
202 | is( $result->output, | 218 | is( $result->output, |
203 | 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:16 2009.', | 219 | 'CRITICAL - Certificate \'Monitoring Plugins\' expired on Wed Jan 2 11:00:26 2008 +0000.', |
204 | "output ok" ); | 220 | "output ok" ); |
205 | 221 | ||
206 | } | 222 | } |
207 | 223 | ||
224 | my $cmd; | ||
225 | # check virtual port behaviour | ||
226 | # | ||
227 | # http without virtual port | ||
228 | $cmd = "$command -p $port_http -u /virtual_port -r ^127.0.0.1:$port_http\$"; | ||
229 | $result = NPTest->testCmd( $cmd ); | ||
230 | is( $result->return_code, 0, $cmd); | ||
231 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
232 | |||
233 | # http with virtual port | ||
234 | $cmd = "$command:80 -p $port_http -u /virtual_port -r ^127.0.0.1\$"; | ||
235 | $result = NPTest->testCmd( $cmd ); | ||
236 | is( $result->return_code, 0, $cmd); | ||
237 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
238 | |||
239 | SKIP: { | ||
240 | skip "HTTP::Daemon::SSL not installed", 4 if ! exists $servers->{https}; | ||
241 | # https without virtual port | ||
242 | $cmd = "$command -p $port_https --ssl -u /virtual_port -r ^127.0.0.1:$port_https\$"; | ||
243 | $result = NPTest->testCmd( $cmd ); | ||
244 | is( $result->return_code, 0, $cmd); | ||
245 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
246 | |||
247 | # https with virtual port | ||
248 | $cmd = "$command:443 -p $port_https --ssl -u /virtual_port -r ^127.0.0.1\$"; | ||
249 | $result = NPTest->testCmd( $cmd ); | ||
250 | is( $result->return_code, 0, $cmd); | ||
251 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
252 | } | ||
253 | |||
254 | |||
208 | sub run_common_tests { | 255 | sub run_common_tests { |
209 | my ($opts) = @_; | 256 | my ($opts) = @_; |
210 | my $command = $opts->{command}; | 257 | my $command = $opts->{command}; |
@@ -370,27 +417,29 @@ sub run_common_tests { | |||
370 | 417 | ||
371 | # stickyport - on full urlS port is set back to 80 otherwise | 418 | # stickyport - on full urlS port is set back to 80 otherwise |
372 | $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; | 419 | $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; |
420 | alarm(2); | ||
373 | eval { | 421 | eval { |
374 | local $SIG{ALRM} = sub { die "alarm\n" }; | 422 | local $SIG{ALRM} = sub { die "alarm\n" }; |
375 | alarm(2); | ||
376 | $result = NPTest->testCmd( $cmd ); | 423 | $result = NPTest->testCmd( $cmd ); |
377 | alarm(0); }; | 424 | }; |
378 | isnt( $@, "alarm\n", $cmd ); | 425 | isnt( $@, "alarm\n", $cmd ); |
426 | alarm(0); | ||
379 | is( $result->return_code, 0, $cmd ); | 427 | is( $result->return_code, 0, $cmd ); |
380 | 428 | ||
381 | # Let's hope there won't be any web server on :80 returning "redirected"! | 429 | # Let's hope there won't be any web server on :80 returning "redirected"! |
382 | $cmd = "$command -f sticky -u /redir_external -t 5 -s redirected"; | 430 | $cmd = "$command -f sticky -u /redir_external -t 5 -s redirected"; |
431 | alarm(2); | ||
383 | eval { | 432 | eval { |
384 | local $SIG{ALRM} = sub { die "alarm\n" }; | 433 | local $SIG{ALRM} = sub { die "alarm\n" }; |
385 | alarm(2); | ||
386 | $result = NPTest->testCmd( $cmd ); | 434 | $result = NPTest->testCmd( $cmd ); |
387 | alarm(0); }; | 435 | }; |
388 | isnt( $@, "alarm\n", $cmd ); | 436 | isnt( $@, "alarm\n", $cmd ); |
437 | alarm(0); | ||
389 | isnt( $result->return_code, 0, $cmd ); | 438 | isnt( $result->return_code, 0, $cmd ); |
390 | 439 | ||
391 | # Test an external address - timeout | 440 | # Test an external address - timeout |
392 | SKIP: { | 441 | SKIP: { |
393 | skip "This doesn't seems to work all the time", 1 unless ($ENV{HTTP_EXTERNAL}); | 442 | skip "This doesn't seem to work all the time", 1 unless ($ENV{HTTP_EXTERNAL}); |
394 | $cmd = "$command -f follow -u /redir_external -t 5"; | 443 | $cmd = "$command -f follow -u /redir_external -t 5"; |
395 | eval { | 444 | eval { |
396 | $result = NPTest->testCmd( $cmd, 2 ); | 445 | $result = NPTest->testCmd( $cmd, 2 ); |
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; | |||
7 | use Test::More; | 7 | use Test::More; |
8 | use NPTest; | 8 | use NPTest; |
9 | use FindBin qw($Bin); | 9 | use FindBin qw($Bin); |
10 | use POSIX qw/strftime/; | ||
10 | 11 | ||
11 | my $tests = 67; | 12 | my $tests = 67; |
12 | # Check that all dependent modules are available | 13 | # Check that all dependent modules are available |
@@ -37,6 +38,7 @@ if ($@) { | |||
37 | 38 | ||
38 | my $port_snmp = 16100 + int(rand(100)); | 39 | my $port_snmp = 16100 + int(rand(100)); |
39 | 40 | ||
41 | my $faketime = -x '/usr/bin/faketime' ? 1 : 0; | ||
40 | 42 | ||
41 | # Start up server | 43 | # Start up server |
42 | my @pids; | 44 | my @pids; |
@@ -118,77 +120,81 @@ like($res->output, '/'.quotemeta('SNMP OK - And now have fun with with this: \"C | |||
118 | "And now have fun with with this: \"C:\\\\\" | 120 | "And now have fun with with this: \"C:\\\\\" |
119 | because we\'re not done yet!"').'/m', "Attempt to confuse parser No.3"); | 121 | because we\'re not done yet!"').'/m', "Attempt to confuse parser No.3"); |
120 | 122 | ||
121 | system("rm -f ".$ENV{'MP_STATE_PATH'}."/check_snmp/*"); | 123 | system("rm -f ".$ENV{'MP_STATE_PATH'}."/*/check_snmp/*"); |
122 | $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" ); | ||
123 | is($res->return_code, 0, "Returns OK"); | ||
124 | is($res->output, "No previous data to calculate rate - assume okay"); | ||
125 | 124 | ||
126 | # Need to sleep, otherwise duration=0 | 125 | # run rate checks with faketime. rate checks depend on the exact amount of time spend between the |
127 | sleep 1; | 126 | # plugin runs which may fail on busy machines. |
127 | # using faketime removes this race condition and also saves all the sleeps in between. | ||
128 | SKIP: { | ||
129 | skip "No faketime binary found", 28 if !$faketime; | ||
128 | 130 | ||
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" ); | 131 | my $ts = time(); |
130 | is($res->return_code, 1, "WARNING - due to going above rate calculation" ); | 132 | $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" ); |
131 | is($res->output, "SNMP RATE WARNING - *666* | iso.3.6.1.4.1.8072.3.2.67.10=666;600 "); | 133 | is($res->return_code, 0, "Returns OK"); |
134 | is($res->output, "No previous data to calculate rate - assume okay"); | ||
132 | 135 | ||
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" ); | 136 | # test rate 1 second later |
134 | is($res->return_code, 3, "UNKNOWN - basically the divide by zero error" ); | 137 | $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" ); |
135 | is($res->output, "Time duration between plugin calls is invalid"); | 138 | is($res->return_code, 1, "WARNING - due to going above rate calculation" ); |
139 | is($res->output, "SNMP RATE WARNING - *666* | iso.3.6.1.4.1.8072.3.2.67.10=666;600 "); | ||
136 | 140 | ||
141 | # test rate with same time | ||
142 | $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" ); | ||
143 | is($res->return_code, 3, "UNKNOWN - basically the divide by zero error" ); | ||
144 | is($res->output, "Time duration between plugin calls is invalid"); | ||
137 | 145 | ||
138 | $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" ); | ||
139 | is($res->return_code, 0, "OK for first call" ); | ||
140 | is($res->output, "No previous data to calculate rate - assume okay" ); | ||
141 | 146 | ||
142 | # Need to sleep, otherwise duration=0 | 147 | $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" ); |
143 | sleep 1; | 148 | is($res->return_code, 0, "OK for first call" ); |
149 | is($res->output, "No previous data to calculate rate - assume okay" ); | ||
144 | 150 | ||
145 | $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" ); | 151 | # test rate 1 second later |
146 | is($res->return_code, 0, "OK as no thresholds" ); | 152 | $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" ); |
147 | is($res->output, "SNMP RATE OK - inoctets 666 | inoctets=666 ", "Check label"); | 153 | is($res->return_code, 0, "OK as no thresholds" ); |
154 | is($res->output, "SNMP RATE OK - inoctets 666 | inoctets=666 ", "Check label"); | ||
148 | 155 | ||
149 | sleep 2; | 156 | # test rate 3 seconds later |
157 | $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" ); | ||
158 | is($res->return_code, 0, "OK as no thresholds" ); | ||
159 | is($res->output, "SNMP RATE OK - inoctets 333 | inoctets=333 ", "Check rate decreases due to longer interval"); | ||
150 | 160 | ||
151 | $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" ); | ||
152 | is($res->return_code, 0, "OK as no thresholds" ); | ||
153 | is($res->output, "SNMP RATE OK - inoctets 333 | inoctets=333 ", "Check rate decreases due to longer interval"); | ||
154 | 161 | ||
162 | # label performance data check | ||
163 | $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" ); | ||
164 | is($res->return_code, 0, "OK as no thresholds" ); | ||
165 | is($res->output, "SNMP OK - test 67996 | test=67996c ", "Check label"); | ||
155 | 166 | ||
156 | # label performance data check | 167 | $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\"" ); |
157 | $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" ); | 168 | is($res->return_code, 0, "OK as no thresholds" ); |
158 | is($res->return_code, 0, "OK as no thresholds" ); | 169 | is($res->output, "SNMP OK - test'test 68662 | \"test'test\"=68662c ", "Check label"); |
159 | is($res->output, "SNMP OK - test 67996 | test=67996c ", "Check label"); | ||
160 | 170 | ||
161 | $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\"" ); | 171 | $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'" ); |
162 | is($res->return_code, 0, "OK as no thresholds" ); | 172 | is($res->return_code, 0, "OK as no thresholds" ); |
163 | is($res->output, "SNMP OK - test'test 68662 | \"test'test\"=68662c ", "Check label"); | 173 | is($res->output, "SNMP OK - test\"test 69328 | 'test\"test'=69328c ", "Check label"); |
164 | 174 | ||
165 | $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'" ); | 175 | $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" ); |
166 | is($res->return_code, 0, "OK as no thresholds" ); | 176 | is($res->return_code, 0, "OK as no thresholds" ); |
167 | is($res->output, "SNMP OK - test\"test 69328 | 'test\"test'=69328c ", "Check label"); | 177 | is($res->output, "SNMP OK - test 69994 | iso.3.6.1.4.1.8072.3.2.67.10=69994c ", "Check label"); |
168 | 178 | ||
169 | $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" ); | 179 | $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" ); |
170 | is($res->return_code, 0, "OK as no thresholds" ); | 180 | is($res->return_code, 0, "OK as no thresholds" ); |
171 | is($res->output, "SNMP OK - test 69994 | iso.3.6.1.4.1.8072.3.2.67.10=69994c ", "Check label"); | 181 | is($res->output, "SNMP OK - 70660 | iso.3.6.1.4.1.8072.3.2.67.10=70660c ", "Check label"); |
172 | 182 | ||
173 | $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" ); | 183 | $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'" ); |
174 | is($res->return_code, 0, "OK as no thresholds" ); | 184 | is($res->return_code, 0, "OK as no thresholds" ); |
175 | is($res->output, "SNMP OK - 70660 | iso.3.6.1.4.1.8072.3.2.67.10=70660c ", "Check label"); | 185 | is($res->output, "SNMP OK - test test 71326 | 'test test'=71326c ", "Check label"); |
176 | 186 | ||
177 | $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'" ); | ||
178 | is($res->return_code, 0, "OK as no thresholds" ); | ||
179 | is($res->output, "SNMP OK - test test 71326 | 'test test'=71326c ", "Check label"); | ||
180 | 187 | ||
188 | $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" ); | ||
189 | is($res->return_code, 0, "OK for first call" ); | ||
190 | is($res->output, "No previous data to calculate rate - assume okay" ); | ||
181 | 191 | ||
182 | $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" ); | 192 | # test 1 second later |
183 | is($res->return_code, 0, "OK for first call" ); | 193 | $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" ); |
184 | is($res->output, "No previous data to calculate rate - assume okay" ); | 194 | is($res->return_code, 0, "OK as no thresholds" ); |
185 | 195 | is($res->output, "SNMP RATE OK - inoctets_per_minute 39960 | inoctets_per_minute=39960 ", "Checking multiplier"); | |
186 | # Need to sleep, otherwise duration=0 | 196 | }; |
187 | sleep 1; | ||
188 | 197 | ||
189 | $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" ); | ||
190 | is($res->return_code, 0, "OK as no thresholds" ); | ||
191 | is($res->output, "SNMP RATE OK - inoctets_per_minute 39960 | inoctets_per_minute=39960 ", "Checking multiplier"); | ||
192 | 198 | ||
193 | 199 | ||
194 | $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\"'" ); | 200 | $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\"'" ); |