diff options
78 files changed, 5570 insertions, 1004 deletions
@@ -142,6 +142,7 @@ NP-VERSION-FILE | |||
142 | /plugins/check_by_ssh | 142 | /plugins/check_by_ssh |
143 | /plugins/check_clamd | 143 | /plugins/check_clamd |
144 | /plugins/check_cluster | 144 | /plugins/check_cluster |
145 | /plugins/check_curl | ||
145 | /plugins/check_dbi | 146 | /plugins/check_dbi |
146 | /plugins/check_dig | 147 | /plugins/check_dig |
147 | /plugins/check_disk | 148 | /plugins/check_disk |
@@ -202,6 +203,12 @@ NP-VERSION-FILE | |||
202 | /plugins/stamp-h* | 203 | /plugins/stamp-h* |
203 | /plugins/urlize | 204 | /plugins/urlize |
204 | 205 | ||
206 | # /plugins/picohttpparser | ||
207 | /plugins/picohttpparser/Makefile | ||
208 | /plugins/picohttpparser/Makefile.in | ||
209 | /plugins/picohttpparser/.deps | ||
210 | /plugins/picohttpparser/libpicohttpparser.a | ||
211 | |||
205 | # /plugins/t/ | 212 | # /plugins/t/ |
206 | /plugins/t/*.tmp | 213 | /plugins/t/*.tmp |
207 | 214 | ||
diff --git a/.travis.yml b/.travis.yml index 123e1783..3d9fe64e 100644 --- a/.travis.yml +++ b/.travis.yml | |||
@@ -1,5 +1,5 @@ | |||
1 | sudo: required | 1 | sudo: required |
2 | dist: trusty | 2 | dist: xenial |
3 | language: c | 3 | language: c |
4 | 4 | ||
5 | env: | 5 | env: |
@@ -39,12 +39,8 @@ before_install: | |||
39 | - "sudo killall -9 ntpd ||:" | 39 | - "sudo killall -9 ntpd ||:" |
40 | # Trusty has no swap, lets create some | 40 | # Trusty has no swap, lets create some |
41 | - sudo fallocate -l 20M /swapfile; sudo chmod 600 /swapfile; sudo mkswap /swapfile; sudo swapon /swapfile | 41 | - sudo fallocate -l 20M /swapfile; sudo chmod 600 /swapfile; sudo mkswap /swapfile; sudo swapon /swapfile |
42 | - sudo add-apt-repository -y ppa:waja/trusty-backports | ||
43 | - sudo apt-get update -qq | 42 | - sudo apt-get update -qq |
44 | - sudo apt-get purge -qq gawk | 43 | - sudo apt-get purge -qq gawk |
45 | # http://docs.travis-ci.com/user/trusty-ci-environment/ indicates, no MySQL on Trusty (yet) | ||
46 | # # ensure we have a test database in place for tests | ||
47 | # - mysql -e "create database IF NOT EXISTS test;" -uroot | ||
48 | 44 | ||
49 | install: | 45 | install: |
50 | - sudo apt-get install -qq --no-install-recommends perl autotools-dev libdbi-dev libldap2-dev libpq-dev libmysqlclient-dev libradcli-dev libkrb5-dev libnet-snmp-perl procps | 46 | - sudo apt-get install -qq --no-install-recommends perl autotools-dev libdbi-dev libldap2-dev libpq-dev libmysqlclient-dev libradcli-dev libkrb5-dev libnet-snmp-perl procps |
@@ -55,7 +51,9 @@ install: | |||
55 | - sudo apt-get install -qq --no-install-recommends autoconf automake | 51 | - sudo apt-get install -qq --no-install-recommends autoconf automake |
56 | - sudo apt-get install -qq --no-install-recommends faketime | 52 | - sudo apt-get install -qq --no-install-recommends faketime |
57 | - sudo apt-get install -qq --no-install-recommends libmonitoring-plugin-perl | 53 | - sudo apt-get install -qq --no-install-recommends libmonitoring-plugin-perl |
58 | - sudo apt-get install -qq --no-install-recommends squid3 | 54 | - sudo apt-get install -qq --no-install-recommends libcurl4-openssl-dev |
55 | - sudo apt-get install -qq --no-install-recommends liburiparser-dev | ||
56 | - sudo apt-get install -qq --no-install-recommends squid | ||
59 | # Trusty related dependencies (not yet provided) | 57 | # Trusty related dependencies (not yet provided) |
60 | - test "$(dpkg -l | grep -E "mysql-(client|server)-[0-9].[0-9]" | grep -c ^ii)" -gt 0 || sudo apt-get install -qq --no-install-recommends mariadb-client mariadb-server | 58 | - test "$(dpkg -l | grep -E "mysql-(client|server)-[0-9].[0-9]" | grep -c ^ii)" -gt 0 || sudo apt-get install -qq --no-install-recommends mariadb-client mariadb-server |
61 | # enable ssl apache | 59 | # enable ssl apache |
@@ -63,8 +61,9 @@ install: | |||
63 | - sudo a2ensite default-ssl | 61 | - sudo a2ensite default-ssl |
64 | - sudo make-ssl-cert generate-default-snakeoil --force-overwrite | 62 | - sudo make-ssl-cert generate-default-snakeoil --force-overwrite |
65 | - sudo service apache2 reload | 63 | - sudo service apache2 reload |
66 | - sudo cp tools/squid.conf /etc/squid3/squid.conf | 64 | - sudo cp tools/squid.conf /etc/squid/squid.conf |
67 | - sudo service squid3 reload | 65 | - sudo service squid reload |
66 | - sudo service mysql restart | ||
68 | 67 | ||
69 | before_script: | 68 | before_script: |
70 | # ensure we have a test database in place for tests | 69 | # ensure we have a test database in place for tests |
@@ -74,15 +73,16 @@ before_script: | |||
74 | - tools/setup | 73 | - tools/setup |
75 | - ./configure --enable-libtap | 74 | - ./configure --enable-libtap |
76 | - make | 75 | - make |
76 | - export NPTEST_ACCEPTDEFAULT=1 | ||
77 | - export NPTEST_CACHE="$(pwd)/plugins/t/NPTest.cache.travis" | 77 | - export NPTEST_CACHE="$(pwd)/plugins/t/NPTest.cache.travis" |
78 | - ssh-keygen -t dsa -N "" -f ~/.ssh/id_dsa | 78 | - ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa |
79 | - cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys | 79 | - cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys |
80 | - ssh-keyscan localhost >> ~/.ssh/known_hosts | 80 | - ssh-keyscan localhost >> ~/.ssh/known_hosts |
81 | - touch ~/.ssh/config | 81 | - touch ~/.ssh/config |
82 | - sudo rm -f /usr/share/mibs/ietf/SNMPv2-PDU /usr/share/mibs/ietf/IPSEC-SPD-MIB /usr/share/mibs/ietf/IPATM-IPMC-MIB /usr/share/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB | 82 | - sudo rm -f /usr/share/mibs/ietf/SNMPv2-PDU /usr/share/mibs/ietf/IPSEC-SPD-MIB /usr/share/mibs/ietf/IPATM-IPMC-MIB /usr/share/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB |
83 | - sudo mkdir -p /var/lib/snmp/mib_indexes | 83 | - sudo mkdir -p /var/lib/snmp/mib_indexes |
84 | - sudo mkdir /media/ramdisk && sudo chmod 777 /media/ramdisk && sudo mount -t tmpfs -o size=20% none /media/ramdisk | 84 | - sudo mkdir /media/ramdisk && sudo chmod 777 /media/ramdisk && sudo mount -t tmpfs -o size=20% none /media/ramdisk |
85 | - sed "/host_tls_cert/s/.*/'host_tls_cert' => '$(hostname)',/" -i $NPTEST_CACHE | 85 | - sed "/NP_HOST_TLS_CERT/s/.*/'NP_HOST_TLS_CERT' => '$(hostname)',/" -i $NPTEST_CACHE |
86 | 86 | ||
87 | script: | 87 | script: |
88 | - if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then make test; fi | 88 | - if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then make test; fi |
diff --git a/ACKNOWLEDGEMENTS b/ACKNOWLEDGEMENTS index 50c714c3..d73be549 100644 --- a/ACKNOWLEDGEMENTS +++ b/ACKNOWLEDGEMENTS | |||
@@ -20,7 +20,7 @@ Using the DLPI support on SysV systems to get the host MAC address in check_dhcp | |||
20 | Stenberg, Daniel | 20 | Stenberg, Daniel |
21 | Copyright (c) 1996 - 2004, Daniel Stenberg, <daniel@haxx.se> | 21 | Copyright (c) 1996 - 2004, Daniel Stenberg, <daniel@haxx.se> |
22 | http://curl.haxx.se/ | 22 | http://curl.haxx.se/ |
23 | Use of duplication of macros in m4/np_curl.m4 | 23 | Use of duplication of macros in m4/np_curl.m4 (slighly adapted for m4/uriparser.m4 too) |
24 | 24 | ||
25 | Coreutils team | 25 | Coreutils team |
26 | Copyright (C) 91, 1995-2004 Free Software Foundation, Inc. | 26 | Copyright (C) 91, 1995-2004 Free Software Foundation, Inc. |
@@ -31,3 +31,9 @@ Gnulib team | |||
31 | Copyright (C) 2001, 2003, 2004, 2006 Free Software Foundation, Inc | 31 | Copyright (C) 2001, 2003, 2004, 2006 Free Software Foundation, Inc |
32 | http://www.gnu.org/software/gnulib/ | 32 | http://www.gnu.org/software/gnulib/ |
33 | Use of lib files that originally were used from coreutils | 33 | Use of lib files that originally were used from coreutils |
34 | |||
35 | Copyright (c) 2009-2014 Kazuho Oku, Tokuhiro Matsuno, Daisuke Murase, | ||
36 | Shigeo Mitsunari | ||
37 | picohttpparser | ||
38 | https://github.com/h2o/picohttpparser | ||
39 | Use of the library for HTTP header parsing in check_curl. | ||
diff --git a/Makefile.am b/Makefile.am index 7e0d4131..df1bcbb3 100644 --- a/Makefile.am +++ b/Makefile.am | |||
@@ -34,6 +34,7 @@ test test-debug: | |||
34 | if test "$(PERLMODS_DIR)" != ""; then cd perlmods && $(MAKE) $@; fi | 34 | if test "$(PERLMODS_DIR)" != ""; then cd perlmods && $(MAKE) $@; fi |
35 | cd plugins && $(MAKE) $@ | 35 | cd plugins && $(MAKE) $@ |
36 | cd plugins-scripts && $(MAKE) $@ | 36 | cd plugins-scripts && $(MAKE) $@ |
37 | cd plugins-root && $(MAKE) $@ | ||
37 | 38 | ||
38 | # Solaris pkgmk | 39 | # Solaris pkgmk |
39 | BUILDDIR = build-solaris | 40 | BUILDDIR = build-solaris |
@@ -1,15 +1,56 @@ | |||
1 | This file documents the major additions and syntax changes between releases. | 1 | This file documents the major additions and syntax changes between releases. |
2 | 2 | ||
3 | 2.3 [...] | 3 | 2.4 [...] |
4 | ENHANCEMENTS | ||
5 | |||
6 | FIXES | ||
7 | |||
8 | 2.3 10th December 2020 | ||
4 | ENHANCEMENTS | 9 | ENHANCEMENTS |
5 | check_dns: allow 'expected address' (-a) to be specified in CIDR notation | 10 | check_dns: allow 'expected address' (-a) to be specified in CIDR notation |
6 | (IPv4 only). | 11 | (IPv4 only). |
7 | check_dns: allow for IPv6 RDNS | 12 | check_dns: allow for IPv6 RDNS |
13 | check_dns: Accept CIDR | ||
14 | check_dns: allow unsorted addresses | ||
15 | check_dns: allow forcing complete match of all addresses | ||
8 | check_apt: add --only-critical switch | 16 | check_apt: add --only-critical switch |
9 | check_apt: add -l/--list option to print packages | 17 | check_apt: add -l/--list option to print packages |
18 | check_file_age: add range checking | ||
19 | check_file_age: enable to test for maximum file size | ||
20 | check_apt: adding packages-warning option | ||
21 | check_load: Adding top consuming processes option | ||
22 | check_http: Adding Proxy-Authorization and extra headers | ||
23 | check_snmp: make calcualtion of timeout value in help output more clear | ||
24 | check_uptime: new plugin for checking uptime to see how long the system is running | ||
25 | check_curl: check_http replacement based on libcurl | ||
26 | check_http: Allow user to specify HTTP method after proxy CONNECT | ||
27 | check_http: Add new flag --show-body/-B to print body | ||
28 | check_cluster: Added data argument validation | ||
29 | check_icmp: Add IPv6 support | ||
30 | check_icmp: Automatically detect IP protocol | ||
31 | check_icmp: emit error if multiple protocol version | ||
32 | check_disk: add support to display inodes usage in perfdata | ||
33 | check_hpjd: Added -D option to disable warning on 'out of paper' | ||
34 | check_http: support the --show-body/-B flag when --expect is used | ||
35 | check_mysql: allow mariadbclient to be used | ||
36 | check_tcp: add --sni | ||
37 | check_dns: detect unreachable dns service in nslookup output | ||
10 | 38 | ||
11 | FIXES | 39 | FIXES |
12 | Fix regression where check_dhcp was rereading response in a tight loop | 40 | Fix regression where check_dhcp was rereading response in a tight loop |
41 | check_dns: fix error detection on sles nslookup | ||
42 | check_disk_smb: fix timeout issue | ||
43 | check_swap: repaired "-n" behaviour | ||
44 | check_icmp: Correctly set address_family on lookup | ||
45 | check_icmp: Do not overwrite -4,-6 on lookup | ||
46 | check_smtp: initializes n before it is used | ||
47 | check_dns: fix typo in parameter description | ||
48 | check_by_ssh: fix child process leak on timeouts | ||
49 | check_mysql: Allow sockets to be specified to -H | ||
50 | check_procs: improve command examples for 'at least' processes | ||
51 | check_swap: repaired "-n" behaviour | ||
52 | check_disk: include -P switch in help | ||
53 | check_mailq: restore accidentially removed options | ||
13 | 54 | ||
14 | 2.2 29th November 2016 | 55 | 2.2 29th November 2016 |
15 | ENHANCEMENTS | 56 | ENHANCEMENTS |
diff --git a/NP-VERSION-GEN b/NP-VERSION-GEN index cf78d69c..c353b1d1 100755 --- a/NP-VERSION-GEN +++ b/NP-VERSION-GEN | |||
@@ -6,7 +6,7 @@ | |||
6 | SRC_ROOT=`dirname $0` | 6 | SRC_ROOT=`dirname $0` |
7 | 7 | ||
8 | NPVF=NP-VERSION-FILE | 8 | NPVF=NP-VERSION-FILE |
9 | DEF_VER=2.2.git | 9 | DEF_VER=2.3git |
10 | 10 | ||
11 | LF=' | 11 | LF=' |
12 | ' | 12 | ' |
@@ -53,8 +53,8 @@ developer to interactively request test parameter information from the | |||
53 | user. The user can accept the developer's default value or reply "none" | 53 | user. The user can accept the developer's default value or reply "none" |
54 | which will then be returned as "" for the test to skip if appropriate. | 54 | which will then be returned as "" for the test to skip if appropriate. |
55 | 55 | ||
56 | If a parameter needs to be entered and the test is run without a tty | 56 | If a parameter needs to be entered and the test is run without a tty |
57 | attached (such as a cronjob), the parameter will be assigned as if it | 57 | attached (such as a cronjob), the parameter will be assigned as if it |
58 | was "none". Tests can check for the parameter and skip if not set. | 58 | was "none". Tests can check for the parameter and skip if not set. |
59 | 59 | ||
60 | Responses are stored in an external, file-based cache so subsequent test | 60 | Responses are stored in an external, file-based cache so subsequent test |
@@ -62,17 +62,6 @@ runs will use these values. The user is able to change the values by | |||
62 | amending the values in the file /var/tmp/NPTest.cache, or by setting | 62 | amending the values in the file /var/tmp/NPTest.cache, or by setting |
63 | the appropriate environment variable before running the test. | 63 | the appropriate environment variable before running the test. |
64 | 64 | ||
65 | The option exists to store parameters in a scoped means, allowing a | ||
66 | test harness to a localise a parameter should the need arise. This | ||
67 | allows a parameter of the same name to exist in a test harness | ||
68 | specific scope, while not affecting the globally scoped parameter. The | ||
69 | scoping identifier is the name of the test harness sans the trailing | ||
70 | ".t". All cache searches first look to a scoped parameter before | ||
71 | looking for the parameter at global scope. Thus for a test harness | ||
72 | called "check_disk.t" requesting the parameter "mountpoint_valid", the | ||
73 | cache is first searched for "check_disk"/"mountpoint_valid", if this | ||
74 | fails, then a search is conducted for "mountpoint_valid". | ||
75 | |||
76 | To facilitate quick testing setup, it is possible to accept all the | 65 | To facilitate quick testing setup, it is possible to accept all the |
77 | developer provided defaults by setting the environment variable | 66 | developer provided defaults by setting the environment variable |
78 | "NPTEST_ACCEPTDEFAULT" to "1" (or any other perl truth value). Note | 67 | "NPTEST_ACCEPTDEFAULT" to "1" (or any other perl truth value). Note |
@@ -249,26 +238,26 @@ sub checkCmd | |||
249 | { | 238 | { |
250 | if ( scalar( grep { $_ == $exitStatus } @{$desiredExitStatus} ) ) | 239 | if ( scalar( grep { $_ == $exitStatus } @{$desiredExitStatus} ) ) |
251 | { | 240 | { |
252 | $desiredExitStatus = $exitStatus; | 241 | $desiredExitStatus = $exitStatus; |
253 | } | 242 | } |
254 | else | 243 | else |
255 | { | 244 | { |
256 | $desiredExitStatus = -1; | 245 | $desiredExitStatus = -1; |
257 | } | 246 | } |
258 | } | 247 | } |
259 | elsif ( ref $desiredExitStatus eq "HASH" ) | 248 | elsif ( ref $desiredExitStatus eq "HASH" ) |
260 | { | 249 | { |
261 | if ( exists( ${$desiredExitStatus}{$exitStatus} ) ) | 250 | if ( exists( ${$desiredExitStatus}{$exitStatus} ) ) |
262 | { | 251 | { |
263 | if ( defined( ${$desiredExitStatus}{$exitStatus} ) ) | 252 | if ( defined( ${$desiredExitStatus}{$exitStatus} ) ) |
264 | { | 253 | { |
265 | $testOutput = ${$desiredExitStatus}{$exitStatus}; | 254 | $testOutput = ${$desiredExitStatus}{$exitStatus}; |
266 | } | 255 | } |
267 | $desiredExitStatus = $exitStatus; | 256 | $desiredExitStatus = $exitStatus; |
268 | } | 257 | } |
269 | else | 258 | else |
270 | { | 259 | { |
271 | $desiredExitStatus = -1; | 260 | $desiredExitStatus = -1; |
272 | } | 261 | } |
273 | } | 262 | } |
274 | 263 | ||
@@ -327,78 +316,51 @@ sub skipMsg | |||
327 | return $testStatus; | 316 | return $testStatus; |
328 | } | 317 | } |
329 | 318 | ||
330 | sub getTestParameter | 319 | sub getTestParameter { |
331 | { | 320 | my($param, $description, $default) = @_; |
332 | my( $param, $envvar, $default, $brief, $scoped ); | ||
333 | my $new_style; | ||
334 | if (scalar @_ <= 3) { | ||
335 | ($param, $brief, $default) = @_; | ||
336 | $envvar = $param; | ||
337 | $new_style = 1; | ||
338 | } else { | ||
339 | ( $param, $envvar, $default, $brief, $scoped ) = @_; | ||
340 | $new_style = 0; | ||
341 | } | ||
342 | |||
343 | # Apply default values for optional arguments | ||
344 | $scoped = ( defined( $scoped ) && $scoped ); | ||
345 | |||
346 | my $testharness = basename( (caller(0))[1], ".t" ); # used for scoping | ||
347 | 321 | ||
348 | if ( defined( $envvar ) && exists( $ENV{$envvar} ) && $ENV{$envvar} ) | 322 | if($param !~ m/^NP_[A-Z0-9_]+$/mx) { |
349 | { | 323 | die("parameter should be all uppercase and start with NP_ (requested from ".(caller(0))[1].")"); |
350 | return $ENV{$envvar}; | ||
351 | } | 324 | } |
352 | 325 | ||
353 | my $cachedValue = SearchCache( $param, $testharness ); | 326 | return $ENV{$param} if $ENV{$param}; |
354 | if ( defined( $cachedValue ) ) | 327 | |
355 | { | 328 | my $cachedValue = SearchCache($param); |
356 | # This save required to convert to new style because the key required is | 329 | if(defined $cachedValue) { |
357 | # changing to the environment variable | ||
358 | if ($new_style == 0) { | ||
359 | SetCacheParameter( $envvar, undef, $cachedValue ); | ||
360 | } | ||
361 | return $cachedValue; | 330 | return $cachedValue; |
362 | } | 331 | } |
363 | 332 | ||
364 | my $defaultValid = ( defined( $default ) && $default ); | 333 | if($ENV{'NPTEST_ACCEPTDEFAULT'}) { |
365 | my $autoAcceptDefault = ( exists( $ENV{'NPTEST_ACCEPTDEFAULT'} ) && $ENV{'NPTEST_ACCEPTDEFAULT'} ); | 334 | return $default if $default; |
366 | 335 | return ""; | |
367 | if ( $autoAcceptDefault && $defaultValid ) | ||
368 | { | ||
369 | return $default; | ||
370 | } | 336 | } |
371 | 337 | ||
372 | # Set "none" if no terminal attached (eg, tinderbox build servers when new variables set) | 338 | # Set "none" if no terminal attached (eg, tinderbox build servers when new variables set) |
373 | return "" unless (-t STDIN); | 339 | return "" unless (-t STDIN); |
374 | 340 | ||
375 | my $userResponse = ""; | 341 | my $userResponse = ""; |
376 | 342 | while($userResponse eq "") { | |
377 | while ( $userResponse eq "" ) | ||
378 | { | ||
379 | print STDERR "\n"; | 343 | print STDERR "\n"; |
380 | print STDERR "Test Harness : $testharness\n"; | 344 | print STDERR "Test File : ".(caller(0))[1]."\n"; |
381 | print STDERR "Test Parameter : $param\n"; | 345 | print STDERR "Test Parameter : $param\n"; |
382 | print STDERR "Environment Variable : $envvar\n" if ($param ne $envvar); | 346 | print STDERR "Description : $description\n"; |
383 | print STDERR "Brief Description : $brief\n"; | 347 | print STDERR "Enter value (or 'none') ", ($default ? "[${default}]" : "[]"), " => "; |
384 | print STDERR "Enter value (or 'none') ", ($defaultValid ? "[${default}]" : "[]"), " => "; | ||
385 | $userResponse = <STDIN>; | 348 | $userResponse = <STDIN>; |
386 | $userResponse = "" if ! defined( $userResponse ); # Handle EOF | 349 | $userResponse = "" if ! defined( $userResponse ); # Handle EOF |
387 | chomp( $userResponse ); | 350 | chomp($userResponse); |
388 | if ( $defaultValid && $userResponse eq "" ) | 351 | if($default && $userResponse eq "") { |
389 | { | ||
390 | $userResponse = $default; | 352 | $userResponse = $default; |
391 | } | 353 | } |
392 | } | 354 | } |
393 | 355 | ||
394 | print STDERR "\n"; | 356 | print STDERR "\n"; |
395 | 357 | ||
396 | if ($userResponse =~ /^(na|none)$/) { | 358 | if($userResponse =~ /^(na|none)$/) { |
397 | $userResponse = ""; | 359 | $userResponse = ""; |
398 | } | 360 | } |
399 | 361 | ||
400 | # define all user responses at global scope | 362 | # store user responses |
401 | SetCacheParameter( $param, ( $scoped ? $testharness : undef ), $userResponse ); | 363 | SetCacheParameter($param, $userResponse); |
402 | 364 | ||
403 | return $userResponse; | 365 | return $userResponse; |
404 | } | 366 | } |
@@ -407,37 +369,20 @@ sub getTestParameter | |||
407 | # Internal Cache Management Functions | 369 | # Internal Cache Management Functions |
408 | # | 370 | # |
409 | 371 | ||
410 | sub SearchCache | 372 | sub SearchCache { |
411 | { | 373 | my($param) = @_; |
412 | my( $param, $scope ) = @_; | ||
413 | 374 | ||
414 | LoadCache(); | 375 | LoadCache(); |
415 | 376 | ||
416 | if ( exists( $CACHE{$scope} ) && exists( $CACHE{$scope}{$param} ) ) | 377 | if(exists $CACHE{$param}) { |
417 | { | ||
418 | return $CACHE{$scope}{$param}; | ||
419 | } | ||
420 | |||
421 | if ( exists( $CACHE{$param} ) ) | ||
422 | { | ||
423 | return $CACHE{$param}; | 378 | return $CACHE{$param}; |
424 | } | 379 | } |
425 | return undef; # Need this to say "nothing found" | 380 | return undef; # Need this to say "nothing found" |
426 | } | 381 | } |
427 | 382 | ||
428 | sub SetCacheParameter | 383 | sub SetCacheParameter { |
429 | { | 384 | my($param, $value) = @_; |
430 | my( $param, $scope, $value ) = @_; | 385 | $CACHE{$param} = $value; |
431 | |||
432 | if ( defined( $scope ) ) | ||
433 | { | ||
434 | $CACHE{$scope}{$param} = $value; | ||
435 | } | ||
436 | else | ||
437 | { | ||
438 | $CACHE{$param} = $value; | ||
439 | } | ||
440 | |||
441 | SaveCache(); | 386 | SaveCache(); |
442 | } | 387 | } |
443 | 388 | ||
@@ -475,6 +420,11 @@ sub SaveCache | |||
475 | delete $CACHE{'_cache_loaded_'}; | 420 | delete $CACHE{'_cache_loaded_'}; |
476 | my $oldFileContents = delete $CACHE{'_original_cache'}; | 421 | my $oldFileContents = delete $CACHE{'_original_cache'}; |
477 | 422 | ||
423 | # clean up old style params | ||
424 | for my $key (keys %CACHE) { | ||
425 | delete $CACHE{$key} if $key !~ m/^NP_[A-Z0-9_]+$/mx; | ||
426 | } | ||
427 | |||
478 | my($dataDumper) = new Data::Dumper([\%CACHE]); | 428 | my($dataDumper) = new Data::Dumper([\%CACHE]); |
479 | $dataDumper->Terse(1); | 429 | $dataDumper->Terse(1); |
480 | $dataDumper->Sortkeys(1); | 430 | $dataDumper->Sortkeys(1); |
@@ -486,7 +436,7 @@ sub SaveCache | |||
486 | if($oldFileContents ne $data) { | 436 | if($oldFileContents ne $data) { |
487 | my($fileHandle) = new IO::File; | 437 | my($fileHandle) = new IO::File; |
488 | if (!$fileHandle->open( "> ${CACHEFILENAME}")) { | 438 | if (!$fileHandle->open( "> ${CACHEFILENAME}")) { |
489 | print STDERR "NPTest::LoadCache() : Problem saving ${CACHEFILENAME} : $!\n"; | 439 | print STDERR "NPTest::SaveCache() : Problem saving ${CACHEFILENAME} : $!\n"; |
490 | return; | 440 | return; |
491 | } | 441 | } |
492 | print $fileHandle $data; | 442 | print $fileHandle $data; |
@@ -542,10 +492,10 @@ sub DetermineTestHarnessDirectory | |||
542 | push ( @dirs, "./tests"); | 492 | push ( @dirs, "./tests"); |
543 | } | 493 | } |
544 | 494 | ||
545 | if ( @dirs > 0 ) | 495 | if ( @dirs > 0 ) |
546 | { | 496 | { |
547 | return @dirs; | 497 | return @dirs; |
548 | } | 498 | } |
549 | 499 | ||
550 | # To be honest I don't understand which case satisfies the | 500 | # To be honest I don't understand which case satisfies the |
551 | # original code in test.pl : when $tstdir == `pwd` w.r.t. | 501 | # original code in test.pl : when $tstdir == `pwd` w.r.t. |
@@ -611,73 +561,73 @@ sub TestsFrom | |||
611 | 561 | ||
612 | # All the new object oriented stuff below | 562 | # All the new object oriented stuff below |
613 | 563 | ||
614 | sub new { | 564 | sub new { |
615 | my $type = shift; | 565 | my $type = shift; |
616 | my $self = {}; | 566 | my $self = {}; |
617 | return bless $self, $type; | 567 | return bless $self, $type; |
618 | } | 568 | } |
619 | 569 | ||
620 | # Accessors | 570 | # Accessors |
621 | sub return_code { | 571 | sub return_code { |
622 | my $self = shift; | 572 | my $self = shift; |
623 | if (@_) { | 573 | if (@_) { |
624 | return $self->{return_code} = shift; | 574 | return $self->{return_code} = shift; |
625 | } else { | 575 | } else { |
626 | return $self->{return_code}; | 576 | return $self->{return_code}; |
627 | } | 577 | } |
628 | } | 578 | } |
629 | sub output { | 579 | sub output { |
630 | my $self = shift; | 580 | my $self = shift; |
631 | if (@_) { | 581 | if (@_) { |
632 | return $self->{output} = shift; | 582 | return $self->{output} = shift; |
633 | } else { | 583 | } else { |
634 | return $self->{output}; | 584 | return $self->{output}; |
635 | } | 585 | } |
636 | } | 586 | } |
637 | 587 | ||
638 | sub perf_output { | 588 | sub perf_output { |
639 | my $self = shift; | 589 | my $self = shift; |
640 | $_ = $self->{output}; | 590 | $_ = $self->{output}; |
641 | /\|(.*)$/; | 591 | /\|(.*)$/; |
642 | return $1 || ""; | 592 | return $1 || ""; |
643 | } | 593 | } |
644 | 594 | ||
645 | sub only_output { | 595 | sub only_output { |
646 | my $self = shift; | 596 | my $self = shift; |
647 | $_ = $self->{output}; | 597 | $_ = $self->{output}; |
648 | /(.*?)\|/; | 598 | /(.*?)\|/; |
649 | return $1 || ""; | 599 | return $1 || ""; |
650 | } | 600 | } |
651 | 601 | ||
652 | sub testCmd { | 602 | sub testCmd { |
653 | my $class = shift; | 603 | my $class = shift; |
654 | my $command = shift or die "No command passed to testCmd"; | 604 | my $command = shift or die "No command passed to testCmd"; |
655 | my $timeout = shift || 120; | 605 | my $timeout = shift || 120; |
656 | my $object = $class->new; | 606 | my $object = $class->new; |
657 | 607 | ||
658 | local $SIG{'ALRM'} = sub { die("timeout in command: $command"); }; | 608 | local $SIG{'ALRM'} = sub { die("timeout in command: $command"); }; |
659 | alarm($timeout); # no test should take longer than 120 seconds | 609 | alarm($timeout); # no test should take longer than 120 seconds |
660 | 610 | ||
661 | my $output = `$command`; | 611 | my $output = `$command`; |
662 | $object->return_code($? >> 8); | 612 | $object->return_code($? >> 8); |
663 | $_ = $? & 127; | 613 | $_ = $? & 127; |
664 | if ($_) { | 614 | if ($_) { |
665 | die "Got signal $_ for command $command"; | 615 | die "Got signal $_ for command $command"; |
666 | } | 616 | } |
667 | chomp $output; | 617 | chomp $output; |
668 | $object->output($output); | 618 | $object->output($output); |
669 | 619 | ||
670 | alarm(0); | 620 | alarm(0); |
671 | 621 | ||
672 | my ($pkg, $file, $line) = caller(0); | 622 | my ($pkg, $file, $line) = caller(0); |
673 | print "Testing: $command", $/; | 623 | print "Testing: $command", $/; |
674 | if ($ENV{'NPTEST_DEBUG'}) { | 624 | if ($ENV{'NPTEST_DEBUG'}) { |
675 | print "testCmd: Called from line $line in $file", $/; | 625 | print "testCmd: Called from line $line in $file", $/; |
676 | print "Output: ", $object->output, $/; | 626 | print "Output: ", $object->output, $/; |
677 | print "Return code: ", $object->return_code, $/; | 627 | print "Return code: ", $object->return_code, $/; |
678 | } | 628 | } |
679 | 629 | ||
680 | return $object; | 630 | return $object; |
681 | } | 631 | } |
682 | 632 | ||
683 | # do we have ipv6 | 633 | # do we have ipv6 |
@@ -10,7 +10,7 @@ Monitoring Plugins | |||
10 | * For information on detailed changes that have been made or plugins | 10 | * For information on detailed changes that have been made or plugins |
11 | that have been added, read the `ChangeLog` file. | 11 | that have been added, read the `ChangeLog` file. |
12 | 12 | ||
13 | * Some plugins require that you have additional programs and/or | 13 | * Some plugins require that you have additional programs or |
14 | libraries installed on your system before they can be used. Plugins that | 14 | libraries installed on your system before they can be used. Plugins that |
15 | are dependent on other programs/libraries that are missing are usually not | 15 | are dependent on other programs/libraries that are missing are usually not |
16 | compiled. Read the `REQUIREMENTS` file for more information. | 16 | compiled. Read the `REQUIREMENTS` file for more information. |
@@ -19,7 +19,7 @@ Monitoring Plugins | |||
19 | the basic guidelines for development will provide detailed help when | 19 | the basic guidelines for development will provide detailed help when |
20 | invoked with the `-h` or `--help` options. | 20 | invoked with the `-h` or `--help` options. |
21 | 21 | ||
22 | You can check for the latest plugins at: | 22 | You can check the latest plugins at: |
23 | 23 | ||
24 | * <https://www.monitoring-plugins.org/> | 24 | * <https://www.monitoring-plugins.org/> |
25 | 25 | ||
diff --git a/REQUIREMENTS b/REQUIREMENTS index ac7b5935..f3b1c01d 100644 --- a/REQUIREMENTS +++ b/REQUIREMENTS | |||
@@ -11,6 +11,22 @@ check_ldaps, check_http --ssl, check_tcp --ssl, check_smtp --starttls | |||
11 | - Requires openssl or gnutls libraries for SSL connections | 11 | - Requires openssl or gnutls libraries for SSL connections |
12 | http://www.openssl.org, http://www.gnu.org/software/gnutls | 12 | http://www.openssl.org, http://www.gnu.org/software/gnutls |
13 | 13 | ||
14 | check_curl: | ||
15 | - Requires libcurl 7.15.2 or later | ||
16 | http://www.haxx.se | ||
17 | - --ssl/-S and -C requires OpenSSL for certificate checks, otherwise | ||
18 | libcurl must be quite new to support CURLINFO_CERTINFO with | ||
19 | GnuTLS and NSS libraries: | ||
20 | - 7.42.0 or newer for GnuTLS | ||
21 | - 7.34.0 or newer for NSS | ||
22 | GnuTLS is known to create problems on some distributions with | ||
23 | self-signed certificate chains | ||
24 | http://www.openssl.org, http://www.gnu.org/software/gnutls, | ||
25 | http://www.mozilla.org/projects/security/pki/nss/, | ||
26 | other SSL implementations are currently not supported | ||
27 | - uriparser 0.7.5 or later | ||
28 | https://uriparser.github.io/ | ||
29 | |||
14 | check_fping: | 30 | check_fping: |
15 | - Requires the fping utility distributed with SATAN. Either | 31 | - Requires the fping utility distributed with SATAN. Either |
16 | download and install SATAN or grab the fping program from | 32 | download and install SATAN or grab the fping program from |
@@ -356,3 +356,28 @@ Sven Geggus | |||
356 | Thomas Kurschel | 356 | Thomas Kurschel |
357 | Yannick Charton | 357 | Yannick Charton |
358 | Nicolai Søborg | 358 | Nicolai Søborg |
359 | Rolf Eike Beer | ||
360 | Bernd Arnold | ||
361 | Andreas Baumann | ||
362 | Tobias Wolf | ||
363 | Lars Michelsen | ||
364 | Vincent Danjean | ||
365 | Kostyantyn Hushchyn | ||
366 | Christian Tacke | ||
367 | Alexander A. Klimov | ||
368 | Vadim Zhukov | ||
369 | Bernard Spil | ||
370 | Christian Schmidt | ||
371 | Guido Falsi | ||
372 | Harald Koch | ||
373 | Iustin Pop | ||
374 | Jacob Hansen | ||
375 | Jean-François Rameau | ||
376 | Karol Babioch | ||
377 | Lucas Bussey | ||
378 | Marc Sánchez | ||
379 | Markus Frosch | ||
380 | Michael Kraus | ||
381 | Patrick Rauscher | ||
382 | Prathamesh Bhanuse | ||
383 | Valentin Vidic | ||
diff --git a/configure.ac b/configure.ac index bf129956..7c17dcd1 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -1,6 +1,6 @@ | |||
1 | dnl Process this file with autoconf to produce a configure script. | 1 | dnl Process this file with autoconf to produce a configure script. |
2 | AC_PREREQ(2.59) | 2 | AC_PREREQ(2.59) |
3 | AC_INIT(monitoring-plugins,2.2) | 3 | AC_INIT(monitoring-plugins,2.3git) |
4 | AC_CONFIG_SRCDIR(NPTest.pm) | 4 | AC_CONFIG_SRCDIR(NPTest.pm) |
5 | AC_CONFIG_FILES([gl/Makefile]) | 5 | AC_CONFIG_FILES([gl/Makefile]) |
6 | AC_CONFIG_AUX_DIR(build-aux) | 6 | AC_CONFIG_AUX_DIR(build-aux) |
@@ -385,6 +385,42 @@ if test "$ac_cv_header_wtsapi32_h" = "yes"; then | |||
385 | AC_SUBST(WTSAPI32LIBS) | 385 | AC_SUBST(WTSAPI32LIBS) |
386 | fi | 386 | fi |
387 | 387 | ||
388 | _can_enable_check_curl=no | ||
389 | dnl Check for cURL library | ||
390 | LIBCURL_CHECK_CONFIG(yes, 7.15.2, [ | ||
391 | _can_enable_check_curl=yes | ||
392 | LIBCURLINCLUDE="$LIBCURL_CPPFLAGS" | ||
393 | LIBCURLLIBS="$LIBCURL" | ||
394 | LIBCURLCFLAGS="$LIBCURL_CPPFLAGS" | ||
395 | AC_SUBST(LIBCURLINCLUDE) | ||
396 | AC_SUBST(LIBCURLLIBS) | ||
397 | AC_SUBST(LIBCURLCFLAGS) | ||
398 | ], [ | ||
399 | _can_enable_check_curl=no | ||
400 | AC_MSG_WARN([Skipping curl plugin]) | ||
401 | AC_MSG_WARN([install libcurl libs to compile this plugin (see REQUIREMENTS).]) | ||
402 | ]) | ||
403 | |||
404 | dnl Check for uriparser library | ||
405 | URIPARSER_CHECK(yes, 0.7.5, [ | ||
406 | URIPARSERINCLUDE="$URIPARSER_CPPFLAGS" | ||
407 | URIPARSERLIBS="$URIPARSER" | ||
408 | URIPARSERCFLAGS="$URIPARSER_CPPFLAGS" | ||
409 | AC_SUBST(URIPARSERINCLUDE) | ||
410 | AC_SUBST(URIPARSERLIBS) | ||
411 | AC_SUBST(URIPARSERCFLAGS) | ||
412 | ], [ | ||
413 | _can_enable_check_curl=no | ||
414 | AC_MSG_WARN([Skipping curl plugin]) | ||
415 | AC_MSG_WARN([install the uriparser library to compile this plugin (see REQUIREMENTS).]) | ||
416 | ]) | ||
417 | |||
418 | dnl prerequisites met, enable the plugin | ||
419 | if test x$_can_enable_check_curl = xyes; then | ||
420 | EXTRAS="$EXTRAS check_curl\$(EXEEXT)" | ||
421 | fi | ||
422 | AC_CONFIG_FILES([plugins/picohttpparser/Makefile]) | ||
423 | |||
388 | dnl Fallback to who(1) if the system doesn't provide an utmpx(5) interface | 424 | dnl Fallback to who(1) if the system doesn't provide an utmpx(5) interface |
389 | if test "$ac_cv_header_utmpx_h" = "no" -a "$ac_cv_header_wtsapi32_h" = "no" | 425 | if test "$ac_cv_header_utmpx_h" = "no" -a "$ac_cv_header_wtsapi32_h" = "no" |
390 | then | 426 | then |
@@ -1016,6 +1052,10 @@ if test -n "$ac_cv_ps_varlist" ; then | |||
1016 | AC_DEFINE(PS_USES_PROCETIME,"yes", | 1052 | AC_DEFINE(PS_USES_PROCETIME,"yes", |
1017 | [Whether the ps utility uses the "procetime" field]) | 1053 | [Whether the ps utility uses the "procetime" field]) |
1018 | fi | 1054 | fi |
1055 | if echo "$ac_cv_ps_varlist" | grep "procpcpu" >/dev/null; then | ||
1056 | AC_DEFINE(PS_USES_PROCPCPU,"yes", | ||
1057 | [Whether the ps utility uses the "procpcpu" field]) | ||
1058 | fi | ||
1019 | fi | 1059 | fi |
1020 | 1060 | ||
1021 | AC_PATH_PROG(PATH_TO_PING,ping) | 1061 | AC_PATH_PROG(PATH_TO_PING,ping) |
@@ -1060,6 +1100,14 @@ then | |||
1060 | ac_cv_ping_packets_first=yes | 1100 | ac_cv_ping_packets_first=yes |
1061 | AC_MSG_RESULT([$with_ping_command]) | 1101 | AC_MSG_RESULT([$with_ping_command]) |
1062 | 1102 | ||
1103 | elif $PATH_TO_PING -4 -n -U -w 10 -c 1 127.0.0.1 2>/dev/null | \ | ||
1104 | egrep -i "^round-trip|^rtt" >/dev/null | ||
1105 | then | ||
1106 | # check if -4 is supported - issue #1550 | ||
1107 | with_ping_command="$PATH_TO_PING -4 -n -U -w %d -c %d %s" | ||
1108 | ac_cv_ping_packets_first=yes | ||
1109 | ac_cv_ping_has_timeout=yes | ||
1110 | AC_MSG_RESULT([$with_ping_command]) | ||
1063 | elif $PATH_TO_PING -n -U -w 10 -c 1 127.0.0.1 2>/dev/null | \ | 1111 | elif $PATH_TO_PING -n -U -w 10 -c 1 127.0.0.1 2>/dev/null | \ |
1064 | egrep -i "^round-trip|^rtt" >/dev/null | 1112 | egrep -i "^round-trip|^rtt" >/dev/null |
1065 | then | 1113 | then |
@@ -1882,4 +1930,5 @@ ACX_FEATURE([enable],[perl-modules]) | |||
1882 | ACX_FEATURE([with],[cgiurl]) | 1930 | ACX_FEATURE([with],[cgiurl]) |
1883 | ACX_FEATURE([with],[trusted-path]) | 1931 | ACX_FEATURE([with],[trusted-path]) |
1884 | ACX_FEATURE([enable],[libtap]) | 1932 | ACX_FEATURE([enable],[libtap]) |
1885 | 1933 | ACX_FEATURE([with],[libcurl]) | |
1934 | ACX_FEATURE([with],[uriparser]) | ||
diff --git a/doc/RELEASING.md b/doc/RELEASING.md index 1f9db078..bcd2c5ac 100644 --- a/doc/RELEASING.md +++ b/doc/RELEASING.md | |||
@@ -11,14 +11,14 @@ Before you start | |||
11 | 11 | ||
12 | - Check Travis CI status. | 12 | - Check Travis CI status. |
13 | - Update local Git repository to the current `master` tip. For a | 13 | - Update local Git repository to the current `master` tip. For a |
14 | maintenance release (e.g., version 2.2.2), update to the current | 14 | maintenance release (e.g., version 2.3.2), update to the current |
15 | `maint-2.2` tip, instead. | 15 | `maint-2.3` tip, instead. |
16 | 16 | ||
17 | Prepare and commit files | 17 | Prepare and commit files |
18 | ------------------------ | 18 | ------------------------ |
19 | 19 | ||
20 | - Update `configure.ac` and `NP-VERSION-GEN` with new version. | 20 | - Update `configure.ac` and `NP-VERSION-GEN` with new version. |
21 | - Update `NEWS` from `git log --reverse v2.2.1..` output, and specify | 21 | - Update `NEWS` from `git log --reverse v2.3.1..` output, and specify |
22 | the release version/date. | 22 | the release version/date. |
23 | - Update `AUTHORS` if there are new team members. | 23 | - Update `AUTHORS` if there are new team members. |
24 | - Update `THANKS.in` using `tools/update-thanks`. | 24 | - Update `THANKS.in` using `tools/update-thanks`. |
@@ -29,27 +29,27 @@ Prepare and commit files | |||
29 | Create annotated tag | 29 | Create annotated tag |
30 | -------------------- | 30 | -------------------- |
31 | 31 | ||
32 | git tag -a -m 'Monitoring Plugins 2.3' v2.3 | 32 | git tag -a -m 'Monitoring Plugins 2.4' v2.4 |
33 | 33 | ||
34 | Push the code and tag to GitHub | 34 | Push the code and tag to GitHub |
35 | ------------------------------- | 35 | ------------------------------- |
36 | 36 | ||
37 | git push monitoring-plugins master | 37 | git push monitoring-plugins master |
38 | git push monitoring-plugins v2.3 | 38 | git push monitoring-plugins v2.4 |
39 | 39 | ||
40 | Create new maintenance branch | 40 | Create new maintenance branch |
41 | ----------------------------- | 41 | ----------------------------- |
42 | 42 | ||
43 | _Only necessary when creating a feature release._ | 43 | _Only necessary when creating a feature release._ |
44 | 44 | ||
45 | git checkout -b maint-2.3 v2.3 | 45 | git checkout -b maint-2.4 v2.4 |
46 | git push -u monitoring-plugins maint-2.3 | 46 | git push -u monitoring-plugins maint-2.4 |
47 | 47 | ||
48 | Checkout new version | 48 | Checkout new version |
49 | -------------------- | 49 | -------------------- |
50 | 50 | ||
51 | rm -rf /tmp/plugins | 51 | rm -rf /tmp/plugins |
52 | git archive --prefix=tmp/plugins/ v2.3 | (cd /; tar -xf -) | 52 | git archive --prefix=tmp/plugins/ v2.4 | (cd /; tar -xf -) |
53 | 53 | ||
54 | Build the tarball | 54 | Build the tarball |
55 | ----------------- | 55 | ----------------- |
@@ -62,26 +62,26 @@ Build the tarball | |||
62 | Upload tarball to web site | 62 | Upload tarball to web site |
63 | -------------------------- | 63 | -------------------------- |
64 | 64 | ||
65 | scp monitoring-plugins-2.3.tar.gz \ | 65 | scp monitoring-plugins-2.4.tar.gz \ |
66 | plugins@orwell.monitoring-plugins.org:web/download/ | 66 | plugins@orwell.monitoring-plugins.org:web/download/ |
67 | 67 | ||
68 | Generate SHA1 checksum file on web site | 68 | Generate SHA1 checksum file on web site |
69 | --------------------------------------- | 69 | --------------------------------------- |
70 | 70 | ||
71 | ssh plugins@orwell.monitoring-plugins.org \ | 71 | ssh plugins@orwell.monitoring-plugins.org \ |
72 | '(cd web/download; $HOME/bin/create-checksum monitoring-plugins-2.3.tar.gz)' | 72 | '(cd web/download; $HOME/bin/create-checksum monitoring-plugins-2.4.tar.gz)' |
73 | 73 | ||
74 | Announce new release | 74 | Announce new release |
75 | -------------------- | 75 | -------------------- |
76 | 76 | ||
77 | - In the site.git repository: | 77 | - In the site.git repository: |
78 | 78 | ||
79 | - Create `web/input/news/release-2-3.md`. | 79 | - Create `web/input/news/release-2-4.md`. |
80 | - Update the `plugins_release` version in `web/macros.py`. | 80 | - Update the `plugins_release` version in `web/macros.py`. |
81 | - Commit and push the result: | 81 | - Commit and push the result: |
82 | 82 | ||
83 | git add web/input/news/release-2-3.md | 83 | git add web/input/news/release-2-4.md |
84 | git commit web/input/news/release-2-3.md web/macros.py | 84 | git commit web/input/news/release-2-4.md web/macros.py |
85 | git push origin master | 85 | git push origin master |
86 | 86 | ||
87 | - Post an announcement on (at least) the following mailing lists: | 87 | - Post an announcement on (at least) the following mailing lists: |
@@ -93,6 +93,6 @@ Announce new release | |||
93 | 93 | ||
94 | If you want to mention the number of contributors in the announcement: | 94 | If you want to mention the number of contributors in the announcement: |
95 | 95 | ||
96 | git shortlog -s v2.2.1..v2.3 | wc -l | 96 | git shortlog -s v2.3.1..v2.4 | wc -l |
97 | 97 | ||
98 | <!-- vim:set filetype=markdown textwidth=72: --> | 98 | <!-- vim:set filetype=markdown textwidth=72: --> |
diff --git a/gl/fsusage.c b/gl/fsusage.c index 0657555f..6103ecf3 100644 --- a/gl/fsusage.c +++ b/gl/fsusage.c | |||
@@ -143,6 +143,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) | |||
143 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (vfsd.f_bavail) != 0; | 143 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (vfsd.f_bavail) != 0; |
144 | fsp->fsu_files = PROPAGATE_ALL_ONES (vfsd.f_files); | 144 | fsp->fsu_files = PROPAGATE_ALL_ONES (vfsd.f_files); |
145 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (vfsd.f_ffree); | 145 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (vfsd.f_ffree); |
146 | fsp->fsu_favail = PROPAGATE_ALL_ONES (vfsd.f_favail); | ||
146 | return 0; | 147 | return 0; |
147 | } | 148 | } |
148 | 149 | ||
@@ -174,6 +175,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) | |||
174 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.fd_req.bfreen) != 0; | 175 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.fd_req.bfreen) != 0; |
175 | fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot); | 176 | fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot); |
176 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree); | 177 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree); |
178 | fsp->fsu_favail = PROPAGATE_ALL_ONES (fsd.fd_req.gfree); | ||
177 | 179 | ||
178 | #elif defined STAT_READ_FILSYS /* SVR2 */ | 180 | #elif defined STAT_READ_FILSYS /* SVR2 */ |
179 | # ifndef SUPERBOFF | 181 | # ifndef SUPERBOFF |
@@ -209,6 +211,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) | |||
209 | ? UINTMAX_MAX | 211 | ? UINTMAX_MAX |
210 | : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1)); | 212 | : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1)); |
211 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode); | 213 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode); |
214 | fsp->fsu_favail = PROPAGATE_ALL_ONES (fsd.s_tinode); | ||
212 | 215 | ||
213 | #elif defined STAT_STATFS3_OSF1 /* OSF/1 */ | 216 | #elif defined STAT_STATFS3_OSF1 /* OSF/1 */ |
214 | 217 | ||
@@ -296,6 +299,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) | |||
296 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.f_bavail) != 0; | 299 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.f_bavail) != 0; |
297 | fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.f_files); | 300 | fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.f_files); |
298 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.f_ffree); | 301 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.f_ffree); |
302 | fsp->fsu_favail = PROPAGATE_ALL_ONES (fsd.f_ffree); | ||
299 | 303 | ||
300 | #endif | 304 | #endif |
301 | 305 | ||
@@ -323,6 +327,7 @@ statfs (char *file, struct statfs *fsb) | |||
323 | fsb->f_bavail = fsd.du_tfree; | 327 | fsb->f_bavail = fsd.du_tfree; |
324 | fsb->f_files = (fsd.du_isize - 2) * fsd.du_inopb; | 328 | fsb->f_files = (fsd.du_isize - 2) * fsd.du_inopb; |
325 | fsb->f_ffree = fsd.du_tinode; | 329 | fsb->f_ffree = fsd.du_tinode; |
330 | fsb->f_favail = fsd.du_tinode; | ||
326 | fsb->f_fsid.val[0] = fsd.du_site; | 331 | fsb->f_fsid.val[0] = fsd.du_site; |
327 | fsb->f_fsid.val[1] = fsd.du_pckno; | 332 | fsb->f_fsid.val[1] = fsd.du_pckno; |
328 | return 0; | 333 | return 0; |
diff --git a/gl/fsusage.h b/gl/fsusage.h index 7810fc01..e2654fd8 100644 --- a/gl/fsusage.h +++ b/gl/fsusage.h | |||
@@ -32,7 +32,8 @@ struct fs_usage | |||
32 | uintmax_t fsu_bavail; /* Free blocks available to non-superuser. */ | 32 | uintmax_t fsu_bavail; /* Free blocks available to non-superuser. */ |
33 | bool fsu_bavail_top_bit_set; /* 1 if fsu_bavail represents a value < 0. */ | 33 | bool fsu_bavail_top_bit_set; /* 1 if fsu_bavail represents a value < 0. */ |
34 | uintmax_t fsu_files; /* Total file nodes. */ | 34 | uintmax_t fsu_files; /* Total file nodes. */ |
35 | uintmax_t fsu_ffree; /* Free file nodes. */ | 35 | uintmax_t fsu_ffree; /* Free file nodes to superuser. */ |
36 | uintmax_t fsu_favail; /* Free file nodes to non-superuser. */ | ||
36 | }; | 37 | }; |
37 | 38 | ||
38 | int get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp); | 39 | int get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp); |
diff --git a/lib/utils_base.c b/lib/utils_base.c index 19a531f5..fd7058da 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c | |||
@@ -37,6 +37,9 @@ | |||
37 | 37 | ||
38 | monitoring_plugin *this_monitoring_plugin=NULL; | 38 | monitoring_plugin *this_monitoring_plugin=NULL; |
39 | 39 | ||
40 | unsigned int timeout_state = STATE_CRITICAL; | ||
41 | unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT; | ||
42 | |||
40 | int _np_state_read_file(FILE *); | 43 | int _np_state_read_file(FILE *); |
41 | 44 | ||
42 | void np_init( char *plugin_name, int argc, char **argv ) { | 45 | void np_init( char *plugin_name, int argc, char **argv ) { |
@@ -359,6 +362,22 @@ char *np_extract_value(const char *varlist, const char *name, char sep) { | |||
359 | return value; | 362 | return value; |
360 | } | 363 | } |
361 | 364 | ||
365 | const char * | ||
366 | state_text (int result) | ||
367 | { | ||
368 | switch (result) { | ||
369 | case STATE_OK: | ||
370 | return "OK"; | ||
371 | case STATE_WARNING: | ||
372 | return "WARNING"; | ||
373 | case STATE_CRITICAL: | ||
374 | return "CRITICAL"; | ||
375 | case STATE_DEPENDENT: | ||
376 | return "DEPENDENT"; | ||
377 | default: | ||
378 | return "UNKNOWN"; | ||
379 | } | ||
380 | } | ||
362 | 381 | ||
363 | /* | 382 | /* |
364 | * Read a string representing a state (ok, warning... or numeric: 0, 1) and | 383 | * Read a string representing a state (ok, warning... or numeric: 0, 1) and |
diff --git a/lib/utils_base.h b/lib/utils_base.h index 42ae0c09..d7e7dffa 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h | |||
@@ -61,6 +61,10 @@ void print_thresholds(const char *, thresholds *); | |||
61 | int check_range(double, range *); | 61 | int check_range(double, range *); |
62 | int get_status(double, thresholds *); | 62 | int get_status(double, thresholds *); |
63 | 63 | ||
64 | /* Handle timeouts */ | ||
65 | extern unsigned int timeout_state; | ||
66 | extern unsigned int timeout_interval; | ||
67 | |||
64 | /* All possible characters in a threshold range */ | 68 | /* All possible characters in a threshold range */ |
65 | #define NP_THRESHOLDS_CHARS "-0123456789.:@~" | 69 | #define NP_THRESHOLDS_CHARS "-0123456789.:@~" |
66 | 70 | ||
@@ -107,5 +111,6 @@ void np_state_write_string(time_t, char *); | |||
107 | void np_init(char *, int argc, char **argv); | 111 | void np_init(char *, int argc, char **argv); |
108 | void np_set_args(int argc, char **argv); | 112 | void np_set_args(int argc, char **argv); |
109 | void np_cleanup(); | 113 | void np_cleanup(); |
114 | const char *state_text (int); | ||
110 | 115 | ||
111 | #endif /* _UTILS_BASE_ */ | 116 | #endif /* _UTILS_BASE_ */ |
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c index 7eb9a3a0..795840d3 100644 --- a/lib/utils_cmd.c +++ b/lib/utils_cmd.c | |||
@@ -40,6 +40,7 @@ | |||
40 | 40 | ||
41 | /** includes **/ | 41 | /** includes **/ |
42 | #include "common.h" | 42 | #include "common.h" |
43 | #include "utils.h" | ||
43 | #include "utils_cmd.h" | 44 | #include "utils_cmd.h" |
44 | #include "utils_base.h" | 45 | #include "utils_base.h" |
45 | #include <fcntl.h> | 46 | #include <fcntl.h> |
@@ -65,31 +66,6 @@ extern char **environ; | |||
65 | # define SIG_ERR ((Sigfunc *)-1) | 66 | # define SIG_ERR ((Sigfunc *)-1) |
66 | #endif | 67 | #endif |
67 | 68 | ||
68 | /* This variable must be global, since there's no way the caller | ||
69 | * can forcibly slay a dead or ungainly running program otherwise. | ||
70 | * Multithreading apps and plugins can initialize it (via CMD_INIT) | ||
71 | * in an async safe manner PRIOR to calling cmd_run() or cmd_run_array() | ||
72 | * for the first time. | ||
73 | * | ||
74 | * The check for initialized values is atomic and can | ||
75 | * occur in any number of threads simultaneously. */ | ||
76 | static pid_t *_cmd_pids = NULL; | ||
77 | |||
78 | /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX. | ||
79 | * If that fails and the macro isn't defined, we fall back to an educated | ||
80 | * guess. There's no guarantee that our guess is adequate and the program | ||
81 | * will die with SIGSEGV if it isn't and the upper boundary is breached. */ | ||
82 | #define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */ | ||
83 | #define MAXFD_LIMIT 8192 /* upper limit of open files */ | ||
84 | #ifdef _SC_OPEN_MAX | ||
85 | static long maxfd = 0; | ||
86 | #elif defined(OPEN_MAX) | ||
87 | # define maxfd OPEN_MAX | ||
88 | #else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */ | ||
89 | # define maxfd DEFAULT_MAXFD | ||
90 | #endif | ||
91 | |||
92 | |||
93 | /** prototypes **/ | 69 | /** prototypes **/ |
94 | static int _cmd_open (char *const *, int *, int *) | 70 | static int _cmd_open (char *const *, int *, int *) |
95 | __attribute__ ((__nonnull__ (1, 2, 3))); | 71 | __attribute__ ((__nonnull__ (1, 2, 3))); |
@@ -406,3 +382,19 @@ cmd_file_read ( char *filename, output *out, int flags) | |||
406 | 382 | ||
407 | return 0; | 383 | return 0; |
408 | } | 384 | } |
385 | |||
386 | void | ||
387 | timeout_alarm_handler (int signo) | ||
388 | { | ||
389 | size_t i; | ||
390 | if (signo == SIGALRM) { | ||
391 | printf (_("%s - Plugin timed out after %d seconds\n"), | ||
392 | state_text(timeout_state), timeout_interval); | ||
393 | |||
394 | if(_cmd_pids) for(i = 0; i < maxfd; i++) { | ||
395 | if(_cmd_pids[i] != 0) kill(_cmd_pids[i], SIGKILL); | ||
396 | } | ||
397 | |||
398 | exit (timeout_state); | ||
399 | } | ||
400 | } | ||
diff --git a/lib/utils_cmd.h b/lib/utils_cmd.h index ebaf15be..6f3aeb81 100644 --- a/lib/utils_cmd.h +++ b/lib/utils_cmd.h | |||
@@ -32,4 +32,17 @@ void cmd_init (void); | |||
32 | #define CMD_NO_ARRAYS 0x01 /* don't populate arrays at all */ | 32 | #define CMD_NO_ARRAYS 0x01 /* don't populate arrays at all */ |
33 | #define CMD_NO_ASSOC 0x02 /* output.line won't point to buf */ | 33 | #define CMD_NO_ASSOC 0x02 /* output.line won't point to buf */ |
34 | 34 | ||
35 | /* This variable must be global, since there's no way the caller | ||
36 | * can forcibly slay a dead or ungainly running program otherwise. | ||
37 | * Multithreading apps and plugins can initialize it (via CMD_INIT) | ||
38 | * in an async safe manner PRIOR to calling cmd_run() or cmd_run_array() | ||
39 | * for the first time. | ||
40 | * | ||
41 | * The check for initialized values is atomic and can | ||
42 | * occur in any number of threads simultaneously. */ | ||
43 | static pid_t *_cmd_pids = NULL; | ||
44 | |||
45 | RETSIGTYPE timeout_alarm_handler (int); | ||
46 | |||
47 | |||
35 | #endif /* _UTILS_CMD_ */ | 48 | #endif /* _UTILS_CMD_ */ |
diff --git a/lib/utils_disk.c b/lib/utils_disk.c index efe35fc5..c7c9126e 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c | |||
@@ -69,6 +69,8 @@ np_add_parameter(struct parameter_list **list, const char *name) | |||
69 | new_path->dtotal_units = 0; | 69 | new_path->dtotal_units = 0; |
70 | new_path->inodes_total = 0; | 70 | new_path->inodes_total = 0; |
71 | new_path->inodes_free = 0; | 71 | new_path->inodes_free = 0; |
72 | new_path->inodes_free_to_root = 0; | ||
73 | new_path->inodes_used = 0; | ||
72 | new_path->dused_inodes_percent = 0; | 74 | new_path->dused_inodes_percent = 0; |
73 | new_path->dfree_inodes_percent = 0; | 75 | new_path->dfree_inodes_percent = 0; |
74 | 76 | ||
diff --git a/lib/utils_disk.h b/lib/utils_disk.h index 83a37639..999270cd 100644 --- a/lib/utils_disk.h +++ b/lib/utils_disk.h | |||
@@ -24,7 +24,8 @@ struct parameter_list | |||
24 | char *group; | 24 | char *group; |
25 | struct mount_entry *best_match; | 25 | struct mount_entry *best_match; |
26 | struct parameter_list *name_next; | 26 | struct parameter_list *name_next; |
27 | uintmax_t total, available, available_to_root, used, inodes_free, inodes_total; | 27 | uintmax_t total, available, available_to_root, used, |
28 | inodes_free, inodes_free_to_root, inodes_used, inodes_total; | ||
28 | double dfree_pct, dused_pct; | 29 | double dfree_pct, dused_pct; |
29 | double dused_units, dfree_units, dtotal_units; | 30 | double dused_units, dfree_units, dtotal_units; |
30 | double dused_inodes_percent, dfree_inodes_percent; | 31 | double dused_inodes_percent, dfree_inodes_percent; |
diff --git a/m4/libcurl.m4 b/m4/libcurl.m4 new file mode 100644 index 00000000..53d694d0 --- /dev/null +++ b/m4/libcurl.m4 | |||
@@ -0,0 +1,272 @@ | |||
1 | #*************************************************************************** | ||
2 | # _ _ ____ _ | ||
3 | # Project ___| | | | _ \| | | ||
4 | # / __| | | | |_) | | | ||
5 | # | (__| |_| | _ <| |___ | ||
6 | # \___|\___/|_| \_\_____| | ||
7 | # | ||
8 | # Copyright (C) 2006, David Shaw <dshaw@jabberwocky.com> | ||
9 | # | ||
10 | # This software is licensed as described in the file COPYING, which | ||
11 | # you should have received as part of this distribution. The terms | ||
12 | # are also available at https://curl.haxx.se/docs/copyright.html. | ||
13 | # | ||
14 | # You may opt to use, copy, modify, merge, publish, distribute and/or sell | ||
15 | # copies of the Software, and permit persons to whom the Software is | ||
16 | # furnished to do so, under the terms of the COPYING file. | ||
17 | # | ||
18 | # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | # KIND, either express or implied. | ||
20 | # | ||
21 | ########################################################################### | ||
22 | # LIBCURL_CHECK_CONFIG ([DEFAULT-ACTION], [MINIMUM-VERSION], | ||
23 | # [ACTION-IF-YES], [ACTION-IF-NO]) | ||
24 | # ---------------------------------------------------------- | ||
25 | # David Shaw <dshaw@jabberwocky.com> May-09-2006 | ||
26 | # | ||
27 | # Checks for libcurl. DEFAULT-ACTION is the string yes or no to | ||
28 | # specify whether to default to --with-libcurl or --without-libcurl. | ||
29 | # If not supplied, DEFAULT-ACTION is yes. MINIMUM-VERSION is the | ||
30 | # minimum version of libcurl to accept. Pass the version as a regular | ||
31 | # version number like 7.10.1. If not supplied, any version is | ||
32 | # accepted. ACTION-IF-YES is a list of shell commands to run if | ||
33 | # libcurl was successfully found and passed the various tests. | ||
34 | # ACTION-IF-NO is a list of shell commands that are run otherwise. | ||
35 | # Note that using --without-libcurl does run ACTION-IF-NO. | ||
36 | # | ||
37 | # This macro #defines HAVE_LIBCURL if a working libcurl setup is | ||
38 | # found, and sets @LIBCURL@ and @LIBCURL_CPPFLAGS@ to the necessary | ||
39 | # values. Other useful defines are LIBCURL_FEATURE_xxx where xxx are | ||
40 | # the various features supported by libcurl, and LIBCURL_PROTOCOL_yyy | ||
41 | # where yyy are the various protocols supported by libcurl. Both xxx | ||
42 | # and yyy are capitalized. See the list of AH_TEMPLATEs at the top of | ||
43 | # the macro for the complete list of possible defines. Shell | ||
44 | # variables $libcurl_feature_xxx and $libcurl_protocol_yyy are also | ||
45 | # defined to 'yes' for those features and protocols that were found. | ||
46 | # Note that xxx and yyy keep the same capitalization as in the | ||
47 | # curl-config list (e.g. it's "HTTP" and not "http"). | ||
48 | # | ||
49 | # Users may override the detected values by doing something like: | ||
50 | # LIBCURL="-lcurl" LIBCURL_CPPFLAGS="-I/usr/myinclude" ./configure | ||
51 | # | ||
52 | # For the sake of sanity, this macro assumes that any libcurl that is | ||
53 | # found is after version 7.7.2, the first version that included the | ||
54 | # curl-config script. Note that it is very important for people | ||
55 | # packaging binary versions of libcurl to include this script! | ||
56 | # Without curl-config, we can only guess what protocols are available, | ||
57 | # or use curl_version_info to figure it out at runtime. | ||
58 | |||
59 | AC_DEFUN([LIBCURL_CHECK_CONFIG], | ||
60 | [ | ||
61 | AH_TEMPLATE([LIBCURL_FEATURE_SSL],[Defined if libcurl supports SSL]) | ||
62 | AH_TEMPLATE([LIBCURL_FEATURE_KRB4],[Defined if libcurl supports KRB4]) | ||
63 | AH_TEMPLATE([LIBCURL_FEATURE_IPV6],[Defined if libcurl supports IPv6]) | ||
64 | AH_TEMPLATE([LIBCURL_FEATURE_LIBZ],[Defined if libcurl supports libz]) | ||
65 | AH_TEMPLATE([LIBCURL_FEATURE_ASYNCHDNS],[Defined if libcurl supports AsynchDNS]) | ||
66 | AH_TEMPLATE([LIBCURL_FEATURE_IDN],[Defined if libcurl supports IDN]) | ||
67 | AH_TEMPLATE([LIBCURL_FEATURE_SSPI],[Defined if libcurl supports SSPI]) | ||
68 | AH_TEMPLATE([LIBCURL_FEATURE_NTLM],[Defined if libcurl supports NTLM]) | ||
69 | |||
70 | AH_TEMPLATE([LIBCURL_PROTOCOL_HTTP],[Defined if libcurl supports HTTP]) | ||
71 | AH_TEMPLATE([LIBCURL_PROTOCOL_HTTPS],[Defined if libcurl supports HTTPS]) | ||
72 | AH_TEMPLATE([LIBCURL_PROTOCOL_FTP],[Defined if libcurl supports FTP]) | ||
73 | AH_TEMPLATE([LIBCURL_PROTOCOL_FTPS],[Defined if libcurl supports FTPS]) | ||
74 | AH_TEMPLATE([LIBCURL_PROTOCOL_FILE],[Defined if libcurl supports FILE]) | ||
75 | AH_TEMPLATE([LIBCURL_PROTOCOL_TELNET],[Defined if libcurl supports TELNET]) | ||
76 | AH_TEMPLATE([LIBCURL_PROTOCOL_LDAP],[Defined if libcurl supports LDAP]) | ||
77 | AH_TEMPLATE([LIBCURL_PROTOCOL_DICT],[Defined if libcurl supports DICT]) | ||
78 | AH_TEMPLATE([LIBCURL_PROTOCOL_TFTP],[Defined if libcurl supports TFTP]) | ||
79 | AH_TEMPLATE([LIBCURL_PROTOCOL_RTSP],[Defined if libcurl supports RTSP]) | ||
80 | AH_TEMPLATE([LIBCURL_PROTOCOL_POP3],[Defined if libcurl supports POP3]) | ||
81 | AH_TEMPLATE([LIBCURL_PROTOCOL_IMAP],[Defined if libcurl supports IMAP]) | ||
82 | AH_TEMPLATE([LIBCURL_PROTOCOL_SMTP],[Defined if libcurl supports SMTP]) | ||
83 | |||
84 | AC_ARG_WITH(libcurl, | ||
85 | AS_HELP_STRING([--with-libcurl=PREFIX],[look for the curl library in PREFIX/lib and headers in PREFIX/include]), | ||
86 | [_libcurl_with=$withval],[_libcurl_with=ifelse([$1],,[yes],[$1])]) | ||
87 | |||
88 | if test "$_libcurl_with" != "no" ; then | ||
89 | |||
90 | AC_PROG_AWK | ||
91 | |||
92 | _libcurl_version_parse="eval $AWK '{split(\$NF,A,\".\"); X=256*256*A[[1]]+256*A[[2]]+A[[3]]; print X;}'" | ||
93 | |||
94 | _libcurl_try_link=yes | ||
95 | |||
96 | if test -d "$_libcurl_with" ; then | ||
97 | LIBCURL_CPPFLAGS="-I$withval/include" | ||
98 | _libcurl_ldflags="-L$withval/lib" | ||
99 | AC_PATH_PROG([_libcurl_config],[curl-config],[], | ||
100 | ["$withval/bin"]) | ||
101 | else | ||
102 | AC_PATH_PROG([_libcurl_config],[curl-config],[],[$PATH]) | ||
103 | fi | ||
104 | |||
105 | if test x$_libcurl_config != "x" ; then | ||
106 | AC_CACHE_CHECK([for the version of libcurl], | ||
107 | [libcurl_cv_lib_curl_version], | ||
108 | [libcurl_cv_lib_curl_version=`$_libcurl_config --version | $AWK '{print $[]2}'`]) | ||
109 | |||
110 | _libcurl_version=`echo $libcurl_cv_lib_curl_version | $_libcurl_version_parse` | ||
111 | _libcurl_wanted=`echo ifelse([$2],,[0],[$2]) | $_libcurl_version_parse` | ||
112 | |||
113 | if test $_libcurl_wanted -gt 0 ; then | ||
114 | AC_CACHE_CHECK([for libcurl >= version $2], | ||
115 | [libcurl_cv_lib_version_ok], | ||
116 | [ | ||
117 | if test $_libcurl_version -ge $_libcurl_wanted ; then | ||
118 | libcurl_cv_lib_version_ok=yes | ||
119 | else | ||
120 | libcurl_cv_lib_version_ok=no | ||
121 | fi | ||
122 | ]) | ||
123 | fi | ||
124 | |||
125 | if test $_libcurl_wanted -eq 0 || test x$libcurl_cv_lib_version_ok = xyes ; then | ||
126 | if test x"$LIBCURL_CPPFLAGS" = "x" ; then | ||
127 | LIBCURL_CPPFLAGS=`$_libcurl_config --cflags` | ||
128 | fi | ||
129 | if test x"$LIBCURL" = "x" ; then | ||
130 | LIBCURL=`$_libcurl_config --libs` | ||
131 | |||
132 | # This is so silly, but Apple actually has a bug in their | ||
133 | # curl-config script. Fixed in Tiger, but there are still | ||
134 | # lots of Panther installs around. | ||
135 | case "${host}" in | ||
136 | powerpc-apple-darwin7*) | ||
137 | LIBCURL=`echo $LIBCURL | sed -e 's|-arch i386||g'` | ||
138 | ;; | ||
139 | esac | ||
140 | fi | ||
141 | |||
142 | # All curl-config scripts support --feature | ||
143 | _libcurl_features=`$_libcurl_config --feature` | ||
144 | |||
145 | # Is it modern enough to have --protocols? (7.12.4) | ||
146 | if test $_libcurl_version -ge 461828 ; then | ||
147 | _libcurl_protocols=`$_libcurl_config --protocols` | ||
148 | fi | ||
149 | else | ||
150 | _libcurl_try_link=no | ||
151 | fi | ||
152 | |||
153 | unset _libcurl_wanted | ||
154 | fi | ||
155 | |||
156 | if test $_libcurl_try_link = yes ; then | ||
157 | |||
158 | # we didn't find curl-config, so let's see if the user-supplied | ||
159 | # link line (or failing that, "-lcurl") is enough. | ||
160 | LIBCURL=${LIBCURL-"$_libcurl_ldflags -lcurl"} | ||
161 | |||
162 | AC_CACHE_CHECK([whether libcurl is usable], | ||
163 | [libcurl_cv_lib_curl_usable], | ||
164 | [ | ||
165 | _libcurl_save_cppflags=$CPPFLAGS | ||
166 | CPPFLAGS="$LIBCURL_CPPFLAGS $CPPFLAGS" | ||
167 | _libcurl_save_libs=$LIBS | ||
168 | LIBS="$LIBCURL $LIBS" | ||
169 | |||
170 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <curl/curl.h>]],[[ | ||
171 | /* Try and use a few common options to force a failure if we are | ||
172 | missing symbols or can't link. */ | ||
173 | int x; | ||
174 | curl_easy_setopt(NULL,CURLOPT_URL,NULL); | ||
175 | x=CURL_ERROR_SIZE; | ||
176 | x=CURLOPT_WRITEFUNCTION; | ||
177 | x=CURLOPT_WRITEDATA; | ||
178 | x=CURLOPT_ERRORBUFFER; | ||
179 | x=CURLOPT_STDERR; | ||
180 | x=CURLOPT_VERBOSE; | ||
181 | if (x) {;} | ||
182 | ]])],libcurl_cv_lib_curl_usable=yes,libcurl_cv_lib_curl_usable=no) | ||
183 | |||
184 | CPPFLAGS=$_libcurl_save_cppflags | ||
185 | LIBS=$_libcurl_save_libs | ||
186 | unset _libcurl_save_cppflags | ||
187 | unset _libcurl_save_libs | ||
188 | ]) | ||
189 | |||
190 | if test $libcurl_cv_lib_curl_usable = yes ; then | ||
191 | |||
192 | # Does curl_free() exist in this version of libcurl? | ||
193 | # If not, fake it with free() | ||
194 | |||
195 | _libcurl_save_cppflags=$CPPFLAGS | ||
196 | CPPFLAGS="$CPPFLAGS $LIBCURL_CPPFLAGS" | ||
197 | _libcurl_save_libs=$LIBS | ||
198 | LIBS="$LIBS $LIBCURL" | ||
199 | |||
200 | AC_CHECK_FUNC(curl_free,, | ||
201 | AC_DEFINE(curl_free,free, | ||
202 | [Define curl_free() as free() if our version of curl lacks curl_free.])) | ||
203 | |||
204 | CPPFLAGS=$_libcurl_save_cppflags | ||
205 | LIBS=$_libcurl_save_libs | ||
206 | unset _libcurl_save_cppflags | ||
207 | unset _libcurl_save_libs | ||
208 | |||
209 | AC_DEFINE(HAVE_LIBCURL,1, | ||
210 | [Define to 1 if you have a functional curl library.]) | ||
211 | AC_SUBST(LIBCURL_CPPFLAGS) | ||
212 | AC_SUBST(LIBCURL) | ||
213 | |||
214 | for _libcurl_feature in $_libcurl_features ; do | ||
215 | AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_feature_$_libcurl_feature),[1]) | ||
216 | eval AS_TR_SH(libcurl_feature_$_libcurl_feature)=yes | ||
217 | done | ||
218 | |||
219 | if test "x$_libcurl_protocols" = "x" ; then | ||
220 | |||
221 | # We don't have --protocols, so just assume that all | ||
222 | # protocols are available | ||
223 | _libcurl_protocols="HTTP FTP FILE TELNET LDAP DICT TFTP" | ||
224 | |||
225 | if test x$libcurl_feature_SSL = xyes ; then | ||
226 | _libcurl_protocols="$_libcurl_protocols HTTPS" | ||
227 | |||
228 | # FTPS wasn't standards-compliant until version | ||
229 | # 7.11.0 (0x070b00 == 461568) | ||
230 | if test $_libcurl_version -ge 461568; then | ||
231 | _libcurl_protocols="$_libcurl_protocols FTPS" | ||
232 | fi | ||
233 | fi | ||
234 | |||
235 | # RTSP, IMAP, POP3 and SMTP were added in | ||
236 | # 7.20.0 (0x071400 == 463872) | ||
237 | if test $_libcurl_version -ge 463872; then | ||
238 | _libcurl_protocols="$_libcurl_protocols RTSP IMAP POP3 SMTP" | ||
239 | fi | ||
240 | fi | ||
241 | |||
242 | for _libcurl_protocol in $_libcurl_protocols ; do | ||
243 | AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_protocol_$_libcurl_protocol),[1]) | ||
244 | eval AS_TR_SH(libcurl_protocol_$_libcurl_protocol)=yes | ||
245 | done | ||
246 | else | ||
247 | unset LIBCURL | ||
248 | unset LIBCURL_CPPFLAGS | ||
249 | fi | ||
250 | fi | ||
251 | |||
252 | unset _libcurl_try_link | ||
253 | unset _libcurl_version_parse | ||
254 | unset _libcurl_config | ||
255 | unset _libcurl_feature | ||
256 | unset _libcurl_features | ||
257 | unset _libcurl_protocol | ||
258 | unset _libcurl_protocols | ||
259 | unset _libcurl_version | ||
260 | unset _libcurl_ldflags | ||
261 | fi | ||
262 | |||
263 | if test x$_libcurl_with = xno || test x$libcurl_cv_lib_curl_usable != xyes ; then | ||
264 | # This is the IF-NO path | ||
265 | ifelse([$4],,:,[$4]) | ||
266 | else | ||
267 | # This is the IF-YES path | ||
268 | ifelse([$3],,:,[$3]) | ||
269 | fi | ||
270 | |||
271 | unset _libcurl_with | ||
272 | ])dnl | ||
diff --git a/m4/np_mysqlclient.m4 b/m4/np_mysqlclient.m4 index c2a4d2a7..5099a02b 100644 --- a/m4/np_mysqlclient.m4 +++ b/m4/np_mysqlclient.m4 | |||
@@ -53,18 +53,34 @@ AC_DEFUN([np_mysqlclient], | |||
53 | _savedcppflags="$CPPFLAGS" | 53 | _savedcppflags="$CPPFLAGS" |
54 | CPPFLAGS="$CPPFLAGS $np_mysql_include" | 54 | CPPFLAGS="$CPPFLAGS $np_mysql_include" |
55 | 55 | ||
56 | dnl Putting $np_mysql_libs as other libraries ensures that all mysql dependencies are linked in | 56 | np_check_lib_mysqlclient |
57 | dnl Although -lmysqlclient is duplicated, it is not a problem | 57 | |
58 | AC_CHECK_LIB([mysqlclient], [mysql_init], [ | ||
59 | with_mysql=$np_mysql_config | ||
60 | AC_DEFINE(HAVE_MYSQLCLIENT, 1, [Defined if mysqlclient is found and can compile]) | ||
61 | ], [with_mysql=no], [$np_mysql_libs]) | ||
62 | CPPFLAGS=$_savedcppflags | 58 | CPPFLAGS=$_savedcppflags |
63 | 59 | ||
64 | fi | 60 | fi |
65 | fi | 61 | fi |
66 | ]) | 62 | ]) |
67 | 63 | ||
64 | dnl Test mysql_init using mysqlclient | ||
65 | AC_DEFUN([np_check_lib_mysqlclient], | ||
66 | [ | ||
67 | dnl Putting $np_mysql_libs as other libraries ensures that all mysql dependencies are linked in | ||
68 | dnl Although -lmysqlclient is duplicated, it is not a problem | ||
69 | AC_CHECK_LIB([mysqlclient], [mysql_init], [ | ||
70 | with_mysql=$np_mysql_config | ||
71 | AC_DEFINE(HAVE_MYSQLCLIENT, 1, [Defined if mysqlclient is found and can compile]) | ||
72 | ], [np_check_lib_mariadbclient], [$np_mysql_libs]) | ||
73 | ]) | ||
74 | |||
75 | dnl Test mysql_init using mariadbclient | ||
76 | AC_DEFUN([np_check_lib_mariadbclient], | ||
77 | [ | ||
78 | AC_CHECK_LIB([mariadbclient], [mysql_init], [ | ||
79 | with_mysql=$np_mysql_config | ||
80 | AC_DEFINE(HAVE_MYSQLCLIENT, 1, [Defined if mariadbclient is found and can compile]) | ||
81 | ], [with_mysql=no], [$np_mysql_libs]) | ||
82 | ]) | ||
83 | |||
68 | dnl Will take $1, find last occurrance of -LDIR and add DIR to LD_RUN_PATH | 84 | dnl Will take $1, find last occurrance of -LDIR and add DIR to LD_RUN_PATH |
69 | AC_DEFUN([np_add_to_runpath], | 85 | AC_DEFUN([np_add_to_runpath], |
70 | [ | 86 | [ |
diff --git a/m4/uriparser.m4 b/m4/uriparser.m4 new file mode 100644 index 00000000..dbb8a551 --- /dev/null +++ b/m4/uriparser.m4 | |||
@@ -0,0 +1,140 @@ | |||
1 | # (this check is rougly based on and inspired libcurl.m4) | ||
2 | # URIPARSER_CHECK ([DEFAULT-ACTION], [MINIMUM-VERSION], | ||
3 | # [ACTION-IF-YES], [ACTION-IF-NO]) | ||
4 | # Checks for uriparser library. DEFAULT-ACTION is the string yes or no to | ||
5 | # specify whether to default to --with-uriparser or --without-liburiparser. | ||
6 | # If not supplied, DEFAULT-ACTION is yes. MINIMUM-VERSION is the | ||
7 | # minimum version of uriparser to accept. Pass the version as a regular | ||
8 | # version number like 0.8.5. If not supplied, any version is | ||
9 | # accepted. ACTION-IF-YES is a list of shell commands to run if | ||
10 | # uriparser was successfully found and passed the various tests. | ||
11 | # ACTION-IF-NO is a list of shell commands that are run otherwise. | ||
12 | # Note that using --without-uriparser does run ACTION-IF-NO. | ||
13 | # | ||
14 | # This macro #defines HAVE_URIPARSER if a working uriparser setup is | ||
15 | # found, and sets @URIPARSER@ and @URIPARSER_CPPFLAGS@ to the necessary | ||
16 | # values. | ||
17 | # | ||
18 | # Users may override the detected values by doing something like: | ||
19 | # URIPARSER="-luriparser" URIPARSER_CPPFLAGS="-I/usr/myinclude" ./configure | ||
20 | # | ||
21 | |||
22 | AC_DEFUN([URIPARSER_CHECK], | ||
23 | [ | ||
24 | AC_ARG_WITH(uriparser, | ||
25 | AS_HELP_STRING([--with-uriparser=PREFIX],[look for the uriparser library in PREFIX/lib and headers in PREFIX/include]), | ||
26 | [_uriparser_with=$withval],[_uriparser_with=ifelse([$1],,[yes],[$1])]) | ||
27 | |||
28 | if test "$_uriparser_with" != "no" ; then | ||
29 | |||
30 | _uriparser_try_link=yes | ||
31 | |||
32 | AC_CHECK_PROG(PKGCONFIG,pkg-config,pkg-config,no) | ||
33 | |||
34 | if test "x$URIPARSER" != "x" || test "x$URIPARSER_CPPFLAGS" != "x"; then | ||
35 | : | ||
36 | elif test -d "$_uriparser_with" ; then | ||
37 | URIPARSER_CPPFLAGS="-I$withval/include" | ||
38 | _uriparser_ldflags="-L$withval/lib" | ||
39 | |||
40 | elif test x$PKGCONFIG != xno; then | ||
41 | |||
42 | AC_CACHE_CHECK([for the version of uriparser], | ||
43 | [uriparser_cv_uriparser_version], | ||
44 | [uriparser_cv_uriparser_version=`$PKGCONFIG liburiparser --modversion`]) | ||
45 | |||
46 | AC_PROG_AWK | ||
47 | |||
48 | _uriparser_version_parse="eval $AWK '{split(\$NF,A,\".\"); X=256*256*A[[1]]+256*A[[2]]+A[[3]]; print X;}'" | ||
49 | |||
50 | _uriparser_version=`echo $uriparser_cv_uriparser_version | $_uriparser_version_parse` | ||
51 | _uriparser_wanted=`echo ifelse([$2],,[0],[$2]) | $_uriparser_version_parse` | ||
52 | |||
53 | if test $_uriparser_wanted -gt 0 ; then | ||
54 | AC_CACHE_CHECK([for uriparser >= version $2], | ||
55 | [uriparser_cv_lib_version_ok], | ||
56 | [ | ||
57 | if test $_uriparser_version -ge $_uriparser_wanted ; then | ||
58 | uriparser_cv_lib_version_ok=yes | ||
59 | else | ||
60 | uriparser_cv_lib_version_ok=no | ||
61 | fi | ||
62 | ]) | ||
63 | fi | ||
64 | |||
65 | if test $_uriparser_wanted -eq 0 || test x$uriparser_cv_lib_version_ok = xyes ; then | ||
66 | if test x"$URIPARSER_CPPFLAGS" = "x" ; then | ||
67 | URIPARSER_CPPFLAGS=`$PKGCONFIG liburiparser --cflags` | ||
68 | fi | ||
69 | if test x"$URIPARSER" = "x" ; then | ||
70 | URIPARSER=`$PKGCONFIG liburiparser --libs` | ||
71 | fi | ||
72 | else | ||
73 | _uriparser_try_link=no | ||
74 | fi | ||
75 | |||
76 | unset _uriparser_wanted | ||
77 | else | ||
78 | dnl no pkg-config, ok, do our best and set some defaults | ||
79 | URIPARSER_CPPFLAGS="-I/usr/include" | ||
80 | URIPARSER="-luriparser -L/usr/lib -L/usr/lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/i686-linux-gnu" | ||
81 | fi | ||
82 | |||
83 | if test $_uriparser_try_link = yes ; then | ||
84 | |||
85 | # let's see if the user-supplied | ||
86 | # link line (or failing that, "-luriparser") is enough. | ||
87 | URIPARSER=${URIPARSER-"$_uriparser_ldflags -luriparser"} | ||
88 | |||
89 | AC_CACHE_CHECK([whether uriparser is usable], | ||
90 | [uriparser_cv_lib_uriparser_usable], | ||
91 | [ | ||
92 | _liburiparser_save_cppflags=$CPPFLAGS | ||
93 | CPPFLAGS="$URIPARSER_CPPFLAGS $CPPFLAGS" | ||
94 | _liburiparser_save_libs=$LIBS | ||
95 | LIBS="$URIPARSER $LIBS" | ||
96 | |||
97 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <uriparser/Uri.h>]],[[ | ||
98 | /* Try and use a few common options to force a failure if we are | ||
99 | missing symbols or cannot link. */ | ||
100 | UriParserStateA state; | ||
101 | UriUriA uri; | ||
102 | state.uri = &uri; | ||
103 | char *location = "http://test.dom/dir/file.ext"; | ||
104 | int x = uriParseUriA (&state, location); | ||
105 | if (x == URI_SUCCESS) {;} | ||
106 | ]])],uriparser_cv_lib_uriparser_usable=yes,uriparser_cv_lib_uriparser_usable=no) | ||
107 | |||
108 | CPPFLAGS=$_liburiparser_save_cppflags | ||
109 | LIBS=$_liburiparser_save_libs | ||
110 | unset _liburiparser_save_cppflags | ||
111 | unset _liburiparser_save_libs | ||
112 | ]) | ||
113 | |||
114 | if test $uriparser_cv_lib_uriparser_usable = yes ; then | ||
115 | AC_DEFINE(HAVE_URIPARSER,1, | ||
116 | [Define to 1 if you have a functional uriparser library.]) | ||
117 | AC_SUBST(URIPARSER_CPPFLAGS) | ||
118 | AC_SUBST(URIPARSER) | ||
119 | else | ||
120 | unset URIPARSER | ||
121 | unset URIPARSER_CPPFLAGS | ||
122 | fi | ||
123 | fi | ||
124 | |||
125 | unset _uriparser_try_link | ||
126 | unset _uriparser_version_parse | ||
127 | unset _uriparser_version | ||
128 | unset _uriparser_ldflags | ||
129 | fi | ||
130 | |||
131 | if test x$_uriparser_with = xno || test x$uriparser_cv_lib_uriparser_usable != xyes ; then | ||
132 | # This is the IF-NO path | ||
133 | ifelse([$4],,:,[$4]) | ||
134 | else | ||
135 | # This is the IF-YES path | ||
136 | ifelse([$3],,:,[$3]) | ||
137 | fi | ||
138 | |||
139 | unset _uriparser_with | ||
140 | ])dnl | ||
diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c index f4c2dafd..ad673237 100644 --- a/plugins-root/check_dhcp.c +++ b/plugins-root/check_dhcp.c | |||
@@ -323,7 +323,8 @@ int get_hardware_address(int sock,char *interface_name){ | |||
323 | #elif defined(__bsd__) | 323 | #elif defined(__bsd__) |
324 | /* King 2004 see ACKNOWLEDGEMENTS */ | 324 | /* King 2004 see ACKNOWLEDGEMENTS */ |
325 | 325 | ||
326 | int mib[6], len; | 326 | size_t len; |
327 | int mib[6]; | ||
327 | char *buf; | 328 | char *buf; |
328 | unsigned char *ptr; | 329 | unsigned char *ptr; |
329 | struct if_msghdr *ifm; | 330 | struct if_msghdr *ifm; |
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 4098874c..31eb4c65 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c | |||
@@ -67,7 +67,9 @@ const char *email = "devel@monitoring-plugins.org"; | |||
67 | #include <netinet/in_systm.h> | 67 | #include <netinet/in_systm.h> |
68 | #include <netinet/in.h> | 68 | #include <netinet/in.h> |
69 | #include <netinet/ip.h> | 69 | #include <netinet/ip.h> |
70 | #include <netinet/ip6.h> | ||
70 | #include <netinet/ip_icmp.h> | 71 | #include <netinet/ip_icmp.h> |
72 | #include <netinet/icmp6.h> | ||
71 | #include <arpa/inet.h> | 73 | #include <arpa/inet.h> |
72 | #include <signal.h> | 74 | #include <signal.h> |
73 | #include <float.h> | 75 | #include <float.h> |
@@ -113,8 +115,8 @@ typedef struct rta_host { | |||
113 | unsigned short id; /* id in **table, and icmp pkts */ | 115 | unsigned short id; /* id in **table, and icmp pkts */ |
114 | char *name; /* arg used for adding this host */ | 116 | char *name; /* arg used for adding this host */ |
115 | char *msg; /* icmp error message, if any */ | 117 | char *msg; /* icmp error message, if any */ |
116 | struct sockaddr_in saddr_in; /* the address of this host */ | 118 | struct sockaddr_storage saddr_in; /* the address of this host */ |
117 | struct in_addr error_addr; /* stores address of error replies */ | 119 | struct sockaddr_storage error_addr; /* stores address of error replies */ |
118 | unsigned long long time_waited; /* total time waited, in usecs */ | 120 | unsigned long long time_waited; /* total time waited, in usecs */ |
119 | unsigned int icmp_sent, icmp_recv, icmp_lost; /* counters */ | 121 | unsigned int icmp_sent, icmp_recv, icmp_lost; /* counters */ |
120 | unsigned char icmp_type, icmp_code; /* type and code from errors */ | 122 | unsigned char icmp_type, icmp_code; /* type and code from errors */ |
@@ -140,6 +142,18 @@ typedef struct icmp_ping_data { | |||
140 | unsigned short ping_id; | 142 | unsigned short ping_id; |
141 | } icmp_ping_data; | 143 | } icmp_ping_data; |
142 | 144 | ||
145 | typedef union ip_hdr { | ||
146 | struct ip ip; | ||
147 | struct ip6_hdr ip6; | ||
148 | } ip_hdr; | ||
149 | |||
150 | typedef union icmp_packet { | ||
151 | void *buf; | ||
152 | struct icmp *icp; | ||
153 | struct icmp6_hdr *icp6; | ||
154 | u_short *cksum_in; | ||
155 | } icmp_packet; | ||
156 | |||
143 | /* the different modes of this program are as follows: | 157 | /* the different modes of this program are as follows: |
144 | * MODE_RTA: send all packets no matter what (mimic check_icmp and check_ping) | 158 | * MODE_RTA: send all packets no matter what (mimic check_icmp and check_ping) |
145 | * MODE_HOSTCHECK: Return immediately upon any sign of life | 159 | * MODE_HOSTCHECK: Return immediately upon any sign of life |
@@ -190,8 +204,9 @@ static int get_threshold(char *str, threshold *th); | |||
190 | static void run_checks(void); | 204 | static void run_checks(void); |
191 | static void set_source_ip(char *); | 205 | static void set_source_ip(char *); |
192 | static int add_target(char *); | 206 | static int add_target(char *); |
193 | static int add_target_ip(char *, struct in_addr *); | 207 | static int add_target_ip(char *, struct sockaddr_storage *); |
194 | static int handle_random_icmp(unsigned char *, struct sockaddr_in *); | 208 | static int handle_random_icmp(unsigned char *, struct sockaddr_storage *); |
209 | static void parse_address(struct sockaddr_storage *, char *, int); | ||
195 | static unsigned short icmp_checksum(unsigned short *, int); | 210 | static unsigned short icmp_checksum(unsigned short *, int); |
196 | static void finish(int); | 211 | static void finish(int); |
197 | static void crash(const char *, ...); | 212 | static void crash(const char *, ...); |
@@ -300,7 +315,7 @@ get_icmp_error_msg(unsigned char icmp_type, unsigned char icmp_code) | |||
300 | } | 315 | } |
301 | 316 | ||
302 | static int | 317 | static int |
303 | handle_random_icmp(unsigned char *packet, struct sockaddr_in *addr) | 318 | handle_random_icmp(unsigned char *packet, struct sockaddr_storage *addr) |
304 | { | 319 | { |
305 | struct icmp p, sent_icmp; | 320 | struct icmp p, sent_icmp; |
306 | struct rta_host *host = NULL; | 321 | struct rta_host *host = NULL; |
@@ -342,9 +357,11 @@ handle_random_icmp(unsigned char *packet, struct sockaddr_in *addr) | |||
342 | /* it is indeed a response for us */ | 357 | /* it is indeed a response for us */ |
343 | host = table[ntohs(sent_icmp.icmp_seq)/packets]; | 358 | host = table[ntohs(sent_icmp.icmp_seq)/packets]; |
344 | if(debug) { | 359 | if(debug) { |
360 | char address[INET6_ADDRSTRLEN]; | ||
361 | parse_address(addr, address, sizeof(address)); | ||
345 | printf("Received \"%s\" from %s for ICMP ECHO sent to %s.\n", | 362 | printf("Received \"%s\" from %s for ICMP ECHO sent to %s.\n", |
346 | get_icmp_error_msg(p.icmp_type, p.icmp_code), | 363 | get_icmp_error_msg(p.icmp_type, p.icmp_code), |
347 | inet_ntoa(addr->sin_addr), host->name); | 364 | address, host->name); |
348 | } | 365 | } |
349 | 366 | ||
350 | icmp_lost++; | 367 | icmp_lost++; |
@@ -364,11 +381,23 @@ handle_random_icmp(unsigned char *packet, struct sockaddr_in *addr) | |||
364 | } | 381 | } |
365 | host->icmp_type = p.icmp_type; | 382 | host->icmp_type = p.icmp_type; |
366 | host->icmp_code = p.icmp_code; | 383 | host->icmp_code = p.icmp_code; |
367 | host->error_addr.s_addr = addr->sin_addr.s_addr; | 384 | host->error_addr = *addr; |
368 | 385 | ||
369 | return 0; | 386 | return 0; |
370 | } | 387 | } |
371 | 388 | ||
389 | void parse_address(struct sockaddr_storage *addr, char *address, int size) | ||
390 | { | ||
391 | switch (address_family) { | ||
392 | case AF_INET: | ||
393 | inet_ntop(address_family, &((struct sockaddr_in *)addr)->sin_addr, address, size); | ||
394 | break; | ||
395 | case AF_INET6: | ||
396 | inet_ntop(address_family, &((struct sockaddr_in6 *)addr)->sin6_addr, address, size); | ||
397 | break; | ||
398 | } | ||
399 | } | ||
400 | |||
372 | int | 401 | int |
373 | main(int argc, char **argv) | 402 | main(int argc, char **argv) |
374 | { | 403 | { |
@@ -381,6 +410,7 @@ main(int argc, char **argv) | |||
381 | #ifdef SO_TIMESTAMP | 410 | #ifdef SO_TIMESTAMP |
382 | int on = 1; | 411 | int on = 1; |
383 | #endif | 412 | #endif |
413 | char * opts_str = "vhVw:c:n:p:t:H:s:i:b:I:l:m:64"; | ||
384 | 414 | ||
385 | setlocale (LC_ALL, ""); | 415 | setlocale (LC_ALL, ""); |
386 | bindtextdomain (PACKAGE, LOCALEDIR); | 416 | bindtextdomain (PACKAGE, LOCALEDIR); |
@@ -390,33 +420,8 @@ main(int argc, char **argv) | |||
390 | * that before pointer magic (esp. on network data) */ | 420 | * that before pointer magic (esp. on network data) */ |
391 | icmp_sockerrno = udp_sockerrno = tcp_sockerrno = sockets = 0; | 421 | icmp_sockerrno = udp_sockerrno = tcp_sockerrno = sockets = 0; |
392 | 422 | ||
393 | if((icmp_sock = socket(PF_INET, SOCK_RAW, IPPROTO_ICMP)) != -1) | 423 | address_family = -1; |
394 | sockets |= HAVE_ICMP; | 424 | int icmp_proto = IPPROTO_ICMP; |
395 | else icmp_sockerrno = errno; | ||
396 | |||
397 | /* if((udp_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) != -1) */ | ||
398 | /* sockets |= HAVE_UDP; */ | ||
399 | /* else udp_sockerrno = errno; */ | ||
400 | |||
401 | /* if((tcp_sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) != -1) */ | ||
402 | /* sockets |= HAVE_TCP; */ | ||
403 | /* else tcp_sockerrno = errno; */ | ||
404 | |||
405 | /* now drop privileges (no effect if not setsuid or geteuid() == 0) */ | ||
406 | setuid(getuid()); | ||
407 | |||
408 | #ifdef SO_TIMESTAMP | ||
409 | if(setsockopt(icmp_sock, SOL_SOCKET, SO_TIMESTAMP, &on, sizeof(on))) | ||
410 | if(debug) printf("Warning: no SO_TIMESTAMP support\n"); | ||
411 | #endif // SO_TIMESTAMP | ||
412 | |||
413 | /* POSIXLY_CORRECT might break things, so unset it (the portable way) */ | ||
414 | environ = NULL; | ||
415 | |||
416 | /* use the pid to mark packets as ours */ | ||
417 | /* Some systems have 32-bit pid_t so mask off only 16 bits */ | ||
418 | pid = getpid() & 0xffff; | ||
419 | /* printf("pid = %u\n", pid); */ | ||
420 | 425 | ||
421 | /* get calling name the old-fashioned way for portability instead | 426 | /* get calling name the old-fashioned way for portability instead |
422 | * of relying on the glibc-ism __progname */ | 427 | * of relying on the glibc-ism __progname */ |
@@ -456,20 +461,35 @@ main(int argc, char **argv) | |||
456 | packets = 5; | 461 | packets = 5; |
457 | } | 462 | } |
458 | 463 | ||
459 | /* Parse extra opts if any */ | 464 | /* Parse protocol arguments first */ |
460 | argv=np_extra_opts(&argc, argv, progname); | 465 | for(i = 1; i < argc; i++) { |
461 | 466 | while((arg = getopt(argc, argv, opts_str)) != EOF) { | |
462 | /* support "--help" and "--version" */ | 467 | unsigned short size; |
463 | if(argc == 2) { | 468 | switch(arg) { |
464 | if(!strcmp(argv[1], "--help")) | 469 | case '4': |
465 | strcpy(argv[1], "-h"); | 470 | if (address_family != -1) |
466 | if(!strcmp(argv[1], "--version")) | 471 | crash("Multiple protocol versions not supported"); |
467 | strcpy(argv[1], "-V"); | 472 | address_family = AF_INET; |
473 | break; | ||
474 | case '6': | ||
475 | #ifdef USE_IPV6 | ||
476 | if (address_family != -1) | ||
477 | crash("Multiple protocol versions not supported"); | ||
478 | address_family = AF_INET6; | ||
479 | #else | ||
480 | usage (_("IPv6 support not available\n")); | ||
481 | #endif | ||
482 | break; | ||
483 | } | ||
484 | } | ||
468 | } | 485 | } |
469 | 486 | ||
487 | /* Reset argument scanning */ | ||
488 | optind = 1; | ||
489 | |||
470 | /* parse the arguments */ | 490 | /* parse the arguments */ |
471 | for(i = 1; i < argc; i++) { | 491 | for(i = 1; i < argc; i++) { |
472 | while((arg = getopt(argc, argv, "vhVw:c:n:p:t:H:s:i:b:I:l:m:")) != EOF) { | 492 | while((arg = getopt(argc, argv, opts_str)) != EOF) { |
473 | unsigned short size; | 493 | unsigned short size; |
474 | switch(arg) { | 494 | switch(arg) { |
475 | case 'v': | 495 | case 'v': |
@@ -530,10 +550,30 @@ main(int argc, char **argv) | |||
530 | case 'h': /* help */ | 550 | case 'h': /* help */ |
531 | print_help (); | 551 | print_help (); |
532 | exit (STATE_UNKNOWN); | 552 | exit (STATE_UNKNOWN); |
553 | break; | ||
533 | } | 554 | } |
534 | } | 555 | } |
535 | } | 556 | } |
536 | 557 | ||
558 | /* POSIXLY_CORRECT might break things, so unset it (the portable way) */ | ||
559 | environ = NULL; | ||
560 | |||
561 | /* use the pid to mark packets as ours */ | ||
562 | /* Some systems have 32-bit pid_t so mask off only 16 bits */ | ||
563 | pid = getpid() & 0xffff; | ||
564 | /* printf("pid = %u\n", pid); */ | ||
565 | |||
566 | /* Parse extra opts if any */ | ||
567 | argv=np_extra_opts(&argc, argv, progname); | ||
568 | |||
569 | /* support "--help" and "--version" */ | ||
570 | if(argc == 2) { | ||
571 | if(!strcmp(argv[1], "--help")) | ||
572 | strcpy(argv[1], "-h"); | ||
573 | if(!strcmp(argv[1], "--version")) | ||
574 | strcpy(argv[1], "-V"); | ||
575 | } | ||
576 | |||
537 | argv = &argv[optind]; | 577 | argv = &argv[optind]; |
538 | while(*argv) { | 578 | while(*argv) { |
539 | add_target(*argv); | 579 | add_target(*argv); |
@@ -545,6 +585,30 @@ main(int argc, char **argv) | |||
545 | exit(3); | 585 | exit(3); |
546 | } | 586 | } |
547 | 587 | ||
588 | // add_target might change address_family | ||
589 | switch ( address_family ){ | ||
590 | case AF_INET: icmp_proto = IPPROTO_ICMP; | ||
591 | break; | ||
592 | case AF_INET6: icmp_proto = IPPROTO_ICMPV6; | ||
593 | break; | ||
594 | default: crash("Address family not supported"); | ||
595 | } | ||
596 | if((icmp_sock = socket(address_family, SOCK_RAW, icmp_proto)) != -1) | ||
597 | sockets |= HAVE_ICMP; | ||
598 | else icmp_sockerrno = errno; | ||
599 | |||
600 | |||
601 | #ifdef SO_TIMESTAMP | ||
602 | if(setsockopt(icmp_sock, SOL_SOCKET, SO_TIMESTAMP, &on, sizeof(on))) | ||
603 | if(debug) printf("Warning: no SO_TIMESTAMP support\n"); | ||
604 | #endif // SO_TIMESTAMP | ||
605 | |||
606 | /* now drop privileges (no effect if not setsuid or geteuid() == 0) */ | ||
607 | if (setuid(getuid()) == -1) { | ||
608 | printf("ERROR: Failed to drop privileges\n"); | ||
609 | return 1; | ||
610 | } | ||
611 | |||
548 | if(!sockets) { | 612 | if(!sockets) { |
549 | if(icmp_sock == -1) { | 613 | if(icmp_sock == -1) { |
550 | errno = icmp_sockerrno; | 614 | errno = icmp_sockerrno; |
@@ -633,7 +697,7 @@ main(int argc, char **argv) | |||
633 | } | 697 | } |
634 | 698 | ||
635 | host = list; | 699 | host = list; |
636 | table = malloc(sizeof(struct rta_host **) * targets); | 700 | table = (struct rta_host**)malloc(sizeof(struct rta_host **) * targets); |
637 | i = 0; | 701 | i = 0; |
638 | while(host) { | 702 | while(host) { |
639 | host->id = i*packets; | 703 | host->id = i*packets; |
@@ -697,9 +761,15 @@ run_checks() | |||
697 | } | 761 | } |
698 | } | 762 | } |
699 | 763 | ||
764 | |||
700 | /* response structure: | 765 | /* response structure: |
766 | * IPv4: | ||
701 | * ip header : 20 bytes | 767 | * ip header : 20 bytes |
702 | * icmp header : 28 bytes | 768 | * icmp header : 28 bytes |
769 | * IPv6: | ||
770 | * ip header : 40 bytes | ||
771 | * icmp header : 28 bytes | ||
772 | * both: | ||
703 | * icmp echo reply : the rest | 773 | * icmp echo reply : the rest |
704 | */ | 774 | */ |
705 | static int | 775 | static int |
@@ -707,16 +777,27 @@ wait_for_reply(int sock, u_int t) | |||
707 | { | 777 | { |
708 | int n, hlen; | 778 | int n, hlen; |
709 | static unsigned char buf[4096]; | 779 | static unsigned char buf[4096]; |
710 | struct sockaddr_in resp_addr; | 780 | struct sockaddr_storage resp_addr; |
711 | struct ip *ip; | 781 | union ip_hdr *ip; |
712 | struct icmp icp; | 782 | union icmp_packet packet; |
713 | struct rta_host *host; | 783 | struct rta_host *host; |
714 | struct icmp_ping_data data; | 784 | struct icmp_ping_data data; |
715 | struct timeval wait_start, now; | 785 | struct timeval wait_start, now; |
716 | u_int tdiff, i, per_pkt_wait; | 786 | u_int tdiff, i, per_pkt_wait; |
717 | 787 | ||
788 | if (!(packet.buf = malloc(icmp_pkt_size))) { | ||
789 | crash("send_icmp_ping(): failed to malloc %d bytes for send buffer", | ||
790 | icmp_pkt_size); | ||
791 | return -1; /* might be reached if we're in debug mode */ | ||
792 | } | ||
793 | |||
794 | memset(packet.buf, 0, icmp_pkt_size); | ||
795 | |||
718 | /* if we can't listen or don't have anything to listen to, just return */ | 796 | /* if we can't listen or don't have anything to listen to, just return */ |
719 | if(!t || !icmp_pkts_en_route) return 0; | 797 | if(!t || !icmp_pkts_en_route) { |
798 | free(packet.buf); | ||
799 | return 0; | ||
800 | } | ||
720 | 801 | ||
721 | gettimeofday(&wait_start, &tz); | 802 | gettimeofday(&wait_start, &tz); |
722 | 803 | ||
@@ -735,7 +816,7 @@ wait_for_reply(int sock, u_int t) | |||
735 | 816 | ||
736 | /* reap responses until we hit a timeout */ | 817 | /* reap responses until we hit a timeout */ |
737 | n = recvfrom_wto(sock, buf, sizeof(buf), | 818 | n = recvfrom_wto(sock, buf, sizeof(buf), |
738 | (struct sockaddr *)&resp_addr, &t, &now); | 819 | (struct sockaddr *)&resp_addr, &t, &now); |
739 | if(!n) { | 820 | if(!n) { |
740 | if(debug > 1) { | 821 | if(debug > 1) { |
741 | printf("recvfrom_wto() timed out during a %u usecs wait\n", | 822 | printf("recvfrom_wto() timed out during a %u usecs wait\n", |
@@ -745,12 +826,23 @@ wait_for_reply(int sock, u_int t) | |||
745 | } | 826 | } |
746 | if(n < 0) { | 827 | if(n < 0) { |
747 | if(debug) printf("recvfrom_wto() returned errors\n"); | 828 | if(debug) printf("recvfrom_wto() returned errors\n"); |
829 | free(packet.buf); | ||
748 | return n; | 830 | return n; |
749 | } | 831 | } |
750 | 832 | ||
751 | ip = (struct ip *)buf; | 833 | // FIXME: with ipv6 we don't have an ip header here |
752 | if(debug > 1) printf("received %u bytes from %s\n", | 834 | if (address_family != AF_INET6) { |
753 | ntohs(ip->ip_len), inet_ntoa(resp_addr.sin_addr)); | 835 | ip = (union ip_hdr *)buf; |
836 | |||
837 | if(debug > 1) { | ||
838 | char address[INET6_ADDRSTRLEN]; | ||
839 | parse_address(&resp_addr, address, sizeof(address)); | ||
840 | printf("received %u bytes from %s\n", | ||
841 | address_family == AF_INET6 ? ntohs(ip->ip6.ip6_plen) | ||
842 | : ntohs(ip->ip.ip_len), | ||
843 | address); | ||
844 | } | ||
845 | } | ||
754 | 846 | ||
755 | /* obsolete. alpha on tru64 provides the necessary defines, but isn't broken */ | 847 | /* obsolete. alpha on tru64 provides the necessary defines, but isn't broken */ |
756 | /* #if defined( __alpha__ ) && __STDC__ && !defined( __GLIBC__ ) */ | 848 | /* #if defined( __alpha__ ) && __STDC__ && !defined( __GLIBC__ ) */ |
@@ -759,12 +851,14 @@ wait_for_reply(int sock, u_int t) | |||
759 | * off the bottom 4 bits */ | 851 | * off the bottom 4 bits */ |
760 | /* hlen = (ip->ip_vhl & 0x0f) << 2; */ | 852 | /* hlen = (ip->ip_vhl & 0x0f) << 2; */ |
761 | /* #else */ | 853 | /* #else */ |
762 | hlen = ip->ip_hl << 2; | 854 | hlen = (address_family == AF_INET6) ? 0 : ip->ip.ip_hl << 2; |
763 | /* #endif */ | 855 | /* #endif */ |
764 | 856 | ||
765 | if(n < (hlen + ICMP_MINLEN)) { | 857 | if(n < (hlen + ICMP_MINLEN)) { |
858 | char address[INET6_ADDRSTRLEN]; | ||
859 | parse_address(&resp_addr, address, sizeof(address)); | ||
766 | crash("received packet too short for ICMP (%d bytes, expected %d) from %s\n", | 860 | crash("received packet too short for ICMP (%d bytes, expected %d) from %s\n", |
767 | n, hlen + icmp_pkt_size, inet_ntoa(resp_addr.sin_addr)); | 861 | n, hlen + icmp_pkt_size, address); |
768 | } | 862 | } |
769 | /* else if(debug) { */ | 863 | /* else if(debug) { */ |
770 | /* printf("ip header size: %u, packet size: %u (expected %u, %u)\n", */ | 864 | /* printf("ip header size: %u, packet size: %u (expected %u, %u)\n", */ |
@@ -773,23 +867,39 @@ wait_for_reply(int sock, u_int t) | |||
773 | /* } */ | 867 | /* } */ |
774 | 868 | ||
775 | /* check the response */ | 869 | /* check the response */ |
776 | memcpy(&icp, buf + hlen, sizeof(icp)); | ||
777 | 870 | ||
778 | if(ntohs(icp.icmp_id) != pid || icp.icmp_type != ICMP_ECHOREPLY || | 871 | memcpy(packet.buf, buf + hlen, icmp_pkt_size); |
779 | ntohs(icp.icmp_seq) >= targets*packets) { | 872 | /* address_family == AF_INET6 ? sizeof(struct icmp6_hdr) |
873 | : sizeof(struct icmp));*/ | ||
874 | |||
875 | if( (address_family == PF_INET && | ||
876 | (ntohs(packet.icp->icmp_id) != pid || packet.icp->icmp_type != ICMP_ECHOREPLY | ||
877 | || ntohs(packet.icp->icmp_seq) >= targets * packets)) | ||
878 | || (address_family == PF_INET6 && | ||
879 | (ntohs(packet.icp6->icmp6_id) != pid || packet.icp6->icmp6_type != ICMP6_ECHO_REPLY | ||
880 | || ntohs(packet.icp6->icmp6_seq) >= targets * packets))) { | ||
780 | if(debug > 2) printf("not a proper ICMP_ECHOREPLY\n"); | 881 | if(debug > 2) printf("not a proper ICMP_ECHOREPLY\n"); |
781 | handle_random_icmp(buf + hlen, &resp_addr); | 882 | handle_random_icmp(buf + hlen, &resp_addr); |
782 | continue; | 883 | continue; |
783 | } | 884 | } |
784 | 885 | ||
785 | /* this is indeed a valid response */ | 886 | /* this is indeed a valid response */ |
786 | memcpy(&data, icp.icmp_data, sizeof(data)); | 887 | if (address_family == PF_INET) { |
787 | if (debug > 2) | 888 | memcpy(&data, packet.icp->icmp_data, sizeof(data)); |
788 | printf("ICMP echo-reply of len %lu, id %u, seq %u, cksum 0x%X\n", | 889 | if (debug > 2) |
789 | (unsigned long)sizeof(data), ntohs(icp.icmp_id), | 890 | printf("ICMP echo-reply of len %lu, id %u, seq %u, cksum 0x%X\n", |
790 | ntohs(icp.icmp_seq), icp.icmp_cksum); | 891 | (unsigned long)sizeof(data), ntohs(packet.icp->icmp_id), |
892 | ntohs(packet.icp->icmp_seq), packet.icp->icmp_cksum); | ||
893 | host = table[ntohs(packet.icp->icmp_seq)/packets]; | ||
894 | } else { | ||
895 | memcpy(&data, &packet.icp6->icmp6_dataun.icmp6_un_data8[4], sizeof(data)); | ||
896 | if (debug > 2) | ||
897 | printf("ICMP echo-reply of len %lu, id %u, seq %u, cksum 0x%X\n", | ||
898 | (unsigned long)sizeof(data), ntohs(packet.icp6->icmp6_id), | ||
899 | ntohs(packet.icp6->icmp6_seq), packet.icp6->icmp6_cksum); | ||
900 | host = table[ntohs(packet.icp6->icmp6_seq)/packets]; | ||
901 | } | ||
791 | 902 | ||
792 | host = table[ntohs(icp.icmp_seq)/packets]; | ||
793 | tdiff = get_timevaldiff(&data.stime, &now); | 903 | tdiff = get_timevaldiff(&data.stime, &now); |
794 | 904 | ||
795 | host->time_waited += tdiff; | 905 | host->time_waited += tdiff; |
@@ -801,22 +911,25 @@ wait_for_reply(int sock, u_int t) | |||
801 | host->rtmin = tdiff; | 911 | host->rtmin = tdiff; |
802 | 912 | ||
803 | if(debug) { | 913 | if(debug) { |
914 | char address[INET6_ADDRSTRLEN]; | ||
915 | parse_address(&resp_addr, address, sizeof(address)); | ||
804 | printf("%0.3f ms rtt from %s, outgoing ttl: %u, incoming ttl: %u, max: %0.3f, min: %0.3f\n", | 916 | printf("%0.3f ms rtt from %s, outgoing ttl: %u, incoming ttl: %u, max: %0.3f, min: %0.3f\n", |
805 | (float)tdiff / 1000, inet_ntoa(resp_addr.sin_addr), | 917 | (float)tdiff / 1000, address, |
806 | ttl, ip->ip_ttl, (float)host->rtmax / 1000, (float)host->rtmin / 1000); | 918 | ttl, ip->ip.ip_ttl, (float)host->rtmax / 1000, (float)host->rtmin / 1000); |
807 | } | 919 | } |
808 | 920 | ||
809 | /* if we're in hostcheck mode, exit with limited printouts */ | 921 | /* if we're in hostcheck mode, exit with limited printouts */ |
810 | if(mode == MODE_HOSTCHECK) { | 922 | if(mode == MODE_HOSTCHECK) { |
811 | printf("OK - %s responds to ICMP. Packet %u, rta %0.3fms|" | 923 | printf("OK - %s responds to ICMP. Packet %u, rta %0.3fms|" |
812 | "pkt=%u;;0;%u rta=%0.3f;%0.3f;%0.3f;;\n", | 924 | "pkt=%u;;0;%u rta=%0.3f;%0.3f;%0.3f;;\n", |
813 | host->name, icmp_recv, (float)tdiff / 1000, | 925 | host->name, icmp_recv, (float)tdiff / 1000, |
814 | icmp_recv, packets, (float)tdiff / 1000, | 926 | icmp_recv, packets, (float)tdiff / 1000, |
815 | (float)warn.rta / 1000, (float)crit.rta / 1000); | 927 | (float)warn.rta / 1000, (float)crit.rta / 1000); |
816 | exit(STATE_OK); | 928 | exit(STATE_OK); |
817 | } | 929 | } |
818 | } | 930 | } |
819 | 931 | ||
932 | free(packet.buf); | ||
820 | return 0; | 933 | return 0; |
821 | } | 934 | } |
822 | 935 | ||
@@ -824,62 +937,81 @@ wait_for_reply(int sock, u_int t) | |||
824 | static int | 937 | static int |
825 | send_icmp_ping(int sock, struct rta_host *host) | 938 | send_icmp_ping(int sock, struct rta_host *host) |
826 | { | 939 | { |
827 | static union { | ||
828 | void *buf; /* re-use so we prevent leaks */ | ||
829 | struct icmp *icp; | ||
830 | u_short *cksum_in; | ||
831 | } packet = { NULL }; | ||
832 | long int len; | 940 | long int len; |
833 | struct icmp_ping_data data; | 941 | struct icmp_ping_data data; |
834 | struct msghdr hdr; | 942 | struct msghdr hdr; |
835 | struct iovec iov; | 943 | struct iovec iov; |
836 | struct timeval tv; | 944 | struct timeval tv; |
837 | struct sockaddr *addr; | 945 | void *buf = NULL; |
838 | 946 | ||
839 | if(sock == -1) { | 947 | if(sock == -1) { |
840 | errno = 0; | 948 | errno = 0; |
841 | crash("Attempt to send on bogus socket"); | 949 | crash("Attempt to send on bogus socket"); |
842 | return -1; | 950 | return -1; |
843 | } | 951 | } |
844 | addr = (struct sockaddr *)&host->saddr_in; | ||
845 | 952 | ||
846 | if(!packet.buf) { | 953 | if(!buf) { |
847 | if (!(packet.buf = malloc(icmp_pkt_size))) { | 954 | if (!(buf = malloc(icmp_pkt_size))) { |
848 | crash("send_icmp_ping(): failed to malloc %d bytes for send buffer", | 955 | crash("send_icmp_ping(): failed to malloc %d bytes for send buffer", |
849 | icmp_pkt_size); | 956 | icmp_pkt_size); |
850 | return -1; /* might be reached if we're in debug mode */ | 957 | return -1; /* might be reached if we're in debug mode */ |
851 | } | 958 | } |
852 | } | 959 | } |
853 | memset(packet.buf, 0, icmp_pkt_size); | 960 | memset(buf, 0, icmp_pkt_size); |
854 | 961 | ||
855 | if((gettimeofday(&tv, &tz)) == -1) return -1; | 962 | if((gettimeofday(&tv, &tz)) == -1) { |
963 | free(buf); | ||
964 | return -1; | ||
965 | } | ||
856 | 966 | ||
857 | data.ping_id = 10; /* host->icmp.icmp_sent; */ | 967 | data.ping_id = 10; /* host->icmp.icmp_sent; */ |
858 | memcpy(&data.stime, &tv, sizeof(tv)); | 968 | memcpy(&data.stime, &tv, sizeof(tv)); |
859 | memcpy(&packet.icp->icmp_data, &data, sizeof(data)); | 969 | |
860 | packet.icp->icmp_type = ICMP_ECHO; | 970 | if (address_family == AF_INET) { |
861 | packet.icp->icmp_code = 0; | 971 | struct icmp *icp = (struct icmp*)buf; |
862 | packet.icp->icmp_cksum = 0; | 972 | |
863 | packet.icp->icmp_id = htons(pid); | 973 | memcpy(&icp->icmp_data, &data, sizeof(data)); |
864 | packet.icp->icmp_seq = htons(host->id++); | 974 | |
865 | packet.icp->icmp_cksum = icmp_checksum(packet.cksum_in, icmp_pkt_size); | 975 | icp->icmp_type = ICMP_ECHO; |
866 | 976 | icp->icmp_code = 0; | |
867 | if (debug > 2) | 977 | icp->icmp_cksum = 0; |
868 | printf("Sending ICMP echo-request of len %lu, id %u, seq %u, cksum 0x%X to host %s\n", | 978 | icp->icmp_id = htons(pid); |
869 | (unsigned long)sizeof(data), ntohs(packet.icp->icmp_id), | 979 | icp->icmp_seq = htons(host->id++); |
870 | ntohs(packet.icp->icmp_seq), packet.icp->icmp_cksum, | 980 | icp->icmp_cksum = icmp_checksum((unsigned short*)buf, icmp_pkt_size); |
871 | host->name); | 981 | |
982 | if (debug > 2) | ||
983 | printf("Sending ICMP echo-request of len %lu, id %u, seq %u, cksum 0x%X to host %s\n", | ||
984 | (unsigned long)sizeof(data), ntohs(icp->icmp_id), ntohs(icp->icmp_seq), icp->icmp_cksum, host->name); | ||
985 | } | ||
986 | else { | ||
987 | struct icmp6_hdr *icp6 = (struct icmp6_hdr*)buf; | ||
988 | memcpy(&icp6->icmp6_dataun.icmp6_un_data8[4], &data, sizeof(data)); | ||
989 | icp6->icmp6_type = ICMP6_ECHO_REQUEST; | ||
990 | icp6->icmp6_code = 0; | ||
991 | icp6->icmp6_cksum = 0; | ||
992 | icp6->icmp6_id = htons(pid); | ||
993 | icp6->icmp6_seq = htons(host->id++); | ||
994 | // let checksum be calculated automatically | ||
995 | |||
996 | if (debug > 2) { | ||
997 | printf("Sending ICMP echo-request of len %lu, id %u, seq %u, cksum 0x%X to host %s\n", | ||
998 | (unsigned long)sizeof(data), ntohs(icp6->icmp6_id), | ||
999 | ntohs(icp6->icmp6_seq), icp6->icmp6_cksum, host->name); | ||
1000 | } | ||
1001 | } | ||
872 | 1002 | ||
873 | memset(&iov, 0, sizeof(iov)); | 1003 | memset(&iov, 0, sizeof(iov)); |
874 | iov.iov_base = packet.buf; | 1004 | iov.iov_base = buf; |
875 | iov.iov_len = icmp_pkt_size; | 1005 | iov.iov_len = icmp_pkt_size; |
876 | 1006 | ||
877 | memset(&hdr, 0, sizeof(hdr)); | 1007 | memset(&hdr, 0, sizeof(hdr)); |
878 | hdr.msg_name = addr; | 1008 | hdr.msg_name = (struct sockaddr *)&host->saddr_in; |
879 | hdr.msg_namelen = sizeof(struct sockaddr); | 1009 | hdr.msg_namelen = sizeof(struct sockaddr_storage); |
880 | hdr.msg_iov = &iov; | 1010 | hdr.msg_iov = &iov; |
881 | hdr.msg_iovlen = 1; | 1011 | hdr.msg_iovlen = 1; |
882 | 1012 | ||
1013 | errno = 0; | ||
1014 | |||
883 | /* MSG_CONFIRM is a linux thing and only available on linux kernels >= 2.3.15, see send(2) */ | 1015 | /* MSG_CONFIRM is a linux thing and only available on linux kernels >= 2.3.15, see send(2) */ |
884 | #ifdef MSG_CONFIRM | 1016 | #ifdef MSG_CONFIRM |
885 | len = sendmsg(sock, &hdr, MSG_CONFIRM); | 1017 | len = sendmsg(sock, &hdr, MSG_CONFIRM); |
@@ -887,9 +1019,15 @@ send_icmp_ping(int sock, struct rta_host *host) | |||
887 | len = sendmsg(sock, &hdr, 0); | 1019 | len = sendmsg(sock, &hdr, 0); |
888 | #endif | 1020 | #endif |
889 | 1021 | ||
1022 | free(buf); | ||
1023 | |||
890 | if(len < 0 || (unsigned int)len != icmp_pkt_size) { | 1024 | if(len < 0 || (unsigned int)len != icmp_pkt_size) { |
891 | if(debug) printf("Failed to send ping to %s\n", | 1025 | if(debug) { |
892 | inet_ntoa(host->saddr_in.sin_addr)); | 1026 | char address[INET6_ADDRSTRLEN]; |
1027 | parse_address((struct sockaddr_storage *)&host->saddr_in, address, sizeof(address)); | ||
1028 | printf("Failed to send ping to %s: %s\n", address, strerror(errno)); | ||
1029 | } | ||
1030 | errno = 0; | ||
893 | return -1; | 1031 | return -1; |
894 | } | 1032 | } |
895 | 1033 | ||
@@ -934,7 +1072,7 @@ recvfrom_wto(int sock, void *buf, unsigned int len, struct sockaddr *saddr, | |||
934 | 1072 | ||
935 | if(!n) return 0; /* timeout */ | 1073 | if(!n) return 0; /* timeout */ |
936 | 1074 | ||
937 | slen = sizeof(struct sockaddr); | 1075 | slen = sizeof(struct sockaddr_storage); |
938 | 1076 | ||
939 | memset(&iov, 0, sizeof(iov)); | 1077 | memset(&iov, 0, sizeof(iov)); |
940 | iov.iov_base = buf; | 1078 | iov.iov_base = buf; |
@@ -958,6 +1096,7 @@ recvfrom_wto(int sock, void *buf, unsigned int len, struct sockaddr *saddr, | |||
958 | break ; | 1096 | break ; |
959 | } | 1097 | } |
960 | } | 1098 | } |
1099 | |||
961 | if (!chdr) | 1100 | if (!chdr) |
962 | #endif // SO_TIMESTAMP | 1101 | #endif // SO_TIMESTAMP |
963 | gettimeofday(tv, &tz); | 1102 | gettimeofday(tv, &tz); |
@@ -991,10 +1130,11 @@ finish(int sig) | |||
991 | 1130 | ||
992 | /* iterate thrice to calculate values, give output, and print perfparse */ | 1131 | /* iterate thrice to calculate values, give output, and print perfparse */ |
993 | host = list; | 1132 | host = list; |
1133 | |||
994 | while(host) { | 1134 | while(host) { |
995 | if(!host->icmp_recv) { | 1135 | if(!host->icmp_recv) { |
996 | /* rta 0 is ofcourse not entirely correct, but will still show up | 1136 | /* rta 0 is ofcourse not entirely correct, but will still show up |
997 | * conspicuosly as missing entries in perfparse and cacti */ | 1137 | * conspicuously as missing entries in perfparse and cacti */ |
998 | pl = 100; | 1138 | pl = 100; |
999 | rta = 0; | 1139 | rta = 0; |
1000 | status = STATE_CRITICAL; | 1140 | status = STATE_CRITICAL; |
@@ -1039,10 +1179,12 @@ finish(int sig) | |||
1039 | if(!host->icmp_recv) { | 1179 | if(!host->icmp_recv) { |
1040 | status = STATE_CRITICAL; | 1180 | status = STATE_CRITICAL; |
1041 | if(host->flags & FLAG_LOST_CAUSE) { | 1181 | if(host->flags & FLAG_LOST_CAUSE) { |
1182 | char address[INET6_ADDRSTRLEN]; | ||
1183 | parse_address(&host->error_addr, address, sizeof(address)); | ||
1042 | printf("%s: %s @ %s. rta nan, lost %d%%", | 1184 | printf("%s: %s @ %s. rta nan, lost %d%%", |
1043 | host->name, | 1185 | host->name, |
1044 | get_icmp_error_msg(host->icmp_type, host->icmp_code), | 1186 | get_icmp_error_msg(host->icmp_type, host->icmp_code), |
1045 | inet_ntoa(host->error_addr), | 1187 | address, |
1046 | 100); | 1188 | 100); |
1047 | } | 1189 | } |
1048 | else { /* not marked as lost cause, so we have no flags for it */ | 1190 | else { /* not marked as lost cause, so we have no flags for it */ |
@@ -1104,7 +1246,6 @@ get_timevaldiff(struct timeval *early, struct timeval *later) | |||
1104 | { | 1246 | { |
1105 | return 0; | 1247 | return 0; |
1106 | } | 1248 | } |
1107 | |||
1108 | ret = (later->tv_sec - early->tv_sec) * 1000000; | 1249 | ret = (later->tv_sec - early->tv_sec) * 1000000; |
1109 | ret += later->tv_usec - early->tv_usec; | 1250 | ret += later->tv_usec - early->tv_usec; |
1110 | 1251 | ||
@@ -1112,18 +1253,35 @@ get_timevaldiff(struct timeval *early, struct timeval *later) | |||
1112 | } | 1253 | } |
1113 | 1254 | ||
1114 | static int | 1255 | static int |
1115 | add_target_ip(char *arg, struct in_addr *in) | 1256 | add_target_ip(char *arg, struct sockaddr_storage *in) |
1116 | { | 1257 | { |
1117 | struct rta_host *host; | 1258 | struct rta_host *host; |
1259 | struct sockaddr_in *sin, *host_sin; | ||
1260 | struct sockaddr_in6 *sin6, *host_sin6; | ||
1261 | |||
1262 | if (address_family == AF_INET) | ||
1263 | sin = (struct sockaddr_in *)in; | ||
1264 | else | ||
1265 | sin6 = (struct sockaddr_in6 *)in; | ||
1118 | 1266 | ||
1119 | /* disregard obviously stupid addresses */ | 1267 | |
1120 | if(in->s_addr == INADDR_NONE || in->s_addr == INADDR_ANY) | 1268 | |
1269 | /* disregard obviously stupid addresses | ||
1270 | * (I didn't find an ipv6 equivalent to INADDR_NONE) */ | ||
1271 | if (((address_family == AF_INET && (sin->sin_addr.s_addr == INADDR_NONE | ||
1272 | || sin->sin_addr.s_addr == INADDR_ANY))) | ||
1273 | || (address_family == AF_INET6 && (sin6->sin6_addr.s6_addr == in6addr_any.s6_addr))) { | ||
1121 | return -1; | 1274 | return -1; |
1275 | } | ||
1122 | 1276 | ||
1123 | /* no point in adding two identical IP's, so don't. ;) */ | 1277 | /* no point in adding two identical IP's, so don't. ;) */ |
1124 | host = list; | 1278 | host = list; |
1125 | while(host) { | 1279 | while(host) { |
1126 | if(host->saddr_in.sin_addr.s_addr == in->s_addr) { | 1280 | host_sin = (struct sockaddr_in *)&host->saddr_in; |
1281 | host_sin6 = (struct sockaddr_in6 *)&host->saddr_in; | ||
1282 | |||
1283 | if( (address_family == AF_INET && host_sin->sin_addr.s_addr == sin->sin_addr.s_addr) | ||
1284 | || (address_family == AF_INET6 && host_sin6->sin6_addr.s6_addr == sin6->sin6_addr.s6_addr)) { | ||
1127 | if(debug) printf("Identical IP already exists. Not adding %s\n", arg); | 1285 | if(debug) printf("Identical IP already exists. Not adding %s\n", arg); |
1128 | return -1; | 1286 | return -1; |
1129 | } | 1287 | } |
@@ -1131,19 +1289,29 @@ add_target_ip(char *arg, struct in_addr *in) | |||
1131 | } | 1289 | } |
1132 | 1290 | ||
1133 | /* add the fresh ip */ | 1291 | /* add the fresh ip */ |
1134 | host = malloc(sizeof(struct rta_host)); | 1292 | host = (struct rta_host*)malloc(sizeof(struct rta_host)); |
1135 | if(!host) { | 1293 | if(!host) { |
1294 | char straddr[INET6_ADDRSTRLEN]; | ||
1295 | parse_address((struct sockaddr_storage*)&in, straddr, sizeof(straddr)); | ||
1136 | crash("add_target_ip(%s, %s): malloc(%d) failed", | 1296 | crash("add_target_ip(%s, %s): malloc(%d) failed", |
1137 | arg, inet_ntoa(*in), sizeof(struct rta_host)); | 1297 | arg, straddr, sizeof(struct rta_host)); |
1138 | } | 1298 | } |
1139 | memset(host, 0, sizeof(struct rta_host)); | 1299 | memset(host, 0, sizeof(struct rta_host)); |
1140 | 1300 | ||
1141 | /* set the values. use calling name for output */ | 1301 | /* set the values. use calling name for output */ |
1142 | host->name = strdup(arg); | 1302 | host->name = strdup(arg); |
1143 | 1303 | ||
1144 | /* fill out the sockaddr_in struct */ | 1304 | /* fill out the sockaddr_storage struct */ |
1145 | host->saddr_in.sin_family = AF_INET; | 1305 | if(address_family == AF_INET) { |
1146 | host->saddr_in.sin_addr.s_addr = in->s_addr; | 1306 | host_sin = (struct sockaddr_in *)&host->saddr_in; |
1307 | host_sin->sin_family = AF_INET; | ||
1308 | host_sin->sin_addr.s_addr = sin->sin_addr.s_addr; | ||
1309 | } | ||
1310 | else { | ||
1311 | host_sin6 = (struct sockaddr_in6 *)&host->saddr_in; | ||
1312 | host_sin6->sin6_family = AF_INET6; | ||
1313 | memcpy(host_sin6->sin6_addr.s6_addr, sin6->sin6_addr.s6_addr, sizeof host_sin6->sin6_addr.s6_addr); | ||
1314 | } | ||
1147 | 1315 | ||
1148 | host->rtmin = DBL_MAX; | 1316 | host->rtmin = DBL_MAX; |
1149 | 1317 | ||
@@ -1160,31 +1328,67 @@ add_target_ip(char *arg, struct in_addr *in) | |||
1160 | static int | 1328 | static int |
1161 | add_target(char *arg) | 1329 | add_target(char *arg) |
1162 | { | 1330 | { |
1163 | int i; | 1331 | int error, result; |
1164 | struct hostent *he; | 1332 | struct sockaddr_storage ip; |
1165 | struct in_addr *in, ip; | 1333 | struct addrinfo hints, *res, *p; |
1334 | struct sockaddr_in *sin; | ||
1335 | struct sockaddr_in6 *sin6; | ||
1336 | |||
1337 | switch (address_family) { | ||
1338 | case -1: | ||
1339 | /* -4 and -6 are not specified on cmdline */ | ||
1340 | address_family = AF_INET; | ||
1341 | sin = (struct sockaddr_in *)&ip; | ||
1342 | result = inet_pton(address_family, arg, &sin->sin_addr); | ||
1343 | #ifdef USE_IPV6 | ||
1344 | if( result != 1 ){ | ||
1345 | address_family = AF_INET6; | ||
1346 | sin6 = (struct sockaddr_in6 *)&ip; | ||
1347 | result = inet_pton(address_family, arg, &sin6->sin6_addr); | ||
1348 | } | ||
1349 | #endif | ||
1350 | /* If we don't find any valid addresses, we still don't know the address_family */ | ||
1351 | if ( result != 1) { | ||
1352 | address_family = -1; | ||
1353 | } | ||
1354 | break; | ||
1355 | case AF_INET: | ||
1356 | sin = (struct sockaddr_in *)&ip; | ||
1357 | result = inet_pton(address_family, arg, &sin->sin_addr); | ||
1358 | break; | ||
1359 | case AF_INET6: | ||
1360 | sin6 = (struct sockaddr_in6 *)&ip; | ||
1361 | result = inet_pton(address_family, arg, &sin6->sin6_addr); | ||
1362 | break; | ||
1363 | default: crash("Address family not supported"); | ||
1364 | } | ||
1166 | 1365 | ||
1167 | /* don't resolve if we don't have to */ | 1366 | /* don't resolve if we don't have to */ |
1168 | if((ip.s_addr = inet_addr(arg)) != INADDR_NONE) { | 1367 | if(result == 1) { |
1169 | /* don't add all ip's if we were given a specific one */ | 1368 | /* don't add all ip's if we were given a specific one */ |
1170 | return add_target_ip(arg, &ip); | 1369 | return add_target_ip(arg, &ip); |
1171 | /* he = gethostbyaddr((char *)in, sizeof(struct in_addr), AF_INET); */ | ||
1172 | /* if(!he) return add_target_ip(arg, in); */ | ||
1173 | } | 1370 | } |
1174 | else { | 1371 | else { |
1175 | errno = 0; | 1372 | errno = 0; |
1176 | he = gethostbyname(arg); | 1373 | memset(&hints, 0, sizeof(hints)); |
1177 | if(!he) { | 1374 | if (address_family == -1) { |
1375 | hints.ai_family = AF_UNSPEC; | ||
1376 | } else { | ||
1377 | hints.ai_family = address_family == AF_INET ? PF_INET : PF_INET6; | ||
1378 | } | ||
1379 | hints.ai_socktype = SOCK_RAW; | ||
1380 | if((error = getaddrinfo(arg, NULL, &hints, &res)) != 0) { | ||
1178 | errno = 0; | 1381 | errno = 0; |
1179 | crash("Failed to resolve %s", arg); | 1382 | crash("Failed to resolve %s: %s", arg, gai_strerror(error)); |
1180 | return -1; | 1383 | return -1; |
1181 | } | 1384 | } |
1385 | address_family = res->ai_family; | ||
1182 | } | 1386 | } |
1183 | 1387 | ||
1184 | /* possibly add all the IP's as targets */ | 1388 | /* possibly add all the IP's as targets */ |
1185 | for(i = 0; he->h_addr_list[i]; i++) { | 1389 | for(p = res; p != NULL; p = p->ai_next) { |
1186 | in = (struct in_addr *)he->h_addr_list[i]; | 1390 | memcpy(&ip, p->ai_addr, p->ai_addrlen); |
1187 | add_target_ip(arg, in); | 1391 | add_target_ip(arg, &ip); |
1188 | 1392 | ||
1189 | /* this is silly, but it works */ | 1393 | /* this is silly, but it works */ |
1190 | if(mode == MODE_HOSTCHECK || mode == MODE_ALL) { | 1394 | if(mode == MODE_HOSTCHECK || mode == MODE_ALL) { |
@@ -1193,6 +1397,7 @@ add_target(char *arg) | |||
1193 | } | 1397 | } |
1194 | break; | 1398 | break; |
1195 | } | 1399 | } |
1400 | freeaddrinfo(res); | ||
1196 | 1401 | ||
1197 | return 0; | 1402 | return 0; |
1198 | } | 1403 | } |
@@ -1203,7 +1408,7 @@ set_source_ip(char *arg) | |||
1203 | struct sockaddr_in src; | 1408 | struct sockaddr_in src; |
1204 | 1409 | ||
1205 | memset(&src, 0, sizeof(src)); | 1410 | memset(&src, 0, sizeof(src)); |
1206 | src.sin_family = AF_INET; | 1411 | src.sin_family = address_family; |
1207 | if((src.sin_addr.s_addr = inet_addr(arg)) == INADDR_NONE) | 1412 | if((src.sin_addr.s_addr = inet_addr(arg)) == INADDR_NONE) |
1208 | src.sin_addr.s_addr = get_ip_address(arg); | 1413 | src.sin_addr.s_addr = get_ip_address(arg); |
1209 | if(bind(icmp_sock, (struct sockaddr *)&src, sizeof(src)) == -1) | 1414 | if(bind(icmp_sock, (struct sockaddr *)&src, sizeof(src)) == -1) |
@@ -1311,12 +1516,12 @@ get_threshold(char *str, threshold *th) | |||
1311 | unsigned short | 1516 | unsigned short |
1312 | icmp_checksum(unsigned short *p, int n) | 1517 | icmp_checksum(unsigned short *p, int n) |
1313 | { | 1518 | { |
1314 | register unsigned short cksum; | 1519 | unsigned short cksum; |
1315 | register long sum = 0; | 1520 | long sum = 0; |
1316 | 1521 | ||
1317 | while(n > 1) { | 1522 | while(n > 2) { |
1318 | sum += *p++; | 1523 | sum += *p++; |
1319 | n -= 2; | 1524 | n -= sizeof(unsigned short); |
1320 | } | 1525 | } |
1321 | 1526 | ||
1322 | /* mop up the occasional odd byte */ | 1527 | /* mop up the occasional odd byte */ |
@@ -1347,6 +1552,8 @@ print_help(void) | |||
1347 | 1552 | ||
1348 | printf (" %s\n", "-H"); | 1553 | printf (" %s\n", "-H"); |
1349 | printf (" %s\n", _("specify a target")); | 1554 | printf (" %s\n", _("specify a target")); |
1555 | printf (" %s\n", "[-4|-6]"); | ||
1556 | printf (" %s\n", _("Use IPv4 (default) or IPv6 to communicate with the targets")); | ||
1350 | printf (" %s\n", "-w"); | 1557 | printf (" %s\n", "-w"); |
1351 | printf (" %s", _("warning threshold (currently ")); | 1558 | printf (" %s", _("warning threshold (currently ")); |
1352 | printf ("%0.3fms,%u%%)\n", (float)warn.rta / 1000, warn.pl); | 1559 | printf ("%0.3fms,%u%%)\n", (float)warn.rta / 1000, warn.pl); |
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl index 32f498d3..aac1310e 100755 --- a/plugins-scripts/check_mailq.pl +++ b/plugins-scripts/check_mailq.pl | |||
@@ -568,7 +568,9 @@ sub process_arguments(){ | |||
568 | "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number | 568 | "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number |
569 | "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number | 569 | "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number |
570 | "t=i" => \$opt_t, "timeout=i" => \$opt_t, | 570 | "t=i" => \$opt_t, "timeout=i" => \$opt_t, |
571 | "s" => \$opt_s, "sudo" => \$opt_s | 571 | "s" => \$opt_s, "sudo" => \$opt_s, |
572 | "W=i" => \$opt_W, # warning if above this number | ||
573 | "C=i" => \$opt_C, # critical if above this number | ||
572 | ); | 574 | ); |
573 | 575 | ||
574 | if ($opt_V) { | 576 | if ($opt_V) { |
@@ -662,8 +664,8 @@ sub print_help () { | |||
662 | print " Feedback/patches to support non-sendmail mailqueue welcome\n\n"; | 664 | print " Feedback/patches to support non-sendmail mailqueue welcome\n\n"; |
663 | print "-w (--warning) = Min. number of messages in queue to generate warning\n"; | 665 | print "-w (--warning) = Min. number of messages in queue to generate warning\n"; |
664 | print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n"; | 666 | print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n"; |
665 | print "-W (--Warning) = Min. number of messages for same domain in queue to generate warning\n"; | 667 | print "-W = Min. number of messages for same domain in queue to generate warning\n"; |
666 | print "-C (--Critical) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; | 668 | print "-C = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; |
667 | print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; | 669 | print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; |
668 | print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; | 670 | print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; |
669 | print "-s (--sudo) = Use sudo to call the mailq command\n"; | 671 | print "-s (--sudo) = Use sudo to call the mailq command\n"; |
diff --git a/plugins-scripts/t/check_file_age.t b/plugins-scripts/t/check_file_age.t index ebf673f5..8b876708 100644 --- a/plugins-scripts/t/check_file_age.t +++ b/plugins-scripts/t/check_file_age.t | |||
@@ -20,105 +20,74 @@ my $temp_link = "/tmp/check_file_age.link.tmp"; | |||
20 | 20 | ||
21 | unlink $temp_file, $temp_link; | 21 | unlink $temp_file, $temp_link; |
22 | 22 | ||
23 | $result = NPTest->testCmd( | 23 | $result = NPTest->testCmd("./check_file_age"); |
24 | "./check_file_age" | ||
25 | ); | ||
26 | cmp_ok( $result->return_code, '==', 3, "Missing parameters" ); | 24 | cmp_ok( $result->return_code, '==', 3, "Missing parameters" ); |
27 | like ( $result->output, $unknownOutput, "Output for unknown correct" ); | 25 | like ( $result->output, $unknownOutput, "Output for unknown correct" ); |
28 | 26 | ||
29 | $result = NPTest->testCmd( | 27 | $result = NPTest->testCmd("./check_file_age -f $temp_file"); |
30 | "./check_file_age -f $temp_file" | ||
31 | ); | ||
32 | cmp_ok( $result->return_code, '==', 2, "File not exists" ); | 28 | cmp_ok( $result->return_code, '==', 2, "File not exists" ); |
33 | like ( $result->output, $criticalOutput, "Output for file missing correct" ); | 29 | like ( $result->output, $criticalOutput, "Output for file missing correct" ); |
34 | 30 | ||
35 | write_chars(100); | 31 | write_chars(100); |
36 | $result = NPTest->testCmd( | 32 | $result = NPTest->testCmd("./check_file_age -f $temp_file"); |
37 | "./check_file_age -f $temp_file" | ||
38 | ); | ||
39 | cmp_ok( $result->return_code, '==', 0, "File is new enough" ); | 33 | cmp_ok( $result->return_code, '==', 0, "File is new enough" ); |
40 | like ( $result->output, $successOutput, "Output for success correct" ); | 34 | like ( $result->output, $successOutput, "Output for success correct" ); |
41 | 35 | ||
42 | sleep 2; | 36 | sleep 2; |
43 | 37 | ||
44 | $result = NPTest->testCmd( | 38 | $result = NPTest->testCmd("./check_file_age -f $temp_file -w 1"); |
45 | "./check_file_age -f $temp_file -w 1" | ||
46 | ); | ||
47 | cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old" ); | 39 | cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old" ); |
48 | like ( $result->output, $warningOutput, "Output for warning correct" ); | 40 | like ( $result->output, $warningOutput, "Output for warning correct" ); |
49 | 41 | ||
50 | $result = NPTest->testCmd( | 42 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1"); |
51 | "./check_file_age -f $temp_file -w 0:1" | ||
52 | ); | ||
53 | cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old by range" ); | ||
54 | like ( $result->output, $warningOutput, "Output for warning by range correct" ); | ||
55 | |||
56 | $result = NPTest->testCmd( | ||
57 | "./check_file_age -f $temp_file -c 1" | ||
58 | ); | ||
59 | cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" ); | 43 | cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" ); |
60 | like ( $result->output, $criticalOutput, "Output for critical correct" ); | 44 | like ( $result->output, $criticalOutput, "Output for critical correct" ); |
61 | 45 | ||
62 | $result = NPTest->testCmd( | 46 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100"); |
63 | "./check_file_age -f $temp_file -c 0:1" | ||
64 | ); | ||
65 | cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old by range" ); | ||
66 | like ( $result->output, $criticalOutput, "Output for critical by range correct" ); | ||
67 | |||
68 | $result = NPTest->testCmd( | ||
69 | "./check_file_age -f $temp_file -c 1000 -W 100" | ||
70 | ); | ||
71 | cmp_ok( $result->return_code, '==', 0, "Checking file size" ); | 47 | cmp_ok( $result->return_code, '==', 0, "Checking file size" ); |
72 | 48 | ||
73 | $result = NPTest->testCmd( | 49 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100"); |
74 | "./check_file_age -f $temp_file -c 0:1000 -W 0:100" | ||
75 | ); | ||
76 | cmp_ok( $result->return_code, '==', 0, "Checking file size by range" ); | ||
77 | |||
78 | $result = NPTest->testCmd( | ||
79 | "./check_file_age -f $temp_file -c 1000 -W 100" | ||
80 | ); | ||
81 | like( $result->output, $performanceOutput, "Checking for performance Output" ); | 50 | like( $result->output, $performanceOutput, "Checking for performance Output" ); |
82 | 51 | ||
83 | $result = NPTest->testCmd( | 52 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100"); |
84 | "./check_file_age -f $temp_file -c 1000 -W 100" | ||
85 | ); | ||
86 | like( $result->output, $performanceOutput, "Checking for performance Output from range" ); | 53 | like( $result->output, $performanceOutput, "Checking for performance Output from range" ); |
87 | 54 | ||
88 | $result = NPTest->testCmd( | 55 | $result = NPTest->testCmd("./check_file_age -f /non/existent --ignore-missing"); |
89 | "./check_file_age -f /non/existent --ignore-missing" | ||
90 | ); | ||
91 | cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" ); | 56 | cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" ); |
92 | 57 | ||
93 | $result = NPTest->testCmd( | 58 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 101"); |
94 | "./check_file_age -f $temp_file -c 1000 -W 101" | ||
95 | ); | ||
96 | cmp_ok( $result->return_code, '==', 1, "One byte too short" ); | 59 | cmp_ok( $result->return_code, '==', 1, "One byte too short" ); |
97 | 60 | ||
98 | $result = NPTest->testCmd( | 61 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 101"); |
99 | "./check_file_age -f $temp_file -c 1000 -W 101:" | ||
100 | ); | ||
101 | cmp_ok( $result->return_code, '==', 1, "One byte too short by range" ); | ||
102 | |||
103 | $result = NPTest->testCmd( | ||
104 | "./check_file_age -f $temp_file -c 1000 -C 101" | ||
105 | ); | ||
106 | cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" ); | 62 | cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" ); |
107 | 63 | ||
108 | $result = NPTest->testCmd( | 64 | SKIP: { |
109 | "./check_file_age -f $temp_file -c 1000 -C 101:" | 65 | eval 'use Monitoring::Plugin::Range'; |
110 | ); | 66 | skip "Monitoring::Plugin::Range module require", 9 if $@; |
111 | cmp_ok( $result->return_code, '==', 2, "One byte too short by range - critical" ); | 67 | |
68 | $result = NPTest->testCmd("./check_file_age -f $temp_file -w 0:1"); | ||
69 | cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old by range" ); | ||
70 | like ( $result->output, $warningOutput, "Output for warning by range correct" ); | ||
71 | |||
72 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 0:1"); | ||
73 | cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old by range" ); | ||
74 | like ( $result->output, $criticalOutput, "Output for critical by range correct" ); | ||
75 | |||
76 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 0:1000 -W 0:100"); | ||
77 | cmp_ok( $result->return_code, '==', 0, "Checking file size by range" ); | ||
78 | |||
79 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 101:"); | ||
80 | cmp_ok( $result->return_code, '==', 1, "One byte too short by range" ); | ||
81 | |||
82 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 0:99"); | ||
83 | cmp_ok( $result->return_code, '==', 1, "One byte too long by range" ); | ||
112 | 84 | ||
113 | $result = NPTest->testCmd( | 85 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 101:"); |
114 | "./check_file_age -f $temp_file -c 1000 -W 0:99" | 86 | cmp_ok( $result->return_code, '==', 2, "One byte too short by range - critical" ); |
115 | ); | ||
116 | cmp_ok( $result->return_code, '==', 1, "One byte too long by range" ); | ||
117 | 87 | ||
118 | $result = NPTest->testCmd( | 88 | $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 0:99"); |
119 | "./check_file_age -f $temp_file -c 1000 -C 0:99" | 89 | cmp_ok( $result->return_code, '==', 2, "One byte too long by range - critical" ); |
120 | ); | 90 | }; |
121 | cmp_ok( $result->return_code, '==', 2, "One byte too long by range - critical" ); | ||
122 | 91 | ||
123 | symlink $temp_file, $temp_link or die "Cannot create symlink"; | 92 | symlink $temp_file, $temp_link or die "Cannot create symlink"; |
124 | $result = NPTest->testCmd("./check_file_age -f $temp_link -c 10"); | 93 | $result = NPTest->testCmd("./check_file_age -f $temp_link -c 10"); |
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 0ddf9bd1..3fde54d6 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am | |||
@@ -38,7 +38,9 @@ check_tcp_programs = check_ftp check_imap check_nntp check_pop \ | |||
38 | EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \ | 38 | EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \ |
39 | check_swap check_fping check_ldap check_game check_dig \ | 39 | check_swap check_fping check_ldap check_game check_dig \ |
40 | check_nagios check_by_ssh check_dns check_nt check_ide_smart \ | 40 | check_nagios check_by_ssh check_dns check_nt check_ide_smart \ |
41 | check_procs check_mysql_query check_apt check_dbi | 41 | check_procs check_mysql_query check_apt check_dbi check_curl |
42 | |||
43 | SUBDIRS = picohttpparser | ||
42 | 44 | ||
43 | EXTRA_DIST = t tests | 45 | EXTRA_DIST = t tests |
44 | 46 | ||
@@ -69,6 +71,9 @@ test-debug: | |||
69 | 71 | ||
70 | check_apt_LDADD = $(BASEOBJS) | 72 | check_apt_LDADD = $(BASEOBJS) |
71 | check_cluster_LDADD = $(BASEOBJS) | 73 | check_cluster_LDADD = $(BASEOBJS) |
74 | check_curl_CFLAGS = $(AM_CFLAGS) $(LIBCURLCFLAGS) $(URIPARSERCFLAGS) $(LIBCURLINCLUDE) $(URIPARSERINCLUDE) -Ipicohttpparser | ||
75 | check_curl_CPPFLAGS = $(AM_CPPFLAGS) $(LIBCURLCFLAGS) $(URIPARSERCFLAGS) $(LIBCURLINCLUDE) $(URIPARSERINCLUDE) -Ipicohttpparser | ||
76 | check_curl_LDADD = $(NETLIBS) $(LIBCURLLIBS) $(SSLOBJS) $(URIPARSERLIBS) picohttpparser/libpicohttpparser.a | ||
72 | check_dbi_LDADD = $(NETLIBS) $(DBILIBS) | 77 | check_dbi_LDADD = $(NETLIBS) $(DBILIBS) |
73 | check_dig_LDADD = $(NETLIBS) | 78 | check_dig_LDADD = $(NETLIBS) |
74 | check_disk_LDADD = $(BASEOBJS) | 79 | check_disk_LDADD = $(BASEOBJS) |
@@ -89,7 +94,7 @@ check_mysql_query_CFLAGS = $(AM_CFLAGS) $(MYSQLCFLAGS) | |||
89 | check_mysql_query_CPPFLAGS = $(AM_CPPFLAGS) $(MYSQLINCLUDE) | 94 | check_mysql_query_CPPFLAGS = $(AM_CPPFLAGS) $(MYSQLINCLUDE) |
90 | check_mysql_query_LDADD = $(NETLIBS) $(MYSQLLIBS) | 95 | check_mysql_query_LDADD = $(NETLIBS) $(MYSQLLIBS) |
91 | check_nagios_LDADD = $(BASEOBJS) | 96 | check_nagios_LDADD = $(BASEOBJS) |
92 | check_nt_LDADD = $(NETLIBS) | 97 | check_nt_LDADD = $(NETLIBS) |
93 | check_ntp_LDADD = $(NETLIBS) $(MATHLIBS) | 98 | check_ntp_LDADD = $(NETLIBS) $(MATHLIBS) |
94 | check_ntp_peer_LDADD = $(NETLIBS) $(MATHLIBS) | 99 | check_ntp_peer_LDADD = $(NETLIBS) $(MATHLIBS) |
95 | check_nwstat_LDADD = $(NETLIBS) | 100 | check_nwstat_LDADD = $(NETLIBS) |
diff --git a/plugins/check_apt.c b/plugins/check_apt.c index b69680c2..d7be5750 100644 --- a/plugins/check_apt.c +++ b/plugins/check_apt.c | |||
@@ -86,6 +86,8 @@ static char *do_include = NULL; /* regexp to only include certain packages */ | |||
86 | static char *do_exclude = NULL; /* regexp to only exclude certain packages */ | 86 | static char *do_exclude = NULL; /* regexp to only exclude certain packages */ |
87 | static char *do_critical = NULL; /* regexp specifying critical packages */ | 87 | static char *do_critical = NULL; /* regexp specifying critical packages */ |
88 | static char *input_filename = NULL; /* input filename for testing */ | 88 | static char *input_filename = NULL; /* input filename for testing */ |
89 | /* number of packages available for upgrade to return WARNING status */ | ||
90 | static int packages_warning = 1; | ||
89 | 91 | ||
90 | /* other global variables */ | 92 | /* other global variables */ |
91 | static int stderr_warning = 0; /* if a cmd issued output on stderr */ | 93 | static int stderr_warning = 0; /* if a cmd issued output on stderr */ |
@@ -117,7 +119,7 @@ int main (int argc, char **argv) { | |||
117 | 119 | ||
118 | if(sec_count > 0){ | 120 | if(sec_count > 0){ |
119 | result = max_state(result, STATE_CRITICAL); | 121 | result = max_state(result, STATE_CRITICAL); |
120 | } else if(packages_available > 0 && only_critical == 0){ | 122 | } else if(packages_available >= packages_warning && only_critical == 0){ |
121 | result = max_state(result, STATE_WARNING); | 123 | result = max_state(result, STATE_WARNING); |
122 | } else if(result > STATE_UNKNOWN){ | 124 | } else if(result > STATE_UNKNOWN){ |
123 | result = STATE_UNKNOWN; | 125 | result = STATE_UNKNOWN; |
@@ -170,11 +172,12 @@ int process_arguments (int argc, char **argv) { | |||
170 | {"critical", required_argument, 0, 'c'}, | 172 | {"critical", required_argument, 0, 'c'}, |
171 | {"only-critical", no_argument, 0, 'o'}, | 173 | {"only-critical", no_argument, 0, 'o'}, |
172 | {"input-file", required_argument, 0, INPUT_FILE_OPT}, | 174 | {"input-file", required_argument, 0, INPUT_FILE_OPT}, |
175 | {"packages-warning", required_argument, 0, 'w'}, | ||
173 | {0, 0, 0, 0} | 176 | {0, 0, 0, 0} |
174 | }; | 177 | }; |
175 | 178 | ||
176 | while(1) { | 179 | while(1) { |
177 | c = getopt_long(argc, argv, "hVvt:u::U::d::nli:e:c:o", longopts, NULL); | 180 | c = getopt_long(argc, argv, "hVvt:u::U::d::nli:e:c:ow:", longopts, NULL); |
178 | 181 | ||
179 | if(c == -1 || c == EOF || c == 1) break; | 182 | if(c == -1 || c == EOF || c == 1) break; |
180 | 183 | ||
@@ -233,6 +236,9 @@ int process_arguments (int argc, char **argv) { | |||
233 | case INPUT_FILE_OPT: | 236 | case INPUT_FILE_OPT: |
234 | input_filename = optarg; | 237 | input_filename = optarg; |
235 | break; | 238 | break; |
239 | case 'w': | ||
240 | packages_warning = atoi(optarg); | ||
241 | break; | ||
236 | default: | 242 | default: |
237 | /* print short usage statement if args not parsable */ | 243 | /* print short usage statement if args not parsable */ |
238 | usage5(); | 244 | usage5(); |
@@ -530,7 +536,10 @@ print_help (void) | |||
530 | printf (" %s\n", "-o, --only-critical"); | 536 | printf (" %s\n", "-o, --only-critical"); |
531 | printf (" %s\n", _("Only warn about upgrades matching the critical list. The total number")); | 537 | printf (" %s\n", _("Only warn about upgrades matching the critical list. The total number")); |
532 | printf (" %s\n", _("of upgrades will be printed, but any non-critical upgrades will not cause")); | 538 | printf (" %s\n", _("of upgrades will be printed, but any non-critical upgrades will not cause")); |
533 | printf (" %s\n\n", _("the plugin to return WARNING status.")); | 539 | printf (" %s\n", _("the plugin to return WARNING status.")); |
540 | printf (" %s\n", "-w, --packages-warning"); | ||
541 | printf (" %s\n", _("Minumum number of packages available for upgrade to return WARNING status.")); | ||
542 | printf (" %s\n\n", _("Default is 1 package.")); | ||
534 | 543 | ||
535 | printf ("%s\n\n", _("The following options require root privileges and should be used with care:")); | 544 | printf ("%s\n\n", _("The following options require root privileges and should be used with care:")); |
536 | printf (" %s\n", "-u, --update=OPTS"); | 545 | printf (" %s\n", "-u, --update=OPTS"); |
@@ -548,5 +557,5 @@ void | |||
548 | print_usage(void) | 557 | print_usage(void) |
549 | { | 558 | { |
550 | printf ("%s\n", _("Usage:")); | 559 | printf ("%s\n", _("Usage:")); |
551 | printf ("%s [[-d|-u|-U]opts] [-n] [-l] [-t timeout]\n", progname); | 560 | printf ("%s [[-d|-u|-U]opts] [-n] [-l] [-t timeout] [-w packages-warning]\n", progname); |
552 | } | 561 | } |
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){ | |||
143 | 143 | ||
144 | int process_arguments(int argc, char **argv){ | 144 | int process_arguments(int argc, char **argv){ |
145 | int c; | 145 | int c; |
146 | char *ptr; | ||
146 | int option=0; | 147 | int option=0; |
147 | static struct option longopts[]={ | 148 | static struct option longopts[]={ |
148 | {"data", required_argument,0,'d'}, | 149 | {"data", required_argument,0,'d'}, |
@@ -188,6 +189,15 @@ int process_arguments(int argc, char **argv){ | |||
188 | 189 | ||
189 | case 'd': /* data values */ | 190 | case 'd': /* data values */ |
190 | data_vals=(char *)strdup(optarg); | 191 | data_vals=(char *)strdup(optarg); |
192 | /* validate data */ | ||
193 | for (ptr=data_vals;ptr!=NULL;ptr+=2){ | ||
194 | if (ptr[0]<'0' || ptr[0]>'3') | ||
195 | return ERROR; | ||
196 | if (ptr[1]=='\0') | ||
197 | break; | ||
198 | if (ptr[1]!=',') | ||
199 | return ERROR; | ||
200 | } | ||
191 | break; | 201 | break; |
192 | 202 | ||
193 | case 'l': /* text label */ | 203 | case 'l': /* text label */ |
diff --git a/plugins/check_curl.c b/plugins/check_curl.c new file mode 100644 index 00000000..ee9c8b1d --- /dev/null +++ b/plugins/check_curl.c | |||
@@ -0,0 +1,2358 @@ | |||
1 | /***************************************************************************** | ||
2 | * | ||
3 | * Monitoring check_curl plugin | ||
4 | * | ||
5 | * License: GPL | ||
6 | * Copyright (c) 1999-2019 Monitoring Plugins Development Team | ||
7 | * | ||
8 | * Description: | ||
9 | * | ||
10 | * This file contains the check_curl plugin | ||
11 | * | ||
12 | * This plugin tests the HTTP service on the specified host. It can test | ||
13 | * normal (http) and secure (https) servers, follow redirects, search for | ||
14 | * strings and regular expressions, check connection times, and report on | ||
15 | * certificate expiration times. | ||
16 | * | ||
17 | * This plugin uses functions from the curl library, see | ||
18 | * http://curl.haxx.se | ||
19 | * | ||
20 | * This program is free software: you can redistribute it and/or modify | ||
21 | * it under the terms of the GNU General Public License as published by | ||
22 | * the Free Software Foundation, either version 3 of the License, or | ||
23 | * (at your option) any later version. | ||
24 | * | ||
25 | * This program is distributed in the hope that it will be useful, | ||
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
28 | * GNU General Public License for more details. | ||
29 | * | ||
30 | * You should have received a copy of the GNU General Public License | ||
31 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
32 | * | ||
33 | * | ||
34 | *****************************************************************************/ | ||
35 | const char *progname = "check_curl"; | ||
36 | |||
37 | const char *copyright = "2006-2019"; | ||
38 | const char *email = "devel@monitoring-plugins.org"; | ||
39 | |||
40 | #include <ctype.h> | ||
41 | |||
42 | #include "common.h" | ||
43 | #include "utils.h" | ||
44 | |||
45 | #ifndef LIBCURL_PROTOCOL_HTTP | ||
46 | #error libcurl compiled without HTTP support, compiling check_curl plugin does not makes a lot of sense | ||
47 | #endif | ||
48 | |||
49 | #include "curl/curl.h" | ||
50 | #include "curl/easy.h" | ||
51 | |||
52 | #include "picohttpparser.h" | ||
53 | |||
54 | #include "uriparser/Uri.h" | ||
55 | |||
56 | #include <arpa/inet.h> | ||
57 | |||
58 | #define MAKE_LIBCURL_VERSION(major, minor, patch) ((major)*0x10000 + (minor)*0x100 + (patch)) | ||
59 | |||
60 | #define DEFAULT_BUFFER_SIZE 2048 | ||
61 | #define DEFAULT_SERVER_URL "/" | ||
62 | #define HTTP_EXPECT "HTTP/" | ||
63 | #define DEFAULT_MAX_REDIRS 15 | ||
64 | #define INET_ADDR_MAX_SIZE INET6_ADDRSTRLEN | ||
65 | enum { | ||
66 | MAX_IPV4_HOSTLENGTH = 255, | ||
67 | HTTP_PORT = 80, | ||
68 | HTTPS_PORT = 443, | ||
69 | MAX_PORT = 65535 | ||
70 | }; | ||
71 | |||
72 | enum { | ||
73 | STICKY_NONE = 0, | ||
74 | STICKY_HOST = 1, | ||
75 | STICKY_PORT = 2 | ||
76 | }; | ||
77 | |||
78 | enum { | ||
79 | FOLLOW_HTTP_CURL = 0, | ||
80 | FOLLOW_LIBCURL = 1 | ||
81 | }; | ||
82 | |||
83 | /* for buffers for header and body */ | ||
84 | typedef struct { | ||
85 | char *buf; | ||
86 | size_t buflen; | ||
87 | size_t bufsize; | ||
88 | } curlhelp_write_curlbuf; | ||
89 | |||
90 | /* for buffering the data sent in PUT */ | ||
91 | typedef struct { | ||
92 | char *buf; | ||
93 | size_t buflen; | ||
94 | off_t pos; | ||
95 | } curlhelp_read_curlbuf; | ||
96 | |||
97 | /* for parsing the HTTP status line */ | ||
98 | typedef struct { | ||
99 | int http_major; /* major version of the protocol, always 1 (HTTP/0.9 | ||
100 | * never reached the big internet most likely) */ | ||
101 | int http_minor; /* minor version of the protocol, usually 0 or 1 */ | ||
102 | int http_code; /* HTTP return code as in RFC 2145 */ | ||
103 | int http_subcode; /* Microsoft IIS extension, HTTP subcodes, see | ||
104 | * http://support.microsoft.com/kb/318380/en-us */ | ||
105 | const char *msg; /* the human readable message */ | ||
106 | char *first_line; /* a copy of the first line */ | ||
107 | } curlhelp_statusline; | ||
108 | |||
109 | /* to know the underlying SSL library used by libcurl */ | ||
110 | typedef enum curlhelp_ssl_library { | ||
111 | CURLHELP_SSL_LIBRARY_UNKNOWN, | ||
112 | CURLHELP_SSL_LIBRARY_OPENSSL, | ||
113 | CURLHELP_SSL_LIBRARY_LIBRESSL, | ||
114 | CURLHELP_SSL_LIBRARY_GNUTLS, | ||
115 | CURLHELP_SSL_LIBRARY_NSS | ||
116 | } curlhelp_ssl_library; | ||
117 | |||
118 | enum { | ||
119 | REGS = 2, | ||
120 | MAX_RE_SIZE = 256 | ||
121 | }; | ||
122 | #include "regex.h" | ||
123 | regex_t preg; | ||
124 | regmatch_t pmatch[REGS]; | ||
125 | char regexp[MAX_RE_SIZE]; | ||
126 | int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; | ||
127 | int errcode; | ||
128 | int invert_regex = 0; | ||
129 | |||
130 | char *server_address = NULL; | ||
131 | char *host_name = NULL; | ||
132 | char *server_url = 0; | ||
133 | char server_ip[DEFAULT_BUFFER_SIZE]; | ||
134 | struct curl_slist *server_ips = NULL; | ||
135 | int specify_port = FALSE; | ||
136 | unsigned short server_port = HTTP_PORT; | ||
137 | unsigned short virtual_port = 0; | ||
138 | int host_name_length; | ||
139 | char output_header_search[30] = ""; | ||
140 | char output_string_search[30] = ""; | ||
141 | char *warning_thresholds = NULL; | ||
142 | char *critical_thresholds = NULL; | ||
143 | int days_till_exp_warn, days_till_exp_crit; | ||
144 | thresholds *thlds; | ||
145 | char user_agent[DEFAULT_BUFFER_SIZE]; | ||
146 | int verbose = 0; | ||
147 | int show_extended_perfdata = FALSE; | ||
148 | int min_page_len = 0; | ||
149 | int max_page_len = 0; | ||
150 | int redir_depth = 0; | ||
151 | int max_depth = DEFAULT_MAX_REDIRS; | ||
152 | char *http_method = NULL; | ||
153 | char *http_post_data = NULL; | ||
154 | char *http_content_type = NULL; | ||
155 | CURL *curl; | ||
156 | struct curl_slist *header_list = NULL; | ||
157 | curlhelp_write_curlbuf body_buf; | ||
158 | curlhelp_write_curlbuf header_buf; | ||
159 | curlhelp_statusline status_line; | ||
160 | curlhelp_read_curlbuf put_buf; | ||
161 | char http_header[DEFAULT_BUFFER_SIZE]; | ||
162 | long code; | ||
163 | long socket_timeout = DEFAULT_SOCKET_TIMEOUT; | ||
164 | double total_time; | ||
165 | double time_connect; | ||
166 | double time_appconnect; | ||
167 | double time_headers; | ||
168 | double time_firstbyte; | ||
169 | char errbuf[CURL_ERROR_SIZE+1]; | ||
170 | CURLcode res; | ||
171 | char url[DEFAULT_BUFFER_SIZE]; | ||
172 | char msg[DEFAULT_BUFFER_SIZE]; | ||
173 | char perfstring[DEFAULT_BUFFER_SIZE]; | ||
174 | char header_expect[MAX_INPUT_BUFFER] = ""; | ||
175 | char string_expect[MAX_INPUT_BUFFER] = ""; | ||
176 | char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT; | ||
177 | int server_expect_yn = 0; | ||
178 | char user_auth[MAX_INPUT_BUFFER] = ""; | ||
179 | char proxy_auth[MAX_INPUT_BUFFER] = ""; | ||
180 | char **http_opt_headers; | ||
181 | int http_opt_headers_count = 0; | ||
182 | int display_html = FALSE; | ||
183 | int onredirect = STATE_OK; | ||
184 | int followmethod = FOLLOW_HTTP_CURL; | ||
185 | int followsticky = STICKY_NONE; | ||
186 | int use_ssl = FALSE; | ||
187 | int use_sni = TRUE; | ||
188 | int check_cert = FALSE; | ||
189 | typedef union { | ||
190 | struct curl_slist* to_info; | ||
191 | struct curl_certinfo* to_certinfo; | ||
192 | } cert_ptr_union; | ||
193 | cert_ptr_union cert_ptr; | ||
194 | int ssl_version = CURL_SSLVERSION_DEFAULT; | ||
195 | char *client_cert = NULL; | ||
196 | char *client_privkey = NULL; | ||
197 | char *ca_cert = NULL; | ||
198 | int is_openssl_callback = FALSE; | ||
199 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) | ||
200 | X509 *cert = NULL; | ||
201 | #endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ | ||
202 | int no_body = FALSE; | ||
203 | int maximum_age = -1; | ||
204 | int address_family = AF_UNSPEC; | ||
205 | curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; | ||
206 | int curl_http_version = CURL_HTTP_VERSION_NONE; | ||
207 | |||
208 | int process_arguments (int, char**); | ||
209 | void handle_curl_option_return_code (CURLcode res, const char* option); | ||
210 | int check_http (void); | ||
211 | void redir (curlhelp_write_curlbuf*); | ||
212 | char *perfd_time (double microsec); | ||
213 | char *perfd_time_connect (double microsec); | ||
214 | char *perfd_time_ssl (double microsec); | ||
215 | char *perfd_time_firstbyte (double microsec); | ||
216 | char *perfd_time_headers (double microsec); | ||
217 | char *perfd_time_transfer (double microsec); | ||
218 | char *perfd_size (int page_len); | ||
219 | void print_help (void); | ||
220 | void print_usage (void); | ||
221 | void print_curl_version (void); | ||
222 | int curlhelp_initwritebuffer (curlhelp_write_curlbuf*); | ||
223 | int curlhelp_buffer_write_callback (void*, size_t , size_t , void*); | ||
224 | void curlhelp_freewritebuffer (curlhelp_write_curlbuf*); | ||
225 | int curlhelp_initreadbuffer (curlhelp_read_curlbuf *, const char *, size_t); | ||
226 | int curlhelp_buffer_read_callback (void *, size_t , size_t , void *); | ||
227 | void curlhelp_freereadbuffer (curlhelp_read_curlbuf *); | ||
228 | curlhelp_ssl_library curlhelp_get_ssl_library (CURL*); | ||
229 | const char* curlhelp_get_ssl_library_string (curlhelp_ssl_library); | ||
230 | int net_noopenssl_check_certificate (cert_ptr_union*, int, int); | ||
231 | |||
232 | int curlhelp_parse_statusline (const char*, curlhelp_statusline *); | ||
233 | void curlhelp_free_statusline (curlhelp_statusline *); | ||
234 | char *get_header_value (const struct phr_header* headers, const size_t nof_headers, const char* header); | ||
235 | int check_document_dates (const curlhelp_write_curlbuf *, char (*msg)[DEFAULT_BUFFER_SIZE]); | ||
236 | int get_content_length (const curlhelp_write_curlbuf* header_buf, const curlhelp_write_curlbuf* body_buf); | ||
237 | |||
238 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) | ||
239 | int np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_warn, int days_till_exp_crit); | ||
240 | #endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ | ||
241 | |||
242 | void remove_newlines (char *); | ||
243 | void test_file (char *); | ||
244 | |||
245 | int | ||
246 | main (int argc, char **argv) | ||
247 | { | ||
248 | int result = STATE_UNKNOWN; | ||
249 | |||
250 | setlocale (LC_ALL, ""); | ||
251 | bindtextdomain (PACKAGE, LOCALEDIR); | ||
252 | textdomain (PACKAGE); | ||
253 | |||
254 | /* Parse extra opts if any */ | ||
255 | argv = np_extra_opts (&argc, argv, progname); | ||
256 | |||
257 | /* set defaults */ | ||
258 | snprintf( user_agent, DEFAULT_BUFFER_SIZE, "%s/v%s (monitoring-plugins %s, %s)", | ||
259 | progname, NP_VERSION, VERSION, curl_version()); | ||
260 | |||
261 | /* parse arguments */ | ||
262 | if (process_arguments (argc, argv) == ERROR) | ||
263 | usage4 (_("Could not parse arguments")); | ||
264 | |||
265 | if (display_html == TRUE) | ||
266 | printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">", | ||
267 | use_ssl ? "https" : "http", | ||
268 | host_name ? host_name : server_address, | ||
269 | virtual_port ? virtual_port : server_port, | ||
270 | server_url); | ||
271 | |||
272 | result = check_http (); | ||
273 | return result; | ||
274 | } | ||
275 | |||
276 | #ifdef HAVE_SSL | ||
277 | #ifdef USE_OPENSSL | ||
278 | |||
279 | int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) | ||
280 | { | ||
281 | /* TODO: we get all certificates of the chain, so which ones | ||
282 | * should we test? | ||
283 | * TODO: is the last certificate always the server certificate? | ||
284 | */ | ||
285 | cert = X509_STORE_CTX_get_current_cert(x509_ctx); | ||
286 | return 1; | ||
287 | } | ||
288 | |||
289 | CURLcode sslctxfun(CURL *curl, SSL_CTX *sslctx, void *parm) | ||
290 | { | ||
291 | SSL_CTX_set_verify(sslctx, SSL_VERIFY_PEER, verify_callback); | ||
292 | |||
293 | return CURLE_OK; | ||
294 | } | ||
295 | |||
296 | #endif /* USE_OPENSSL */ | ||
297 | #endif /* HAVE_SSL */ | ||
298 | |||
299 | /* returns a string "HTTP/1.x" or "HTTP/2" */ | ||
300 | static char *string_statuscode (int major, int minor) | ||
301 | { | ||
302 | static char buf[10]; | ||
303 | |||
304 | switch (major) { | ||
305 | case 1: | ||
306 | snprintf (buf, sizeof (buf), "HTTP/%d.%d", major, minor); | ||
307 | break; | ||
308 | case 2: | ||
309 | case 3: | ||
310 | snprintf (buf, sizeof (buf), "HTTP/%d", major); | ||
311 | break; | ||
312 | default: | ||
313 | /* assuming here HTTP/N with N>=4 */ | ||
314 | snprintf (buf, sizeof (buf), "HTTP/%d", major); | ||
315 | break; | ||
316 | } | ||
317 | |||
318 | return buf; | ||
319 | } | ||
320 | |||
321 | /* Checks if the server 'reply' is one of the expected 'statuscodes' */ | ||
322 | static int | ||
323 | expected_statuscode (const char *reply, const char *statuscodes) | ||
324 | { | ||
325 | char *expected, *code; | ||
326 | int result = 0; | ||
327 | |||
328 | if ((expected = strdup (statuscodes)) == NULL) | ||
329 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - Memory allocation error\n")); | ||
330 | |||
331 | for (code = strtok (expected, ","); code != NULL; code = strtok (NULL, ",")) | ||
332 | if (strstr (reply, code) != NULL) { | ||
333 | result = 1; | ||
334 | break; | ||
335 | } | ||
336 | |||
337 | free (expected); | ||
338 | return result; | ||
339 | } | ||
340 | |||
341 | void | ||
342 | handle_curl_option_return_code (CURLcode res, const char* option) | ||
343 | { | ||
344 | if (res != CURLE_OK) { | ||
345 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Error while setting cURL option '%s': cURL returned %d - %s"), | ||
346 | option, res, curl_easy_strerror(res)); | ||
347 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | ||
348 | } | ||
349 | } | ||
350 | |||
351 | int | ||
352 | check_http (void) | ||
353 | { | ||
354 | int result = STATE_OK; | ||
355 | int page_len = 0; | ||
356 | int i; | ||
357 | char *force_host_header = NULL; | ||
358 | |||
359 | /* initialize curl */ | ||
360 | if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) | ||
361 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_global_init failed\n"); | ||
362 | |||
363 | if ((curl = curl_easy_init()) == NULL) | ||
364 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_easy_init failed\n"); | ||
365 | |||
366 | if (verbose >= 1) | ||
367 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_VERBOSE, TRUE), "CURLOPT_VERBOSE"); | ||
368 | |||
369 | /* print everything on stdout like check_http would do */ | ||
370 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_STDERR, stdout), "CURLOPT_STDERR"); | ||
371 | |||
372 | /* initialize buffer for body of the answer */ | ||
373 | if (curlhelp_initwritebuffer(&body_buf) < 0) | ||
374 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for body\n"); | ||
375 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_WRITEFUNCTION"); | ||
376 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *)&body_buf), "CURLOPT_WRITEDATA"); | ||
377 | |||
378 | /* initialize buffer for header of the answer */ | ||
379 | if (curlhelp_initwritebuffer( &header_buf ) < 0) | ||
380 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for header\n" ); | ||
381 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_HEADERFUNCTION"); | ||
382 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEHEADER, (void *)&header_buf), "CURLOPT_WRITEHEADER"); | ||
383 | |||
384 | /* set the error buffer */ | ||
385 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, errbuf), "CURLOPT_ERRORBUFFER"); | ||
386 | |||
387 | /* set timeouts */ | ||
388 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, socket_timeout), "CURLOPT_CONNECTTIMEOUT"); | ||
389 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_TIMEOUT, socket_timeout), "CURLOPT_TIMEOUT"); | ||
390 | |||
391 | // fill dns resolve cache to make curl connect to the given server_address instead of the host_name, only required for ssl, because we use the host_name later on to make SNI happy | ||
392 | if(use_ssl && host_name != NULL) { | ||
393 | struct curl_slist *host = NULL; | ||
394 | char dnscache[DEFAULT_BUFFER_SIZE]; | ||
395 | snprintf (dnscache, DEFAULT_BUFFER_SIZE, "%s:%d:%s", host_name, server_port, server_address); | ||
396 | host = curl_slist_append(NULL, dnscache); | ||
397 | curl_easy_setopt(curl, CURLOPT_RESOLVE, host); | ||
398 | if (verbose>=1) | ||
399 | printf ("* curl CURLOPT_RESOLVE: %s\n", dnscache); | ||
400 | } | ||
401 | |||
402 | /* compose URL: use the address we want to connect to, set Host: header later */ | ||
403 | snprintf (url, DEFAULT_BUFFER_SIZE, "%s://%s:%d%s", | ||
404 | use_ssl ? "https" : "http", | ||
405 | use_ssl & host_name != NULL ? host_name : server_address, | ||
406 | server_port, | ||
407 | server_url | ||
408 | ); | ||
409 | |||
410 | if (verbose>=1) | ||
411 | printf ("* curl CURLOPT_URL: %s\n", url); | ||
412 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_URL, url), "CURLOPT_URL"); | ||
413 | |||
414 | /* extract proxy information for legacy proxy https requests */ | ||
415 | if (!strcmp(http_method, "CONNECT") || strstr(server_url, "http") == server_url) { | ||
416 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_PROXY, server_address), "CURLOPT_PROXY"); | ||
417 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_PROXYPORT, (long)server_port), "CURLOPT_PROXYPORT"); | ||
418 | if (verbose>=2) | ||
419 | printf ("* curl CURLOPT_PROXY: %s:%d\n", server_address, server_port); | ||
420 | http_method = "GET"; | ||
421 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_URL, server_url), "CURLOPT_URL"); | ||
422 | } | ||
423 | |||
424 | /* disable body for HEAD request */ | ||
425 | if (http_method && !strcmp (http_method, "HEAD" )) { | ||
426 | no_body = TRUE; | ||
427 | } | ||
428 | |||
429 | /* set HTTP protocol version */ | ||
430 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_HTTP_VERSION, curl_http_version), "CURLOPT_HTTP_VERSION"); | ||
431 | |||
432 | /* set HTTP method */ | ||
433 | if (http_method) { | ||
434 | if (!strcmp(http_method, "POST")) | ||
435 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_POST, 1), "CURLOPT_POST"); | ||
436 | else if (!strcmp(http_method, "PUT")) | ||
437 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_UPLOAD, 1), "CURLOPT_UPLOAD"); | ||
438 | else | ||
439 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CUSTOMREQUEST, http_method), "CURLOPT_CUSTOMREQUEST"); | ||
440 | } | ||
441 | |||
442 | /* check if Host header is explicitly set in options */ | ||
443 | if (http_opt_headers_count) { | ||
444 | for (i = 0; i < http_opt_headers_count ; i++) { | ||
445 | if (strncmp(http_opt_headers[i], "Host:", 5) == 0) { | ||
446 | force_host_header = http_opt_headers[i]; | ||
447 | } | ||
448 | } | ||
449 | } | ||
450 | |||
451 | /* set hostname (virtual hosts), not needed if CURLOPT_CONNECT_TO is used, but left in anyway */ | ||
452 | if(host_name != NULL && force_host_header == NULL) { | ||
453 | if((virtual_port != HTTP_PORT && !use_ssl) || (virtual_port != HTTPS_PORT && use_ssl)) { | ||
454 | snprintf(http_header, DEFAULT_BUFFER_SIZE, "Host: %s:%d", host_name, virtual_port); | ||
455 | } else { | ||
456 | snprintf(http_header, DEFAULT_BUFFER_SIZE, "Host: %s", host_name); | ||
457 | } | ||
458 | header_list = curl_slist_append (header_list, http_header); | ||
459 | } | ||
460 | |||
461 | /* always close connection, be nice to servers */ | ||
462 | snprintf (http_header, DEFAULT_BUFFER_SIZE, "Connection: close"); | ||
463 | header_list = curl_slist_append (header_list, http_header); | ||
464 | |||
465 | /* attach additional headers supplied by the user */ | ||
466 | /* optionally send any other header tag */ | ||
467 | if (http_opt_headers_count) { | ||
468 | for (i = 0; i < http_opt_headers_count ; i++) { | ||
469 | header_list = curl_slist_append (header_list, http_opt_headers[i]); | ||
470 | } | ||
471 | /* This cannot be free'd here because a redirection will then try to access this and segfault */ | ||
472 | /* Covered in a testcase in tests/check_http.t */ | ||
473 | /* free(http_opt_headers); */ | ||
474 | } | ||
475 | |||
476 | /* set HTTP headers */ | ||
477 | handle_curl_option_return_code (curl_easy_setopt( curl, CURLOPT_HTTPHEADER, header_list ), "CURLOPT_HTTPHEADER"); | ||
478 | |||
479 | #ifdef LIBCURL_FEATURE_SSL | ||
480 | |||
481 | /* set SSL version, warn about unsecure or unsupported versions */ | ||
482 | if (use_ssl) { | ||
483 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_SSLVERSION, ssl_version), "CURLOPT_SSLVERSION"); | ||
484 | } | ||
485 | |||
486 | /* client certificate and key to present to server (SSL) */ | ||
487 | if (client_cert) | ||
488 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_SSLCERT, client_cert), "CURLOPT_SSLCERT"); | ||
489 | if (client_privkey) | ||
490 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_SSLKEY, client_privkey), "CURLOPT_SSLKEY"); | ||
491 | if (ca_cert) { | ||
492 | /* per default if we have a CA verify both the peer and the | ||
493 | * hostname in the certificate, can be switched off later */ | ||
494 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CAINFO, ca_cert), "CURLOPT_CAINFO"); | ||
495 | handle_curl_option_return_code (curl_easy_setopt( curl, CURLOPT_SSL_VERIFYPEER, 1), "CURLOPT_SSL_VERIFYPEER"); | ||
496 | handle_curl_option_return_code (curl_easy_setopt( curl, CURLOPT_SSL_VERIFYHOST, 2), "CURLOPT_SSL_VERIFYHOST"); | ||
497 | } else { | ||
498 | /* backward-compatible behaviour, be tolerant in checks | ||
499 | * TODO: depending on more options have aspects we want | ||
500 | * to be less tolerant about ssl verfications | ||
501 | */ | ||
502 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0), "CURLOPT_SSL_VERIFYPEER"); | ||
503 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0), "CURLOPT_SSL_VERIFYHOST"); | ||
504 | } | ||
505 | |||
506 | /* detect SSL library used by libcurl */ | ||
507 | ssl_library = curlhelp_get_ssl_library (curl); | ||
508 | |||
509 | /* try hard to get a stack of certificates to verify against */ | ||
510 | if (check_cert) { | ||
511 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 1) | ||
512 | /* inform curl to report back certificates */ | ||
513 | switch (ssl_library) { | ||
514 | case CURLHELP_SSL_LIBRARY_OPENSSL: | ||
515 | case CURLHELP_SSL_LIBRARY_LIBRESSL: | ||
516 | /* set callback to extract certificate with OpenSSL context function (works with | ||
517 | * OpenSSL-style libraries only!) */ | ||
518 | #ifdef USE_OPENSSL | ||
519 | /* libcurl and monitoring plugins built with OpenSSL, good */ | ||
520 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun), "CURLOPT_SSL_CTX_FUNCTION"); | ||
521 | is_openssl_callback = TRUE; | ||
522 | #else /* USE_OPENSSL */ | ||
523 | #endif /* USE_OPENSSL */ | ||
524 | /* libcurl is built with OpenSSL, monitoring plugins, so falling | ||
525 | * back to manually extracting certificate information */ | ||
526 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CERTINFO, 1L), "CURLOPT_CERTINFO"); | ||
527 | break; | ||
528 | |||
529 | case CURLHELP_SSL_LIBRARY_NSS: | ||
530 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) | ||
531 | /* NSS: support for CERTINFO is implemented since 7.34.0 */ | ||
532 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CERTINFO, 1L), "CURLOPT_CERTINFO"); | ||
533 | #else /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) */ | ||
534 | die (STATE_CRITICAL, "HTTP CRITICAL - Cannot retrieve certificates (libcurl linked with SSL library '%s' is too old)\n", curlhelp_get_ssl_library_string (ssl_library)); | ||
535 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) */ | ||
536 | break; | ||
537 | |||
538 | case CURLHELP_SSL_LIBRARY_GNUTLS: | ||
539 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 42, 0) | ||
540 | /* GnuTLS: support for CERTINFO is implemented since 7.42.0 */ | ||
541 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CERTINFO, 1L), "CURLOPT_CERTINFO"); | ||
542 | #else /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 42, 0) */ | ||
543 | die (STATE_CRITICAL, "HTTP CRITICAL - Cannot retrieve certificates (libcurl linked with SSL library '%s' is too old)\n", curlhelp_get_ssl_library_string (ssl_library)); | ||
544 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 42, 0) */ | ||
545 | break; | ||
546 | |||
547 | case CURLHELP_SSL_LIBRARY_UNKNOWN: | ||
548 | default: | ||
549 | die (STATE_CRITICAL, "HTTP CRITICAL - Cannot retrieve certificates (unknown SSL library '%s', must implement first)\n", curlhelp_get_ssl_library_string (ssl_library)); | ||
550 | break; | ||
551 | } | ||
552 | #else /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 1) */ | ||
553 | /* old libcurl, our only hope is OpenSSL, otherwise we are out of luck */ | ||
554 | if (ssl_library == CURLHELP_SSL_LIBRARY_OPENSSL || ssl_library == CURLHELP_SSL_LIBRARY_LIBRESSL) | ||
555 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun), "CURLOPT_SSL_CTX_FUNCTION"); | ||
556 | else | ||
557 | die (STATE_CRITICAL, "HTTP CRITICAL - Cannot retrieve certificates (no CURLOPT_SSL_CTX_FUNCTION, no OpenSSL library or libcurl too old and has no CURLOPT_CERTINFO)\n"); | ||
558 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 1) */ | ||
559 | } | ||
560 | |||
561 | #endif /* LIBCURL_FEATURE_SSL */ | ||
562 | |||
563 | /* set default or user-given user agent identification */ | ||
564 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_USERAGENT, user_agent), "CURLOPT_USERAGENT"); | ||
565 | |||
566 | /* proxy-authentication */ | ||
567 | if (strcmp(proxy_auth, "")) | ||
568 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_PROXYUSERPWD, proxy_auth), "CURLOPT_PROXYUSERPWD"); | ||
569 | |||
570 | /* authentication */ | ||
571 | if (strcmp(user_auth, "")) | ||
572 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_USERPWD, user_auth), "CURLOPT_USERPWD"); | ||
573 | |||
574 | /* TODO: parameter auth method, bitfield of following methods: | ||
575 | * CURLAUTH_BASIC (default) | ||
576 | * CURLAUTH_DIGEST | ||
577 | * CURLAUTH_DIGEST_IE | ||
578 | * CURLAUTH_NEGOTIATE | ||
579 | * CURLAUTH_NTLM | ||
580 | * CURLAUTH_NTLM_WB | ||
581 | * | ||
582 | * convenience tokens for typical sets of methods: | ||
583 | * CURLAUTH_ANYSAFE: most secure, without BASIC | ||
584 | * or CURLAUTH_ANY: most secure, even BASIC if necessary | ||
585 | * | ||
586 | * handle_curl_option_return_code (curl_easy_setopt( curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST ), "CURLOPT_HTTPAUTH"); | ||
587 | */ | ||
588 | |||
589 | /* handle redirections */ | ||
590 | if (onredirect == STATE_DEPENDENT) { | ||
591 | if( followmethod == FOLLOW_LIBCURL ) { | ||
592 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1), "CURLOPT_FOLLOWLOCATION"); | ||
593 | |||
594 | /* default -1 is infinite, not good, could lead to zombie plugins! | ||
595 | Setting it to one bigger than maximal limit to handle errors nicely below | ||
596 | */ | ||
597 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_MAXREDIRS, max_depth+1), "CURLOPT_MAXREDIRS"); | ||
598 | |||
599 | /* for now allow only http and https (we are a http(s) check plugin in the end) */ | ||
600 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4) | ||
601 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS), "CURLOPT_REDIRECT_PROTOCOLS"); | ||
602 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4) */ | ||
603 | |||
604 | /* TODO: handle the following aspects of redirection, make them | ||
605 | * command line options too later: | ||
606 | CURLOPT_POSTREDIR: method switch | ||
607 | CURLINFO_REDIRECT_URL: custom redirect option | ||
608 | CURLOPT_REDIRECT_PROTOCOLS: allow people to step outside safe protocols | ||
609 | CURLINFO_REDIRECT_COUNT: get the number of redirects, print it, maybe a range option here is nice like for expected page size? | ||
610 | */ | ||
611 | } else { | ||
612 | /* old style redirection is handled below */ | ||
613 | } | ||
614 | } | ||
615 | |||
616 | /* no-body */ | ||
617 | if (no_body) | ||
618 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_NOBODY, 1), "CURLOPT_NOBODY"); | ||
619 | |||
620 | /* IPv4 or IPv6 forced DNS resolution */ | ||
621 | if (address_family == AF_UNSPEC) | ||
622 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_WHATEVER), "CURLOPT_IPRESOLVE(CURL_IPRESOLVE_WHATEVER)"); | ||
623 | else if (address_family == AF_INET) | ||
624 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4), "CURLOPT_IPRESOLVE(CURL_IPRESOLVE_V4)"); | ||
625 | #if defined (USE_IPV6) && defined (LIBCURL_FEATURE_IPV6) | ||
626 | else if (address_family == AF_INET6) | ||
627 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6), "CURLOPT_IPRESOLVE(CURL_IPRESOLVE_V6)"); | ||
628 | #endif | ||
629 | |||
630 | /* either send http POST data (any data, not only POST)*/ | ||
631 | if (!strcmp(http_method, "POST") ||!strcmp(http_method, "PUT")) { | ||
632 | /* set content of payload for POST and PUT */ | ||
633 | if (http_content_type) { | ||
634 | snprintf (http_header, DEFAULT_BUFFER_SIZE, "Content-Type: %s", http_content_type); | ||
635 | header_list = curl_slist_append (header_list, http_header); | ||
636 | } | ||
637 | /* NULL indicates "HTTP Continue" in libcurl, provide an empty string | ||
638 | * in case of no POST/PUT data */ | ||
639 | if (!http_post_data) | ||
640 | http_post_data = ""; | ||
641 | if (!strcmp(http_method, "POST")) { | ||
642 | /* POST method, set payload with CURLOPT_POSTFIELDS */ | ||
643 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_POSTFIELDS, http_post_data), "CURLOPT_POSTFIELDS"); | ||
644 | } else if (!strcmp(http_method, "PUT")) { | ||
645 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READFUNCTION, (curl_read_callback)curlhelp_buffer_read_callback), "CURLOPT_READFUNCTION"); | ||
646 | curlhelp_initreadbuffer (&put_buf, http_post_data, strlen (http_post_data)); | ||
647 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READDATA, (void *)&put_buf), "CURLOPT_READDATA"); | ||
648 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_INFILESIZE, (curl_off_t)strlen (http_post_data)), "CURLOPT_INFILESIZE"); | ||
649 | } | ||
650 | } | ||
651 | |||
652 | /* do the request */ | ||
653 | res = curl_easy_perform(curl); | ||
654 | |||
655 | if (verbose>=2 && http_post_data) | ||
656 | printf ("**** REQUEST CONTENT ****\n%s\n", http_post_data); | ||
657 | |||
658 | /* free header and server IP resolve lists, we don't need it anymore */ | ||
659 | curl_slist_free_all (header_list); header_list = NULL; | ||
660 | curl_slist_free_all (server_ips); server_ips = NULL; | ||
661 | |||
662 | /* Curl errors, result in critical Nagios state */ | ||
663 | if (res != CURLE_OK) { | ||
664 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: cURL returned %d - %s"), | ||
665 | server_port, res, errbuf[0] ? errbuf : curl_easy_strerror(res)); | ||
666 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | ||
667 | } | ||
668 | |||
669 | /* certificate checks */ | ||
670 | #ifdef LIBCURL_FEATURE_SSL | ||
671 | if (use_ssl == TRUE) { | ||
672 | if (check_cert == TRUE) { | ||
673 | if (is_openssl_callback) { | ||
674 | #ifdef USE_OPENSSL | ||
675 | /* check certificate with OpenSSL functions, curl has been built against OpenSSL | ||
676 | * and we actually have OpenSSL in the monitoring tools | ||
677 | */ | ||
678 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); | ||
679 | return result; | ||
680 | #else /* USE_OPENSSL */ | ||
681 | die (STATE_CRITICAL, "HTTP CRITICAL - Cannot retrieve certificates - OpenSSL callback used and not linked against OpenSSL\n"); | ||
682 | #endif /* USE_OPENSSL */ | ||
683 | } else { | ||
684 | int i; | ||
685 | struct curl_slist *slist; | ||
686 | |||
687 | cert_ptr.to_info = NULL; | ||
688 | res = curl_easy_getinfo (curl, CURLINFO_CERTINFO, &cert_ptr.to_info); | ||
689 | if (!res && cert_ptr.to_info) { | ||
690 | #ifdef USE_OPENSSL | ||
691 | /* We have no OpenSSL in libcurl, but we can use OpenSSL for X509 cert parsing | ||
692 | * We only check the first certificate and assume it's the one of the server | ||
693 | */ | ||
694 | const char* raw_cert = NULL; | ||
695 | for (i = 0; i < cert_ptr.to_certinfo->num_of_certs; i++) { | ||
696 | for (slist = cert_ptr.to_certinfo->certinfo[i]; slist; slist = slist->next) { | ||
697 | if (verbose >= 2) | ||
698 | printf ("%d ** %s\n", i, slist->data); | ||
699 | if (strncmp (slist->data, "Cert:", 5) == 0) { | ||
700 | raw_cert = &slist->data[5]; | ||
701 | goto GOT_FIRST_CERT; | ||
702 | } | ||
703 | } | ||
704 | } | ||
705 | GOT_FIRST_CERT: | ||
706 | if (!raw_cert) { | ||
707 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Cannot retrieve certificates from CERTINFO information - certificate data was empty")); | ||
708 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | ||
709 | } | ||
710 | BIO* cert_BIO = BIO_new (BIO_s_mem()); | ||
711 | BIO_write (cert_BIO, raw_cert, strlen(raw_cert)); | ||
712 | cert = PEM_read_bio_X509 (cert_BIO, NULL, NULL, NULL); | ||
713 | if (!cert) { | ||
714 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Cannot read certificate from CERTINFO information - BIO error")); | ||
715 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | ||
716 | } | ||
717 | BIO_free (cert_BIO); | ||
718 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); | ||
719 | return result; | ||
720 | #else /* USE_OPENSSL */ | ||
721 | /* We assume we don't have OpenSSL and np_net_ssl_check_certificate at our disposal, | ||
722 | * so we use the libcurl CURLINFO data | ||
723 | */ | ||
724 | result = net_noopenssl_check_certificate(&cert_ptr, days_till_exp_warn, days_till_exp_crit); | ||
725 | return result; | ||
726 | #endif /* USE_OPENSSL */ | ||
727 | } else { | ||
728 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Cannot retrieve certificates - cURL returned %d - %s"), | ||
729 | res, curl_easy_strerror(res)); | ||
730 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | ||
731 | } | ||
732 | } | ||
733 | } | ||
734 | } | ||
735 | #endif /* LIBCURL_FEATURE_SSL */ | ||
736 | |||
737 | /* we got the data and we executed the request in a given time, so we can append | ||
738 | * performance data to the answer always | ||
739 | */ | ||
740 | handle_curl_option_return_code (curl_easy_getinfo (curl, CURLINFO_TOTAL_TIME, &total_time), "CURLINFO_TOTAL_TIME"); | ||
741 | page_len = get_content_length(&header_buf, &body_buf); | ||
742 | if(show_extended_perfdata) { | ||
743 | handle_curl_option_return_code (curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &time_connect), "CURLINFO_CONNECT_TIME"); | ||
744 | handle_curl_option_return_code (curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME, &time_appconnect), "CURLINFO_APPCONNECT_TIME"); | ||
745 | handle_curl_option_return_code (curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME, &time_headers), "CURLINFO_PRETRANSFER_TIME"); | ||
746 | handle_curl_option_return_code (curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME, &time_firstbyte), "CURLINFO_STARTTRANSFER_TIME"); | ||
747 | snprintf(perfstring, DEFAULT_BUFFER_SIZE, "%s %s %s %s %s %s %s", | ||
748 | perfd_time(total_time), | ||
749 | perfd_size(page_len), | ||
750 | perfd_time_connect(time_connect), | ||
751 | use_ssl == TRUE ? perfd_time_ssl (time_appconnect-time_connect) : "", | ||
752 | perfd_time_headers(time_headers - time_appconnect), | ||
753 | perfd_time_firstbyte(time_firstbyte - time_headers), | ||
754 | perfd_time_transfer(total_time-time_firstbyte) | ||
755 | ); | ||
756 | } else { | ||
757 | snprintf(perfstring, DEFAULT_BUFFER_SIZE, "%s %s", | ||
758 | perfd_time(total_time), | ||
759 | perfd_size(page_len) | ||
760 | ); | ||
761 | } | ||
762 | |||
763 | /* return a CRITICAL status if we couldn't read any data */ | ||
764 | if (strlen(header_buf.buf) == 0 && strlen(body_buf.buf) == 0) | ||
765 | die (STATE_CRITICAL, _("HTTP CRITICAL - No header received from host\n")); | ||
766 | |||
767 | /* get status line of answer, check sanity of HTTP code */ | ||
768 | if (curlhelp_parse_statusline (header_buf.buf, &status_line) < 0) { | ||
769 | snprintf (msg, DEFAULT_BUFFER_SIZE, "Unparsable status line in %.3g seconds response time|%s\n", | ||
770 | total_time, perfstring); | ||
771 | /* we cannot know the major/minor version here for sure as we cannot parse the first line */ | ||
772 | die (STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg); | ||
773 | } | ||
774 | |||
775 | /* get result code from cURL */ | ||
776 | handle_curl_option_return_code (curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &code), "CURLINFO_RESPONSE_CODE"); | ||
777 | if (verbose>=2) | ||
778 | printf ("* curl CURLINFO_RESPONSE_CODE is %ld\n", code); | ||
779 | |||
780 | /* print status line, header, body if verbose */ | ||
781 | if (verbose >= 2) { | ||
782 | printf ("**** HEADER ****\n%s\n**** CONTENT ****\n%s\n", header_buf.buf, | ||
783 | (no_body ? " [[ skipped ]]" : body_buf.buf)); | ||
784 | } | ||
785 | |||
786 | /* make sure the status line matches the response we are looking for */ | ||
787 | if (!expected_statuscode(status_line.first_line, server_expect)) { | ||
788 | if (server_port == HTTP_PORT) | ||
789 | snprintf(msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host: %s\n"), status_line.first_line); | ||
790 | else | ||
791 | snprintf(msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: %s\n"), server_port, status_line.first_line); | ||
792 | die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg); | ||
793 | } | ||
794 | |||
795 | if( server_expect_yn ) { | ||
796 | snprintf(msg, DEFAULT_BUFFER_SIZE, _("Status line output matched \"%s\" - "), server_expect); | ||
797 | if (verbose) | ||
798 | printf ("%s\n",msg); | ||
799 | result = STATE_OK; | ||
800 | } | ||
801 | else { | ||
802 | /* illegal return codes result in a critical state */ | ||
803 | if (code >= 600 || code < 100) { | ||
804 | die (STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status (%d, %.40s)\n"), status_line.http_code, status_line.msg); | ||
805 | /* server errors result in a critical state */ | ||
806 | } else if (code >= 500) { | ||
807 | result = STATE_CRITICAL; | ||
808 | /* client errors result in a warning state */ | ||
809 | } else if (code >= 400) { | ||
810 | result = STATE_WARNING; | ||
811 | /* check redirected page if specified */ | ||
812 | } else if (code >= 300) { | ||
813 | if (onredirect == STATE_DEPENDENT) { | ||
814 | if( followmethod == FOLLOW_LIBCURL ) { | ||
815 | code = status_line.http_code; | ||
816 | } else { | ||
817 | /* old check_http style redirection, if we come | ||
818 | * back here, we are in the same status as with | ||
819 | * the libcurl method | ||
820 | */ | ||
821 | redir (&header_buf); | ||
822 | } | ||
823 | } else { | ||
824 | /* this is a specific code in the command line to | ||
825 | * be returned when a redirection is encoutered | ||
826 | */ | ||
827 | } | ||
828 | result = max_state_alt (onredirect, result); | ||
829 | /* all other codes are considered ok */ | ||
830 | } else { | ||
831 | result = STATE_OK; | ||
832 | } | ||
833 | } | ||
834 | |||
835 | /* libcurl redirection internally, handle error states here */ | ||
836 | if( followmethod == FOLLOW_LIBCURL ) { | ||
837 | handle_curl_option_return_code (curl_easy_getinfo (curl, CURLINFO_REDIRECT_COUNT, &redir_depth), "CURLINFO_REDIRECT_COUNT"); | ||
838 | if (verbose >= 2) | ||
839 | printf(_("* curl LIBINFO_REDIRECT_COUNT is %d\n"), redir_depth); | ||
840 | if (redir_depth > max_depth) { | ||
841 | snprintf (msg, DEFAULT_BUFFER_SIZE, "maximum redirection depth %d exceeded in libcurl", | ||
842 | max_depth); | ||
843 | die (STATE_WARNING, "HTTP WARNING - %s", msg); | ||
844 | } | ||
845 | } | ||
846 | |||
847 | /* check status codes, set exit status accordingly */ | ||
848 | if( status_line.http_code != code ) { | ||
849 | die (STATE_CRITICAL, _("HTTP CRITICAL %s %d %s - different HTTP codes (cUrl has %ld)\n"), | ||
850 | string_statuscode (status_line.http_major, status_line.http_minor), | ||
851 | status_line.http_code, status_line.msg, code); | ||
852 | } | ||
853 | |||
854 | if (maximum_age >= 0) { | ||
855 | result = max_state_alt(check_document_dates(&header_buf, &msg), result); | ||
856 | } | ||
857 | |||
858 | /* Page and Header content checks go here */ | ||
859 | |||
860 | if (strlen (header_expect)) { | ||
861 | if (!strstr (header_buf.buf, header_expect)) { | ||
862 | strncpy(&output_header_search[0],header_expect,sizeof(output_header_search)); | ||
863 | if(output_header_search[sizeof(output_header_search)-1]!='\0') { | ||
864 | bcopy("...",&output_header_search[sizeof(output_header_search)-4],4); | ||
865 | } | ||
866 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%sheader '%s' not found on '%s://%s:%d%s', "), msg, output_header_search, use_ssl ? "https" : "http", host_name ? host_name : server_address, server_port, server_url); | ||
867 | result = STATE_CRITICAL; | ||
868 | } | ||
869 | } | ||
870 | |||
871 | if (strlen (string_expect)) { | ||
872 | if (!strstr (body_buf.buf, string_expect)) { | ||
873 | strncpy(&output_string_search[0],string_expect,sizeof(output_string_search)); | ||
874 | if(output_string_search[sizeof(output_string_search)-1]!='\0') { | ||
875 | bcopy("...",&output_string_search[sizeof(output_string_search)-4],4); | ||
876 | } | ||
877 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%sstring '%s' not found on '%s://%s:%d%s', "), msg, output_string_search, use_ssl ? "https" : "http", host_name ? host_name : server_address, server_port, server_url); | ||
878 | result = STATE_CRITICAL; | ||
879 | } | ||
880 | } | ||
881 | |||
882 | if (strlen (regexp)) { | ||
883 | errcode = regexec (&preg, body_buf.buf, REGS, pmatch, 0); | ||
884 | if ((errcode == 0 && invert_regex == 0) || (errcode == REG_NOMATCH && invert_regex == 1)) { | ||
885 | /* OK - No-op to avoid changing the logic around it */ | ||
886 | result = max_state_alt(STATE_OK, result); | ||
887 | } | ||
888 | else if ((errcode == REG_NOMATCH && invert_regex == 0) || (errcode == 0 && invert_regex == 1)) { | ||
889 | if (invert_regex == 0) | ||
890 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern not found, "), msg); | ||
891 | else | ||
892 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern found, "), msg); | ||
893 | result = STATE_CRITICAL; | ||
894 | } | ||
895 | else { | ||
896 | regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); | ||
897 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%sExecute Error: %s, "), msg, errbuf); | ||
898 | result = STATE_UNKNOWN; | ||
899 | } | ||
900 | } | ||
901 | |||
902 | /* make sure the page is of an appropriate size */ | ||
903 | if ((max_page_len > 0) && (page_len > max_page_len)) { | ||
904 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spage size %d too large, "), msg, page_len); | ||
905 | result = max_state_alt(STATE_WARNING, result); | ||
906 | } else if ((min_page_len > 0) && (page_len < min_page_len)) { | ||
907 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spage size %d too small, "), msg, page_len); | ||
908 | result = max_state_alt(STATE_WARNING, result); | ||
909 | } | ||
910 | |||
911 | /* -w, -c: check warning and critical level */ | ||
912 | result = max_state_alt(get_status(total_time, thlds), result); | ||
913 | |||
914 | /* Cut-off trailing characters */ | ||
915 | if(msg[strlen(msg)-2] == ',') | ||
916 | msg[strlen(msg)-2] = '\0'; | ||
917 | else | ||
918 | msg[strlen(msg)-3] = '\0'; | ||
919 | |||
920 | /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */ | ||
921 | die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n", | ||
922 | state_text(result), string_statuscode (status_line.http_major, status_line.http_minor), | ||
923 | status_line.http_code, status_line.msg, | ||
924 | strlen(msg) > 0 ? " - " : "", | ||
925 | msg, page_len, total_time, | ||
926 | (display_html ? "</A>" : ""), | ||
927 | perfstring); | ||
928 | |||
929 | /* proper cleanup after die? */ | ||
930 | curlhelp_free_statusline(&status_line); | ||
931 | curl_easy_cleanup (curl); | ||
932 | curl_global_cleanup (); | ||
933 | curlhelp_freewritebuffer (&body_buf); | ||
934 | curlhelp_freewritebuffer (&header_buf); | ||
935 | if (!strcmp (http_method, "PUT")) { | ||
936 | curlhelp_freereadbuffer (&put_buf); | ||
937 | } | ||
938 | |||
939 | return result; | ||
940 | } | ||
941 | |||
942 | int | ||
943 | uri_strcmp (const UriTextRangeA range, const char* s) | ||
944 | { | ||
945 | if (!range.first) return -1; | ||
946 | if (range.afterLast - range.first < strlen (s)) return -1; | ||
947 | return strncmp (s, range.first, min( range.afterLast - range.first, strlen (s))); | ||
948 | } | ||
949 | |||
950 | char* | ||
951 | uri_string (const UriTextRangeA range, char* buf, size_t buflen) | ||
952 | { | ||
953 | if (!range.first) return "(null)"; | ||
954 | strncpy (buf, range.first, max (buflen, range.afterLast - range.first)); | ||
955 | buf[max (buflen, range.afterLast - range.first)] = '\0'; | ||
956 | buf[range.afterLast - range.first] = '\0'; | ||
957 | return buf; | ||
958 | } | ||
959 | |||
960 | void | ||
961 | redir (curlhelp_write_curlbuf* header_buf) | ||
962 | { | ||
963 | char *location = NULL; | ||
964 | curlhelp_statusline status_line; | ||
965 | struct phr_header headers[255]; | ||
966 | size_t nof_headers = 255; | ||
967 | size_t msglen; | ||
968 | char buf[DEFAULT_BUFFER_SIZE]; | ||
969 | char ipstr[INET_ADDR_MAX_SIZE]; | ||
970 | int new_port; | ||
971 | char *new_host; | ||
972 | char *new_url; | ||
973 | |||
974 | int res = phr_parse_response (header_buf->buf, header_buf->buflen, | ||
975 | &status_line.http_minor, &status_line.http_code, &status_line.msg, &msglen, | ||
976 | headers, &nof_headers, 0); | ||
977 | |||
978 | location = get_header_value (headers, nof_headers, "location"); | ||
979 | |||
980 | if (verbose >= 2) | ||
981 | printf(_("* Seen redirect location %s\n"), location); | ||
982 | |||
983 | if (++redir_depth > max_depth) | ||
984 | die (STATE_WARNING, | ||
985 | _("HTTP WARNING - maximum redirection depth %d exceeded - %s%s\n"), | ||
986 | max_depth, location, (display_html ? "</A>" : "")); | ||
987 | |||
988 | UriParserStateA state; | ||
989 | UriUriA uri; | ||
990 | state.uri = &uri; | ||
991 | if (uriParseUriA (&state, location) != URI_SUCCESS) { | ||
992 | if (state.errorCode == URI_ERROR_SYNTAX) { | ||
993 | die (STATE_UNKNOWN, | ||
994 | _("HTTP UNKNOWN - Could not parse redirect location '%s'%s\n"), | ||
995 | location, (display_html ? "</A>" : "")); | ||
996 | } else if (state.errorCode == URI_ERROR_MALLOC) { | ||
997 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate URL\n")); | ||
998 | } | ||
999 | } | ||
1000 | |||
1001 | if (verbose >= 2) { | ||
1002 | printf (_("** scheme: %s\n"), | ||
1003 | uri_string (uri.scheme, buf, DEFAULT_BUFFER_SIZE)); | ||
1004 | printf (_("** host: %s\n"), | ||
1005 | uri_string (uri.hostText, buf, DEFAULT_BUFFER_SIZE)); | ||
1006 | printf (_("** port: %s\n"), | ||
1007 | uri_string (uri.portText, buf, DEFAULT_BUFFER_SIZE)); | ||
1008 | if (uri.hostData.ip4) { | ||
1009 | inet_ntop (AF_INET, uri.hostData.ip4->data, ipstr, sizeof (ipstr)); | ||
1010 | printf (_("** IPv4: %s\n"), ipstr); | ||
1011 | } | ||
1012 | if (uri.hostData.ip6) { | ||
1013 | inet_ntop (AF_INET, uri.hostData.ip6->data, ipstr, sizeof (ipstr)); | ||
1014 | printf (_("** IPv6: %s\n"), ipstr); | ||
1015 | } | ||
1016 | if (uri.pathHead) { | ||
1017 | printf (_("** path: ")); | ||
1018 | const UriPathSegmentA* p = uri.pathHead; | ||
1019 | for (; p; p = p->next) { | ||
1020 | printf ("/%s", uri_string (p->text, buf, DEFAULT_BUFFER_SIZE)); | ||
1021 | } | ||
1022 | puts (""); | ||
1023 | } | ||
1024 | if (uri.query.first) { | ||
1025 | printf (_("** query: %s\n"), | ||
1026 | uri_string (uri.query, buf, DEFAULT_BUFFER_SIZE)); | ||
1027 | } | ||
1028 | if (uri.fragment.first) { | ||
1029 | printf (_("** fragment: %s\n"), | ||
1030 | uri_string (uri.fragment, buf, DEFAULT_BUFFER_SIZE)); | ||
1031 | } | ||
1032 | } | ||
1033 | |||
1034 | use_ssl = !uri_strcmp (uri.scheme, "https"); | ||
1035 | |||
1036 | /* we do a sloppy test here only, because uriparser would have failed | ||
1037 | * above, if the port would be invalid, we just check for MAX_PORT | ||
1038 | */ | ||
1039 | if (uri.portText.first) { | ||
1040 | new_port = atoi (uri_string (uri.portText, buf, DEFAULT_BUFFER_SIZE)); | ||
1041 | } else { | ||
1042 | new_port = HTTP_PORT; | ||
1043 | if (use_ssl) | ||
1044 | new_port = HTTPS_PORT; | ||
1045 | } | ||
1046 | if (new_port > MAX_PORT) | ||
1047 | die (STATE_UNKNOWN, | ||
1048 | _("HTTP UNKNOWN - Redirection to port above %d - %s%s\n"), | ||
1049 | MAX_PORT, location, display_html ? "</A>" : ""); | ||
1050 | |||
1051 | /* by RFC 7231 relative URLs in Location should be taken relative to | ||
1052 | * the original URL, so wy try to form a new absolute URL here | ||
1053 | */ | ||
1054 | if (!uri.scheme.first && !uri.hostText.first) { | ||
1055 | new_host = strdup (host_name ? host_name : server_address); | ||
1056 | } else { | ||
1057 | new_host = strdup (uri_string (uri.hostText, buf, DEFAULT_BUFFER_SIZE)); | ||
1058 | } | ||
1059 | |||
1060 | /* compose new path */ | ||
1061 | /* TODO: handle fragments and query part of URL */ | ||
1062 | new_url = (char *)calloc( 1, DEFAULT_BUFFER_SIZE); | ||
1063 | if (uri.pathHead) { | ||
1064 | const UriPathSegmentA* p = uri.pathHead; | ||
1065 | for (; p; p = p->next) { | ||
1066 | strncat (new_url, "/", DEFAULT_BUFFER_SIZE); | ||
1067 | strncat (new_url, uri_string (p->text, buf, DEFAULT_BUFFER_SIZE), DEFAULT_BUFFER_SIZE-1); | ||
1068 | } | ||
1069 | } | ||
1070 | |||
1071 | if (server_port==new_port && | ||
1072 | !strncmp(server_address, new_host, MAX_IPV4_HOSTLENGTH) && | ||
1073 | (host_name && !strncmp(host_name, new_host, MAX_IPV4_HOSTLENGTH)) && | ||
1074 | !strcmp(server_url, new_url)) | ||
1075 | die (STATE_WARNING, | ||
1076 | _("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"), | ||
1077 | use_ssl ? "https" : "http", new_host, new_port, new_url, (display_html ? "</A>" : "")); | ||
1078 | |||
1079 | /* set new values for redirected request */ | ||
1080 | |||
1081 | if (!(followsticky & STICKY_HOST)) { | ||
1082 | free (server_address); | ||
1083 | server_address = strndup (new_host, MAX_IPV4_HOSTLENGTH); | ||
1084 | } | ||
1085 | if (!(followsticky & STICKY_PORT)) { | ||
1086 | server_port = (unsigned short)new_port; | ||
1087 | } | ||
1088 | |||
1089 | free (host_name); | ||
1090 | host_name = strndup (new_host, MAX_IPV4_HOSTLENGTH); | ||
1091 | |||
1092 | /* reset virtual port */ | ||
1093 | virtual_port = server_port; | ||
1094 | |||
1095 | free(new_host); | ||
1096 | free (server_url); | ||
1097 | server_url = new_url; | ||
1098 | |||
1099 | uriFreeUriMembersA (&uri); | ||
1100 | |||
1101 | if (verbose) | ||
1102 | printf (_("Redirection to %s://%s:%d%s\n"), use_ssl ? "https" : "http", | ||
1103 | host_name ? host_name : server_address, server_port, server_url); | ||
1104 | |||
1105 | /* TODO: the hash component MUST be taken from the original URL and | ||
1106 | * attached to the URL in Location | ||
1107 | */ | ||
1108 | |||
1109 | check_http (); | ||
1110 | } | ||
1111 | |||
1112 | /* check whether a file exists */ | ||
1113 | void | ||
1114 | test_file (char *path) | ||
1115 | { | ||
1116 | if (access(path, R_OK) == 0) | ||
1117 | return; | ||
1118 | usage2 (_("file does not exist or is not readable"), path); | ||
1119 | } | ||
1120 | |||
1121 | int | ||
1122 | process_arguments (int argc, char **argv) | ||
1123 | { | ||
1124 | char *p; | ||
1125 | int c = 1; | ||
1126 | char *temp; | ||
1127 | |||
1128 | enum { | ||
1129 | INVERT_REGEX = CHAR_MAX + 1, | ||
1130 | SNI_OPTION, | ||
1131 | CA_CERT_OPTION, | ||
1132 | HTTP_VERSION_OPTION | ||
1133 | }; | ||
1134 | |||
1135 | int option = 0; | ||
1136 | int got_plus = 0; | ||
1137 | static struct option longopts[] = { | ||
1138 | STD_LONG_OPTS, | ||
1139 | {"link", no_argument, 0, 'L'}, | ||
1140 | {"nohtml", no_argument, 0, 'n'}, | ||
1141 | {"ssl", optional_argument, 0, 'S'}, | ||
1142 | {"sni", no_argument, 0, SNI_OPTION}, | ||
1143 | {"post", required_argument, 0, 'P'}, | ||
1144 | {"method", required_argument, 0, 'j'}, | ||
1145 | {"IP-address", required_argument, 0, 'I'}, | ||
1146 | {"url", required_argument, 0, 'u'}, | ||
1147 | {"port", required_argument, 0, 'p'}, | ||
1148 | {"authorization", required_argument, 0, 'a'}, | ||
1149 | {"proxy-authorization", required_argument, 0, 'b'}, | ||
1150 | {"header-string", required_argument, 0, 'd'}, | ||
1151 | {"string", required_argument, 0, 's'}, | ||
1152 | {"expect", required_argument, 0, 'e'}, | ||
1153 | {"regex", required_argument, 0, 'r'}, | ||
1154 | {"ereg", required_argument, 0, 'r'}, | ||
1155 | {"eregi", required_argument, 0, 'R'}, | ||
1156 | {"linespan", no_argument, 0, 'l'}, | ||
1157 | {"onredirect", required_argument, 0, 'f'}, | ||
1158 | {"certificate", required_argument, 0, 'C'}, | ||
1159 | {"client-cert", required_argument, 0, 'J'}, | ||
1160 | {"private-key", required_argument, 0, 'K'}, | ||
1161 | {"ca-cert", required_argument, 0, CA_CERT_OPTION}, | ||
1162 | {"useragent", required_argument, 0, 'A'}, | ||
1163 | {"header", required_argument, 0, 'k'}, | ||
1164 | {"no-body", no_argument, 0, 'N'}, | ||
1165 | {"max-age", required_argument, 0, 'M'}, | ||
1166 | {"content-type", required_argument, 0, 'T'}, | ||
1167 | {"pagesize", required_argument, 0, 'm'}, | ||
1168 | {"invert-regex", no_argument, NULL, INVERT_REGEX}, | ||
1169 | {"use-ipv4", no_argument, 0, '4'}, | ||
1170 | {"use-ipv6", no_argument, 0, '6'}, | ||
1171 | {"extended-perfdata", no_argument, 0, 'E'}, | ||
1172 | {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, | ||
1173 | {0, 0, 0, 0} | ||
1174 | }; | ||
1175 | |||
1176 | if (argc < 2) | ||
1177 | return ERROR; | ||
1178 | |||
1179 | /* support check_http compatible arguments */ | ||
1180 | for (c = 1; c < argc; c++) { | ||
1181 | if (strcmp ("-to", argv[c]) == 0) | ||
1182 | strcpy (argv[c], "-t"); | ||
1183 | if (strcmp ("-hn", argv[c]) == 0) | ||
1184 | strcpy (argv[c], "-H"); | ||
1185 | if (strcmp ("-wt", argv[c]) == 0) | ||
1186 | strcpy (argv[c], "-w"); | ||
1187 | if (strcmp ("-ct", argv[c]) == 0) | ||
1188 | strcpy (argv[c], "-c"); | ||
1189 | if (strcmp ("-nohtml", argv[c]) == 0) | ||
1190 | strcpy (argv[c], "-n"); | ||
1191 | } | ||
1192 | |||
1193 | server_url = strdup(DEFAULT_SERVER_URL); | ||
1194 | |||
1195 | while (1) { | ||
1196 | 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); | ||
1197 | if (c == -1 || c == EOF || c == 1) | ||
1198 | break; | ||
1199 | |||
1200 | switch (c) { | ||
1201 | case 'h': | ||
1202 | print_help(); | ||
1203 | exit(STATE_UNKNOWN); | ||
1204 | break; | ||
1205 | case 'V': | ||
1206 | print_revision(progname, NP_VERSION); | ||
1207 | print_curl_version(); | ||
1208 | exit(STATE_UNKNOWN); | ||
1209 | break; | ||
1210 | case 'v': | ||
1211 | verbose++; | ||
1212 | break; | ||
1213 | case 't': /* timeout period */ | ||
1214 | if (!is_intnonneg (optarg)) | ||
1215 | usage2 (_("Timeout interval must be a positive integer"), optarg); | ||
1216 | else | ||
1217 | socket_timeout = (int)strtol (optarg, NULL, 10); | ||
1218 | break; | ||
1219 | case 'c': /* critical time threshold */ | ||
1220 | critical_thresholds = optarg; | ||
1221 | break; | ||
1222 | case 'w': /* warning time threshold */ | ||
1223 | warning_thresholds = optarg; | ||
1224 | break; | ||
1225 | case 'H': /* virtual host */ | ||
1226 | host_name = strdup (optarg); | ||
1227 | if (host_name[0] == '[') { | ||
1228 | if ((p = strstr (host_name, "]:")) != NULL) { /* [IPv6]:port */ | ||
1229 | virtual_port = atoi (p + 2); | ||
1230 | /* cut off the port */ | ||
1231 | host_name_length = strlen (host_name) - strlen (p) - 1; | ||
1232 | free (host_name); | ||
1233 | host_name = strndup (optarg, host_name_length); | ||
1234 | } | ||
1235 | } else if ((p = strchr (host_name, ':')) != NULL | ||
1236 | && strchr (++p, ':') == NULL) { /* IPv4:port or host:port */ | ||
1237 | virtual_port = atoi (p); | ||
1238 | /* cut off the port */ | ||
1239 | host_name_length = strlen (host_name) - strlen (p) - 1; | ||
1240 | free (host_name); | ||
1241 | host_name = strndup (optarg, host_name_length); | ||
1242 | } | ||
1243 | break; | ||
1244 | case 'I': /* internet address */ | ||
1245 | server_address = strdup (optarg); | ||
1246 | break; | ||
1247 | case 'u': /* URL path */ | ||
1248 | server_url = strdup (optarg); | ||
1249 | break; | ||
1250 | case 'p': /* Server port */ | ||
1251 | if (!is_intnonneg (optarg)) | ||
1252 | usage2 (_("Invalid port number, expecting a non-negative number"), optarg); | ||
1253 | else { | ||
1254 | if( strtol(optarg, NULL, 10) > MAX_PORT) | ||
1255 | usage2 (_("Invalid port number, supplied port number is too big"), optarg); | ||
1256 | server_port = (unsigned short)strtol(optarg, NULL, 10); | ||
1257 | specify_port = TRUE; | ||
1258 | } | ||
1259 | break; | ||
1260 | case 'a': /* authorization info */ | ||
1261 | strncpy (user_auth, optarg, MAX_INPUT_BUFFER - 1); | ||
1262 | user_auth[MAX_INPUT_BUFFER - 1] = 0; | ||
1263 | break; | ||
1264 | case 'b': /* proxy-authorization info */ | ||
1265 | strncpy (proxy_auth, optarg, MAX_INPUT_BUFFER - 1); | ||
1266 | proxy_auth[MAX_INPUT_BUFFER - 1] = 0; | ||
1267 | break; | ||
1268 | case 'P': /* HTTP POST data in URL encoded format; ignored if settings already */ | ||
1269 | if (! http_post_data) | ||
1270 | http_post_data = strdup (optarg); | ||
1271 | if (! http_method) | ||
1272 | http_method = strdup("POST"); | ||
1273 | break; | ||
1274 | case 'j': /* Set HTTP method */ | ||
1275 | if (http_method) | ||
1276 | free(http_method); | ||
1277 | http_method = strdup (optarg); | ||
1278 | break; | ||
1279 | case 'A': /* useragent */ | ||
1280 | strncpy (user_agent, optarg, DEFAULT_BUFFER_SIZE); | ||
1281 | user_agent[DEFAULT_BUFFER_SIZE-1] = '\0'; | ||
1282 | break; | ||
1283 | case 'k': /* Additional headers */ | ||
1284 | if (http_opt_headers_count == 0) | ||
1285 | http_opt_headers = malloc (sizeof (char *) * (++http_opt_headers_count)); | ||
1286 | else | ||
1287 | http_opt_headers = realloc (http_opt_headers, sizeof (char *) * (++http_opt_headers_count)); | ||
1288 | http_opt_headers[http_opt_headers_count - 1] = optarg; | ||
1289 | break; | ||
1290 | case 'L': /* show html link */ | ||
1291 | display_html = TRUE; | ||
1292 | break; | ||
1293 | case 'n': /* do not show html link */ | ||
1294 | display_html = FALSE; | ||
1295 | break; | ||
1296 | case 'C': /* Check SSL cert validity */ | ||
1297 | #ifdef LIBCURL_FEATURE_SSL | ||
1298 | if ((temp=strchr(optarg,','))!=NULL) { | ||
1299 | *temp='\0'; | ||
1300 | if (!is_intnonneg (optarg)) | ||
1301 | usage2 (_("Invalid certificate expiration period"), optarg); | ||
1302 | days_till_exp_warn = atoi(optarg); | ||
1303 | *temp=','; | ||
1304 | temp++; | ||
1305 | if (!is_intnonneg (temp)) | ||
1306 | usage2 (_("Invalid certificate expiration period"), temp); | ||
1307 | days_till_exp_crit = atoi (temp); | ||
1308 | } | ||
1309 | else { | ||
1310 | days_till_exp_crit=0; | ||
1311 | if (!is_intnonneg (optarg)) | ||
1312 | usage2 (_("Invalid certificate expiration period"), optarg); | ||
1313 | days_till_exp_warn = atoi (optarg); | ||
1314 | } | ||
1315 | check_cert = TRUE; | ||
1316 | goto enable_ssl; | ||
1317 | #endif | ||
1318 | case 'J': /* use client certificate */ | ||
1319 | #ifdef LIBCURL_FEATURE_SSL | ||
1320 | test_file(optarg); | ||
1321 | client_cert = optarg; | ||
1322 | goto enable_ssl; | ||
1323 | #endif | ||
1324 | case 'K': /* use client private key */ | ||
1325 | #ifdef LIBCURL_FEATURE_SSL | ||
1326 | test_file(optarg); | ||
1327 | client_privkey = optarg; | ||
1328 | goto enable_ssl; | ||
1329 | #endif | ||
1330 | #ifdef LIBCURL_FEATURE_SSL | ||
1331 | case CA_CERT_OPTION: /* use CA chain file */ | ||
1332 | test_file(optarg); | ||
1333 | ca_cert = optarg; | ||
1334 | goto enable_ssl; | ||
1335 | #endif | ||
1336 | case 'S': /* use SSL */ | ||
1337 | #ifdef LIBCURL_FEATURE_SSL | ||
1338 | enable_ssl: | ||
1339 | use_ssl = TRUE; | ||
1340 | /* ssl_version initialized to CURL_SSLVERSION_DEFAULT as a default. | ||
1341 | * Only set if it's non-zero. This helps when we include multiple | ||
1342 | * parameters, like -S and -C combinations */ | ||
1343 | ssl_version = CURL_SSLVERSION_DEFAULT; | ||
1344 | if (c=='S' && optarg != NULL) { | ||
1345 | char *plus_ptr = strchr(optarg, '+'); | ||
1346 | if (plus_ptr) { | ||
1347 | got_plus = 1; | ||
1348 | *plus_ptr = '\0'; | ||
1349 | } | ||
1350 | |||
1351 | if (optarg[0] == '2') | ||
1352 | ssl_version = CURL_SSLVERSION_SSLv2; | ||
1353 | else if (optarg[0] == '3') | ||
1354 | ssl_version = CURL_SSLVERSION_SSLv3; | ||
1355 | else if (!strcmp (optarg, "1") || !strcmp (optarg, "1.0")) | ||
1356 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) | ||
1357 | ssl_version = CURL_SSLVERSION_TLSv1_0; | ||
1358 | #else | ||
1359 | ssl_version = CURL_SSLVERSION_DEFAULT; | ||
1360 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) */ | ||
1361 | else if (!strcmp (optarg, "1.1")) | ||
1362 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) | ||
1363 | ssl_version = CURL_SSLVERSION_TLSv1_1; | ||
1364 | #else | ||
1365 | ssl_version = CURL_SSLVERSION_DEFAULT; | ||
1366 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) */ | ||
1367 | else if (!strcmp (optarg, "1.2")) | ||
1368 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) | ||
1369 | ssl_version = CURL_SSLVERSION_TLSv1_2; | ||
1370 | #else | ||
1371 | ssl_version = CURL_SSLVERSION_DEFAULT; | ||
1372 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 34, 0) */ | ||
1373 | else if (!strcmp (optarg, "1.3")) | ||
1374 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 52, 0) | ||
1375 | ssl_version = CURL_SSLVERSION_TLSv1_3; | ||
1376 | #else | ||
1377 | ssl_version = CURL_SSLVERSION_DEFAULT; | ||
1378 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 52, 0) */ | ||
1379 | else | ||
1380 | usage4 (_("Invalid option - Valid SSL/TLS versions: 2, 3, 1, 1.1, 1.2, 1.3 (with optional '+' suffix)")); | ||
1381 | } | ||
1382 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 54, 0) | ||
1383 | if (got_plus) { | ||
1384 | switch (ssl_version) { | ||
1385 | case CURL_SSLVERSION_TLSv1_3: | ||
1386 | ssl_version |= CURL_SSLVERSION_MAX_TLSv1_3; | ||
1387 | break; | ||
1388 | case CURL_SSLVERSION_TLSv1_2: | ||
1389 | case CURL_SSLVERSION_TLSv1_1: | ||
1390 | case CURL_SSLVERSION_TLSv1_0: | ||
1391 | ssl_version |= CURL_SSLVERSION_MAX_DEFAULT; | ||
1392 | break; | ||
1393 | } | ||
1394 | } else { | ||
1395 | switch (ssl_version) { | ||
1396 | case CURL_SSLVERSION_TLSv1_3: | ||
1397 | ssl_version |= CURL_SSLVERSION_MAX_TLSv1_3; | ||
1398 | break; | ||
1399 | case CURL_SSLVERSION_TLSv1_2: | ||
1400 | ssl_version |= CURL_SSLVERSION_MAX_TLSv1_2; | ||
1401 | break; | ||
1402 | case CURL_SSLVERSION_TLSv1_1: | ||
1403 | ssl_version |= CURL_SSLVERSION_MAX_TLSv1_1; | ||
1404 | break; | ||
1405 | case CURL_SSLVERSION_TLSv1_0: | ||
1406 | ssl_version |= CURL_SSLVERSION_MAX_TLSv1_0; | ||
1407 | break; | ||
1408 | } | ||
1409 | } | ||
1410 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 54, 0) */ | ||
1411 | if (verbose >= 2) | ||
1412 | printf(_("* Set SSL/TLS version to %d\n"), ssl_version); | ||
1413 | if (specify_port == FALSE) | ||
1414 | server_port = HTTPS_PORT; | ||
1415 | break; | ||
1416 | #else /* LIBCURL_FEATURE_SSL */ | ||
1417 | /* -C -J and -K fall through to here without SSL */ | ||
1418 | usage4 (_("Invalid option - SSL is not available")); | ||
1419 | break; | ||
1420 | case SNI_OPTION: /* --sni is parsed, but ignored, the default is TRUE with libcurl */ | ||
1421 | use_sni = TRUE; | ||
1422 | break; | ||
1423 | #endif /* LIBCURL_FEATURE_SSL */ | ||
1424 | case 'f': /* onredirect */ | ||
1425 | if (!strcmp (optarg, "ok")) | ||
1426 | onredirect = STATE_OK; | ||
1427 | else if (!strcmp (optarg, "warning")) | ||
1428 | onredirect = STATE_WARNING; | ||
1429 | else if (!strcmp (optarg, "critical")) | ||
1430 | onredirect = STATE_CRITICAL; | ||
1431 | else if (!strcmp (optarg, "unknown")) | ||
1432 | onredirect = STATE_UNKNOWN; | ||
1433 | else if (!strcmp (optarg, "follow")) | ||
1434 | onredirect = STATE_DEPENDENT; | ||
1435 | else if (!strcmp (optarg, "stickyport")) | ||
1436 | onredirect = STATE_DEPENDENT, followmethod = FOLLOW_HTTP_CURL, followsticky = STICKY_HOST|STICKY_PORT; | ||
1437 | else if (!strcmp (optarg, "sticky")) | ||
1438 | onredirect = STATE_DEPENDENT, followmethod = FOLLOW_HTTP_CURL, followsticky = STICKY_HOST; | ||
1439 | else if (!strcmp (optarg, "follow")) | ||
1440 | onredirect = STATE_DEPENDENT, followmethod = FOLLOW_HTTP_CURL, followsticky = STICKY_NONE; | ||
1441 | else if (!strcmp (optarg, "curl")) | ||
1442 | onredirect = STATE_DEPENDENT, followmethod = FOLLOW_LIBCURL; | ||
1443 | else usage2 (_("Invalid onredirect option"), optarg); | ||
1444 | if (verbose >= 2) | ||
1445 | printf(_("* Following redirects set to %s\n"), state_text(onredirect)); | ||
1446 | break; | ||
1447 | case 'd': /* string or substring */ | ||
1448 | strncpy (header_expect, optarg, MAX_INPUT_BUFFER - 1); | ||
1449 | header_expect[MAX_INPUT_BUFFER - 1] = 0; | ||
1450 | break; | ||
1451 | case 's': /* string or substring */ | ||
1452 | strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1); | ||
1453 | string_expect[MAX_INPUT_BUFFER - 1] = 0; | ||
1454 | break; | ||
1455 | case 'e': /* string or substring */ | ||
1456 | strncpy (server_expect, optarg, MAX_INPUT_BUFFER - 1); | ||
1457 | server_expect[MAX_INPUT_BUFFER - 1] = 0; | ||
1458 | server_expect_yn = 1; | ||
1459 | break; | ||
1460 | case 'T': /* Content-type */ | ||
1461 | http_content_type = strdup (optarg); | ||
1462 | break; | ||
1463 | case 'l': /* linespan */ | ||
1464 | cflags &= ~REG_NEWLINE; | ||
1465 | break; | ||
1466 | case 'R': /* regex */ | ||
1467 | cflags |= REG_ICASE; | ||
1468 | case 'r': /* regex */ | ||
1469 | strncpy (regexp, optarg, MAX_RE_SIZE - 1); | ||
1470 | regexp[MAX_RE_SIZE - 1] = 0; | ||
1471 | errcode = regcomp (&preg, regexp, cflags); | ||
1472 | if (errcode != 0) { | ||
1473 | (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); | ||
1474 | printf (_("Could Not Compile Regular Expression: %s"), errbuf); | ||
1475 | return ERROR; | ||
1476 | } | ||
1477 | break; | ||
1478 | case INVERT_REGEX: | ||
1479 | invert_regex = 1; | ||
1480 | break; | ||
1481 | case '4': | ||
1482 | address_family = AF_INET; | ||
1483 | break; | ||
1484 | case '6': | ||
1485 | #if defined (USE_IPV6) && defined (LIBCURL_FEATURE_IPV6) | ||
1486 | address_family = AF_INET6; | ||
1487 | #else | ||
1488 | usage4 (_("IPv6 support not available")); | ||
1489 | #endif | ||
1490 | break; | ||
1491 | case 'm': /* min_page_length */ | ||
1492 | { | ||
1493 | char *tmp; | ||
1494 | if (strchr(optarg, ':') != (char *)NULL) { | ||
1495 | /* range, so get two values, min:max */ | ||
1496 | tmp = strtok(optarg, ":"); | ||
1497 | if (tmp == NULL) { | ||
1498 | printf("Bad format: try \"-m min:max\"\n"); | ||
1499 | exit (STATE_WARNING); | ||
1500 | } else | ||
1501 | min_page_len = atoi(tmp); | ||
1502 | |||
1503 | tmp = strtok(NULL, ":"); | ||
1504 | if (tmp == NULL) { | ||
1505 | printf("Bad format: try \"-m min:max\"\n"); | ||
1506 | exit (STATE_WARNING); | ||
1507 | } else | ||
1508 | max_page_len = atoi(tmp); | ||
1509 | } else | ||
1510 | min_page_len = atoi (optarg); | ||
1511 | break; | ||
1512 | } | ||
1513 | case 'N': /* no-body */ | ||
1514 | no_body = TRUE; | ||
1515 | break; | ||
1516 | case 'M': /* max-age */ | ||
1517 | { | ||
1518 | int L = strlen(optarg); | ||
1519 | if (L && optarg[L-1] == 'm') | ||
1520 | maximum_age = atoi (optarg) * 60; | ||
1521 | else if (L && optarg[L-1] == 'h') | ||
1522 | maximum_age = atoi (optarg) * 60 * 60; | ||
1523 | else if (L && optarg[L-1] == 'd') | ||
1524 | maximum_age = atoi (optarg) * 60 * 60 * 24; | ||
1525 | else if (L && (optarg[L-1] == 's' || | ||
1526 | isdigit (optarg[L-1]))) | ||
1527 | maximum_age = atoi (optarg); | ||
1528 | else { | ||
1529 | fprintf (stderr, "unparsable max-age: %s\n", optarg); | ||
1530 | exit (STATE_WARNING); | ||
1531 | } | ||
1532 | if (verbose >= 2) | ||
1533 | printf ("* Maximal age of document set to %d seconds\n", maximum_age); | ||
1534 | } | ||
1535 | break; | ||
1536 | case 'E': /* show extended perfdata */ | ||
1537 | show_extended_perfdata = TRUE; | ||
1538 | break; | ||
1539 | case HTTP_VERSION_OPTION: | ||
1540 | curl_http_version = CURL_HTTP_VERSION_NONE; | ||
1541 | if (strcmp (optarg, "1.0") == 0) { | ||
1542 | curl_http_version = CURL_HTTP_VERSION_1_0; | ||
1543 | } else if (strcmp (optarg, "1.1") == 0) { | ||
1544 | curl_http_version = CURL_HTTP_VERSION_1_1; | ||
1545 | } else if ((strcmp (optarg, "2.0") == 0) || (strcmp (optarg, "2") == 0)) { | ||
1546 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 33, 0) | ||
1547 | curl_http_version = CURL_HTTP_VERSION_2_0; | ||
1548 | #else | ||
1549 | curl_http_version = CURL_HTTP_VERSION_NONE; | ||
1550 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 33, 0) */ | ||
1551 | } else { | ||
1552 | fprintf (stderr, "unkown http-version parameter: %s\n", optarg); | ||
1553 | exit (STATE_WARNING); | ||
1554 | } | ||
1555 | break; | ||
1556 | case '?': | ||
1557 | /* print short usage statement if args not parsable */ | ||
1558 | usage5 (); | ||
1559 | break; | ||
1560 | } | ||
1561 | } | ||
1562 | |||
1563 | c = optind; | ||
1564 | |||
1565 | if (server_address == NULL && c < argc) | ||
1566 | server_address = strdup (argv[c++]); | ||
1567 | |||
1568 | if (host_name == NULL && c < argc) | ||
1569 | host_name = strdup (argv[c++]); | ||
1570 | |||
1571 | if (server_address == NULL) { | ||
1572 | if (host_name == NULL) | ||
1573 | usage4 (_("You must specify a server address or host name")); | ||
1574 | else | ||
1575 | server_address = strdup (host_name); | ||
1576 | } | ||
1577 | |||
1578 | set_thresholds(&thlds, warning_thresholds, critical_thresholds); | ||
1579 | |||
1580 | if (critical_thresholds && thlds->critical->end>(double)socket_timeout) | ||
1581 | socket_timeout = (int)thlds->critical->end + 1; | ||
1582 | if (verbose >= 2) | ||
1583 | printf ("* Socket timeout set to %ld seconds\n", socket_timeout); | ||
1584 | |||
1585 | if (http_method == NULL) | ||
1586 | http_method = strdup ("GET"); | ||
1587 | |||
1588 | if (client_cert && !client_privkey) | ||
1589 | usage4 (_("If you use a client certificate you must also specify a private key file")); | ||
1590 | |||
1591 | if (virtual_port == 0) | ||
1592 | virtual_port = server_port; | ||
1593 | else { | ||
1594 | if ((use_ssl && server_port == HTTPS_PORT) || (!use_ssl && server_port == HTTP_PORT)) | ||
1595 | if(specify_port == FALSE) | ||
1596 | server_port = virtual_port; | ||
1597 | } | ||
1598 | |||
1599 | return TRUE; | ||
1600 | } | ||
1601 | |||
1602 | char *perfd_time (double elapsed_time) | ||
1603 | { | ||
1604 | return fperfdata ("time", elapsed_time, "s", | ||
1605 | thlds->warning?TRUE:FALSE, thlds->warning?thlds->warning->end:0, | ||
1606 | thlds->critical?TRUE:FALSE, thlds->critical?thlds->critical->end:0, | ||
1607 | TRUE, 0, TRUE, socket_timeout); | ||
1608 | } | ||
1609 | |||
1610 | char *perfd_time_connect (double elapsed_time_connect) | ||
1611 | { | ||
1612 | return fperfdata ("time_connect", elapsed_time_connect, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | ||
1613 | } | ||
1614 | |||
1615 | char *perfd_time_ssl (double elapsed_time_ssl) | ||
1616 | { | ||
1617 | return fperfdata ("time_ssl", elapsed_time_ssl, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | ||
1618 | } | ||
1619 | |||
1620 | char *perfd_time_headers (double elapsed_time_headers) | ||
1621 | { | ||
1622 | return fperfdata ("time_headers", elapsed_time_headers, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | ||
1623 | } | ||
1624 | |||
1625 | char *perfd_time_firstbyte (double elapsed_time_firstbyte) | ||
1626 | { | ||
1627 | return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | ||
1628 | } | ||
1629 | |||
1630 | char *perfd_time_transfer (double elapsed_time_transfer) | ||
1631 | { | ||
1632 | return fperfdata ("time_transfer", elapsed_time_transfer, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | ||
1633 | } | ||
1634 | |||
1635 | char *perfd_size (int page_len) | ||
1636 | { | ||
1637 | return perfdata ("size", page_len, "B", | ||
1638 | (min_page_len>0?TRUE:FALSE), min_page_len, | ||
1639 | (min_page_len>0?TRUE:FALSE), 0, | ||
1640 | TRUE, 0, FALSE, 0); | ||
1641 | } | ||
1642 | |||
1643 | void | ||
1644 | print_help (void) | ||
1645 | { | ||
1646 | print_revision (progname, NP_VERSION); | ||
1647 | |||
1648 | printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); | ||
1649 | printf (COPYRIGHT, copyright, email); | ||
1650 | |||
1651 | printf ("%s\n", _("This plugin tests the HTTP service on the specified host. It can test")); | ||
1652 | printf ("%s\n", _("normal (http) and secure (https) servers, follow redirects, search for")); | ||
1653 | printf ("%s\n", _("strings and regular expressions, check connection times, and report on")); | ||
1654 | printf ("%s\n", _("certificate expiration times.")); | ||
1655 | printf ("\n"); | ||
1656 | printf ("%s\n", _("It makes use of libcurl to do so. It tries to be as compatible to check_http")); | ||
1657 | printf ("%s\n", _("as possible.")); | ||
1658 | |||
1659 | printf ("\n\n"); | ||
1660 | |||
1661 | print_usage (); | ||
1662 | |||
1663 | printf (_("NOTE: One or both of -H and -I must be specified")); | ||
1664 | |||
1665 | printf ("\n"); | ||
1666 | |||
1667 | printf (UT_HELP_VRSN); | ||
1668 | printf (UT_EXTRA_OPTS); | ||
1669 | |||
1670 | printf (" %s\n", "-H, --hostname=ADDRESS"); | ||
1671 | printf (" %s\n", _("Host name argument for servers using host headers (virtual host)")); | ||
1672 | printf (" %s\n", _("Append a port to include it in the header (eg: example.com:5000)")); | ||
1673 | printf (" %s\n", "-I, --IP-address=ADDRESS"); | ||
1674 | printf (" %s\n", _("IP address or name (use numeric address if possible to bypass DNS lookup).")); | ||
1675 | printf (" %s\n", "-p, --port=INTEGER"); | ||
1676 | printf (" %s", _("Port number (default: ")); | ||
1677 | printf ("%d)\n", HTTP_PORT); | ||
1678 | |||
1679 | printf (UT_IPv46); | ||
1680 | |||
1681 | #ifdef LIBCURL_FEATURE_SSL | ||
1682 | printf (" %s\n", "-S, --ssl=VERSION[+]"); | ||
1683 | printf (" %s\n", _("Connect via SSL. Port defaults to 443. VERSION is optional, and prevents")); | ||
1684 | printf (" %s\n", _("auto-negotiation (2 = SSLv2, 3 = SSLv3, 1 = TLSv1, 1.1 = TLSv1.1,")); | ||
1685 | printf (" %s\n", _("1.2 = TLSv1.2, 1.3 = TLSv1.3). With a '+' suffix, newer versions are also accepted.")); | ||
1686 | printf (" %s\n", _("Note: SSLv2 and SSLv3 are deprecated and are usually disabled in libcurl")); | ||
1687 | printf (" %s\n", "--sni"); | ||
1688 | printf (" %s\n", _("Enable SSL/TLS hostname extension support (SNI)")); | ||
1689 | #if LIBCURL_VERSION_NUM >= 0x071801 | ||
1690 | printf (" %s\n", _("Note: --sni is the default in libcurl as SSLv2 and SSLV3 are deprecated and")); | ||
1691 | printf (" %s\n", _(" SNI only really works since TLSv1.0")); | ||
1692 | #else | ||
1693 | printf (" %s\n", _("Note: SNI is not supported in libcurl before 7.18.1")); | ||
1694 | #endif | ||
1695 | printf (" %s\n", "-C, --certificate=INTEGER[,INTEGER]"); | ||
1696 | printf (" %s\n", _("Minimum number of days a certificate has to be valid. Port defaults to 443")); | ||
1697 | printf (" %s\n", _("(when this option is used the URL is not checked.)")); | ||
1698 | printf (" %s\n", "-J, --client-cert=FILE"); | ||
1699 | printf (" %s\n", _("Name of file that contains the client certificate (PEM format)")); | ||
1700 | printf (" %s\n", _("to be used in establishing the SSL session")); | ||
1701 | printf (" %s\n", "-K, --private-key=FILE"); | ||
1702 | printf (" %s\n", _("Name of file containing the private key (PEM format)")); | ||
1703 | printf (" %s\n", _("matching the client certificate")); | ||
1704 | printf (" %s\n", "--ca-cert=FILE"); | ||
1705 | printf (" %s\n", _("CA certificate file to verify peer against")); | ||
1706 | #endif | ||
1707 | |||
1708 | printf (" %s\n", "-e, --expect=STRING"); | ||
1709 | printf (" %s\n", _("Comma-delimited list of strings, at least one of them is expected in")); | ||
1710 | printf (" %s", _("the first (status) line of the server response (default: ")); | ||
1711 | printf ("%s)\n", HTTP_EXPECT); | ||
1712 | printf (" %s\n", _("If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)")); | ||
1713 | printf (" %s\n", "-d, --header-string=STRING"); | ||
1714 | printf (" %s\n", _("String to expect in the response headers")); | ||
1715 | printf (" %s\n", "-s, --string=STRING"); | ||
1716 | printf (" %s\n", _("String to expect in the content")); | ||
1717 | printf (" %s\n", "-u, --url=PATH"); | ||
1718 | printf (" %s\n", _("URL to GET or POST (default: /)")); | ||
1719 | printf (" %s\n", "-P, --post=STRING"); | ||
1720 | printf (" %s\n", _("URL encoded http POST data")); | ||
1721 | printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT)"); | ||
1722 | printf (" %s\n", _("Set HTTP method.")); | ||
1723 | printf (" %s\n", "-N, --no-body"); | ||
1724 | printf (" %s\n", _("Don't wait for document body: stop reading after headers.")); | ||
1725 | printf (" %s\n", _("(Note that this still does an HTTP GET or POST, not a HEAD.)")); | ||
1726 | printf (" %s\n", "-M, --max-age=SECONDS"); | ||
1727 | printf (" %s\n", _("Warn if document is more than SECONDS old. the number can also be of")); | ||
1728 | printf (" %s\n", _("the form \"10m\" for minutes, \"10h\" for hours, or \"10d\" for days.")); | ||
1729 | printf (" %s\n", "-T, --content-type=STRING"); | ||
1730 | printf (" %s\n", _("specify Content-Type header media type when POSTing\n")); | ||
1731 | printf (" %s\n", "-l, --linespan"); | ||
1732 | printf (" %s\n", _("Allow regex to span newlines (must precede -r or -R)")); | ||
1733 | printf (" %s\n", "-r, --regex, --ereg=STRING"); | ||
1734 | printf (" %s\n", _("Search page for regex STRING")); | ||
1735 | printf (" %s\n", "-R, --eregi=STRING"); | ||
1736 | printf (" %s\n", _("Search page for case-insensitive regex STRING")); | ||
1737 | printf (" %s\n", "--invert-regex"); | ||
1738 | printf (" %s\n", _("Return CRITICAL if found, OK if not\n")); | ||
1739 | printf (" %s\n", "-a, --authorization=AUTH_PAIR"); | ||
1740 | printf (" %s\n", _("Username:password on sites with basic authentication")); | ||
1741 | printf (" %s\n", "-b, --proxy-authorization=AUTH_PAIR"); | ||
1742 | printf (" %s\n", _("Username:password on proxy-servers with basic authentication")); | ||
1743 | printf (" %s\n", "-A, --useragent=STRING"); | ||
1744 | printf (" %s\n", _("String to be sent in http header as \"User Agent\"")); | ||
1745 | printf (" %s\n", "-k, --header=STRING"); | ||
1746 | printf (" %s\n", _("Any other tags to be sent in http header. Use multiple times for additional headers")); | ||
1747 | printf (" %s\n", "-E, --extended-perfdata"); | ||
1748 | printf (" %s\n", _("Print additional performance data")); | ||
1749 | printf (" %s\n", "-L, --link"); | ||
1750 | printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)")); | ||
1751 | printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport|curl>"); | ||
1752 | printf (" %s\n", _("How to handle redirected pages. sticky is like follow but stick to the")); | ||
1753 | printf (" %s\n", _("specified IP address. stickyport also ensures port stays the same.")); | ||
1754 | printf (" %s\n", _("follow uses the old redirection algorithm of check_http.")); | ||
1755 | printf (" %s\n", _("curl uses CURL_FOLLOWLOCATION built into libcurl.")); | ||
1756 | printf (" %s\n", "-m, --pagesize=INTEGER<:INTEGER>"); | ||
1757 | printf (" %s\n", _("Minimum page size required (bytes) : Maximum page size required (bytes)")); | ||
1758 | printf ("\n"); | ||
1759 | printf (" %s\n", "--http-version=VERSION"); | ||
1760 | printf (" %s\n", _("Connect via specific HTTP protocol.")); | ||
1761 | printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)")); | ||
1762 | printf ("\n"); | ||
1763 | |||
1764 | printf (UT_WARN_CRIT); | ||
1765 | |||
1766 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | ||
1767 | |||
1768 | printf (UT_VERBOSE); | ||
1769 | |||
1770 | printf ("\n"); | ||
1771 | printf ("%s\n", _("Notes:")); | ||
1772 | printf (" %s\n", _("This plugin will attempt to open an HTTP connection with the host.")); | ||
1773 | printf (" %s\n", _("Successful connects return STATE_OK, refusals and timeouts return STATE_CRITICAL")); | ||
1774 | printf (" %s\n", _("other errors return STATE_UNKNOWN. Successful connects, but incorrect response")); | ||
1775 | printf (" %s\n", _("messages from the host result in STATE_WARNING return values. If you are")); | ||
1776 | printf (" %s\n", _("checking a virtual server that uses 'host headers' you must supply the FQDN")); | ||
1777 | printf (" %s\n", _("(fully qualified domain name) as the [host_name] argument.")); | ||
1778 | |||
1779 | #ifdef LIBCURL_FEATURE_SSL | ||
1780 | printf ("\n"); | ||
1781 | printf (" %s\n", _("This plugin can also check whether an SSL enabled web server is able to")); | ||
1782 | printf (" %s\n", _("serve content (optionally within a specified time) or whether the X509 ")); | ||
1783 | printf (" %s\n", _("certificate is still valid for the specified number of days.")); | ||
1784 | printf ("\n"); | ||
1785 | printf (" %s\n", _("Please note that this plugin does not check if the presented server")); | ||
1786 | printf (" %s\n", _("certificate matches the hostname of the server, or if the certificate")); | ||
1787 | printf (" %s\n", _("has a valid chain of trust to one of the locally installed CAs.")); | ||
1788 | printf ("\n"); | ||
1789 | printf ("%s\n", _("Examples:")); | ||
1790 | printf (" %s\n\n", "CHECK CONTENT: check_curl -w 5 -c 10 --ssl -H www.verisign.com"); | ||
1791 | printf (" %s\n", _("When the 'www.verisign.com' server returns its content within 5 seconds,")); | ||
1792 | printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds")); | ||
1793 | printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,")); | ||
1794 | printf (" %s\n", _("a STATE_CRITICAL will be returned.")); | ||
1795 | printf ("\n"); | ||
1796 | printf (" %s\n\n", "CHECK CERTIFICATE: check_curl -H www.verisign.com -C 14"); | ||
1797 | printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 14 days,")); | ||
1798 | printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than")); | ||
1799 | printf (" %s\n", _("14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when")); | ||
1800 | printf (" %s\n\n", _("the certificate is expired.")); | ||
1801 | printf ("\n"); | ||
1802 | printf (" %s\n\n", "CHECK CERTIFICATE: check_curl -H www.verisign.com -C 30,14"); | ||
1803 | printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 30 days,")); | ||
1804 | printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than")); | ||
1805 | printf (" %s\n", _("30 days, but more than 14 days, a STATE_WARNING is returned.")); | ||
1806 | printf (" %s\n", _("A STATE_CRITICAL will be returned when certificate expires in less than 14 days")); | ||
1807 | #endif | ||
1808 | |||
1809 | printf ("\n %s\n", "CHECK WEBSERVER CONTENT VIA PROXY:"); | ||
1810 | printf (" %s\n", _("It is recommended to use an environment proxy like:")); | ||
1811 | printf (" %s\n", _("http_proxy=http://192.168.100.35:3128 ./check_curl -H www.monitoring-plugins.org")); | ||
1812 | printf (" %s\n", _("legacy proxy requests in check_http style still work:")); | ||
1813 | printf (" %s\n", _("check_curl -I 192.168.100.35 -p 3128 -u http://www.monitoring-plugins.org/ -H www.monitoring-plugins.org")); | ||
1814 | |||
1815 | #ifdef LIBCURL_FEATURE_SSL | ||
1816 | printf ("\n %s\n", "CHECK SSL WEBSERVER CONTENT VIA PROXY USING HTTP 1.1 CONNECT: "); | ||
1817 | printf (" %s\n", _("It is recommended to use an environment proxy like:")); | ||
1818 | printf (" %s\n", _("https_proxy=http://192.168.100.35:3128 ./check_curl -H www.verisign.com -S")); | ||
1819 | printf (" %s\n", _("legacy proxy requests in check_http style still work:")); | ||
1820 | printf (" %s\n", _("check_curl -I 192.168.100.35 -p 3128 -u https://www.verisign.com/ -S -j CONNECT -H www.verisign.com ")); | ||
1821 | printf (" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> -S(sl) -j CONNECT -H <webserver>")); | ||
1822 | printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds")); | ||
1823 | printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,")); | ||
1824 | printf (" %s\n", _("a STATE_CRITICAL will be returned.")); | ||
1825 | |||
1826 | #endif | ||
1827 | |||
1828 | printf (UT_SUPPORT); | ||
1829 | |||
1830 | } | ||
1831 | |||
1832 | |||
1833 | |||
1834 | void | ||
1835 | print_usage (void) | ||
1836 | { | ||
1837 | printf ("%s\n", _("Usage:")); | ||
1838 | printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname); | ||
1839 | printf (" [-J <client certificate file>] [-K <private key>] [--ca-cert <CA certificate file>]\n"); | ||
1840 | printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-E] [-a auth]\n"); | ||
1841 | printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport|curl>]\n"); | ||
1842 | printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); | ||
1843 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); | ||
1844 | printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n"); | ||
1845 | printf (" [-T <content-type>] [-j method]\n"); | ||
1846 | printf (" [--http-version=<version>]\n"); | ||
1847 | printf ("\n"); | ||
1848 | printf ("%s\n", _("WARNING: check_curl is experimental. Please use")); | ||
1849 | printf ("%s\n\n", _("check_http if you need a stable version.")); | ||
1850 | } | ||
1851 | |||
1852 | void | ||
1853 | print_curl_version (void) | ||
1854 | { | ||
1855 | printf( "%s\n", curl_version()); | ||
1856 | } | ||
1857 | |||
1858 | int | ||
1859 | curlhelp_initwritebuffer (curlhelp_write_curlbuf *buf) | ||
1860 | { | ||
1861 | buf->bufsize = DEFAULT_BUFFER_SIZE; | ||
1862 | buf->buflen = 0; | ||
1863 | buf->buf = (char *)malloc ((size_t)buf->bufsize); | ||
1864 | if (buf->buf == NULL) return -1; | ||
1865 | return 0; | ||
1866 | } | ||
1867 | |||
1868 | int | ||
1869 | curlhelp_buffer_write_callback (void *buffer, size_t size, size_t nmemb, void *stream) | ||
1870 | { | ||
1871 | curlhelp_write_curlbuf *buf = (curlhelp_write_curlbuf *)stream; | ||
1872 | |||
1873 | while (buf->bufsize < buf->buflen + size * nmemb + 1) { | ||
1874 | buf->bufsize *= buf->bufsize * 2; | ||
1875 | buf->buf = (char *)realloc (buf->buf, buf->bufsize); | ||
1876 | if (buf->buf == NULL) return -1; | ||
1877 | } | ||
1878 | |||
1879 | memcpy (buf->buf + buf->buflen, buffer, size * nmemb); | ||
1880 | buf->buflen += size * nmemb; | ||
1881 | buf->buf[buf->buflen] = '\0'; | ||
1882 | |||
1883 | return (int)(size * nmemb); | ||
1884 | } | ||
1885 | |||
1886 | int | ||
1887 | curlhelp_buffer_read_callback (void *buffer, size_t size, size_t nmemb, void *stream) | ||
1888 | { | ||
1889 | curlhelp_read_curlbuf *buf = (curlhelp_read_curlbuf *)stream; | ||
1890 | |||
1891 | size_t n = min (nmemb * size, buf->buflen - buf->pos); | ||
1892 | |||
1893 | memcpy (buffer, buf->buf + buf->pos, n); | ||
1894 | buf->pos += n; | ||
1895 | |||
1896 | return (int)n; | ||
1897 | } | ||
1898 | |||
1899 | void | ||
1900 | curlhelp_freewritebuffer (curlhelp_write_curlbuf *buf) | ||
1901 | { | ||
1902 | free (buf->buf); | ||
1903 | buf->buf = NULL; | ||
1904 | } | ||
1905 | |||
1906 | int | ||
1907 | curlhelp_initreadbuffer (curlhelp_read_curlbuf *buf, const char *data, size_t datalen) | ||
1908 | { | ||
1909 | buf->buflen = datalen; | ||
1910 | buf->buf = (char *)malloc ((size_t)buf->buflen); | ||
1911 | if (buf->buf == NULL) return -1; | ||
1912 | memcpy (buf->buf, data, datalen); | ||
1913 | buf->pos = 0; | ||
1914 | return 0; | ||
1915 | } | ||
1916 | |||
1917 | void | ||
1918 | curlhelp_freereadbuffer (curlhelp_read_curlbuf *buf) | ||
1919 | { | ||
1920 | free (buf->buf); | ||
1921 | buf->buf = NULL; | ||
1922 | } | ||
1923 | |||
1924 | /* TODO: where to put this, it's actually part of sstrings2 (logically)? | ||
1925 | */ | ||
1926 | const char* | ||
1927 | strrstr2(const char *haystack, const char *needle) | ||
1928 | { | ||
1929 | int counter; | ||
1930 | size_t len; | ||
1931 | const char *prev_pos; | ||
1932 | const char *pos; | ||
1933 | |||
1934 | if (haystack == NULL || needle == NULL) | ||
1935 | return NULL; | ||
1936 | |||
1937 | if (haystack[0] == '\0' || needle[0] == '\0') | ||
1938 | return NULL; | ||
1939 | |||
1940 | counter = 0; | ||
1941 | prev_pos = NULL; | ||
1942 | pos = haystack; | ||
1943 | len = strlen (needle); | ||
1944 | for (;;) { | ||
1945 | pos = strstr (pos, needle); | ||
1946 | if (pos == NULL) { | ||
1947 | if (counter == 0) | ||
1948 | return NULL; | ||
1949 | else | ||
1950 | return prev_pos; | ||
1951 | } | ||
1952 | counter++; | ||
1953 | prev_pos = pos; | ||
1954 | pos += len; | ||
1955 | if (*pos == '\0') return prev_pos; | ||
1956 | } | ||
1957 | } | ||
1958 | |||
1959 | int | ||
1960 | curlhelp_parse_statusline (const char *buf, curlhelp_statusline *status_line) | ||
1961 | { | ||
1962 | char *first_line_end; | ||
1963 | char *p; | ||
1964 | size_t first_line_len; | ||
1965 | char *pp; | ||
1966 | const char *start; | ||
1967 | char *first_line_buf; | ||
1968 | |||
1969 | /* find last start of a new header */ | ||
1970 | start = strrstr2 (buf, "\r\nHTTP"); | ||
1971 | if (start != NULL) { | ||
1972 | start += 2; | ||
1973 | buf = start; | ||
1974 | } | ||
1975 | |||
1976 | first_line_end = strstr(buf, "\r\n"); | ||
1977 | if (first_line_end == NULL) return -1; | ||
1978 | |||
1979 | first_line_len = (size_t)(first_line_end - buf); | ||
1980 | status_line->first_line = (char *)malloc (first_line_len + 1); | ||
1981 | if (status_line->first_line == NULL) return -1; | ||
1982 | memcpy (status_line->first_line, buf, first_line_len); | ||
1983 | status_line->first_line[first_line_len] = '\0'; | ||
1984 | first_line_buf = strdup( status_line->first_line ); | ||
1985 | |||
1986 | /* protocol and version: "HTTP/x.x" SP or "HTTP/2" SP */ | ||
1987 | |||
1988 | p = strtok(first_line_buf, "/"); | ||
1989 | if( p == NULL ) { free( first_line_buf ); return -1; } | ||
1990 | if( strcmp( p, "HTTP" ) != 0 ) { free( first_line_buf ); return -1; } | ||
1991 | |||
1992 | p = strtok( NULL, " " ); | ||
1993 | if( p == NULL ) { free( first_line_buf ); return -1; } | ||
1994 | if( strchr( p, '.' ) != NULL ) { | ||
1995 | |||
1996 | /* HTTP 1.x case */ | ||
1997 | char *ppp; | ||
1998 | ppp = strtok( p, "." ); | ||
1999 | status_line->http_major = (int)strtol( p, &pp, 10 ); | ||
2000 | if( *pp != '\0' ) { free( first_line_buf ); return -1; } | ||
2001 | ppp = strtok( NULL, " " ); | ||
2002 | status_line->http_minor = (int)strtol( p, &pp, 10 ); | ||
2003 | if( *pp != '\0' ) { free( first_line_buf ); return -1; } | ||
2004 | p += 4; /* 1.x SP */ | ||
2005 | } else { | ||
2006 | /* HTTP 2 case */ | ||
2007 | status_line->http_major = (int)strtol( p, &pp, 10 ); | ||
2008 | status_line->http_minor = 0; | ||
2009 | p += 2; /* 2 SP */ | ||
2010 | } | ||
2011 | |||
2012 | /* status code: "404" or "404.1", then SP */ | ||
2013 | |||
2014 | p = strtok( p, " " ); | ||
2015 | if( p == NULL ) { free( first_line_buf ); return -1; } | ||
2016 | if( strchr( p, '.' ) != NULL ) { | ||
2017 | char *ppp; | ||
2018 | ppp = strtok( p, "." ); | ||
2019 | status_line->http_code = (int)strtol( ppp, &pp, 10 ); | ||
2020 | if( *pp != '\0' ) { free( first_line_buf ); return -1; } | ||
2021 | ppp = strtok( NULL, "" ); | ||
2022 | status_line->http_subcode = (int)strtol( ppp, &pp, 10 ); | ||
2023 | if( *pp != '\0' ) { free( first_line_buf ); return -1; } | ||
2024 | p += 6; /* 400.1 SP */ | ||
2025 | } else { | ||
2026 | status_line->http_code = (int)strtol( p, &pp, 10 ); | ||
2027 | status_line->http_subcode = -1; | ||
2028 | if( *pp != '\0' ) { free( first_line_buf ); return -1; } | ||
2029 | p += 4; /* 400 SP */ | ||
2030 | } | ||
2031 | |||
2032 | /* Human readable message: "Not Found" CRLF */ | ||
2033 | |||
2034 | p = strtok( p, "" ); | ||
2035 | if( p == NULL ) { status_line->msg = ""; return 0; } | ||
2036 | status_line->msg = status_line->first_line + ( p - first_line_buf ); | ||
2037 | free( first_line_buf ); | ||
2038 | |||
2039 | return 0; | ||
2040 | } | ||
2041 | |||
2042 | void | ||
2043 | curlhelp_free_statusline (curlhelp_statusline *status_line) | ||
2044 | { | ||
2045 | free (status_line->first_line); | ||
2046 | } | ||
2047 | |||
2048 | void | ||
2049 | remove_newlines (char *s) | ||
2050 | { | ||
2051 | char *p; | ||
2052 | |||
2053 | for (p = s; *p != '\0'; p++) | ||
2054 | if (*p == '\r' || *p == '\n') | ||
2055 | *p = ' '; | ||
2056 | } | ||
2057 | |||
2058 | char * | ||
2059 | get_header_value (const struct phr_header* headers, const size_t nof_headers, const char* header) | ||
2060 | { | ||
2061 | int i; | ||
2062 | for( i = 0; i < nof_headers; i++ ) { | ||
2063 | if(headers[i].name != NULL && strncasecmp( header, headers[i].name, max( headers[i].name_len, 4 ) ) == 0 ) { | ||
2064 | return strndup( headers[i].value, headers[i].value_len ); | ||
2065 | } | ||
2066 | } | ||
2067 | return NULL; | ||
2068 | } | ||
2069 | |||
2070 | int | ||
2071 | check_document_dates (const curlhelp_write_curlbuf *header_buf, char (*msg)[DEFAULT_BUFFER_SIZE]) | ||
2072 | { | ||
2073 | char *server_date = NULL; | ||
2074 | char *document_date = NULL; | ||
2075 | int date_result = STATE_OK; | ||
2076 | curlhelp_statusline status_line; | ||
2077 | struct phr_header headers[255]; | ||
2078 | size_t nof_headers = 255; | ||
2079 | size_t msglen; | ||
2080 | |||
2081 | int res = phr_parse_response (header_buf->buf, header_buf->buflen, | ||
2082 | &status_line.http_minor, &status_line.http_code, &status_line.msg, &msglen, | ||
2083 | headers, &nof_headers, 0); | ||
2084 | |||
2085 | server_date = get_header_value (headers, nof_headers, "date"); | ||
2086 | document_date = get_header_value (headers, nof_headers, "last-modified"); | ||
2087 | |||
2088 | if (!server_date || !*server_date) { | ||
2089 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sServer date unknown, "), *msg); | ||
2090 | date_result = max_state_alt(STATE_UNKNOWN, date_result); | ||
2091 | } else if (!document_date || !*document_date) { | ||
2092 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sDocument modification date unknown, "), *msg); | ||
2093 | date_result = max_state_alt(STATE_CRITICAL, date_result); | ||
2094 | } else { | ||
2095 | time_t srv_data = curl_getdate (server_date, NULL); | ||
2096 | time_t doc_data = curl_getdate (document_date, NULL); | ||
2097 | if (verbose >= 2) | ||
2098 | printf ("* server date: '%s' (%d), doc_date: '%s' (%d)\n", server_date, (int)srv_data, document_date, (int)doc_data); | ||
2099 | if (srv_data <= 0) { | ||
2100 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sServer date \"%100s\" unparsable, "), *msg, server_date); | ||
2101 | date_result = max_state_alt(STATE_CRITICAL, date_result); | ||
2102 | } else if (doc_data <= 0) { | ||
2103 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sDocument date \"%100s\" unparsable, "), *msg, document_date); | ||
2104 | date_result = max_state_alt(STATE_CRITICAL, date_result); | ||
2105 | } else if (doc_data > srv_data + 30) { | ||
2106 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sDocument is %d seconds in the future, "), *msg, (int)doc_data - (int)srv_data); | ||
2107 | date_result = max_state_alt(STATE_CRITICAL, date_result); | ||
2108 | } else if (doc_data < srv_data - maximum_age) { | ||
2109 | int n = (srv_data - doc_data); | ||
2110 | if (n > (60 * 60 * 24 * 2)) { | ||
2111 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sLast modified %.1f days ago, "), *msg, ((float) n) / (60 * 60 * 24)); | ||
2112 | date_result = max_state_alt(STATE_CRITICAL, date_result); | ||
2113 | } else { | ||
2114 | snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sLast modified %d:%02d:%02d ago, "), *msg, n / (60 * 60), (n / 60) % 60, n % 60); | ||
2115 | date_result = max_state_alt(STATE_CRITICAL, date_result); | ||
2116 | } | ||
2117 | } | ||
2118 | } | ||
2119 | |||
2120 | if (server_date) free (server_date); | ||
2121 | if (document_date) free (document_date); | ||
2122 | |||
2123 | return date_result; | ||
2124 | } | ||
2125 | |||
2126 | |||
2127 | int | ||
2128 | get_content_length (const curlhelp_write_curlbuf* header_buf, const curlhelp_write_curlbuf* body_buf) | ||
2129 | { | ||
2130 | const char *s; | ||
2131 | int content_length = 0; | ||
2132 | char *copy; | ||
2133 | struct phr_header headers[255]; | ||
2134 | size_t nof_headers = 255; | ||
2135 | size_t msglen; | ||
2136 | char *content_length_s = NULL; | ||
2137 | curlhelp_statusline status_line; | ||
2138 | |||
2139 | int res = phr_parse_response (header_buf->buf, header_buf->buflen, | ||
2140 | &status_line.http_minor, &status_line.http_code, &status_line.msg, &msglen, | ||
2141 | headers, &nof_headers, 0); | ||
2142 | |||
2143 | content_length_s = get_header_value (headers, nof_headers, "content-length"); | ||
2144 | if (!content_length_s) { | ||
2145 | return header_buf->buflen + body_buf->buflen; | ||
2146 | } | ||
2147 | content_length_s += strspn (content_length_s, " \t"); | ||
2148 | content_length = atoi (content_length_s); | ||
2149 | if (content_length != body_buf->buflen) { | ||
2150 | /* TODO: should we warn if the actual and the reported body length don't match? */ | ||
2151 | } | ||
2152 | |||
2153 | if (content_length_s) free (content_length_s); | ||
2154 | |||
2155 | return header_buf->buflen + body_buf->buflen; | ||
2156 | } | ||
2157 | |||
2158 | /* TODO: is there a better way in libcurl to check for the SSL library? */ | ||
2159 | curlhelp_ssl_library | ||
2160 | curlhelp_get_ssl_library (CURL* curl) | ||
2161 | { | ||
2162 | curl_version_info_data* version_data; | ||
2163 | char *ssl_version; | ||
2164 | char *library; | ||
2165 | curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; | ||
2166 | |||
2167 | version_data = curl_version_info (CURLVERSION_NOW); | ||
2168 | if (version_data == NULL) return CURLHELP_SSL_LIBRARY_UNKNOWN; | ||
2169 | |||
2170 | ssl_version = strdup (version_data->ssl_version); | ||
2171 | if (ssl_version == NULL ) return CURLHELP_SSL_LIBRARY_UNKNOWN; | ||
2172 | |||
2173 | library = strtok (ssl_version, "/"); | ||
2174 | if (library == NULL) return CURLHELP_SSL_LIBRARY_UNKNOWN; | ||
2175 | |||
2176 | if (strcmp (library, "OpenSSL") == 0) | ||
2177 | ssl_library = CURLHELP_SSL_LIBRARY_OPENSSL; | ||
2178 | else if (strcmp (library, "LibreSSL") == 0) | ||
2179 | ssl_library = CURLHELP_SSL_LIBRARY_LIBRESSL; | ||
2180 | else if (strcmp (library, "GnuTLS") == 0) | ||
2181 | ssl_library = CURLHELP_SSL_LIBRARY_GNUTLS; | ||
2182 | else if (strcmp (library, "NSS") == 0) | ||
2183 | ssl_library = CURLHELP_SSL_LIBRARY_NSS; | ||
2184 | |||
2185 | if (verbose >= 2) | ||
2186 | printf ("* SSL library string is : %s %s (%d)\n", version_data->ssl_version, library, ssl_library); | ||
2187 | |||
2188 | free (ssl_version); | ||
2189 | |||
2190 | return ssl_library; | ||
2191 | } | ||
2192 | |||
2193 | const char* | ||
2194 | curlhelp_get_ssl_library_string (curlhelp_ssl_library ssl_library) | ||
2195 | { | ||
2196 | switch (ssl_library) { | ||
2197 | case CURLHELP_SSL_LIBRARY_OPENSSL: | ||
2198 | return "OpenSSL"; | ||
2199 | case CURLHELP_SSL_LIBRARY_LIBRESSL: | ||
2200 | return "LibreSSL"; | ||
2201 | case CURLHELP_SSL_LIBRARY_GNUTLS: | ||
2202 | return "GnuTLS"; | ||
2203 | case CURLHELP_SSL_LIBRARY_NSS: | ||
2204 | return "NSS"; | ||
2205 | case CURLHELP_SSL_LIBRARY_UNKNOWN: | ||
2206 | default: | ||
2207 | return "unknown"; | ||
2208 | } | ||
2209 | } | ||
2210 | |||
2211 | #ifdef LIBCURL_FEATURE_SSL | ||
2212 | #ifndef USE_OPENSSL | ||
2213 | time_t | ||
2214 | parse_cert_date (const char *s) | ||
2215 | { | ||
2216 | struct tm tm; | ||
2217 | time_t date; | ||
2218 | char *res; | ||
2219 | |||
2220 | if (!s) return -1; | ||
2221 | |||
2222 | /* Jan 17 14:25:12 2020 GMT */ | ||
2223 | res = strptime (s, "%Y-%m-%d %H:%M:%S GMT", &tm); | ||
2224 | /* Sep 11 12:00:00 2020 GMT */ | ||
2225 | if (res == NULL) strptime (s, "%Y %m %d %H:%M:%S GMT", &tm); | ||
2226 | date = mktime (&tm); | ||
2227 | |||
2228 | return date; | ||
2229 | } | ||
2230 | |||
2231 | /* TODO: this needs cleanup in the sslutils.c, maybe we the #else case to | ||
2232 | * OpenSSL could be this function | ||
2233 | */ | ||
2234 | int | ||
2235 | net_noopenssl_check_certificate (cert_ptr_union* cert_ptr, int days_till_exp_warn, int days_till_exp_crit) | ||
2236 | { | ||
2237 | int i; | ||
2238 | struct curl_slist* slist; | ||
2239 | int cname_found = 0; | ||
2240 | char* start_date_str = NULL; | ||
2241 | char* end_date_str = NULL; | ||
2242 | time_t start_date; | ||
2243 | time_t end_date; | ||
2244 | char *tz; | ||
2245 | float time_left; | ||
2246 | int days_left; | ||
2247 | int time_remaining; | ||
2248 | char timestamp[50] = ""; | ||
2249 | int status = STATE_UNKNOWN; | ||
2250 | |||
2251 | if (verbose >= 2) | ||
2252 | printf ("**** REQUEST CERTIFICATES ****\n"); | ||
2253 | |||
2254 | for (i = 0; i < cert_ptr->to_certinfo->num_of_certs; i++) { | ||
2255 | for (slist = cert_ptr->to_certinfo->certinfo[i]; slist; slist = slist->next) { | ||
2256 | /* find first common name in subject, | ||
2257 | * TODO: check alternative subjects for | ||
2258 | * TODO: have a decent parser here and not a hack | ||
2259 | * multi-host certificate, check wildcards | ||
2260 | */ | ||
2261 | if (strncasecmp (slist->data, "Subject:", 8) == 0) { | ||
2262 | int d = 3; | ||
2263 | char* p = strstr (slist->data, "CN="); | ||
2264 | if (p == NULL) { | ||
2265 | d = 5; | ||
2266 | p = strstr (slist->data, "CN = "); | ||
2267 | } | ||
2268 | if (p != NULL) { | ||
2269 | if (strncmp (host_name, p+d, strlen (host_name)) == 0) { | ||
2270 | cname_found = 1; | ||
2271 | } | ||
2272 | } | ||
2273 | } else if (strncasecmp (slist->data, "Start Date:", 11) == 0) { | ||
2274 | start_date_str = &slist->data[11]; | ||
2275 | } else if (strncasecmp (slist->data, "Expire Date:", 12) == 0) { | ||
2276 | end_date_str = &slist->data[12]; | ||
2277 | } else if (strncasecmp (slist->data, "Cert:", 5) == 0) { | ||
2278 | goto HAVE_FIRST_CERT; | ||
2279 | } | ||
2280 | if (verbose >= 2) | ||
2281 | printf ("%d ** %s\n", i, slist->data); | ||
2282 | } | ||
2283 | } | ||
2284 | HAVE_FIRST_CERT: | ||
2285 | |||
2286 | if (verbose >= 2) | ||
2287 | printf ("**** REQUEST CERTIFICATES ****\n"); | ||
2288 | |||
2289 | if (!cname_found) { | ||
2290 | printf("%s\n",_("CRITICAL - Cannot retrieve certificate subject.")); | ||
2291 | return STATE_CRITICAL; | ||
2292 | } | ||
2293 | |||
2294 | start_date = parse_cert_date (start_date_str); | ||
2295 | if (start_date <= 0) { | ||
2296 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("WARNING - Unparsable 'Start Date' in certificate: '%s'"), | ||
2297 | start_date_str); | ||
2298 | puts (msg); | ||
2299 | return STATE_WARNING; | ||
2300 | } | ||
2301 | |||
2302 | end_date = parse_cert_date (end_date_str); | ||
2303 | if (end_date <= 0) { | ||
2304 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("WARNING - Unparsable 'Expire Date' in certificate: '%s'"), | ||
2305 | start_date_str); | ||
2306 | puts (msg); | ||
2307 | return STATE_WARNING; | ||
2308 | } | ||
2309 | |||
2310 | time_left = difftime (end_date, time(NULL)); | ||
2311 | days_left = time_left / 86400; | ||
2312 | tz = getenv("TZ"); | ||
2313 | setenv("TZ", "GMT", 1); | ||
2314 | tzset(); | ||
2315 | strftime(timestamp, 50, "%c %z", localtime(&end_date)); | ||
2316 | if (tz) | ||
2317 | setenv("TZ", tz, 1); | ||
2318 | else | ||
2319 | unsetenv("TZ"); | ||
2320 | tzset(); | ||
2321 | |||
2322 | if (days_left > 0 && days_left <= days_till_exp_warn) { | ||
2323 | printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", host_name, days_left, timestamp); | ||
2324 | if (days_left > days_till_exp_crit) | ||
2325 | status = STATE_WARNING; | ||
2326 | else | ||
2327 | status = STATE_CRITICAL; | ||
2328 | } else if (days_left == 0 && time_left > 0) { | ||
2329 | if (time_left >= 3600) | ||
2330 | time_remaining = (int) time_left / 3600; | ||
2331 | else | ||
2332 | time_remaining = (int) time_left / 60; | ||
2333 | |||
2334 | printf (_("%s - Certificate '%s' expires in %u %s (%s)\n"), | ||
2335 | (days_left>days_till_exp_crit) ? "WARNING" : "CRITICAL", host_name, time_remaining, | ||
2336 | time_left >= 3600 ? "hours" : "minutes", timestamp); | ||
2337 | |||
2338 | if ( days_left > days_till_exp_crit) | ||
2339 | status = STATE_WARNING; | ||
2340 | else | ||
2341 | status = STATE_CRITICAL; | ||
2342 | } else if (time_left < 0) { | ||
2343 | printf(_("CRITICAL - Certificate '%s' expired on %s.\n"), host_name, timestamp); | ||
2344 | status=STATE_CRITICAL; | ||
2345 | } else if (days_left == 0) { | ||
2346 | printf (_("%s - Certificate '%s' just expired (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", host_name, timestamp); | ||
2347 | if (days_left > days_till_exp_crit) | ||
2348 | status = STATE_WARNING; | ||
2349 | else | ||
2350 | status = STATE_CRITICAL; | ||
2351 | } else { | ||
2352 | printf(_("OK - Certificate '%s' will expire on %s.\n"), host_name, timestamp); | ||
2353 | status = STATE_OK; | ||
2354 | } | ||
2355 | return status; | ||
2356 | } | ||
2357 | #endif /* USE_OPENSSL */ | ||
2358 | #endif /* LIBCURL_FEATURE_SSL */ | ||
diff --git a/plugins/check_dbi.c b/plugins/check_dbi.c index 826eb8d9..ced13d05 100644 --- a/plugins/check_dbi.c +++ b/plugins/check_dbi.c | |||
@@ -35,6 +35,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
35 | 35 | ||
36 | #include "common.h" | 36 | #include "common.h" |
37 | #include "utils.h" | 37 | #include "utils.h" |
38 | #include "utils_cmd.h" | ||
38 | 39 | ||
39 | #include "netutils.h" | 40 | #include "netutils.h" |
40 | 41 | ||
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index e73a0083..844e625f 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -141,6 +141,7 @@ int erronly = FALSE; | |||
141 | int display_mntp = FALSE; | 141 | int display_mntp = FALSE; |
142 | int exact_match = FALSE; | 142 | int exact_match = FALSE; |
143 | int freespace_ignore_reserved = FALSE; | 143 | int freespace_ignore_reserved = FALSE; |
144 | int display_inodes_perfdata = FALSE; | ||
144 | char *warn_freespace_units = NULL; | 145 | char *warn_freespace_units = NULL; |
145 | char *crit_freespace_units = NULL; | 146 | char *crit_freespace_units = NULL; |
146 | char *warn_freespace_percent = NULL; | 147 | char *warn_freespace_percent = NULL; |
@@ -167,6 +168,7 @@ main (int argc, char **argv) | |||
167 | char *output; | 168 | char *output; |
168 | char *details; | 169 | char *details; |
169 | char *perf; | 170 | char *perf; |
171 | char *perf_ilabel; | ||
170 | char *preamble; | 172 | char *preamble; |
171 | char *flag_header; | 173 | char *flag_header; |
172 | double inode_space_pct; | 174 | double inode_space_pct; |
@@ -186,6 +188,7 @@ main (int argc, char **argv) | |||
186 | output = strdup (""); | 188 | output = strdup (""); |
187 | details = strdup (""); | 189 | details = strdup (""); |
188 | perf = strdup (""); | 190 | perf = strdup (""); |
191 | perf_ilabel = strdup (""); | ||
189 | stat_buf = malloc(sizeof *stat_buf); | 192 | stat_buf = malloc(sizeof *stat_buf); |
190 | 193 | ||
191 | setlocale (LC_ALL, ""); | 194 | setlocale (LC_ALL, ""); |
@@ -348,6 +351,29 @@ main (int argc, char **argv) | |||
348 | TRUE, 0, | 351 | TRUE, 0, |
349 | TRUE, path->dtotal_units)); | 352 | TRUE, path->dtotal_units)); |
350 | 353 | ||
354 | if (display_inodes_perfdata) { | ||
355 | /* *_high_tide must be reinitialized at each run */ | ||
356 | warning_high_tide = UINT_MAX; | ||
357 | critical_high_tide = UINT_MAX; | ||
358 | |||
359 | if (path->freeinodes_percent->warning != NULL) { | ||
360 | warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total )); | ||
361 | } | ||
362 | if (path->freeinodes_percent->critical != NULL) { | ||
363 | critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total )); | ||
364 | } | ||
365 | |||
366 | xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir); | ||
367 | /* Nb: *_high_tide are unset when == UINT_MAX */ | ||
368 | xasprintf (&perf, "%s %s", perf, | ||
369 | perfdata (perf_ilabel, | ||
370 | path->inodes_used, "", | ||
371 | (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, | ||
372 | (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide, | ||
373 | TRUE, 0, | ||
374 | TRUE, path->inodes_total)); | ||
375 | } | ||
376 | |||
351 | if (disk_result==STATE_OK && erronly && !verbose) | 377 | if (disk_result==STATE_OK && erronly && !verbose) |
352 | continue; | 378 | continue; |
353 | 379 | ||
@@ -455,6 +481,7 @@ process_arguments (int argc, char **argv) | |||
455 | {"ignore-eregi-partition", required_argument, 0, 'I'}, | 481 | {"ignore-eregi-partition", required_argument, 0, 'I'}, |
456 | {"local", no_argument, 0, 'l'}, | 482 | {"local", no_argument, 0, 'l'}, |
457 | {"stat-remote-fs", no_argument, 0, 'L'}, | 483 | {"stat-remote-fs", no_argument, 0, 'L'}, |
484 | {"iperfdata", no_argument, 0, 'P'}, | ||
458 | {"mountpoint", no_argument, 0, 'M'}, | 485 | {"mountpoint", no_argument, 0, 'M'}, |
459 | {"errors-only", no_argument, 0, 'e'}, | 486 | {"errors-only", no_argument, 0, 'e'}, |
460 | {"exact-match", no_argument, 0, 'E'}, | 487 | {"exact-match", no_argument, 0, 'E'}, |
@@ -477,7 +504,7 @@ process_arguments (int argc, char **argv) | |||
477 | strcpy (argv[c], "-t"); | 504 | strcpy (argv[c], "-t"); |
478 | 505 | ||
479 | while (1) { | 506 | while (1) { |
480 | c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLg:R:r:i:I:MEA", longopts, &option); | 507 | c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEA", longopts, &option); |
481 | 508 | ||
482 | if (c == -1 || c == EOF) | 509 | if (c == -1 || c == EOF) |
483 | break; | 510 | break; |
@@ -582,9 +609,13 @@ process_arguments (int argc, char **argv) | |||
582 | break; | 609 | break; |
583 | case 'L': | 610 | case 'L': |
584 | stat_remote_fs = 1; | 611 | stat_remote_fs = 1; |
612 | /* fallthrough */ | ||
585 | case 'l': | 613 | case 'l': |
586 | show_local_fs = 1; | 614 | show_local_fs = 1; |
587 | break; | 615 | break; |
616 | case 'P': | ||
617 | display_inodes_perfdata = 1; | ||
618 | break; | ||
588 | case 'p': /* select path */ | 619 | case 'p': /* select path */ |
589 | if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || | 620 | if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || |
590 | crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || | 621 | crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || |
@@ -904,6 +935,8 @@ print_help (void) | |||
904 | printf (" %s\n", _("Display only devices/mountpoints with errors")); | 935 | printf (" %s\n", _("Display only devices/mountpoints with errors")); |
905 | printf (" %s\n", "-f, --freespace-ignore-reserved"); | 936 | printf (" %s\n", "-f, --freespace-ignore-reserved"); |
906 | printf (" %s\n", _("Don't account root-reserved blocks into freespace in perfdata")); | 937 | printf (" %s\n", _("Don't account root-reserved blocks into freespace in perfdata")); |
938 | printf (" %s\n", "-P, --iperfdata"); | ||
939 | printf (" %s\n", _("Display inode usage in perfdata")); | ||
907 | printf (" %s\n", "-g, --group=NAME"); | 940 | printf (" %s\n", "-g, --group=NAME"); |
908 | printf (" %s\n", _("Group paths. Thresholds apply to (free-)space of all partitions together")); | 941 | printf (" %s\n", _("Group paths. Thresholds apply to (free-)space of all partitions together")); |
909 | printf (" %s\n", "-k, --kilobytes"); | 942 | printf (" %s\n", "-k, --kilobytes"); |
@@ -1012,6 +1045,8 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1012 | p->dtotal_units += p_list->dtotal_units; | 1045 | p->dtotal_units += p_list->dtotal_units; |
1013 | p->inodes_total += p_list->inodes_total; | 1046 | p->inodes_total += p_list->inodes_total; |
1014 | p->inodes_free += p_list->inodes_free; | 1047 | p->inodes_free += p_list->inodes_free; |
1048 | p->inodes_free_to_root += p_list->inodes_free_to_root; | ||
1049 | p->inodes_used += p_list->inodes_used; | ||
1015 | } | 1050 | } |
1016 | first = 0; | 1051 | first = 0; |
1017 | } | 1052 | } |
@@ -1050,7 +1085,18 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1050 | p->dused_units = p->used*fsp->fsu_blocksize/mult; | 1085 | p->dused_units = p->used*fsp->fsu_blocksize/mult; |
1051 | p->dfree_units = p->available*fsp->fsu_blocksize/mult; | 1086 | p->dfree_units = p->available*fsp->fsu_blocksize/mult; |
1052 | p->dtotal_units = p->total*fsp->fsu_blocksize/mult; | 1087 | p->dtotal_units = p->total*fsp->fsu_blocksize/mult; |
1053 | p->inodes_total = fsp->fsu_files; /* Total file nodes. */ | 1088 | /* Free file nodes. Not sure the workaround is required, but in case...*/ |
1054 | p->inodes_free = fsp->fsu_ffree; /* Free file nodes. */ | 1089 | p->inodes_free = fsp->fsu_favail > fsp->fsu_ffree ? 0 : fsp->fsu_favail; |
1090 | p->inodes_free_to_root = fsp->fsu_ffree; /* Free file nodes for root. */ | ||
1091 | p->inodes_used = fsp->fsu_files - fsp->fsu_ffree; | ||
1092 | if (freespace_ignore_reserved) { | ||
1093 | /* option activated : we substract the root-reserved inodes from the total */ | ||
1094 | /* not all OS report fsp->fsu_favail, only the ones with statvfs syscall */ | ||
1095 | /* for others, fsp->fsu_ffree == fsp->fsu_favail */ | ||
1096 | p->inodes_total = fsp->fsu_files - p->inodes_free_to_root + p->inodes_free; | ||
1097 | } else { | ||
1098 | /* default behaviour : take all the inodes into account */ | ||
1099 | p->inodes_total = fsp->fsu_files; | ||
1100 | } | ||
1055 | np_add_name(&seen, p->best_match->me_mountdir); | 1101 | np_add_name(&seen, p->best_match->me_mountdir); |
1056 | } | 1102 | } |
diff --git a/plugins/check_dns.c b/plugins/check_dns.c index f2061636..0f2e6541 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c | |||
@@ -56,6 +56,7 @@ char **expected_address = NULL; | |||
56 | int expected_address_cnt = 0; | 56 | int expected_address_cnt = 0; |
57 | 57 | ||
58 | int expect_authority = FALSE; | 58 | int expect_authority = FALSE; |
59 | int all_match = FALSE; | ||
59 | thresholds *time_thresholds = NULL; | 60 | thresholds *time_thresholds = NULL; |
60 | 61 | ||
61 | static int | 62 | static int |
@@ -168,8 +169,8 @@ main (int argc, char **argv) | |||
168 | temp_buffer++; | 169 | temp_buffer++; |
169 | 170 | ||
170 | /* Strip leading spaces */ | 171 | /* Strip leading spaces */ |
171 | for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++) | 172 | while (*temp_buffer == ' ') |
172 | /* NOOP */; | 173 | temp_buffer++; |
173 | 174 | ||
174 | strip(temp_buffer); | 175 | strip(temp_buffer); |
175 | if (temp_buffer==NULL || strlen(temp_buffer)==0) { | 176 | if (temp_buffer==NULL || strlen(temp_buffer)==0) { |
@@ -201,7 +202,10 @@ main (int argc, char **argv) | |||
201 | if (error_scan (chld_err.line[i]) != STATE_OK) { | 202 | if (error_scan (chld_err.line[i]) != STATE_OK) { |
202 | result = max_state (result, error_scan (chld_err.line[i])); | 203 | result = max_state (result, error_scan (chld_err.line[i])); |
203 | msg = strchr(input_buffer, ':'); | 204 | msg = strchr(input_buffer, ':'); |
204 | if(msg) msg++; | 205 | if(msg) |
206 | msg++; | ||
207 | else | ||
208 | msg = input_buffer; | ||
205 | } | 209 | } |
206 | } | 210 | } |
207 | 211 | ||
@@ -228,16 +232,27 @@ main (int argc, char **argv) | |||
228 | if (result == STATE_OK && expected_address_cnt > 0) { | 232 | if (result == STATE_OK && expected_address_cnt > 0) { |
229 | result = STATE_CRITICAL; | 233 | result = STATE_CRITICAL; |
230 | temp_buffer = ""; | 234 | temp_buffer = ""; |
235 | unsigned long expect_match = (1 << expected_address_cnt) - 1; | ||
236 | unsigned long addr_match = (1 << n_addresses) - 1; | ||
231 | 237 | ||
232 | for (i=0; i<expected_address_cnt; i++) { | 238 | for (i=0; i<expected_address_cnt; i++) { |
239 | int j; | ||
233 | /* check if we get a match on 'raw' ip or cidr */ | 240 | /* check if we get a match on 'raw' ip or cidr */ |
234 | if ( strcmp(address, expected_address[i]) == 0 | 241 | for (j=0; j<n_addresses; j++) { |
235 | || ip_match_cidr(address, expected_address[i]) ) | 242 | if ( strcmp(addresses[j], expected_address[i]) == 0 |
236 | result = STATE_OK; | 243 | || ip_match_cidr(addresses[j], expected_address[i]) ) { |
244 | result = STATE_OK; | ||
245 | addr_match &= ~(1 << j); | ||
246 | expect_match &= ~(1 << i); | ||
247 | } | ||
248 | } | ||
237 | 249 | ||
238 | /* prepare an error string */ | 250 | /* prepare an error string */ |
239 | xasprintf(&temp_buffer, "%s%s; ", temp_buffer, expected_address[i]); | 251 | xasprintf(&temp_buffer, "%s%s; ", temp_buffer, expected_address[i]); |
240 | } | 252 | } |
253 | /* check if expected_address must cover all in addresses and none may be missing */ | ||
254 | if (all_match && (expect_match != 0 || addr_match != 0)) | ||
255 | result = STATE_CRITICAL; | ||
241 | if (result == STATE_CRITICAL) { | 256 | if (result == STATE_CRITICAL) { |
242 | /* Strip off last semicolon... */ | 257 | /* Strip off last semicolon... */ |
243 | temp_buffer[strlen(temp_buffer)-2] = '\0'; | 258 | temp_buffer[strlen(temp_buffer)-2] = '\0'; |
@@ -336,6 +351,8 @@ error_scan (char *input_buffer) | |||
336 | /* DNS server is not running... */ | 351 | /* DNS server is not running... */ |
337 | else if (strstr (input_buffer, "No response from server")) | 352 | else if (strstr (input_buffer, "No response from server")) |
338 | die (STATE_CRITICAL, _("No response from DNS %s\n"), dns_server); | 353 | die (STATE_CRITICAL, _("No response from DNS %s\n"), dns_server); |
354 | else if (strstr (input_buffer, "no servers could be reached")) | ||
355 | die (STATE_CRITICAL, _("No response from DNS %s\n"), dns_server); | ||
339 | 356 | ||
340 | /* Host name is valid, but server doesn't have records... */ | 357 | /* Host name is valid, but server doesn't have records... */ |
341 | else if (strstr (input_buffer, "No records")) | 358 | else if (strstr (input_buffer, "No records")) |
@@ -401,6 +418,7 @@ process_arguments (int argc, char **argv) | |||
401 | {"reverse-server", required_argument, 0, 'r'}, | 418 | {"reverse-server", required_argument, 0, 'r'}, |
402 | {"expected-address", required_argument, 0, 'a'}, | 419 | {"expected-address", required_argument, 0, 'a'}, |
403 | {"expect-authority", no_argument, 0, 'A'}, | 420 | {"expect-authority", no_argument, 0, 'A'}, |
421 | {"all", no_argument, 0, 'L'}, | ||
404 | {"warning", required_argument, 0, 'w'}, | 422 | {"warning", required_argument, 0, 'w'}, |
405 | {"critical", required_argument, 0, 'c'}, | 423 | {"critical", required_argument, 0, 'c'}, |
406 | {0, 0, 0, 0} | 424 | {0, 0, 0, 0} |
@@ -414,7 +432,7 @@ process_arguments (int argc, char **argv) | |||
414 | strcpy (argv[c], "-t"); | 432 | strcpy (argv[c], "-t"); |
415 | 433 | ||
416 | while (1) { | 434 | while (1) { |
417 | c = getopt_long (argc, argv, "hVvAt:H:s:r:a:w:c:", long_opts, &opt_index); | 435 | c = getopt_long (argc, argv, "hVvALt:H:s:r:a:w:c:", long_opts, &opt_index); |
418 | 436 | ||
419 | if (c == -1 || c == EOF) | 437 | if (c == -1 || c == EOF) |
420 | break; | 438 | break; |
@@ -455,13 +473,30 @@ process_arguments (int argc, char **argv) | |||
455 | case 'a': /* expected address */ | 473 | case 'a': /* expected address */ |
456 | if (strlen (optarg) >= ADDRESS_LENGTH) | 474 | if (strlen (optarg) >= ADDRESS_LENGTH) |
457 | die (STATE_UNKNOWN, _("Input buffer overflow\n")); | 475 | die (STATE_UNKNOWN, _("Input buffer overflow\n")); |
458 | expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**)); | 476 | if (strchr(optarg, ',') != NULL) { |
459 | expected_address[expected_address_cnt] = strdup(optarg); | 477 | char *comma = strchr(optarg, ','); |
460 | expected_address_cnt++; | 478 | while (comma != NULL) { |
479 | expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**)); | ||
480 | expected_address[expected_address_cnt] = strndup(optarg, comma - optarg); | ||
481 | expected_address_cnt++; | ||
482 | optarg = comma + 1; | ||
483 | comma = strchr(optarg, ','); | ||
484 | } | ||
485 | expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**)); | ||
486 | expected_address[expected_address_cnt] = strdup(optarg); | ||
487 | expected_address_cnt++; | ||
488 | } else { | ||
489 | expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**)); | ||
490 | expected_address[expected_address_cnt] = strdup(optarg); | ||
491 | expected_address_cnt++; | ||
492 | } | ||
461 | break; | 493 | break; |
462 | case 'A': /* expect authority */ | 494 | case 'A': /* expect authority */ |
463 | expect_authority = TRUE; | 495 | expect_authority = TRUE; |
464 | break; | 496 | break; |
497 | case 'L': /* all must match */ | ||
498 | all_match = TRUE; | ||
499 | break; | ||
465 | case 'w': | 500 | case 'w': |
466 | warning = optarg; | 501 | warning = optarg; |
467 | break; | 502 | break; |
@@ -530,14 +565,16 @@ print_help (void) | |||
530 | printf (" -a, --expected-address=IP-ADDRESS|CIDR|HOST\n"); | 565 | printf (" -a, --expected-address=IP-ADDRESS|CIDR|HOST\n"); |
531 | printf (" %s\n", _("Optional IP-ADDRESS/CIDR you expect the DNS server to return. HOST must end")); | 566 | printf (" %s\n", _("Optional IP-ADDRESS/CIDR you expect the DNS server to return. HOST must end")); |
532 | printf (" %s\n", _("with a dot (.). This option can be repeated multiple times (Returns OK if any")); | 567 | printf (" %s\n", _("with a dot (.). This option can be repeated multiple times (Returns OK if any")); |
533 | printf (" %s\n", _("value match). If multiple addresses are returned at once, you have to match")); | 568 | printf (" %s\n", _("value matches).")); |
534 | printf (" %s\n", _("the whole string of addresses separated with commas (sorted alphabetically).")); | ||
535 | printf (" -A, --expect-authority\n"); | 569 | printf (" -A, --expect-authority\n"); |
536 | printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup")); | 570 | printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup")); |
537 | printf (" -w, --warning=seconds\n"); | 571 | printf (" -w, --warning=seconds\n"); |
538 | printf (" %s\n", _("Return warning if elapsed time exceeds value. Default off")); | 572 | printf (" %s\n", _("Return warning if elapsed time exceeds value. Default off")); |
539 | printf (" -c, --critical=seconds\n"); | 573 | printf (" -c, --critical=seconds\n"); |
540 | printf (" %s\n", _("Return critical if elapsed time exceeds value. Default off")); | 574 | printf (" %s\n", _("Return critical if elapsed time exceeds value. Default off")); |
575 | printf (" -L, --all\n"); | ||
576 | printf (" %s\n", _("Return critical if the list of expected addresses does not match all addresses")); | ||
577 | printf (" %s\n", _("returned. Default off")); | ||
541 | 578 | ||
542 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 579 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
543 | 580 | ||
@@ -549,5 +586,5 @@ void | |||
549 | print_usage (void) | 586 | print_usage (void) |
550 | { | 587 | { |
551 | printf ("%s\n", _("Usage:")); | 588 | printf ("%s\n", _("Usage:")); |
552 | printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit]\n", progname); | 589 | printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit] [-L]\n", progname); |
553 | } | 590 | } |
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); | |||
67 | char *community = NULL; | 67 | char *community = NULL; |
68 | char *address = NULL; | 68 | char *address = NULL; |
69 | char *port = NULL; | 69 | char *port = NULL; |
70 | int check_paper_out = 1; | ||
70 | 71 | ||
71 | int | 72 | int |
72 | main (int argc, char **argv) | 73 | main (int argc, char **argv) |
@@ -240,7 +241,8 @@ main (int argc, char **argv) | |||
240 | strcpy (errmsg, _("Paper Jam")); | 241 | strcpy (errmsg, _("Paper Jam")); |
241 | } | 242 | } |
242 | else if (paper_out) { | 243 | else if (paper_out) { |
243 | result = STATE_WARNING; | 244 | if (check_paper_out) |
245 | result = STATE_WARNING; | ||
244 | strcpy (errmsg, _("Out of Paper")); | 246 | strcpy (errmsg, _("Out of Paper")); |
245 | } | 247 | } |
246 | else if (line_status == OFFLINE) { | 248 | else if (line_status == OFFLINE) { |
@@ -325,7 +327,7 @@ process_arguments (int argc, char **argv) | |||
325 | 327 | ||
326 | 328 | ||
327 | while (1) { | 329 | while (1) { |
328 | c = getopt_long (argc, argv, "+hVH:C:p:", longopts, &option); | 330 | c = getopt_long (argc, argv, "+hVH:C:p:D", longopts, &option); |
329 | 331 | ||
330 | if (c == -1 || c == EOF || c == 1) | 332 | if (c == -1 || c == EOF || c == 1) |
331 | break; | 333 | break; |
@@ -347,6 +349,8 @@ process_arguments (int argc, char **argv) | |||
347 | usage2 (_("Port must be a positive short integer"), optarg); | 349 | usage2 (_("Port must be a positive short integer"), optarg); |
348 | else | 350 | else |
349 | port = atoi(optarg); | 351 | port = atoi(optarg); |
352 | case 'D': /* disable paper out check*/ | ||
353 | check_paper_out = 0; | ||
350 | break; | 354 | break; |
351 | case 'V': /* version */ | 355 | case 'V': /* version */ |
352 | print_revision (progname, NP_VERSION); | 356 | print_revision (progname, NP_VERSION); |
@@ -420,6 +424,8 @@ print_help (void) | |||
420 | printf (" %s", _("Specify the port to check ")); | 424 | printf (" %s", _("Specify the port to check ")); |
421 | printf (_("(default=%s)"), DEFAULT_PORT); | 425 | printf (_("(default=%s)"), DEFAULT_PORT); |
422 | printf ("\n"); | 426 | printf ("\n"); |
427 | printf (" %s\n", "-D"); | ||
428 | printf (" %s", _("Disable paper check ")); | ||
423 | 429 | ||
424 | printf (UT_SUPPORT); | 430 | printf (UT_SUPPORT); |
425 | } | 431 | } |
@@ -430,5 +436,5 @@ void | |||
430 | print_usage (void) | 436 | print_usage (void) |
431 | { | 437 | { |
432 | printf ("%s\n", _("Usage:")); | 438 | printf ("%s\n", _("Usage:")); |
433 | printf ("%s -H host [-C community] [-p port]\n", progname); | 439 | printf ("%s -H host [-C community] [-p port] [-D]\n", progname); |
434 | } | 440 | } |
diff --git a/plugins/check_http.c b/plugins/check_http.c index a25f1ec0..986cdf2f 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -931,6 +931,21 @@ check_http (void) | |||
931 | 931 | ||
932 | if (verbose) printf ("Entering CONNECT tunnel mode with proxy %s:%d to dst %s:%d\n", server_address, server_port, host_name, HTTPS_PORT); | 932 | if (verbose) printf ("Entering CONNECT tunnel mode with proxy %s:%d to dst %s:%d\n", server_address, server_port, host_name, HTTPS_PORT); |
933 | asprintf (&buf, "%s %s:%d HTTP/1.1\r\n%s\r\n", http_method, host_name, HTTPS_PORT, user_agent); | 933 | asprintf (&buf, "%s %s:%d HTTP/1.1\r\n%s\r\n", http_method, host_name, HTTPS_PORT, user_agent); |
934 | if (strlen(proxy_auth)) { | ||
935 | base64_encode_alloc (proxy_auth, strlen (proxy_auth), &auth); | ||
936 | xasprintf (&buf, "%sProxy-Authorization: Basic %s\r\n", buf, auth); | ||
937 | } | ||
938 | /* optionally send any other header tag */ | ||
939 | if (http_opt_headers_count) { | ||
940 | for (i = 0; i < http_opt_headers_count ; i++) { | ||
941 | if (force_host_header != http_opt_headers[i]) { | ||
942 | xasprintf (&buf, "%s%s\r\n", buf, http_opt_headers[i]); | ||
943 | } | ||
944 | } | ||
945 | /* This cannot be free'd here because a redirection will then try to access this and segfault */ | ||
946 | /* Covered in a testcase in tests/check_http.t */ | ||
947 | /* free(http_opt_headers); */ | ||
948 | } | ||
934 | asprintf (&buf, "%sProxy-Connection: keep-alive\r\n", buf); | 949 | asprintf (&buf, "%sProxy-Connection: keep-alive\r\n", buf); |
935 | asprintf (&buf, "%sHost: %s\r\n", buf, host_name); | 950 | asprintf (&buf, "%sHost: %s\r\n", buf, host_name); |
936 | /* we finished our request, send empty line with CRLF */ | 951 | /* we finished our request, send empty line with CRLF */ |
@@ -1155,6 +1170,8 @@ check_http (void) | |||
1155 | xasprintf (&msg, | 1170 | xasprintf (&msg, |
1156 | _("Invalid HTTP response received from host on port %d: %s\n"), | 1171 | _("Invalid HTTP response received from host on port %d: %s\n"), |
1157 | server_port, status_line); | 1172 | server_port, status_line); |
1173 | if (show_body) | ||
1174 | xasprintf (&msg, _("%s\n%s"), msg, page); | ||
1158 | die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg); | 1175 | die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg); |
1159 | } | 1176 | } |
1160 | 1177 | ||
diff --git a/plugins/check_load.c b/plugins/check_load.c index b1cc498f..bf7b94b4 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c | |||
@@ -33,6 +33,7 @@ const char *copyright = "1999-2007"; | |||
33 | const char *email = "devel@monitoring-plugins.org"; | 33 | const char *email = "devel@monitoring-plugins.org"; |
34 | 34 | ||
35 | #include "common.h" | 35 | #include "common.h" |
36 | #include "runcmd.h" | ||
36 | #include "utils.h" | 37 | #include "utils.h" |
37 | #include "popen.h" | 38 | #include "popen.h" |
38 | 39 | ||
@@ -52,6 +53,9 @@ static int process_arguments (int argc, char **argv); | |||
52 | static int validate_arguments (void); | 53 | static int validate_arguments (void); |
53 | void print_help (void); | 54 | void print_help (void); |
54 | void print_usage (void); | 55 | void print_usage (void); |
56 | static int print_top_consuming_processes(); | ||
57 | |||
58 | static int n_procs_to_show = 0; | ||
55 | 59 | ||
56 | /* strictly for pretty-print usage in loops */ | 60 | /* strictly for pretty-print usage in loops */ |
57 | static const int nums[3] = { 1, 5, 15 }; | 61 | static const int nums[3] = { 1, 5, 15 }; |
@@ -210,6 +214,9 @@ main (int argc, char **argv) | |||
210 | printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]); | 214 | printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]); |
211 | 215 | ||
212 | putchar('\n'); | 216 | putchar('\n'); |
217 | if (n_procs_to_show > 0) { | ||
218 | print_top_consuming_processes(); | ||
219 | } | ||
213 | return result; | 220 | return result; |
214 | } | 221 | } |
215 | 222 | ||
@@ -227,6 +234,7 @@ process_arguments (int argc, char **argv) | |||
227 | {"percpu", no_argument, 0, 'r'}, | 234 | {"percpu", no_argument, 0, 'r'}, |
228 | {"version", no_argument, 0, 'V'}, | 235 | {"version", no_argument, 0, 'V'}, |
229 | {"help", no_argument, 0, 'h'}, | 236 | {"help", no_argument, 0, 'h'}, |
237 | {"procs-to-show", required_argument, 0, 'n'}, | ||
230 | {0, 0, 0, 0} | 238 | {0, 0, 0, 0} |
231 | }; | 239 | }; |
232 | 240 | ||
@@ -234,7 +242,7 @@ process_arguments (int argc, char **argv) | |||
234 | return ERROR; | 242 | return ERROR; |
235 | 243 | ||
236 | while (1) { | 244 | while (1) { |
237 | c = getopt_long (argc, argv, "Vhrc:w:", longopts, &option); | 245 | c = getopt_long (argc, argv, "Vhrc:w:n:", longopts, &option); |
238 | 246 | ||
239 | if (c == -1 || c == EOF) | 247 | if (c == -1 || c == EOF) |
240 | break; | 248 | break; |
@@ -255,6 +263,9 @@ process_arguments (int argc, char **argv) | |||
255 | case 'h': /* help */ | 263 | case 'h': /* help */ |
256 | print_help (); | 264 | print_help (); |
257 | exit (STATE_UNKNOWN); | 265 | exit (STATE_UNKNOWN); |
266 | case 'n': | ||
267 | n_procs_to_show = atoi(optarg); | ||
268 | break; | ||
258 | case '?': /* help */ | 269 | case '?': /* help */ |
259 | usage5 (); | 270 | usage5 (); |
260 | } | 271 | } |
@@ -324,6 +335,9 @@ print_help (void) | |||
324 | printf (" %s\n", _("the load average format is the same used by \"uptime\" and \"w\"")); | 335 | printf (" %s\n", _("the load average format is the same used by \"uptime\" and \"w\"")); |
325 | printf (" %s\n", "-r, --percpu"); | 336 | printf (" %s\n", "-r, --percpu"); |
326 | printf (" %s\n", _("Divide the load averages by the number of CPUs (when possible)")); | 337 | printf (" %s\n", _("Divide the load averages by the number of CPUs (when possible)")); |
338 | printf (" %s\n", "-n, --procs-to-show=NUMBER_OF_PROCS"); | ||
339 | printf (" %s\n", _("Number of processes to show when printing the top consuming processes.")); | ||
340 | printf (" %s\n", _("NUMBER_OF_PROCS=0 disables this feature. Default value is 0")); | ||
327 | 341 | ||
328 | printf (UT_SUPPORT); | 342 | printf (UT_SUPPORT); |
329 | } | 343 | } |
@@ -332,5 +346,48 @@ void | |||
332 | print_usage (void) | 346 | print_usage (void) |
333 | { | 347 | { |
334 | printf ("%s\n", _("Usage:")); | 348 | printf ("%s\n", _("Usage:")); |
335 | printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15\n", progname); | 349 | printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15 [-n NUMBER_OF_PROCS]\n", progname); |
350 | } | ||
351 | |||
352 | #ifdef PS_USES_PROCPCPU | ||
353 | int cmpstringp(const void *p1, const void *p2) { | ||
354 | int procuid = 0; | ||
355 | int procpid = 0; | ||
356 | int procppid = 0; | ||
357 | int procvsz = 0; | ||
358 | int procrss = 0; | ||
359 | float procpcpu = 0; | ||
360 | char procstat[8]; | ||
361 | #ifdef PS_USES_PROCETIME | ||
362 | char procetime[MAX_INPUT_BUFFER]; | ||
363 | #endif /* PS_USES_PROCETIME */ | ||
364 | char procprog[MAX_INPUT_BUFFER]; | ||
365 | int pos; | ||
366 | sscanf (* (char * const *) p1, PS_FORMAT, PS_VARLIST); | ||
367 | float procpcpu1 = procpcpu; | ||
368 | sscanf (* (char * const *) p2, PS_FORMAT, PS_VARLIST); | ||
369 | return procpcpu1 < procpcpu; | ||
370 | } | ||
371 | #endif /* PS_USES_PROCPCPU */ | ||
372 | |||
373 | static int print_top_consuming_processes() { | ||
374 | int i = 0; | ||
375 | struct output chld_out, chld_err; | ||
376 | if(np_runcmd(PS_COMMAND, &chld_out, &chld_err, 0) != 0){ | ||
377 | fprintf(stderr, _("'%s' exited with non-zero status.\n"), PS_COMMAND); | ||
378 | return STATE_UNKNOWN; | ||
379 | } | ||
380 | if (chld_out.lines < 2) { | ||
381 | fprintf(stderr, _("some error occurred getting procs list.\n")); | ||
382 | return STATE_UNKNOWN; | ||
383 | } | ||
384 | #ifdef PS_USES_PROCPCPU | ||
385 | qsort(chld_out.line + 1, chld_out.lines - 1, sizeof(char*), cmpstringp); | ||
386 | #endif /* PS_USES_PROCPCPU */ | ||
387 | int lines_to_show = chld_out.lines < (n_procs_to_show + 1) | ||
388 | ? chld_out.lines : n_procs_to_show + 1; | ||
389 | for (i = 0; i < lines_to_show; i += 1) { | ||
390 | printf("%s\n", chld_out.line[i]); | ||
391 | } | ||
392 | return OK; | ||
336 | } | 393 | } |
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 5773afd9..0cba50e6 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c | |||
@@ -379,6 +379,9 @@ process_arguments (int argc, char **argv) | |||
379 | if (is_host (optarg)) { | 379 | if (is_host (optarg)) { |
380 | db_host = optarg; | 380 | db_host = optarg; |
381 | } | 381 | } |
382 | else if (*optarg == '/') { | ||
383 | db_socket = optarg; | ||
384 | } | ||
382 | else { | 385 | else { |
383 | usage2 (_("Invalid hostname/address"), optarg); | 386 | usage2 (_("Invalid hostname/address"), optarg); |
384 | } | 387 | } |
diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c index 49a14dd3..ac2fb15d 100644 --- a/plugins/check_mysql_query.c +++ b/plugins/check_mysql_query.c | |||
@@ -136,18 +136,18 @@ main (int argc, char **argv) | |||
136 | die (STATE_CRITICAL, "QUERY %s: Fetch row error - %s\n", _("CRITICAL"), error); | 136 | die (STATE_CRITICAL, "QUERY %s: Fetch row error - %s\n", _("CRITICAL"), error); |
137 | } | 137 | } |
138 | 138 | ||
139 | /* free the result */ | ||
140 | mysql_free_result (res); | ||
141 | |||
142 | /* close the connection */ | ||
143 | mysql_close (&mysql); | ||
144 | |||
145 | if (! is_numeric(row[0])) { | 139 | if (! is_numeric(row[0])) { |
146 | die (STATE_CRITICAL, "QUERY %s: %s - '%s'\n", _("CRITICAL"), _("Is not a numeric"), row[0]); | 140 | die (STATE_CRITICAL, "QUERY %s: %s - '%s'\n", _("CRITICAL"), _("Is not a numeric"), row[0]); |
147 | } | 141 | } |
148 | 142 | ||
149 | value = strtod(row[0], NULL); | 143 | value = strtod(row[0], NULL); |
150 | 144 | ||
145 | /* free the result */ | ||
146 | mysql_free_result (res); | ||
147 | |||
148 | /* close the connection */ | ||
149 | mysql_close (&mysql); | ||
150 | |||
151 | if (verbose >= 3) | 151 | if (verbose >= 3) |
152 | printf("mysql result: %f\n", value); | 152 | printf("mysql result: %f\n", value); |
153 | 153 | ||
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index 5cd47093..b8fc5f1d 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c | |||
@@ -34,6 +34,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
34 | 34 | ||
35 | #include "common.h" | 35 | #include "common.h" |
36 | #include "utils.h" | 36 | #include "utils.h" |
37 | #include "utils_cmd.h" | ||
37 | 38 | ||
38 | #include "netutils.h" | 39 | #include "netutils.h" |
39 | #include <libpq-fe.h> | 40 | #include <libpq-fe.h> |
@@ -346,7 +347,7 @@ process_arguments (int argc, char **argv) | |||
346 | if (!is_pg_dbname (optarg)) /* checks length and valid chars */ | 347 | if (!is_pg_dbname (optarg)) /* checks length and valid chars */ |
347 | usage2 (_("Database name is not valid"), optarg); | 348 | usage2 (_("Database name is not valid"), optarg); |
348 | else /* we know length, and know optarg is terminated, so us strcpy */ | 349 | else /* we know length, and know optarg is terminated, so us strcpy */ |
349 | strcpy (dbName, optarg); | 350 | snprintf(dbName, NAMEDATALEN, "%s", optarg); |
350 | break; | 351 | break; |
351 | case 'l': /* login name */ | 352 | case 'l': /* login name */ |
352 | if (!is_pg_logname (optarg)) | 353 | if (!is_pg_logname (optarg)) |
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 4bcc56bc..f7917c34 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
@@ -764,6 +764,11 @@ be the total number of running processes\n\n")); | |||
764 | printf (" %s\n", "check_procs -w 2:2 -c 2:1024 -C portsentry"); | 764 | printf (" %s\n", "check_procs -w 2:2 -c 2:1024 -C portsentry"); |
765 | printf (" %s\n", _("Warning if not two processes with command name portsentry.")); | 765 | printf (" %s\n", _("Warning if not two processes with command name portsentry.")); |
766 | printf (" %s\n\n", _("Critical if < 2 or > 1024 processes")); | 766 | printf (" %s\n\n", _("Critical if < 2 or > 1024 processes")); |
767 | printf (" %s\n", "check_procs -c 1: -C sshd"); | ||
768 | printf (" %s\n", _("Critical if not at least 1 process with command sshd")); | ||
769 | printf (" %s\n", "check_procs -w 1024 -c 1: -C sshd"); | ||
770 | printf (" %s\n", _("Warning if > 1024 processes with command name sshd.")); | ||
771 | printf (" %s\n\n", _("Critical if < 1 processes with command name sshd.")); | ||
767 | printf (" %s\n", "check_procs -w 10 -a '/usr/local/bin/perl' -u root"); | 772 | printf (" %s\n", "check_procs -w 10 -a '/usr/local/bin/perl' -u root"); |
768 | printf (" %s\n", _("Warning alert if > 10 processes with command arguments containing")); | 773 | printf (" %s\n", _("Warning alert if > 10 processes with command arguments containing")); |
769 | printf (" %s\n\n", _("'/usr/local/bin/perl' and owned by root")); | 774 | printf (" %s\n\n", _("'/usr/local/bin/perl' and owned by root")); |
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) | |||
293 | printf("%s", buffer); | 293 | printf("%s", buffer); |
294 | } | 294 | } |
295 | 295 | ||
296 | n = 0; | ||
296 | while (n < ncommands) { | 297 | while (n < ncommands) { |
297 | xasprintf (&cmd_str, "%s%s", commands[n], "\r\n"); | 298 | xasprintf (&cmd_str, "%s%s", commands[n], "\r\n"); |
298 | my_send(cmd_str, strlen(cmd_str)); | 299 | my_send(cmd_str, strlen(cmd_str)); |
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index da9638c4..afc568b2 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -576,6 +576,9 @@ main (int argc, char **argv) | |||
576 | len = sizeof(perfstr)-strlen(perfstr)-1; | 576 | len = sizeof(perfstr)-strlen(perfstr)-1; |
577 | strncat(perfstr, show, len>ptr-show ? ptr-show : len); | 577 | strncat(perfstr, show, len>ptr-show ? ptr-show : len); |
578 | 578 | ||
579 | if (type) | ||
580 | strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); | ||
581 | |||
579 | if (warning_thresholds) { | 582 | if (warning_thresholds) { |
580 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | 583 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); |
581 | strncat(perfstr, warning_thresholds, sizeof(perfstr)-strlen(perfstr)-1); | 584 | strncat(perfstr, warning_thresholds, sizeof(perfstr)-strlen(perfstr)-1); |
@@ -588,8 +591,6 @@ main (int argc, char **argv) | |||
588 | strncat(perfstr, critical_thresholds, sizeof(perfstr)-strlen(perfstr)-1); | 591 | strncat(perfstr, critical_thresholds, sizeof(perfstr)-strlen(perfstr)-1); |
589 | } | 592 | } |
590 | 593 | ||
591 | if (type) | ||
592 | strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); | ||
593 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); | 594 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); |
594 | } | 595 | } |
595 | } | 596 | } |
@@ -1207,8 +1208,9 @@ print_help (void) | |||
1207 | printf (" %s\n", _("Separates output on multiple OID requests")); | 1208 | printf (" %s\n", _("Separates output on multiple OID requests")); |
1208 | 1209 | ||
1209 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 1210 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
1211 | printf (" %s\n", _("NOTE the final timeout value is calculated using this formula: timeout_interval * retries + 5")); | ||
1210 | printf (" %s\n", "-e, --retries=INTEGER"); | 1212 | printf (" %s\n", "-e, --retries=INTEGER"); |
1211 | printf (" %s\n", _("Number of retries to be used in the requests")); | 1213 | printf (" %s%i\n", _("Number of retries to be used in the requests, default: "), DEFAULT_RETRIES); |
1212 | 1214 | ||
1213 | printf (" %s\n", "-O, --perf-oids"); | 1215 | printf (" %s\n", "-O, --perf-oids"); |
1214 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); | 1216 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); |
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 4d5a4071..0ff0c770 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c | |||
@@ -51,7 +51,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
51 | # define SWAP_CONVERSION 1 | 51 | # define SWAP_CONVERSION 1 |
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | int check_swap (int usp, float free_swap_mb); | 54 | int check_swap (int usp, float free_swap_mb, float total_swap_mb); |
55 | int process_arguments (int argc, char **argv); | 55 | int process_arguments (int argc, char **argv); |
56 | int validate_arguments (void); | 56 | int validate_arguments (void); |
57 | void print_usage (void); | 57 | void print_usage (void); |
@@ -128,7 +128,7 @@ main (int argc, char **argv) | |||
128 | percent=100.0; | 128 | percent=100.0; |
129 | else | 129 | else |
130 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); | 130 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); |
131 | result = max_state (result, check_swap (percent, dskfree_mb)); | 131 | result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb)); |
132 | if (verbose) | 132 | if (verbose) |
133 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); | 133 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); |
134 | } | 134 | } |
@@ -227,7 +227,7 @@ main (int argc, char **argv) | |||
227 | free_swap_mb += dskfree_mb; | 227 | free_swap_mb += dskfree_mb; |
228 | if (allswaps) { | 228 | if (allswaps) { |
229 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); | 229 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); |
230 | result = max_state (result, check_swap (percent, dskfree_mb)); | 230 | result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb)); |
231 | if (verbose) | 231 | if (verbose) |
232 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); | 232 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); |
233 | } | 233 | } |
@@ -289,7 +289,7 @@ main (int argc, char **argv) | |||
289 | 289 | ||
290 | if(allswaps && dsktotal_mb > 0){ | 290 | if(allswaps && dsktotal_mb > 0){ |
291 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); | 291 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); |
292 | result = max_state (result, check_swap (percent, dskfree_mb)); | 292 | result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb)); |
293 | if (verbose) { | 293 | if (verbose) { |
294 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); | 294 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); |
295 | } | 295 | } |
@@ -328,7 +328,7 @@ main (int argc, char **argv) | |||
328 | 328 | ||
329 | if(allswaps && dsktotal_mb > 0){ | 329 | if(allswaps && dsktotal_mb > 0){ |
330 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); | 330 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); |
331 | result = max_state (result, check_swap (percent, dskfree_mb)); | 331 | result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb)); |
332 | if (verbose) { | 332 | if (verbose) { |
333 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); | 333 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); |
334 | } | 334 | } |
@@ -355,7 +355,7 @@ main (int argc, char **argv) | |||
355 | status = "- Swap is either disabled, not present, or of zero size. "; | 355 | status = "- Swap is either disabled, not present, or of zero size. "; |
356 | } | 356 | } |
357 | 357 | ||
358 | result = max_state (result, check_swap (percent_used, free_swap_mb)); | 358 | result = max_state (result, check_swap (percent_used, free_swap_mb, total_swap_mb)); |
359 | printf (_("SWAP %s - %d%% free (%d MB out of %d MB) %s|"), | 359 | printf (_("SWAP %s - %d%% free (%d MB out of %d MB) %s|"), |
360 | state_text (result), | 360 | state_text (result), |
361 | (100 - percent_used), (int) free_swap_mb, (int) total_swap_mb, status); | 361 | (100 - percent_used), (int) free_swap_mb, (int) total_swap_mb, status); |
@@ -372,10 +372,10 @@ main (int argc, char **argv) | |||
372 | 372 | ||
373 | 373 | ||
374 | int | 374 | int |
375 | check_swap (int usp, float free_swap_mb) | 375 | check_swap (int usp, float free_swap_mb, float total_swap_mb) |
376 | { | 376 | { |
377 | 377 | ||
378 | if (!free_swap_mb) return no_swap_state; | 378 | if (!total_swap_mb) return no_swap_state; |
379 | 379 | ||
380 | int result = STATE_UNKNOWN; | 380 | int result = STATE_UNKNOWN; |
381 | float free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ | 381 | float free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ |
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index 61333bd7..1365b9cb 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c | |||
@@ -86,6 +86,11 @@ static char buffer[MAXBUF]; | |||
86 | static int expect_mismatch_state = STATE_WARNING; | 86 | static int expect_mismatch_state = STATE_WARNING; |
87 | static int match_flags = NP_MATCH_EXACT; | 87 | static int match_flags = NP_MATCH_EXACT; |
88 | 88 | ||
89 | #ifdef HAVE_SSL | ||
90 | static char *sni = NULL; | ||
91 | static int sni_specified = FALSE; | ||
92 | #endif | ||
93 | |||
89 | #define FLAG_SSL 0x01 | 94 | #define FLAG_SSL 0x01 |
90 | #define FLAG_VERBOSE 0x02 | 95 | #define FLAG_VERBOSE 0x02 |
91 | #define FLAG_TIME_WARN 0x04 | 96 | #define FLAG_TIME_WARN 0x04 |
@@ -241,7 +246,7 @@ main (int argc, char **argv) | |||
241 | 246 | ||
242 | #ifdef HAVE_SSL | 247 | #ifdef HAVE_SSL |
243 | if (flags & FLAG_SSL){ | 248 | if (flags & FLAG_SSL){ |
244 | result = np_net_ssl_init(sd); | 249 | result = np_net_ssl_init_with_hostname(sd, (sni_specified ? sni : NULL)); |
245 | if (result == STATE_OK && check_cert == TRUE) { | 250 | if (result == STATE_OK && check_cert == TRUE) { |
246 | result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); | 251 | result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); |
247 | } | 252 | } |
@@ -401,6 +406,10 @@ process_arguments (int argc, char **argv) | |||
401 | int escape = 0; | 406 | int escape = 0; |
402 | char *temp; | 407 | char *temp; |
403 | 408 | ||
409 | enum { | ||
410 | SNI_OPTION = CHAR_MAX + 1 | ||
411 | }; | ||
412 | |||
404 | int option = 0; | 413 | int option = 0; |
405 | static struct option longopts[] = { | 414 | static struct option longopts[] = { |
406 | {"hostname", required_argument, 0, 'H'}, | 415 | {"hostname", required_argument, 0, 'H'}, |
@@ -427,6 +436,7 @@ process_arguments (int argc, char **argv) | |||
427 | {"version", no_argument, 0, 'V'}, | 436 | {"version", no_argument, 0, 'V'}, |
428 | {"help", no_argument, 0, 'h'}, | 437 | {"help", no_argument, 0, 'h'}, |
429 | {"ssl", no_argument, 0, 'S'}, | 438 | {"ssl", no_argument, 0, 'S'}, |
439 | {"sni", required_argument, 0, SNI_OPTION}, | ||
430 | {"certificate", required_argument, 0, 'D'}, | 440 | {"certificate", required_argument, 0, 'D'}, |
431 | {0, 0, 0, 0} | 441 | {0, 0, 0, 0} |
432 | }; | 442 | }; |
@@ -604,6 +614,15 @@ process_arguments (int argc, char **argv) | |||
604 | die (STATE_UNKNOWN, _("Invalid option - SSL is not available")); | 614 | die (STATE_UNKNOWN, _("Invalid option - SSL is not available")); |
605 | #endif | 615 | #endif |
606 | break; | 616 | break; |
617 | case SNI_OPTION: | ||
618 | #ifdef HAVE_SSL | ||
619 | flags |= FLAG_SSL; | ||
620 | sni_specified = TRUE; | ||
621 | sni = optarg; | ||
622 | #else | ||
623 | die (STATE_UNKNOWN, _("Invalid option - SSL is not available")); | ||
624 | #endif | ||
625 | break; | ||
607 | case 'A': | 626 | case 'A': |
608 | match_flags |= NP_MATCH_ALL; | 627 | match_flags |= NP_MATCH_ALL; |
609 | break; | 628 | break; |
@@ -671,6 +690,8 @@ print_help (void) | |||
671 | printf (" %s\n", _("1st is #days for warning, 2nd is critical (if not specified - 0).")); | 690 | printf (" %s\n", _("1st is #days for warning, 2nd is critical (if not specified - 0).")); |
672 | printf (" %s\n", "-S, --ssl"); | 691 | printf (" %s\n", "-S, --ssl"); |
673 | printf (" %s\n", _("Use SSL for the connection.")); | 692 | printf (" %s\n", _("Use SSL for the connection.")); |
693 | printf (" %s\n", "--sni=STRING"); | ||
694 | printf (" %s\n", _("SSL server_name")); | ||
674 | #endif | 695 | #endif |
675 | 696 | ||
676 | printf (UT_WARN_CRIT); | 697 | printf (UT_WARN_CRIT); |
diff --git a/plugins/common.h b/plugins/common.h index 6bf4fca4..0f08e2f6 100644 --- a/plugins/common.h +++ b/plugins/common.h | |||
@@ -225,4 +225,18 @@ enum { | |||
225 | # define __attribute__(x) /* do nothing */ | 225 | # define __attribute__(x) /* do nothing */ |
226 | #endif | 226 | #endif |
227 | 227 | ||
228 | /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX. | ||
229 | * If that fails and the macro isn't defined, we fall back to an educated | ||
230 | * guess. There's no guarantee that our guess is adequate and the program | ||
231 | * will die with SIGSEGV if it isn't and the upper boundary is breached. */ | ||
232 | #define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */ | ||
233 | #define MAXFD_LIMIT 8192 /* upper limit of open files */ | ||
234 | #ifdef _SC_OPEN_MAX | ||
235 | static long maxfd = 0; | ||
236 | #elif defined(OPEN_MAX) | ||
237 | # define maxfd OPEN_MAX | ||
238 | #else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */ | ||
239 | # define maxfd DEFAULT_MAXFD | ||
240 | #endif | ||
241 | |||
228 | #endif /* _COMMON_H_ */ | 242 | #endif /* _COMMON_H_ */ |
diff --git a/plugins/picohttpparser/Makefile.am b/plugins/picohttpparser/Makefile.am new file mode 100644 index 00000000..87e05313 --- /dev/null +++ b/plugins/picohttpparser/Makefile.am | |||
@@ -0,0 +1,3 @@ | |||
1 | noinst_LIBRARIES = libpicohttpparser.a | ||
2 | |||
3 | libpicohttpparser_a_SOURCES = picohttpparser.c picohttpparser.h | ||
diff --git a/plugins/picohttpparser/picohttpparser.c b/plugins/picohttpparser/picohttpparser.c new file mode 100644 index 00000000..74ccc3ef --- /dev/null +++ b/plugins/picohttpparser/picohttpparser.c | |||
@@ -0,0 +1,645 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2009-2014 Kazuho Oku, Tokuhiro Matsuno, Daisuke Murase, | ||
3 | * Shigeo Mitsunari | ||
4 | * | ||
5 | * The software is licensed under either the MIT License (below) or the Perl | ||
6 | * license. | ||
7 | * | ||
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
9 | * of this software and associated documentation files (the "Software"), to | ||
10 | * deal in the Software without restriction, including without limitation the | ||
11 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
12 | * sell copies of the Software, and to permit persons to whom the Software is | ||
13 | * furnished to do so, subject to the following conditions: | ||
14 | * | ||
15 | * The above copyright notice and this permission notice shall be included in | ||
16 | * all copies or substantial portions of the Software. | ||
17 | * | ||
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
24 | * IN THE SOFTWARE. | ||
25 | */ | ||
26 | |||
27 | #include <assert.h> | ||
28 | #include <stddef.h> | ||
29 | #include <string.h> | ||
30 | #ifdef __SSE4_2__ | ||
31 | #ifdef _MSC_VER | ||
32 | #include <nmmintrin.h> | ||
33 | #else | ||
34 | #include <x86intrin.h> | ||
35 | #endif | ||
36 | #endif | ||
37 | #include "picohttpparser.h" | ||
38 | |||
39 | #if __GNUC__ >= 3 | ||
40 | #define likely(x) __builtin_expect(!!(x), 1) | ||
41 | #define unlikely(x) __builtin_expect(!!(x), 0) | ||
42 | #else | ||
43 | #define likely(x) (x) | ||
44 | #define unlikely(x) (x) | ||
45 | #endif | ||
46 | |||
47 | #ifdef _MSC_VER | ||
48 | #define ALIGNED(n) _declspec(align(n)) | ||
49 | #else | ||
50 | #define ALIGNED(n) __attribute__((aligned(n))) | ||
51 | #endif | ||
52 | |||
53 | #define IS_PRINTABLE_ASCII(c) ((unsigned char)(c)-040u < 0137u) | ||
54 | |||
55 | #define CHECK_EOF() \ | ||
56 | if (buf == buf_end) { \ | ||
57 | *ret = -2; \ | ||
58 | return NULL; \ | ||
59 | } | ||
60 | |||
61 | #define EXPECT_CHAR_NO_CHECK(ch) \ | ||
62 | if (*buf++ != ch) { \ | ||
63 | *ret = -1; \ | ||
64 | return NULL; \ | ||
65 | } | ||
66 | |||
67 | #define EXPECT_CHAR(ch) \ | ||
68 | CHECK_EOF(); \ | ||
69 | EXPECT_CHAR_NO_CHECK(ch); | ||
70 | |||
71 | #define ADVANCE_TOKEN(tok, toklen) \ | ||
72 | do { \ | ||
73 | const char *tok_start = buf; \ | ||
74 | static const char ALIGNED(16) ranges2[16] = "\000\040\177\177"; \ | ||
75 | int found2; \ | ||
76 | buf = findchar_fast(buf, buf_end, ranges2, 4, &found2); \ | ||
77 | if (!found2) { \ | ||
78 | CHECK_EOF(); \ | ||
79 | } \ | ||
80 | while (1) { \ | ||
81 | if (*buf == ' ') { \ | ||
82 | break; \ | ||
83 | } else if (unlikely(!IS_PRINTABLE_ASCII(*buf))) { \ | ||
84 | if ((unsigned char)*buf < '\040' || *buf == '\177') { \ | ||
85 | *ret = -1; \ | ||
86 | return NULL; \ | ||
87 | } \ | ||
88 | } \ | ||
89 | ++buf; \ | ||
90 | CHECK_EOF(); \ | ||
91 | } \ | ||
92 | tok = tok_start; \ | ||
93 | toklen = buf - tok_start; \ | ||
94 | } while (0) | ||
95 | |||
96 | static const char *token_char_map = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||
97 | "\0\1\0\1\1\1\1\1\0\0\1\1\0\1\1\0\1\1\1\1\1\1\1\1\1\1\0\0\0\0\0\0" | ||
98 | "\0\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\0\0\0\1\1" | ||
99 | "\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\0\1\0\1\0" | ||
100 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||
101 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||
102 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||
103 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; | ||
104 | |||
105 | static const char *findchar_fast(const char *buf, const char *buf_end, const char *ranges, size_t ranges_size, int *found) | ||
106 | { | ||
107 | *found = 0; | ||
108 | #if __SSE4_2__ | ||
109 | if (likely(buf_end - buf >= 16)) { | ||
110 | __m128i ranges16 = _mm_loadu_si128((const __m128i *)ranges); | ||
111 | |||
112 | size_t left = (buf_end - buf) & ~15; | ||
113 | do { | ||
114 | __m128i b16 = _mm_loadu_si128((const __m128i *)buf); | ||
115 | int r = _mm_cmpestri(ranges16, ranges_size, b16, 16, _SIDD_LEAST_SIGNIFICANT | _SIDD_CMP_RANGES | _SIDD_UBYTE_OPS); | ||
116 | if (unlikely(r != 16)) { | ||
117 | buf += r; | ||
118 | *found = 1; | ||
119 | break; | ||
120 | } | ||
121 | buf += 16; | ||
122 | left -= 16; | ||
123 | } while (likely(left != 0)); | ||
124 | } | ||
125 | #else | ||
126 | /* suppress unused parameter warning */ | ||
127 | (void)buf_end; | ||
128 | (void)ranges; | ||
129 | (void)ranges_size; | ||
130 | #endif | ||
131 | return buf; | ||
132 | } | ||
133 | |||
134 | static const char *get_token_to_eol(const char *buf, const char *buf_end, const char **token, size_t *token_len, int *ret) | ||
135 | { | ||
136 | const char *token_start = buf; | ||
137 | |||
138 | #ifdef __SSE4_2__ | ||
139 | static const char ALIGNED(16) ranges1[16] = "\0\010" /* allow HT */ | ||
140 | "\012\037" /* allow SP and up to but not including DEL */ | ||
141 | "\177\177"; /* allow chars w. MSB set */ | ||
142 | int found; | ||
143 | buf = findchar_fast(buf, buf_end, ranges1, 6, &found); | ||
144 | if (found) | ||
145 | goto FOUND_CTL; | ||
146 | #else | ||
147 | /* find non-printable char within the next 8 bytes, this is the hottest code; manually inlined */ | ||
148 | while (likely(buf_end - buf >= 8)) { | ||
149 | #define DOIT() \ | ||
150 | do { \ | ||
151 | if (unlikely(!IS_PRINTABLE_ASCII(*buf))) \ | ||
152 | goto NonPrintable; \ | ||
153 | ++buf; \ | ||
154 | } while (0) | ||
155 | DOIT(); | ||
156 | DOIT(); | ||
157 | DOIT(); | ||
158 | DOIT(); | ||
159 | DOIT(); | ||
160 | DOIT(); | ||
161 | DOIT(); | ||
162 | DOIT(); | ||
163 | #undef DOIT | ||
164 | continue; | ||
165 | NonPrintable: | ||
166 | if ((likely((unsigned char)*buf < '\040') && likely(*buf != '\011')) || unlikely(*buf == '\177')) { | ||
167 | goto FOUND_CTL; | ||
168 | } | ||
169 | ++buf; | ||
170 | } | ||
171 | #endif | ||
172 | for (;; ++buf) { | ||
173 | CHECK_EOF(); | ||
174 | if (unlikely(!IS_PRINTABLE_ASCII(*buf))) { | ||
175 | if ((likely((unsigned char)*buf < '\040') && likely(*buf != '\011')) || unlikely(*buf == '\177')) { | ||
176 | goto FOUND_CTL; | ||
177 | } | ||
178 | } | ||
179 | } | ||
180 | FOUND_CTL: | ||
181 | if (likely(*buf == '\015')) { | ||
182 | ++buf; | ||
183 | EXPECT_CHAR('\012'); | ||
184 | *token_len = buf - 2 - token_start; | ||
185 | } else if (*buf == '\012') { | ||
186 | *token_len = buf - token_start; | ||
187 | ++buf; | ||
188 | } else { | ||
189 | *ret = -1; | ||
190 | return NULL; | ||
191 | } | ||
192 | *token = token_start; | ||
193 | |||
194 | return buf; | ||
195 | } | ||
196 | |||
197 | static const char *is_complete(const char *buf, const char *buf_end, size_t last_len, int *ret) | ||
198 | { | ||
199 | int ret_cnt = 0; | ||
200 | buf = last_len < 3 ? buf : buf + last_len - 3; | ||
201 | |||
202 | while (1) { | ||
203 | CHECK_EOF(); | ||
204 | if (*buf == '\015') { | ||
205 | ++buf; | ||
206 | CHECK_EOF(); | ||
207 | EXPECT_CHAR('\012'); | ||
208 | ++ret_cnt; | ||
209 | } else if (*buf == '\012') { | ||
210 | ++buf; | ||
211 | ++ret_cnt; | ||
212 | } else { | ||
213 | ++buf; | ||
214 | ret_cnt = 0; | ||
215 | } | ||
216 | if (ret_cnt == 2) { | ||
217 | return buf; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | *ret = -2; | ||
222 | return NULL; | ||
223 | } | ||
224 | |||
225 | #define PARSE_INT(valp_, mul_) \ | ||
226 | if (*buf < '0' || '9' < *buf) { \ | ||
227 | buf++; \ | ||
228 | *ret = -1; \ | ||
229 | return NULL; \ | ||
230 | } \ | ||
231 | *(valp_) = (mul_) * (*buf++ - '0'); | ||
232 | |||
233 | #define PARSE_INT_3(valp_) \ | ||
234 | do { \ | ||
235 | int res_ = 0; \ | ||
236 | PARSE_INT(&res_, 100) \ | ||
237 | *valp_ = res_; \ | ||
238 | PARSE_INT(&res_, 10) \ | ||
239 | *valp_ += res_; \ | ||
240 | PARSE_INT(&res_, 1) \ | ||
241 | *valp_ += res_; \ | ||
242 | } while (0) | ||
243 | |||
244 | /* returned pointer is always within [buf, buf_end), or null */ | ||
245 | static const char *parse_http_version(const char *buf, const char *buf_end, int *minor_version, int *ret) | ||
246 | { | ||
247 | /* we want at least [HTTP/1.<two chars>] to try to parse */ | ||
248 | if (buf_end - buf < 9) { | ||
249 | *ret = -2; | ||
250 | return NULL; | ||
251 | } | ||
252 | EXPECT_CHAR_NO_CHECK('H'); | ||
253 | EXPECT_CHAR_NO_CHECK('T'); | ||
254 | EXPECT_CHAR_NO_CHECK('T'); | ||
255 | EXPECT_CHAR_NO_CHECK('P'); | ||
256 | EXPECT_CHAR_NO_CHECK('/'); | ||
257 | EXPECT_CHAR_NO_CHECK('1'); | ||
258 | EXPECT_CHAR_NO_CHECK('.'); | ||
259 | PARSE_INT(minor_version, 1); | ||
260 | return buf; | ||
261 | } | ||
262 | |||
263 | static const char *parse_headers(const char *buf, const char *buf_end, struct phr_header *headers, size_t *num_headers, | ||
264 | size_t max_headers, int *ret) | ||
265 | { | ||
266 | for (;; ++*num_headers) { | ||
267 | CHECK_EOF(); | ||
268 | if (*buf == '\015') { | ||
269 | ++buf; | ||
270 | EXPECT_CHAR('\012'); | ||
271 | break; | ||
272 | } else if (*buf == '\012') { | ||
273 | ++buf; | ||
274 | break; | ||
275 | } | ||
276 | if (*num_headers == max_headers) { | ||
277 | *ret = -1; | ||
278 | return NULL; | ||
279 | } | ||
280 | if (!(*num_headers != 0 && (*buf == ' ' || *buf == '\t'))) { | ||
281 | /* parsing name, but do not discard SP before colon, see | ||
282 | * http://www.mozilla.org/security/announce/2006/mfsa2006-33.html */ | ||
283 | headers[*num_headers].name = buf; | ||
284 | static const char ALIGNED(16) ranges1[] = "\x00 " /* control chars and up to SP */ | ||
285 | "\"\"" /* 0x22 */ | ||
286 | "()" /* 0x28,0x29 */ | ||
287 | ",," /* 0x2c */ | ||
288 | "//" /* 0x2f */ | ||
289 | ":@" /* 0x3a-0x40 */ | ||
290 | "[]" /* 0x5b-0x5d */ | ||
291 | "{\377"; /* 0x7b-0xff */ | ||
292 | int found; | ||
293 | buf = findchar_fast(buf, buf_end, ranges1, sizeof(ranges1) - 1, &found); | ||
294 | if (!found) { | ||
295 | CHECK_EOF(); | ||
296 | } | ||
297 | while (1) { | ||
298 | if (*buf == ':') { | ||
299 | break; | ||
300 | } else if (!token_char_map[(unsigned char)*buf]) { | ||
301 | *ret = -1; | ||
302 | return NULL; | ||
303 | } | ||
304 | ++buf; | ||
305 | CHECK_EOF(); | ||
306 | } | ||
307 | if ((headers[*num_headers].name_len = buf - headers[*num_headers].name) == 0) { | ||
308 | *ret = -1; | ||
309 | return NULL; | ||
310 | } | ||
311 | ++buf; | ||
312 | for (;; ++buf) { | ||
313 | CHECK_EOF(); | ||
314 | if (!(*buf == ' ' || *buf == '\t')) { | ||
315 | break; | ||
316 | } | ||
317 | } | ||
318 | } else { | ||
319 | headers[*num_headers].name = NULL; | ||
320 | headers[*num_headers].name_len = 0; | ||
321 | } | ||
322 | const char *value; | ||
323 | size_t value_len; | ||
324 | if ((buf = get_token_to_eol(buf, buf_end, &value, &value_len, ret)) == NULL) { | ||
325 | return NULL; | ||
326 | } | ||
327 | /* remove trailing SPs and HTABs */ | ||
328 | const char *value_end = value + value_len; | ||
329 | for (; value_end != value; --value_end) { | ||
330 | const char c = *(value_end - 1); | ||
331 | if (!(c == ' ' || c == '\t')) { | ||
332 | break; | ||
333 | } | ||
334 | } | ||
335 | headers[*num_headers].value = value; | ||
336 | headers[*num_headers].value_len = value_end - value; | ||
337 | } | ||
338 | return buf; | ||
339 | } | ||
340 | |||
341 | static const char *parse_request(const char *buf, const char *buf_end, const char **method, size_t *method_len, const char **path, | ||
342 | size_t *path_len, int *minor_version, struct phr_header *headers, size_t *num_headers, | ||
343 | size_t max_headers, int *ret) | ||
344 | { | ||
345 | /* skip first empty line (some clients add CRLF after POST content) */ | ||
346 | CHECK_EOF(); | ||
347 | if (*buf == '\015') { | ||
348 | ++buf; | ||
349 | EXPECT_CHAR('\012'); | ||
350 | } else if (*buf == '\012') { | ||
351 | ++buf; | ||
352 | } | ||
353 | |||
354 | /* parse request line */ | ||
355 | ADVANCE_TOKEN(*method, *method_len); | ||
356 | do { | ||
357 | ++buf; | ||
358 | } while (*buf == ' '); | ||
359 | ADVANCE_TOKEN(*path, *path_len); | ||
360 | do { | ||
361 | ++buf; | ||
362 | } while (*buf == ' '); | ||
363 | if (*method_len == 0 || *path_len == 0) { | ||
364 | *ret = -1; | ||
365 | return NULL; | ||
366 | } | ||
367 | if ((buf = parse_http_version(buf, buf_end, minor_version, ret)) == NULL) { | ||
368 | return NULL; | ||
369 | } | ||
370 | if (*buf == '\015') { | ||
371 | ++buf; | ||
372 | EXPECT_CHAR('\012'); | ||
373 | } else if (*buf == '\012') { | ||
374 | ++buf; | ||
375 | } else { | ||
376 | *ret = -1; | ||
377 | return NULL; | ||
378 | } | ||
379 | |||
380 | return parse_headers(buf, buf_end, headers, num_headers, max_headers, ret); | ||
381 | } | ||
382 | |||
383 | int phr_parse_request(const char *buf_start, size_t len, const char **method, size_t *method_len, const char **path, | ||
384 | size_t *path_len, int *minor_version, struct phr_header *headers, size_t *num_headers, size_t last_len) | ||
385 | { | ||
386 | const char *buf = buf_start, *buf_end = buf_start + len; | ||
387 | size_t max_headers = *num_headers; | ||
388 | int r; | ||
389 | |||
390 | *method = NULL; | ||
391 | *method_len = 0; | ||
392 | *path = NULL; | ||
393 | *path_len = 0; | ||
394 | *minor_version = -1; | ||
395 | *num_headers = 0; | ||
396 | |||
397 | /* if last_len != 0, check if the request is complete (a fast countermeasure | ||
398 | againt slowloris */ | ||
399 | if (last_len != 0 && is_complete(buf, buf_end, last_len, &r) == NULL) { | ||
400 | return r; | ||
401 | } | ||
402 | |||
403 | if ((buf = parse_request(buf, buf_end, method, method_len, path, path_len, minor_version, headers, num_headers, max_headers, | ||
404 | &r)) == NULL) { | ||
405 | return r; | ||
406 | } | ||
407 | |||
408 | return (int)(buf - buf_start); | ||
409 | } | ||
410 | |||
411 | static const char *parse_response(const char *buf, const char *buf_end, int *minor_version, int *status, const char **msg, | ||
412 | size_t *msg_len, struct phr_header *headers, size_t *num_headers, size_t max_headers, int *ret) | ||
413 | { | ||
414 | /* parse "HTTP/1.x" */ | ||
415 | if ((buf = parse_http_version(buf, buf_end, minor_version, ret)) == NULL) { | ||
416 | return NULL; | ||
417 | } | ||
418 | /* skip space */ | ||
419 | if (*buf != ' ') { | ||
420 | *ret = -1; | ||
421 | return NULL; | ||
422 | } | ||
423 | do { | ||
424 | ++buf; | ||
425 | } while (*buf == ' '); | ||
426 | /* parse status code, we want at least [:digit:][:digit:][:digit:]<other char> to try to parse */ | ||
427 | if (buf_end - buf < 4) { | ||
428 | *ret = -2; | ||
429 | return NULL; | ||
430 | } | ||
431 | PARSE_INT_3(status); | ||
432 | |||
433 | /* get message includig preceding space */ | ||
434 | if ((buf = get_token_to_eol(buf, buf_end, msg, msg_len, ret)) == NULL) { | ||
435 | return NULL; | ||
436 | } | ||
437 | if (*msg_len == 0) { | ||
438 | /* ok */ | ||
439 | } else if (**msg == ' ') { | ||
440 | /* remove preceding space */ | ||
441 | do { | ||
442 | ++*msg; | ||
443 | --*msg_len; | ||
444 | } while (**msg == ' '); | ||
445 | } else { | ||
446 | /* garbage found after status code */ | ||
447 | *ret = -1; | ||
448 | return NULL; | ||
449 | } | ||
450 | |||
451 | return parse_headers(buf, buf_end, headers, num_headers, max_headers, ret); | ||
452 | } | ||
453 | |||
454 | int phr_parse_response(const char *buf_start, size_t len, int *minor_version, int *status, const char **msg, size_t *msg_len, | ||
455 | struct phr_header *headers, size_t *num_headers, size_t last_len) | ||
456 | { | ||
457 | const char *buf = buf_start, *buf_end = buf + len; | ||
458 | size_t max_headers = *num_headers; | ||
459 | int r; | ||
460 | |||
461 | *minor_version = -1; | ||
462 | *status = 0; | ||
463 | *msg = NULL; | ||
464 | *msg_len = 0; | ||
465 | *num_headers = 0; | ||
466 | |||
467 | /* if last_len != 0, check if the response is complete (a fast countermeasure | ||
468 | against slowloris */ | ||
469 | if (last_len != 0 && is_complete(buf, buf_end, last_len, &r) == NULL) { | ||
470 | return r; | ||
471 | } | ||
472 | |||
473 | if ((buf = parse_response(buf, buf_end, minor_version, status, msg, msg_len, headers, num_headers, max_headers, &r)) == NULL) { | ||
474 | return r; | ||
475 | } | ||
476 | |||
477 | return (int)(buf - buf_start); | ||
478 | } | ||
479 | |||
480 | int phr_parse_headers(const char *buf_start, size_t len, struct phr_header *headers, size_t *num_headers, size_t last_len) | ||
481 | { | ||
482 | const char *buf = buf_start, *buf_end = buf + len; | ||
483 | size_t max_headers = *num_headers; | ||
484 | int r; | ||
485 | |||
486 | *num_headers = 0; | ||
487 | |||
488 | /* if last_len != 0, check if the response is complete (a fast countermeasure | ||
489 | against slowloris */ | ||
490 | if (last_len != 0 && is_complete(buf, buf_end, last_len, &r) == NULL) { | ||
491 | return r; | ||
492 | } | ||
493 | |||
494 | if ((buf = parse_headers(buf, buf_end, headers, num_headers, max_headers, &r)) == NULL) { | ||
495 | return r; | ||
496 | } | ||
497 | |||
498 | return (int)(buf - buf_start); | ||
499 | } | ||
500 | |||
501 | enum { | ||
502 | CHUNKED_IN_CHUNK_SIZE, | ||
503 | CHUNKED_IN_CHUNK_EXT, | ||
504 | CHUNKED_IN_CHUNK_DATA, | ||
505 | CHUNKED_IN_CHUNK_CRLF, | ||
506 | CHUNKED_IN_TRAILERS_LINE_HEAD, | ||
507 | CHUNKED_IN_TRAILERS_LINE_MIDDLE | ||
508 | }; | ||
509 | |||
510 | static int decode_hex(int ch) | ||
511 | { | ||
512 | if ('0' <= ch && ch <= '9') { | ||
513 | return ch - '0'; | ||
514 | } else if ('A' <= ch && ch <= 'F') { | ||
515 | return ch - 'A' + 0xa; | ||
516 | } else if ('a' <= ch && ch <= 'f') { | ||
517 | return ch - 'a' + 0xa; | ||
518 | } else { | ||
519 | return -1; | ||
520 | } | ||
521 | } | ||
522 | |||
523 | ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_t *_bufsz) | ||
524 | { | ||
525 | size_t dst = 0, src = 0, bufsz = *_bufsz; | ||
526 | ssize_t ret = -2; /* incomplete */ | ||
527 | |||
528 | while (1) { | ||
529 | switch (decoder->_state) { | ||
530 | case CHUNKED_IN_CHUNK_SIZE: | ||
531 | for (;; ++src) { | ||
532 | int v; | ||
533 | if (src == bufsz) | ||
534 | goto Exit; | ||
535 | if ((v = decode_hex(buf[src])) == -1) { | ||
536 | if (decoder->_hex_count == 0) { | ||
537 | ret = -1; | ||
538 | goto Exit; | ||
539 | } | ||
540 | break; | ||
541 | } | ||
542 | if (decoder->_hex_count == sizeof(size_t) * 2) { | ||
543 | ret = -1; | ||
544 | goto Exit; | ||
545 | } | ||
546 | decoder->bytes_left_in_chunk = decoder->bytes_left_in_chunk * 16 + v; | ||
547 | ++decoder->_hex_count; | ||
548 | } | ||
549 | decoder->_hex_count = 0; | ||
550 | decoder->_state = CHUNKED_IN_CHUNK_EXT; | ||
551 | /* fallthru */ | ||
552 | case CHUNKED_IN_CHUNK_EXT: | ||
553 | /* RFC 7230 A.2 "Line folding in chunk extensions is disallowed" */ | ||
554 | for (;; ++src) { | ||
555 | if (src == bufsz) | ||
556 | goto Exit; | ||
557 | if (buf[src] == '\012') | ||
558 | break; | ||
559 | } | ||
560 | ++src; | ||
561 | if (decoder->bytes_left_in_chunk == 0) { | ||
562 | if (decoder->consume_trailer) { | ||
563 | decoder->_state = CHUNKED_IN_TRAILERS_LINE_HEAD; | ||
564 | break; | ||
565 | } else { | ||
566 | goto Complete; | ||
567 | } | ||
568 | } | ||
569 | decoder->_state = CHUNKED_IN_CHUNK_DATA; | ||
570 | /* fallthru */ | ||
571 | case CHUNKED_IN_CHUNK_DATA: { | ||
572 | size_t avail = bufsz - src; | ||
573 | if (avail < decoder->bytes_left_in_chunk) { | ||
574 | if (dst != src) | ||
575 | memmove(buf + dst, buf + src, avail); | ||
576 | src += avail; | ||
577 | dst += avail; | ||
578 | decoder->bytes_left_in_chunk -= avail; | ||
579 | goto Exit; | ||
580 | } | ||
581 | if (dst != src) | ||
582 | memmove(buf + dst, buf + src, decoder->bytes_left_in_chunk); | ||
583 | src += decoder->bytes_left_in_chunk; | ||
584 | dst += decoder->bytes_left_in_chunk; | ||
585 | decoder->bytes_left_in_chunk = 0; | ||
586 | decoder->_state = CHUNKED_IN_CHUNK_CRLF; | ||
587 | } | ||
588 | /* fallthru */ | ||
589 | case CHUNKED_IN_CHUNK_CRLF: | ||
590 | for (;; ++src) { | ||
591 | if (src == bufsz) | ||
592 | goto Exit; | ||
593 | if (buf[src] != '\015') | ||
594 | break; | ||
595 | } | ||
596 | if (buf[src] != '\012') { | ||
597 | ret = -1; | ||
598 | goto Exit; | ||
599 | } | ||
600 | ++src; | ||
601 | decoder->_state = CHUNKED_IN_CHUNK_SIZE; | ||
602 | break; | ||
603 | case CHUNKED_IN_TRAILERS_LINE_HEAD: | ||
604 | for (;; ++src) { | ||
605 | if (src == bufsz) | ||
606 | goto Exit; | ||
607 | if (buf[src] != '\015') | ||
608 | break; | ||
609 | } | ||
610 | if (buf[src++] == '\012') | ||
611 | goto Complete; | ||
612 | decoder->_state = CHUNKED_IN_TRAILERS_LINE_MIDDLE; | ||
613 | /* fallthru */ | ||
614 | case CHUNKED_IN_TRAILERS_LINE_MIDDLE: | ||
615 | for (;; ++src) { | ||
616 | if (src == bufsz) | ||
617 | goto Exit; | ||
618 | if (buf[src] == '\012') | ||
619 | break; | ||
620 | } | ||
621 | ++src; | ||
622 | decoder->_state = CHUNKED_IN_TRAILERS_LINE_HEAD; | ||
623 | break; | ||
624 | default: | ||
625 | assert(!"decoder is corrupt"); | ||
626 | } | ||
627 | } | ||
628 | |||
629 | Complete: | ||
630 | ret = bufsz - src; | ||
631 | Exit: | ||
632 | if (dst != src) | ||
633 | memmove(buf + dst, buf + src, bufsz - src); | ||
634 | *_bufsz = dst; | ||
635 | return ret; | ||
636 | } | ||
637 | |||
638 | int phr_decode_chunked_is_in_data(struct phr_chunked_decoder *decoder) | ||
639 | { | ||
640 | return decoder->_state == CHUNKED_IN_CHUNK_DATA; | ||
641 | } | ||
642 | |||
643 | #undef CHECK_EOF | ||
644 | #undef EXPECT_CHAR | ||
645 | #undef ADVANCE_TOKEN | ||
diff --git a/plugins/picohttpparser/picohttpparser.h b/plugins/picohttpparser/picohttpparser.h new file mode 100644 index 00000000..0849f844 --- /dev/null +++ b/plugins/picohttpparser/picohttpparser.h | |||
@@ -0,0 +1,87 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2009-2014 Kazuho Oku, Tokuhiro Matsuno, Daisuke Murase, | ||
3 | * Shigeo Mitsunari | ||
4 | * | ||
5 | * The software is licensed under either the MIT License (below) or the Perl | ||
6 | * license. | ||
7 | * | ||
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
9 | * of this software and associated documentation files (the "Software"), to | ||
10 | * deal in the Software without restriction, including without limitation the | ||
11 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
12 | * sell copies of the Software, and to permit persons to whom the Software is | ||
13 | * furnished to do so, subject to the following conditions: | ||
14 | * | ||
15 | * The above copyright notice and this permission notice shall be included in | ||
16 | * all copies or substantial portions of the Software. | ||
17 | * | ||
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
24 | * IN THE SOFTWARE. | ||
25 | */ | ||
26 | |||
27 | #ifndef picohttpparser_h | ||
28 | #define picohttpparser_h | ||
29 | |||
30 | #include <sys/types.h> | ||
31 | |||
32 | #ifdef _MSC_VER | ||
33 | #define ssize_t intptr_t | ||
34 | #endif | ||
35 | |||
36 | #ifdef __cplusplus | ||
37 | extern "C" { | ||
38 | #endif | ||
39 | |||
40 | /* contains name and value of a header (name == NULL if is a continuing line | ||
41 | * of a multiline header */ | ||
42 | struct phr_header { | ||
43 | const char *name; | ||
44 | size_t name_len; | ||
45 | const char *value; | ||
46 | size_t value_len; | ||
47 | }; | ||
48 | |||
49 | /* returns number of bytes consumed if successful, -2 if request is partial, | ||
50 | * -1 if failed */ | ||
51 | int phr_parse_request(const char *buf, size_t len, const char **method, size_t *method_len, const char **path, size_t *path_len, | ||
52 | int *minor_version, struct phr_header *headers, size_t *num_headers, size_t last_len); | ||
53 | |||
54 | /* ditto */ | ||
55 | int phr_parse_response(const char *_buf, size_t len, int *minor_version, int *status, const char **msg, size_t *msg_len, | ||
56 | struct phr_header *headers, size_t *num_headers, size_t last_len); | ||
57 | |||
58 | /* ditto */ | ||
59 | int phr_parse_headers(const char *buf, size_t len, struct phr_header *headers, size_t *num_headers, size_t last_len); | ||
60 | |||
61 | /* should be zero-filled before start */ | ||
62 | struct phr_chunked_decoder { | ||
63 | size_t bytes_left_in_chunk; /* number of bytes left in current chunk */ | ||
64 | char consume_trailer; /* if trailing headers should be consumed */ | ||
65 | char _hex_count; | ||
66 | char _state; | ||
67 | }; | ||
68 | |||
69 | /* the function rewrites the buffer given as (buf, bufsz) removing the chunked- | ||
70 | * encoding headers. When the function returns without an error, bufsz is | ||
71 | * updated to the length of the decoded data available. Applications should | ||
72 | * repeatedly call the function while it returns -2 (incomplete) every time | ||
73 | * supplying newly arrived data. If the end of the chunked-encoded data is | ||
74 | * found, the function returns a non-negative number indicating the number of | ||
75 | * octets left undecoded at the tail of the supplied buffer. Returns -1 on | ||
76 | * error. | ||
77 | */ | ||
78 | ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_t *bufsz); | ||
79 | |||
80 | /* returns if the chunked decoder is in middle of chunked data */ | ||
81 | int phr_decode_chunked_is_in_data(struct phr_chunked_decoder *decoder); | ||
82 | |||
83 | #ifdef __cplusplus | ||
84 | } | ||
85 | #endif | ||
86 | |||
87 | #endif | ||
diff --git a/plugins/popen.c b/plugins/popen.c index 592263fd..9eb49b62 100644 --- a/plugins/popen.c +++ b/plugins/popen.c | |||
@@ -39,9 +39,9 @@ | |||
39 | *****************************************************************************/ | 39 | *****************************************************************************/ |
40 | 40 | ||
41 | #include "common.h" | 41 | #include "common.h" |
42 | #include "utils.h" | ||
42 | 43 | ||
43 | /* extern so plugin has pid to kill exec'd process on timeouts */ | 44 | /* extern so plugin has pid to kill exec'd process on timeouts */ |
44 | extern int timeout_interval; | ||
45 | extern pid_t *childpid; | 45 | extern pid_t *childpid; |
46 | extern int *child_stderr_array; | 46 | extern int *child_stderr_array; |
47 | extern FILE *child_process; | 47 | extern FILE *child_process; |
@@ -76,18 +76,9 @@ RETSIGTYPE popen_timeout_alarm_handler (int); | |||
76 | #define SIG_ERR ((Sigfunc *)-1) | 76 | #define SIG_ERR ((Sigfunc *)-1) |
77 | #endif | 77 | #endif |
78 | 78 | ||
79 | #define min(a,b) ((a) < (b) ? (a) : (b)) | ||
80 | #define max(a,b) ((a) > (b) ? (a) : (b)) | ||
81 | int open_max (void); /* {Prog openmax} */ | ||
82 | static void err_sys (const char *, ...) __attribute__((noreturn,format(printf, 1, 2))); | ||
83 | char *rtrim (char *, const char *); | ||
84 | 79 | ||
85 | char *pname = NULL; /* caller can set this from argv[0] */ | 80 | char *pname = NULL; /* caller can set this from argv[0] */ |
86 | 81 | ||
87 | /*int *childerr = NULL;*//* ptr to array allocated at run-time */ | ||
88 | /*extern pid_t *childpid = NULL; *//* ptr to array allocated at run-time */ | ||
89 | static int maxfd; /* from our open_max(), {Prog openmax} */ | ||
90 | |||
91 | #ifdef REDHAT_SPOPEN_ERROR | 82 | #ifdef REDHAT_SPOPEN_ERROR |
92 | static volatile int childtermd = 0; | 83 | static volatile int childtermd = 0; |
93 | #endif | 84 | #endif |
@@ -186,14 +177,15 @@ spopen (const char *cmdstring) | |||
186 | } | 177 | } |
187 | argv[i] = NULL; | 178 | argv[i] = NULL; |
188 | 179 | ||
180 | if(maxfd == 0) | ||
181 | maxfd = open_max(); | ||
182 | |||
189 | if (childpid == NULL) { /* first time through */ | 183 | if (childpid == NULL) { /* first time through */ |
190 | maxfd = open_max (); /* allocate zeroed out array for child pids */ | ||
191 | if ((childpid = calloc ((size_t)maxfd, sizeof (pid_t))) == NULL) | 184 | if ((childpid = calloc ((size_t)maxfd, sizeof (pid_t))) == NULL) |
192 | return (NULL); | 185 | return (NULL); |
193 | } | 186 | } |
194 | 187 | ||
195 | if (child_stderr_array == NULL) { /* first time through */ | 188 | if (child_stderr_array == NULL) { /* first time through */ |
196 | maxfd = open_max (); /* allocate zeroed out array for child pids */ | ||
197 | if ((child_stderr_array = calloc ((size_t)maxfd, sizeof (int))) == NULL) | 189 | if ((child_stderr_array = calloc ((size_t)maxfd, sizeof (int))) == NULL) |
198 | return (NULL); | 190 | return (NULL); |
199 | } | 191 | } |
@@ -273,15 +265,6 @@ spclose (FILE * fp) | |||
273 | return (1); | 265 | return (1); |
274 | } | 266 | } |
275 | 267 | ||
276 | #ifdef OPEN_MAX | ||
277 | static int openmax = OPEN_MAX; | ||
278 | #else | ||
279 | static int openmax = 0; | ||
280 | #endif | ||
281 | |||
282 | #define OPEN_MAX_GUESS 256 /* if OPEN_MAX is indeterminate */ | ||
283 | /* no guarantee this is adequate */ | ||
284 | |||
285 | #ifdef REDHAT_SPOPEN_ERROR | 268 | #ifdef REDHAT_SPOPEN_ERROR |
286 | RETSIGTYPE | 269 | RETSIGTYPE |
287 | popen_sigchld_handler (int signo) | 270 | popen_sigchld_handler (int signo) |
@@ -309,63 +292,3 @@ popen_timeout_alarm_handler (int signo) | |||
309 | exit (STATE_CRITICAL); | 292 | exit (STATE_CRITICAL); |
310 | } | 293 | } |
311 | } | 294 | } |
312 | |||
313 | |||
314 | int | ||
315 | open_max (void) | ||
316 | { | ||
317 | if (openmax == 0) { /* first time through */ | ||
318 | errno = 0; | ||
319 | if ((openmax = sysconf (_SC_OPEN_MAX)) < 0) { | ||
320 | if (errno == 0) | ||
321 | openmax = OPEN_MAX_GUESS; /* it's indeterminate */ | ||
322 | else | ||
323 | err_sys (_("sysconf error for _SC_OPEN_MAX")); | ||
324 | } | ||
325 | } | ||
326 | return (openmax); | ||
327 | } | ||
328 | |||
329 | |||
330 | /* Fatal error related to a system call. | ||
331 | * Print a message and die. */ | ||
332 | |||
333 | #define MAXLINE 2048 | ||
334 | static void | ||
335 | err_sys (const char *fmt, ...) | ||
336 | { | ||
337 | int errnoflag = 1; | ||
338 | int errno_save; | ||
339 | char buf[MAXLINE]; | ||
340 | |||
341 | va_list ap; | ||
342 | |||
343 | va_start (ap, fmt); | ||
344 | /* err_doit (1, fmt, ap); */ | ||
345 | errno_save = errno; /* value caller might want printed */ | ||
346 | vsprintf (buf, fmt, ap); | ||
347 | if (errnoflag) | ||
348 | sprintf (buf + strlen (buf), ": %s", strerror (errno_save)); | ||
349 | strcat (buf, "\n"); | ||
350 | fflush (stdout); /* in case stdout and stderr are the same */ | ||
351 | fputs (buf, stderr); | ||
352 | fflush (NULL); /* flushes all stdio output streams */ | ||
353 | va_end (ap); | ||
354 | exit (1); | ||
355 | } | ||
356 | |||
357 | char * | ||
358 | rtrim (char *str, const char *tok) | ||
359 | { | ||
360 | int i = 0; | ||
361 | int j = sizeof (str); | ||
362 | |||
363 | while (str != NULL && i < j) { | ||
364 | if (*(str + i) == *tok) { | ||
365 | sprintf (str + i, "%s", "\0"); | ||
366 | return str; | ||
367 | } | ||
368 | i++; | ||
369 | } | ||
370 | return str; | ||
371 | } | ||
diff --git a/plugins/popen.h b/plugins/popen.h index fc7e78e2..a5dd8fa7 100644 --- a/plugins/popen.h +++ b/plugins/popen.h | |||
@@ -7,7 +7,6 @@ FILE *spopen (const char *); | |||
7 | int spclose (FILE *); | 7 | int spclose (FILE *); |
8 | RETSIGTYPE popen_timeout_alarm_handler (int); | 8 | RETSIGTYPE popen_timeout_alarm_handler (int); |
9 | 9 | ||
10 | extern unsigned int timeout_interval; | ||
11 | pid_t *childpid=NULL; | 10 | pid_t *childpid=NULL; |
12 | int *child_stderr_array=NULL; | 11 | int *child_stderr_array=NULL; |
13 | FILE *child_process=NULL; | 12 | FILE *child_process=NULL; |
diff --git a/plugins/runcmd.c b/plugins/runcmd.c index 1a7c904f..a7155d27 100644 --- a/plugins/runcmd.c +++ b/plugins/runcmd.c | |||
@@ -67,19 +67,6 @@ | |||
67 | * occur in any number of threads simultaneously. */ | 67 | * occur in any number of threads simultaneously. */ |
68 | static pid_t *np_pids = NULL; | 68 | static pid_t *np_pids = NULL; |
69 | 69 | ||
70 | /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX. | ||
71 | * If that fails and the macro isn't defined, we fall back to an educated | ||
72 | * guess. There's no guarantee that our guess is adequate and the program | ||
73 | * will die with SIGSEGV if it isn't and the upper boundary is breached. */ | ||
74 | #ifdef _SC_OPEN_MAX | ||
75 | static long maxfd = 0; | ||
76 | #elif defined(OPEN_MAX) | ||
77 | # define maxfd OPEN_MAX | ||
78 | #else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */ | ||
79 | # define maxfd 256 | ||
80 | #endif | ||
81 | |||
82 | |||
83 | /** prototypes **/ | 70 | /** prototypes **/ |
84 | static int np_runcmd_open(const char *, int *, int *) | 71 | static int np_runcmd_open(const char *, int *, int *) |
85 | __attribute__((__nonnull__(1, 2, 3))); | 72 | __attribute__((__nonnull__(1, 2, 3))); |
@@ -99,14 +86,8 @@ extern void die (int, const char *, ...) | |||
99 | * through this api and thus achieve async-safeness throughout the api */ | 86 | * through this api and thus achieve async-safeness throughout the api */ |
100 | void np_runcmd_init(void) | 87 | void np_runcmd_init(void) |
101 | { | 88 | { |
102 | #ifndef maxfd | 89 | if(maxfd == 0) |
103 | if(!maxfd && (maxfd = sysconf(_SC_OPEN_MAX)) < 0) { | 90 | maxfd = open_max(); |
104 | /* possibly log or emit a warning here, since there's no | ||
105 | * guarantee that our guess at maxfd will be adequate */ | ||
106 | maxfd = 256; | ||
107 | } | ||
108 | #endif | ||
109 | |||
110 | if(!np_pids) np_pids = calloc(maxfd, sizeof(pid_t)); | 91 | if(!np_pids) np_pids = calloc(maxfd, sizeof(pid_t)); |
111 | } | 92 | } |
112 | 93 | ||
diff --git a/plugins/sslutils.c b/plugins/sslutils.c index e38947e3..14f6579d 100644 --- a/plugins/sslutils.c +++ b/plugins/sslutils.c | |||
@@ -1,29 +1,29 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring Plugins SSL utilities | 3 | * Monitoring Plugins SSL utilities |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2005-2010 Monitoring Plugins Development Team | 6 | * Copyright (c) 2005-2010 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains common functions for plugins that require SSL. | 10 | * This file contains common functions for plugins that require SSL. |
11 | * | 11 | * |
12 | * | 12 | * |
13 | * This program is free software: you can redistribute it and/or modify | 13 | * This program is free software: you can redistribute it and/or modify |
14 | * it under the terms of the GNU General Public License as published by | 14 | * it under the terms of the GNU General Public License as published by |
15 | * the Free Software Foundation, either version 3 of the License, or | 15 | * the Free Software Foundation, either version 3 of the License, or |
16 | * (at your option) any later version. | 16 | * (at your option) any later version. |
17 | * | 17 | * |
18 | * This program is distributed in the hope that it will be useful, | 18 | * This program is distributed in the hope that it will be useful, |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 | * GNU General Public License for more details. | 21 | * GNU General Public License for more details. |
22 | * | 22 | * |
23 | * You should have received a copy of the GNU General Public License | 23 | * You should have received a copy of the GNU General Public License |
24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
25 | * | 25 | * |
26 | * | 26 | * |
27 | *****************************************************************************/ | 27 | *****************************************************************************/ |
28 | 28 | ||
29 | #define MAX_CN_LENGTH 256 | 29 | #define MAX_CN_LENGTH 256 |
@@ -193,12 +193,22 @@ int np_net_ssl_read(void *buf, int num) { | |||
193 | 193 | ||
194 | int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){ | 194 | int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){ |
195 | # ifdef USE_OPENSSL | 195 | # ifdef USE_OPENSSL |
196 | X509 *certificate=NULL; | 196 | X509 *certificate = NULL; |
197 | certificate=SSL_get_peer_certificate(s); | ||
198 | return(np_net_ssl_check_certificate(certificate, days_till_exp_warn, days_till_exp_crit)); | ||
199 | # else /* ifndef USE_OPENSSL */ | ||
200 | printf("%s\n", _("WARNING - Plugin does not support checking certificates.")); | ||
201 | return STATE_WARNING; | ||
202 | # endif /* USE_OPENSSL */ | ||
203 | } | ||
204 | |||
205 | int np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_warn, int days_till_exp_crit){ | ||
206 | # ifdef USE_OPENSSL | ||
197 | X509_NAME *subj=NULL; | 207 | X509_NAME *subj=NULL; |
198 | char timestamp[50] = ""; | 208 | char timestamp[50] = ""; |
199 | char cn[MAX_CN_LENGTH]= ""; | 209 | char cn[MAX_CN_LENGTH]= ""; |
200 | char *tz; | 210 | char *tz; |
201 | 211 | ||
202 | int cnlen =-1; | 212 | int cnlen =-1; |
203 | int status=STATE_UNKNOWN; | 213 | int status=STATE_UNKNOWN; |
204 | 214 | ||
@@ -210,7 +220,6 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){ | |||
210 | int time_remaining; | 220 | int time_remaining; |
211 | time_t tm_t; | 221 | time_t tm_t; |
212 | 222 | ||
213 | certificate=SSL_get_peer_certificate(s); | ||
214 | if (!certificate) { | 223 | if (!certificate) { |
215 | printf("%s\n",_("CRITICAL - Cannot retrieve server certificate.")); | 224 | printf("%s\n",_("CRITICAL - Cannot retrieve server certificate.")); |
216 | return STATE_CRITICAL; | 225 | return STATE_CRITICAL; |
diff --git a/plugins/t/NPTest.cache.travis b/plugins/t/NPTest.cache.travis index 28437a00..9b9f8059 100644 --- a/plugins/t/NPTest.cache.travis +++ b/plugins/t/NPTest.cache.travis | |||
@@ -1,64 +1,54 @@ | |||
1 | { | 1 | { |
2 | 'MYSQL_LOGIN_DETAILS' => '-u root -d test', | ||
3 | 'NP_ALLOW_SUDO' => 'yes', | 2 | 'NP_ALLOW_SUDO' => 'yes', |
4 | 'NP_DNS_SERVER' => '8.8.8.8', | 3 | 'NP_DNS_SERVER' => '8.8.8.8', |
5 | 'NP_GOOD_NTP_SERVICE' => '', | 4 | 'NP_GOOD_NTP_SERVICE' => '', |
5 | 'NP_HOST_DHCP_RESPONSIVE' => '', | ||
6 | 'NP_HOST_HPJD_PORT_INVALID' => '161', | ||
7 | 'NP_HOST_HPJD_PORT_VALID' => '', | ||
8 | 'NP_HOSTNAME_INVALID_CIDR' => '130.133.8.39/30', | ||
6 | 'NP_HOSTNAME_INVALID' => 'nosuchhost', | 9 | 'NP_HOSTNAME_INVALID' => 'nosuchhost', |
7 | 'NP_HOSTNAME_VALID' => 'monitoring-plugins.org', | ||
8 | 'NP_HOSTNAME_VALID_IP' => '130.133.8.40', | ||
9 | 'NP_HOSTNAME_VALID_CIDR' => '130.133.8.41/30', | 10 | 'NP_HOSTNAME_VALID_CIDR' => '130.133.8.41/30', |
10 | 'NP_HOSTNAME_INVALID_CIDR' => '130.133.8.39/30', | 11 | 'NP_HOSTNAME_VALID_IP' => '130.133.8.40', |
12 | 'NP_HOSTNAME_VALID' => 'monitoring-plugins.org', | ||
11 | 'NP_HOSTNAME_VALID_REVERSE' => 'orwell.monitoring-plugins.org.', | 13 | 'NP_HOSTNAME_VALID_REVERSE' => 'orwell.monitoring-plugins.org.', |
12 | 'NP_HOST_DHCP_RESPONSIVE' => '', | ||
13 | 'NP_HOST_NONRESPONSIVE' => '10.0.0.1', | 14 | 'NP_HOST_NONRESPONSIVE' => '10.0.0.1', |
14 | 'NP_HOST_RESPONSIVE' => 'localhost', | 15 | 'NP_HOST_RESPONSIVE' => 'localhost', |
15 | 'NP_HOST_SMB' => '', | 16 | 'NP_HOST_SMB' => '', |
16 | 'NP_HOST_SNMP' => 'localhost', | 17 | 'NP_HOST_SNMP' => '', |
17 | 'NP_HOST_TCP_FTP' => '', | 18 | 'NP_HOST_TCP_FTP' => '', |
18 | 'NP_HOST_TCP_HPJD' => '', | 19 | 'NP_HOST_TCP_HPJD' => '', |
19 | 'NP_HOST_HPJD_PORT_INVALID' => '161', | ||
20 | 'NP_HOST_HPJD_PORT_VALID' => '', | ||
21 | 'NP_HOST_TCP_HTTP' => 'localhost', | ||
22 | 'NP_HOST_TCP_HTTP2' => 'test.monitoring-plugins.org', | 20 | 'NP_HOST_TCP_HTTP2' => 'test.monitoring-plugins.org', |
21 | 'NP_HOST_TCP_HTTP' => 'localhost', | ||
23 | 'NP_HOST_TCP_IMAP' => 'imap.web.de', | 22 | 'NP_HOST_TCP_IMAP' => 'imap.web.de', |
23 | 'NP_HOST_TCP_JABBER' => 'jabber.org', | ||
24 | 'NP_HOST_TCP_LDAP' => 'localhost', | 24 | 'NP_HOST_TCP_LDAP' => 'localhost', |
25 | 'NP_HOST_TCP_POP' => 'pop.web.de', | 25 | 'NP_HOST_TCP_POP' => 'pop.web.de', |
26 | 'NP_HOST_TCP_PROXY' => 'localhost', | ||
26 | 'NP_HOST_TCP_SMTP' => 'localhost', | 27 | 'NP_HOST_TCP_SMTP' => 'localhost', |
27 | 'NP_HOST_TCP_SMTP_NOTLS' => '', | 28 | 'NP_HOST_TCP_SMTP_NOTLS' => '', |
28 | 'NP_HOST_TCP_SMTP_TLS' => '', | 29 | 'NP_HOST_TCP_SMTP_TLS' => '', |
30 | 'NP_HOST_TLS_CERT' => 'localhost, | ||
31 | 'NP_HOST_TLS_HTTP' => 'localhost', | ||
32 | 'NP_HOST_UDP_TIME' => 'none', | ||
29 | 'NP_INTERNET_ACCESS' => 'yes', | 33 | 'NP_INTERNET_ACCESS' => 'yes', |
30 | 'NP_LDAP_BASE_DN' => 'cn=admin,dc=nodomain', | 34 | 'NP_LDAP_BASE_DN' => 'cn=admin,dc=nodomain', |
31 | 'NP_MOUNTPOINT2_VALID' => '/media/ramdisk', | 35 | 'NP_MOUNTPOINT2_VALID' => '/media/ramdisk', |
32 | 'NP_MOUNTPOINT_VALID' => '/', | 36 | 'NP_MOUNTPOINT_VALID' => '/', |
37 | 'NP_MYSQL_LOGIN_DETAILS' => '-u root -d test', | ||
33 | 'NP_MYSQL_SERVER' => 'localhost', | 38 | 'NP_MYSQL_SERVER' => 'localhost', |
34 | 'NP_HOST_UDP_TIME' => 'localhost', | ||
35 | 'NP_MYSQL_SOCKET' => '/var/run/mysqld/mysqld.sock', | 39 | 'NP_MYSQL_SOCKET' => '/var/run/mysqld/mysqld.sock', |
36 | 'NP_MYSQL_WITH_SLAVE' => '', | 40 | 'NP_MYSQL_WITH_SLAVE' => '', |
37 | 'NP_MYSQL_WITH_SLAVE_LOGIN' => '', | 41 | 'NP_MYSQL_WITH_SLAVE_LOGIN' => '', |
38 | 'NP_NO_NTP_SERVICE' => 'localhost', | 42 | 'NP_NO_NTP_SERVICE' => 'localhost', |
43 | 'NP_PORT_TCP_PROXY' => '3128', | ||
39 | 'NP_SMB_SHARE' => '', | 44 | 'NP_SMB_SHARE' => '', |
40 | 'NP_SMB_SHARE_DENY' => '', | 45 | 'NP_SMB_SHARE_DENY' => '', |
41 | 'NP_SMB_SHARE_SPC' => '', | 46 | 'NP_SMB_SHARE_SPC' => '', |
42 | 'NP_SMB_VALID_USER' => '', | 47 | 'NP_SMB_VALID_USER' => '', |
43 | 'NP_SMB_VALID_USER_PASS' => '', | 48 | 'NP_SMB_VALID_USER_PASS' => '', |
44 | 'NP_SNMP_COMMUNITY' => 'public', | 49 | 'NP_SNMP_COMMUNITY' => '', |
50 | 'NP_SNMP_USER' => '', | ||
45 | 'NP_SSH_CONFIGFILE' => '~/.ssh/config', | 51 | 'NP_SSH_CONFIGFILE' => '~/.ssh/config', |
46 | 'NP_SSH_HOST' => 'localhost', | 52 | 'NP_SSH_HOST' => 'localhost', |
47 | 'NP_SSH_IDENTITY' => '~/.ssh/id_dsa', | 53 | 'NP_SSH_IDENTITY' => '~/.ssh/id_rsa' |
48 | 'NP_HOST_TCP_JABBER' => 'jabber.org', | ||
49 | 'host_nonresponsive' => '10.0.0.1', | ||
50 | 'host_responsive' => 'localhost', | ||
51 | 'host_snmp' => '', | ||
52 | 'host_tcp_ftp' => '', | ||
53 | 'host_tcp_http' => 'localhost', | ||
54 | 'host_tcp_imap' => 'imap.nierlein.de', | ||
55 | 'host_tcp_smtp' => 'localhost', | ||
56 | 'hostname_invalid' => 'nosuchhost', | ||
57 | 'snmp_community' => '', | ||
58 | 'user_snmp' => '', | ||
59 | 'host_udp_time' => 'none', | ||
60 | 'host_tls_http' => 'localhost', | ||
61 | 'host_tls_cert' => 'localhost', | ||
62 | 'NP_HOST_TCP_PROXY' => 'localhost', | ||
63 | 'NP_PORT_TCP_PROXY' => '3128', | ||
64 | } | 54 | } |
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; | |||
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | # Required parameters | 11 | # Required parameters |
12 | my $ssh_service = getTestParameter( "NP_SSH_HOST", | 12 | my $ssh_service = getTestParameter("NP_SSH_HOST", "A host providing SSH service", "localhost"); |
13 | "A host providing SSH service", | 13 | my $ssh_key = getTestParameter("NP_SSH_IDENTITY", "A key allowing access to NP_SSH_HOST", "~/.ssh/id_dsa"); |
14 | "localhost"); | 14 | my $ssh_conf = getTestParameter( "NP_SSH_CONFIGFILE", "A config file with ssh settings", "~/.ssh/config"); |
15 | |||
16 | my $ssh_key = getTestParameter( "NP_SSH_IDENTITY", | ||
17 | "A key allowing access to NP_SSH_HOST", | ||
18 | "~/.ssh/id_dsa"); | ||
19 | |||
20 | my $ssh_conf = getTestParameter( "NP_SSH_CONFIGFILE", | ||
21 | "A config file with ssh settings", | ||
22 | "~/.ssh/config"); | ||
23 | 15 | ||
24 | 16 | ||
25 | plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_service && $ssh_key); | 17 | plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_service && $ssh_key); |
diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t new file mode 100644 index 00000000..cc65f037 --- /dev/null +++ b/plugins/t/check_curl.t | |||
@@ -0,0 +1,199 @@ | |||
1 | #! /usr/bin/perl -w -I .. | ||
2 | # | ||
3 | # HyperText Transfer Protocol (HTTP) Test via check_http | ||
4 | # | ||
5 | # | ||
6 | |||
7 | use strict; | ||
8 | use Test::More; | ||
9 | use POSIX qw/mktime strftime/; | ||
10 | use NPTest; | ||
11 | |||
12 | plan tests => 57; | ||
13 | |||
14 | my $successOutput = '/OK.*HTTP.*second/'; | ||
15 | |||
16 | my $res; | ||
17 | my $plugin = 'check_http'; | ||
18 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; | ||
19 | |||
20 | my $host_tcp_http = getTestParameter("NP_HOST_TCP_HTTP", "A host providing the HTTP Service (a web server)", "localhost"); | ||
21 | my $host_tls_http = getTestParameter("NP_HOST_TLS_HTTP", "A host providing the HTTPS Service (a tls web server)", "localhost"); | ||
22 | my $host_tls_cert = getTestParameter("NP_HOST_TLS_CERT", "the common name of the certificate.", "localhost"); | ||
23 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); | ||
24 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | ||
25 | my $internet_access = getTestParameter("NP_INTERNET_ACCESS", "Is this system directly connected to the internet?", "yes"); | ||
26 | my $host_tcp_http2 = getTestParameter("NP_HOST_TCP_HTTP2", "A host providing an index page containing the string 'monitoring'", "test.monitoring-plugins.org"); | ||
27 | my $host_tcp_proxy = getTestParameter("NP_HOST_TCP_PROXY", "A host providing a HTTP proxy with CONNECT support", "localhost"); | ||
28 | my $port_tcp_proxy = getTestParameter("NP_PORT_TCP_PROXY", "Port of the proxy with HTTP and CONNECT support", "3128"); | ||
29 | |||
30 | my $faketime = -x '/usr/bin/faketime' ? 1 : 0; | ||
31 | |||
32 | |||
33 | $res = NPTest->testCmd( | ||
34 | "./$plugin $host_tcp_http -wt 300 -ct 600" | ||
35 | ); | ||
36 | cmp_ok( $res->return_code, '==', 0, "Webserver $host_tcp_http responded" ); | ||
37 | like( $res->output, $successOutput, "Output OK" ); | ||
38 | |||
39 | $res = NPTest->testCmd( | ||
40 | "./$plugin $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there' -k 'carl:frown'" | ||
41 | ); | ||
42 | like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); | ||
43 | |||
44 | $res = NPTest->testCmd( | ||
45 | "./$plugin $host_nonresponsive -wt 1 -ct 2 -t 3" | ||
46 | ); | ||
47 | cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); | ||
48 | # was CRITICAL only, but both check_curl and check_http print HTTP CRITICAL (puzzle?!) | ||
49 | like( $res->output, "/HTTP CRITICAL - Invalid HTTP response received from host on port 80: cURL returned 28 - Connection timed out after/", "Output OK"); | ||
50 | |||
51 | $res = NPTest->testCmd( | ||
52 | "./$plugin $hostname_invalid -wt 1 -ct 2" | ||
53 | ); | ||
54 | cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" ); | ||
55 | # The first part of the message comes from the OS catalogue, so cannot check this. | ||
56 | # On Debian, it is Name or service not known, on Darwin, it is No address associated with nodename | ||
57 | # Is also possible to get a socket timeout if DNS is not responding fast enough | ||
58 | # cURL gives us consistent strings from it's own 'lib/strerror.c' | ||
59 | like( $res->output, "/cURL returned 6 - Could not resolve host:/", "Output OK"); | ||
60 | |||
61 | # host header checks | ||
62 | $res = NPTest->testCmd("./$plugin -v -H $host_tcp_http"); | ||
63 | like( $res->output, '/^Host: '.$host_tcp_http.'\s*$/ms', "Host Header OK" ); | ||
64 | like( $res->output, '/CURLOPT_URL: http:\/\/'.$host_tcp_http.':80\//ms', "Url OK" ); | ||
65 | |||
66 | $res = NPTest->testCmd("./$plugin -v -H $host_tcp_http -p 80"); | ||
67 | like( $res->output, '/^Host: '.$host_tcp_http.'\s*$/ms', "Host Header OK" ); | ||
68 | like( $res->output, '/CURLOPT_URL: http:\/\/'.$host_tcp_http.':80\//ms', "Url OK" ); | ||
69 | |||
70 | $res = NPTest->testCmd("./$plugin -v -H $host_tcp_http:8080 -p 80"); | ||
71 | like( $res->output, '/^Host: '.$host_tcp_http.':8080\s*$/ms', "Host Header OK" ); | ||
72 | like( $res->output, '/CURLOPT_URL: http:\/\/'.$host_tcp_http.':80\//ms', "Url OK" ); | ||
73 | |||
74 | $res = NPTest->testCmd("./$plugin -v -H $host_tcp_http:8080 -p 80"); | ||
75 | like( $res->output, '/^Host: '.$host_tcp_http.':8080\s*$/ms', "Host Header OK" ); | ||
76 | like( $res->output, '/CURLOPT_URL: http:\/\/'.$host_tcp_http.':80\//ms', "Url OK" ); | ||
77 | |||
78 | $res = NPTest->testCmd("./$plugin -v -H $host_tcp_http:8080 -p 80 -k 'Host: testhost:8001'"); | ||
79 | like( $res->output, '/^Host: testhost:8001\s*$/ms', "Host Header OK" ); | ||
80 | like( $res->output, '/CURLOPT_URL: http:\/\/'.$host_tcp_http.':80\//ms', "Url OK" ); | ||
81 | |||
82 | $res = NPTest->testCmd("./$plugin -v -I $host_tcp_http -p 80 -k 'Host: testhost:8001'"); | ||
83 | like( $res->output, '/^Host: testhost:8001\s*$/ms', "Host Header OK" ); | ||
84 | like( $res->output, '/CURLOPT_URL: http:\/\/'.$host_tcp_http.':80\//ms', "Url OK" ); | ||
85 | |||
86 | SKIP: { | ||
87 | skip "No internet access", 3 if $internet_access eq "no"; | ||
88 | |||
89 | $res = NPTest->testCmd("./$plugin -v -H $host_tls_http -S"); | ||
90 | like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); | ||
91 | |||
92 | $res = NPTest->testCmd("./$plugin -v -H $host_tls_http:8080 -S -p 443"); | ||
93 | like( $res->output, '/^Host: '.$host_tls_http.':8080\s*$/ms', "Host Header OK" ); | ||
94 | |||
95 | $res = NPTest->testCmd("./$plugin -v -H $host_tls_http:443 -S -p 443"); | ||
96 | like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); | ||
97 | }; | ||
98 | |||
99 | SKIP: { | ||
100 | skip "No host serving monitoring in index file", 7 unless $host_tcp_http2; | ||
101 | |||
102 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'monitoring'" ); | ||
103 | cmp_ok( $res->return_code, "==", 0, "Got a reference to 'monitoring'"); | ||
104 | |||
105 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'mONiTORing'" ); | ||
106 | cmp_ok( $res->return_code, "==", 2, "Not got 'mONiTORing'"); | ||
107 | like ( $res->output, "/pattern not found/", "Error message says 'pattern not found'"); | ||
108 | |||
109 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -R 'mONiTORing'" ); | ||
110 | cmp_ok( $res->return_code, "==", 0, "But case insensitive doesn't mind 'mONiTORing'"); | ||
111 | |||
112 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'monitoring' --invert-regex" ); | ||
113 | cmp_ok( $res->return_code, "==", 2, "Invert results work when found"); | ||
114 | like ( $res->output, "/pattern found/", "Error message says 'pattern found'"); | ||
115 | |||
116 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'mONiTORing' --invert-regex" ); | ||
117 | cmp_ok( $res->return_code, "==", 0, "And also when not found"); | ||
118 | } | ||
119 | SKIP: { | ||
120 | skip "No internet access", 16 if $internet_access eq "no"; | ||
121 | |||
122 | $res = NPTest->testCmd( | ||
123 | "./$plugin --ssl $host_tls_http" | ||
124 | ); | ||
125 | cmp_ok( $res->return_code, '==', 0, "Can read https for $host_tls_http" ); | ||
126 | |||
127 | $res = NPTest->testCmd( "./$plugin -C 1 --ssl $host_tls_http" ); | ||
128 | cmp_ok( $res->return_code, '==', 0, "Checking certificate for $host_tls_http"); | ||
129 | like ( $res->output, "/Certificate '$host_tls_cert' will expire on/", "Output OK" ); | ||
130 | my $saved_cert_output = $res->output; | ||
131 | |||
132 | $res = NPTest->testCmd( "./$plugin -C 8000,1 --ssl $host_tls_http" ); | ||
133 | cmp_ok( $res->return_code, '==', 1, "Checking certificate for $host_tls_http"); | ||
134 | like ( $res->output, qr/WARNING - Certificate '$host_tls_cert' expires in \d+ day/, "Output Warning" ); | ||
135 | |||
136 | $res = NPTest->testCmd( "./$plugin $host_tls_http -C 1" ); | ||
137 | is( $res->return_code, 0, "Old syntax for cert checking okay" ); | ||
138 | is( $res->output, $saved_cert_output, "Same output as new syntax" ); | ||
139 | |||
140 | $res = NPTest->testCmd( "./$plugin -H $host_tls_http -C 1" ); | ||
141 | is( $res->return_code, 0, "Updated syntax for cert checking okay" ); | ||
142 | is( $res->output, $saved_cert_output, "Same output as new syntax" ); | ||
143 | |||
144 | $res = NPTest->testCmd( "./$plugin -C 1 $host_tls_http" ); | ||
145 | cmp_ok( $res->output, 'eq', $saved_cert_output, "--ssl option automatically added"); | ||
146 | |||
147 | $res = NPTest->testCmd( "./$plugin $host_tls_http -C 1" ); | ||
148 | cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works"); | ||
149 | |||
150 | # run some certificate checks with faketime | ||
151 | SKIP: { | ||
152 | skip "No faketime binary found", 12 if !$faketime; | ||
153 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./$plugin -C 1 $host_tls_http"); | ||
154 | like($res->output, qr/OK - Certificate '$host_tls_cert' will expire on/, "Catch cert output"); | ||
155 | is( $res->return_code, 0, "Catch cert output exit code" ); | ||
156 | my($mon,$day,$hour,$min,$sec,$year) = ($res->output =~ /(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)/); | ||
157 | if(!defined $year) { | ||
158 | die("parsing date failed from: ".$res->output); | ||
159 | } | ||
160 | my $months = {'Jan' => 0, 'Feb' => 1, 'Mar' => 2, 'Apr' => 3, 'May' => 4, 'Jun' => 5, 'Jul' => 6, 'Aug' => 7, 'Sep' => 8, 'Oct' => 9, 'Nov' => 10, 'Dec' => 11}; | ||
161 | my $ts = mktime($sec, $min, $hour, $day, $months->{$mon}, $year-1900); | ||
162 | my $time = strftime("%Y-%m-%d %H:%M:%S", localtime($ts)); | ||
163 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./$plugin -C 1 $host_tls_http"); | ||
164 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' just expired/, "Output on expire date"); | ||
165 | is( $res->return_code, 2, "Output on expire date" ); | ||
166 | |||
167 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-1))."' ./$plugin -C 1 $host_tls_http"); | ||
168 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 0 minutes/, "cert expires in 1 second output"); | ||
169 | is( $res->return_code, 2, "cert expires in 1 second exit code" ); | ||
170 | |||
171 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-120))."' ./$plugin -C 1 $host_tls_http"); | ||
172 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 minutes/, "cert expires in 2 minutes output"); | ||
173 | is( $res->return_code, 2, "cert expires in 2 minutes exit code" ); | ||
174 | |||
175 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-7200))."' ./$plugin -C 1 $host_tls_http"); | ||
176 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 hours/, "cert expires in 2 hours output"); | ||
177 | is( $res->return_code, 2, "cert expires in 2 hours exit code" ); | ||
178 | |||
179 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./$plugin -C 1 $host_tls_http"); | ||
180 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expired on/, "Certificate expired output"); | ||
181 | is( $res->return_code, 2, "Certificate expired exit code" ); | ||
182 | }; | ||
183 | |||
184 | $res = NPTest->testCmd( "./$plugin --ssl $host_tls_http -E" ); | ||
185 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | ||
186 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); | ||
187 | |||
188 | $res = NPTest->testCmd( | ||
189 | "./$plugin --ssl -H www.e-paycobalt.com" | ||
190 | ); | ||
191 | cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" ); | ||
192 | |||
193 | |||
194 | $res = NPTest->testCmd( "./$plugin -H www.mozilla.com -u /firefox -f follow" ); | ||
195 | is( $res->return_code, 0, "Redirection based on location is okay"); | ||
196 | |||
197 | $res = NPTest->testCmd( "./$plugin -H www.mozilla.com --extended-perfdata" ); | ||
198 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | ||
199 | } | ||
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} | |||
15 | my $successOutput = '/^FPING OK - /'; | 15 | my $successOutput = '/^FPING OK - /'; |
16 | my $failureOutput = '/^FPING CRITICAL - /'; | 16 | my $failureOutput = '/^FPING CRITICAL - /'; |
17 | 17 | ||
18 | my $host_responsive = getTestParameter( "host_responsive", "NP_HOST_RESPONSIVE", "localhost", | 18 | my $host_responsive = getTestParameter("NP_HOST_RESPONSIVE", "The hostname of system responsive to network requests", "localhost"); |
19 | "The hostname of system responsive to network requests" ); | 19 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); |
20 | 20 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | |
21 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
22 | "The hostname of system not responsive to network requests" ); | ||
23 | |||
24 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
25 | "An invalid (not known to DNS) hostname" ); | ||
26 | |||
27 | 21 | ||
28 | my $t; | 22 | my $t; |
29 | 23 | ||
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; | |||
11 | use vars qw($tests); | 11 | use vars qw($tests); |
12 | BEGIN {$tests = 4; plan tests => $tests} | 12 | BEGIN {$tests = 4; plan tests => $tests} |
13 | 13 | ||
14 | my $host_tcp_ftp = getTestParameter( "host_tcp_ftp", "NP_HOST_TCP_FTP", "localhost", | 14 | my $host_tcp_ftp = getTestParameter("NP_HOST_TCP_FTP", "A host providing the FTP Service (an FTP server)", "localhost"); |
15 | "A host providing the FTP Service (an FTP server)"); | 15 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); |
16 | 16 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | |
17 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
18 | "The hostname of system not responsive to network requests" ); | ||
19 | |||
20 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
21 | "An invalid (not known to DNS) hostname" ); | ||
22 | 17 | ||
23 | my $successOutput = '/FTP OK -\s+[0-9]?\.?[0-9]+ second response time/'; | 18 | my $successOutput = '/FTP OK -\s+[0-9]?\.?[0-9]+ second response time/'; |
24 | 19 | ||
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index 416fbbcb..e92681e9 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t | |||
@@ -9,69 +9,46 @@ use Test::More; | |||
9 | use POSIX qw/mktime strftime/; | 9 | use POSIX qw/mktime strftime/; |
10 | use NPTest; | 10 | use NPTest; |
11 | 11 | ||
12 | plan tests => 55; | 12 | plan tests => 50; |
13 | 13 | ||
14 | my $successOutput = '/OK.*HTTP.*second/'; | 14 | my $successOutput = '/OK.*HTTP.*second/'; |
15 | 15 | ||
16 | my $res; | 16 | my $res; |
17 | 17 | my $plugin = 'check_http'; | |
18 | my $host_tcp_http = getTestParameter( "NP_HOST_TCP_HTTP", | 18 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; |
19 | "A host providing the HTTP Service (a web server)", | 19 | |
20 | "localhost" ); | 20 | my $host_tcp_http = getTestParameter("NP_HOST_TCP_HTTP", "A host providing the HTTP Service (a web server)", "localhost"); |
21 | 21 | my $host_tls_http = getTestParameter("NP_HOST_TLS_HTTP", "A host providing the HTTPS Service (a tls web server)", "localhost"); | |
22 | my $host_tls_http = getTestParameter( "host_tls_http", "NP_HOST_TLS_HTTP", "localhost", | 22 | my $host_tls_cert = getTestParameter("NP_HOST_TLS_CERT", "the common name of the certificate.", "localhost"); |
23 | "A host providing the HTTPS Service (a tls web server)" ); | 23 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); |
24 | 24 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | |
25 | my $host_tls_cert = getTestParameter( "host_tls_cert", "NP_HOST_TLS_CERT", "localhost", | 25 | my $internet_access = getTestParameter("NP_INTERNET_ACCESS", "Is this system directly connected to the internet?", "yes"); |
26 | "the common name of the certificate." ); | 26 | my $host_tcp_http2 = getTestParameter("NP_HOST_TCP_HTTP2", "A host providing an index page containing the string 'monitoring'", "test.monitoring-plugins.org"); |
27 | 27 | my $host_tcp_proxy = getTestParameter("NP_HOST_TCP_PROXY", "A host providing a HTTP proxy with CONNECT support", "localhost"); | |
28 | 28 | my $port_tcp_proxy = getTestParameter("NP_PORT_TCP_PROXY", "Port of the proxy with HTTP and CONNECT support", "3128"); | |
29 | my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", | ||
30 | "The hostname of system not responsive to network requests", | ||
31 | "10.0.0.1" ); | ||
32 | |||
33 | my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", | ||
34 | "An invalid (not known to DNS) hostname", | ||
35 | "nosuchhost"); | ||
36 | |||
37 | my $internet_access = getTestParameter( "NP_INTERNET_ACCESS", | ||
38 | "Is this system directly connected to the internet?", | ||
39 | "yes"); | ||
40 | |||
41 | my $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2", | ||
42 | "A host providing an index page containing the string 'monitoring'", | ||
43 | "test.monitoring-plugins.org" ); | ||
44 | |||
45 | my $host_tcp_proxy = getTestParameter( "NP_HOST_TCP_PROXY", | ||
46 | "A host providing a HTTP proxy with CONNECT support", | ||
47 | "localhost"); | ||
48 | |||
49 | my $port_tcp_proxy = getTestParameter( "NP_PORT_TCP_PROXY", | ||
50 | "Port of the proxy with HTTP and CONNECT support", | ||
51 | "3128"); | ||
52 | 29 | ||
53 | my $faketime = -x '/usr/bin/faketime' ? 1 : 0; | 30 | my $faketime = -x '/usr/bin/faketime' ? 1 : 0; |
54 | 31 | ||
55 | 32 | ||
56 | $res = NPTest->testCmd( | 33 | $res = NPTest->testCmd( |
57 | "./check_http $host_tcp_http -wt 300 -ct 600" | 34 | "./$plugin $host_tcp_http -wt 300 -ct 600" |
58 | ); | 35 | ); |
59 | cmp_ok( $res->return_code, '==', 0, "Webserver $host_tcp_http responded" ); | 36 | cmp_ok( $res->return_code, '==', 0, "Webserver $host_tcp_http responded" ); |
60 | like( $res->output, $successOutput, "Output OK" ); | 37 | like( $res->output, $successOutput, "Output OK" ); |
61 | 38 | ||
62 | $res = NPTest->testCmd( | 39 | $res = NPTest->testCmd( |
63 | "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there' -k 'carl:frown'" | 40 | "./$plugin $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there' -k 'carl:frown'" |
64 | ); | 41 | ); |
65 | like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); | 42 | like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); |
66 | 43 | ||
67 | $res = NPTest->testCmd( | 44 | $res = NPTest->testCmd( |
68 | "./check_http $host_nonresponsive -wt 1 -ct 2 -t 3" | 45 | "./$plugin $host_nonresponsive -wt 1 -ct 2 -t 3" |
69 | ); | 46 | ); |
70 | cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); | 47 | cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); |
71 | cmp_ok( $res->output, 'eq', "CRITICAL - Socket timeout after 3 seconds", "Output OK"); | 48 | cmp_ok( $res->output, 'eq', "CRITICAL - Socket timeout after 3 seconds", "Output OK"); |
72 | 49 | ||
73 | $res = NPTest->testCmd( | 50 | $res = NPTest->testCmd( |
74 | "./check_http $hostname_invalid -wt 1 -ct 2" | 51 | "./$plugin $hostname_invalid -wt 1 -ct 2" |
75 | ); | 52 | ); |
76 | cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" ); | 53 | cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" ); |
77 | # The first part of the message comes from the OS catalogue, so cannot check this. | 54 | # The first part of the message comes from the OS catalogue, so cannot check this. |
@@ -80,86 +57,86 @@ cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" ); | |||
80 | like( $res->output, "/Unable to open TCP socket|Socket timeout after/", "Output OK"); | 57 | like( $res->output, "/Unable to open TCP socket|Socket timeout after/", "Output OK"); |
81 | 58 | ||
82 | # host header checks | 59 | # host header checks |
83 | $res = NPTest->testCmd("./check_http -v -H $host_tcp_http"); | 60 | $res = NPTest->testCmd("./$plugin -v -H $host_tcp_http"); |
84 | like( $res->output, '/^Host: '.$host_tcp_http.'\s*$/ms', "Host Header OK" ); | 61 | like( $res->output, '/^Host: '.$host_tcp_http.'\s*$/ms', "Host Header OK" ); |
85 | 62 | ||
86 | $res = NPTest->testCmd("./check_http -v -H $host_tcp_http -p 80"); | 63 | $res = NPTest->testCmd("./$plugin -v -H $host_tcp_http -p 80"); |
87 | like( $res->output, '/^Host: '.$host_tcp_http.'\s*$/ms', "Host Header OK" ); | 64 | like( $res->output, '/^Host: '.$host_tcp_http.'\s*$/ms', "Host Header OK" ); |
88 | 65 | ||
89 | $res = NPTest->testCmd("./check_http -v -H $host_tcp_http:8080 -p 80"); | 66 | $res = NPTest->testCmd("./$plugin -v -H $host_tcp_http:8080 -p 80"); |
90 | like( $res->output, '/^Host: '.$host_tcp_http.':8080\s*$/ms', "Host Header OK" ); | 67 | like( $res->output, '/^Host: '.$host_tcp_http.':8080\s*$/ms', "Host Header OK" ); |
91 | 68 | ||
92 | $res = NPTest->testCmd("./check_http -v -H $host_tcp_http:8080 -p 80"); | 69 | $res = NPTest->testCmd("./$plugin -v -H $host_tcp_http:8080 -p 80"); |
93 | like( $res->output, '/^Host: '.$host_tcp_http.':8080\s*$/ms', "Host Header OK" ); | 70 | like( $res->output, '/^Host: '.$host_tcp_http.':8080\s*$/ms', "Host Header OK" ); |
94 | 71 | ||
95 | SKIP: { | 72 | SKIP: { |
96 | skip "No internet access", 3 if $internet_access eq "no"; | 73 | skip "No internet access", 3 if $internet_access eq "no"; |
97 | 74 | ||
98 | $res = NPTest->testCmd("./check_http -v -H $host_tls_http -S"); | 75 | $res = NPTest->testCmd("./$plugin -v -H $host_tls_http -S"); |
99 | like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); | 76 | like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); |
100 | 77 | ||
101 | $res = NPTest->testCmd("./check_http -v -H $host_tls_http:8080 -S -p 443"); | 78 | $res = NPTest->testCmd("./$plugin -v -H $host_tls_http:8080 -S -p 443"); |
102 | like( $res->output, '/^Host: '.$host_tls_http.':8080\s*$/ms', "Host Header OK" ); | 79 | like( $res->output, '/^Host: '.$host_tls_http.':8080\s*$/ms', "Host Header OK" ); |
103 | 80 | ||
104 | $res = NPTest->testCmd("./check_http -v -H $host_tls_http:443 -S -p 443"); | 81 | $res = NPTest->testCmd("./$plugin -v -H $host_tls_http:443 -S -p 443"); |
105 | like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); | 82 | like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); |
106 | }; | 83 | }; |
107 | 84 | ||
108 | SKIP: { | 85 | SKIP: { |
109 | skip "No host serving monitoring in index file", 7 unless $host_tcp_http2; | 86 | skip "No host serving monitoring in index file", 7 unless $host_tcp_http2; |
110 | 87 | ||
111 | $res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'monitoring'" ); | 88 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'monitoring'" ); |
112 | cmp_ok( $res->return_code, "==", 0, "Got a reference to 'monitoring'"); | 89 | cmp_ok( $res->return_code, "==", 0, "Got a reference to 'monitoring'"); |
113 | 90 | ||
114 | $res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'mONiTORing'" ); | 91 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'mONiTORing'" ); |
115 | cmp_ok( $res->return_code, "==", 2, "Not got 'mONiTORing'"); | 92 | cmp_ok( $res->return_code, "==", 2, "Not got 'mONiTORing'"); |
116 | like ( $res->output, "/pattern not found/", "Error message says 'pattern not found'"); | 93 | like ( $res->output, "/pattern not found/", "Error message says 'pattern not found'"); |
117 | 94 | ||
118 | $res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -R 'mONiTORing'" ); | 95 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -R 'mONiTORing'" ); |
119 | cmp_ok( $res->return_code, "==", 0, "But case insensitive doesn't mind 'mONiTORing'"); | 96 | cmp_ok( $res->return_code, "==", 0, "But case insensitive doesn't mind 'mONiTORing'"); |
120 | 97 | ||
121 | $res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'monitoring' --invert-regex" ); | 98 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'monitoring' --invert-regex" ); |
122 | cmp_ok( $res->return_code, "==", 2, "Invert results work when found"); | 99 | cmp_ok( $res->return_code, "==", 2, "Invert results work when found"); |
123 | like ( $res->output, "/pattern found/", "Error message says 'pattern found'"); | 100 | like ( $res->output, "/pattern found/", "Error message says 'pattern found'"); |
124 | 101 | ||
125 | $res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'mONiTORing' --invert-regex" ); | 102 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'mONiTORing' --invert-regex" ); |
126 | cmp_ok( $res->return_code, "==", 0, "And also when not found"); | 103 | cmp_ok( $res->return_code, "==", 0, "And also when not found"); |
127 | } | 104 | } |
128 | SKIP: { | 105 | SKIP: { |
129 | skip "No internet access", 16 if $internet_access eq "no"; | 106 | skip "No internet access", 16 if $internet_access eq "no"; |
130 | 107 | ||
131 | $res = NPTest->testCmd( | 108 | $res = NPTest->testCmd( |
132 | "./check_http --ssl $host_tls_http" | 109 | "./$plugin --ssl $host_tls_http" |
133 | ); | 110 | ); |
134 | cmp_ok( $res->return_code, '==', 0, "Can read https for $host_tls_http" ); | 111 | cmp_ok( $res->return_code, '==', 0, "Can read https for $host_tls_http" ); |
135 | 112 | ||
136 | $res = NPTest->testCmd( "./check_http -C 1 --ssl $host_tls_http" ); | 113 | $res = NPTest->testCmd( "./$plugin -C 1 --ssl $host_tls_http" ); |
137 | cmp_ok( $res->return_code, '==', 0, "Checking certificate for $host_tls_http"); | 114 | cmp_ok( $res->return_code, '==', 0, "Checking certificate for $host_tls_http"); |
138 | like ( $res->output, "/Certificate '$host_tls_cert' will expire on/", "Output OK" ); | 115 | like ( $res->output, "/Certificate '$host_tls_cert' will expire on/", "Output OK" ); |
139 | my $saved_cert_output = $res->output; | 116 | my $saved_cert_output = $res->output; |
140 | 117 | ||
141 | $res = NPTest->testCmd( "./check_http -C 8000,1 --ssl $host_tls_http" ); | 118 | $res = NPTest->testCmd( "./$plugin -C 8000,1 --ssl $host_tls_http" ); |
142 | cmp_ok( $res->return_code, '==', 1, "Checking certificate for $host_tls_http"); | 119 | cmp_ok( $res->return_code, '==', 1, "Checking certificate for $host_tls_http"); |
143 | like ( $res->output, qr/WARNING - Certificate '$host_tls_cert' expires in \d+ day/, "Output Warning" ); | 120 | like ( $res->output, qr/WARNING - Certificate '$host_tls_cert' expires in \d+ day/, "Output Warning" ); |
144 | 121 | ||
145 | $res = NPTest->testCmd( "./check_http $host_tls_http -C 1" ); | 122 | $res = NPTest->testCmd( "./$plugin $host_tls_http -C 1" ); |
146 | is( $res->return_code, 0, "Old syntax for cert checking okay" ); | 123 | is( $res->return_code, 0, "Old syntax for cert checking okay" ); |
147 | is( $res->output, $saved_cert_output, "Same output as new syntax" ); | 124 | is( $res->output, $saved_cert_output, "Same output as new syntax" ); |
148 | 125 | ||
149 | $res = NPTest->testCmd( "./check_http -H $host_tls_http -C 1" ); | 126 | $res = NPTest->testCmd( "./$plugin -H $host_tls_http -C 1" ); |
150 | is( $res->return_code, 0, "Updated syntax for cert checking okay" ); | 127 | is( $res->return_code, 0, "Updated syntax for cert checking okay" ); |
151 | is( $res->output, $saved_cert_output, "Same output as new syntax" ); | 128 | is( $res->output, $saved_cert_output, "Same output as new syntax" ); |
152 | 129 | ||
153 | $res = NPTest->testCmd( "./check_http -C 1 $host_tls_http" ); | 130 | $res = NPTest->testCmd( "./$plugin -C 1 $host_tls_http" ); |
154 | cmp_ok( $res->output, 'eq', $saved_cert_output, "--ssl option automatically added"); | 131 | cmp_ok( $res->output, 'eq', $saved_cert_output, "--ssl option automatically added"); |
155 | 132 | ||
156 | $res = NPTest->testCmd( "./check_http $host_tls_http -C 1" ); | 133 | $res = NPTest->testCmd( "./$plugin $host_tls_http -C 1" ); |
157 | cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works"); | 134 | cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works"); |
158 | 135 | ||
159 | # run some certificate checks with faketime | 136 | # run some certificate checks with faketime |
160 | SKIP: { | 137 | SKIP: { |
161 | skip "No faketime binary found", 12 if !$faketime; | 138 | skip "No faketime binary found", 12 if !$faketime; |
162 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./check_http -C 1 $host_tls_http"); | 139 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./$plugin -C 1 $host_tls_http"); |
163 | like($res->output, qr/OK - Certificate '$host_tls_cert' will expire on/, "Catch cert output"); | 140 | like($res->output, qr/OK - Certificate '$host_tls_cert' will expire on/, "Catch cert output"); |
164 | is( $res->return_code, 0, "Catch cert output exit code" ); | 141 | is( $res->return_code, 0, "Catch cert output exit code" ); |
165 | my($mon,$day,$hour,$min,$sec,$year) = ($res->output =~ /(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)/); | 142 | my($mon,$day,$hour,$min,$sec,$year) = ($res->output =~ /(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)/); |
@@ -169,56 +146,51 @@ SKIP: { | |||
169 | my $months = {'Jan' => 0, 'Feb' => 1, 'Mar' => 2, 'Apr' => 3, 'May' => 4, 'Jun' => 5, 'Jul' => 6, 'Aug' => 7, 'Sep' => 8, 'Oct' => 9, 'Nov' => 10, 'Dec' => 11}; | 146 | my $months = {'Jan' => 0, 'Feb' => 1, 'Mar' => 2, 'Apr' => 3, 'May' => 4, 'Jun' => 5, 'Jul' => 6, 'Aug' => 7, 'Sep' => 8, 'Oct' => 9, 'Nov' => 10, 'Dec' => 11}; |
170 | my $ts = mktime($sec, $min, $hour, $day, $months->{$mon}, $year-1900); | 147 | my $ts = mktime($sec, $min, $hour, $day, $months->{$mon}, $year-1900); |
171 | my $time = strftime("%Y-%m-%d %H:%M:%S", localtime($ts)); | 148 | my $time = strftime("%Y-%m-%d %H:%M:%S", localtime($ts)); |
172 | $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"); | 149 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./$plugin -C 1 $host_tls_http"); |
173 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' just expired/, "Output on expire date"); | 150 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' just expired/, "Output on expire date"); |
174 | is( $res->return_code, 2, "Output on expire date" ); | ||
175 | 151 | ||
176 | $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"); | 152 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-1))."' ./$plugin -C 1 $host_tls_http"); |
177 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 0 minutes/, "cert expires in 1 second output"); | 153 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 0 minutes/, "cert expires in 1 second output"); |
178 | is( $res->return_code, 2, "cert expires in 1 second exit code" ); | ||
179 | 154 | ||
180 | $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"); | 155 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-120))."' ./$plugin -C 1 $host_tls_http"); |
181 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 minutes/, "cert expires in 2 minutes output"); | 156 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 minutes/, "cert expires in 2 minutes output"); |
182 | is( $res->return_code, 2, "cert expires in 2 minutes exit code" ); | ||
183 | 157 | ||
184 | $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"); | 158 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-7200))."' ./$plugin -C 1 $host_tls_http"); |
185 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 hours/, "cert expires in 2 hours output"); | 159 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 hours/, "cert expires in 2 hours output"); |
186 | is( $res->return_code, 2, "cert expires in 2 hours exit code" ); | ||
187 | 160 | ||
188 | $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"); | 161 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./$plugin -C 1 $host_tls_http"); |
189 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expired on/, "Certificate expired output"); | 162 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expired on/, "Certificate expired output"); |
190 | is( $res->return_code, 2, "Certificate expired exit code" ); | ||
191 | }; | 163 | }; |
192 | 164 | ||
193 | $res = NPTest->testCmd( "./check_http --ssl $host_tls_http -E" ); | 165 | $res = NPTest->testCmd( "./$plugin --ssl $host_tls_http -E" ); |
194 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 166 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); |
195 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); | 167 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); |
196 | 168 | ||
197 | $res = NPTest->testCmd( | 169 | $res = NPTest->testCmd( |
198 | "./check_http --ssl -H www.e-paycobalt.com" | 170 | "./$plugin --ssl -H www.e-paycobalt.com" |
199 | ); | 171 | ); |
200 | cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" ); | 172 | cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" ); |
201 | 173 | ||
202 | 174 | ||
203 | $res = NPTest->testCmd( "./check_http -H www.mozilla.com -u /firefox -f follow" ); | 175 | $res = NPTest->testCmd( "./$plugin -H www.mozilla.com -u /firefox -f follow" ); |
204 | is( $res->return_code, 0, "Redirection based on location is okay"); | 176 | is( $res->return_code, 0, "Redirection based on location is okay"); |
205 | 177 | ||
206 | $res = NPTest->testCmd( "./check_http -H www.mozilla.com --extended-perfdata" ); | 178 | $res = NPTest->testCmd( "./$plugin -H www.mozilla.com --extended-perfdata" ); |
207 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 179 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); |
208 | } | 180 | } |
209 | 181 | ||
210 | SKIP: { | 182 | SKIP: { |
211 | skip "No internet access or proxy configured", 6 if $internet_access eq "no" or ! $host_tcp_proxy; | 183 | skip "No internet access or proxy configured", 6 if $internet_access eq "no" or ! $host_tcp_proxy; |
212 | 184 | ||
213 | $res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -u http://$host_tcp_http -e 200,301,302"); | 185 | $res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -u http://$host_tcp_http -e 200,301,302"); |
214 | is( $res->return_code, 0, "Proxy HTTP works"); | 186 | is( $res->return_code, 0, "Proxy HTTP works"); |
215 | like($res->output, qr/OK: Status line output matched/, "Proxy HTTP Output is sufficent"); | 187 | like($res->output, qr/OK: Status line output matched/, "Proxy HTTP Output is sufficent"); |
216 | 188 | ||
217 | $res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT"); | 189 | $res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT"); |
218 | is( $res->return_code, 0, "Proxy HTTP CONNECT works"); | 190 | is( $res->return_code, 0, "Proxy HTTP CONNECT works"); |
219 | like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent"); | 191 | like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent"); |
220 | 192 | ||
221 | $res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT:HEAD"); | 193 | $res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT:HEAD"); |
222 | is( $res->return_code, 0, "Proxy HTTP CONNECT works with override method"); | 194 | is( $res->return_code, 0, "Proxy HTTP CONNECT works with override method"); |
223 | like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent"); | 195 | like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent"); |
224 | } | 196 | } |
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; | |||
8 | use Test::More tests => 7; | 8 | use Test::More tests => 7; |
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | my $host_tcp_smtp = getTestParameter( "host_tcp_smtp", "NP_HOST_TCP_SMTP", "mailhost", | 11 | my $host_tcp_smtp = getTestParameter("NP_HOST_TCP_SMTP", "A host providing an STMP Service (a mail server)", "mailhost"); |
12 | "A host providing an STMP Service (a mail server)"); | 12 | my $host_tcp_imap = getTestParameter("NP_HOST_TCP_IMAP", "A host providing an IMAP Service (a mail server)", $host_tcp_smtp); |
13 | 13 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); | |
14 | my $host_tcp_imap = getTestParameter( "host_tcp_imap", "NP_HOST_TCP_IMAP", $host_tcp_smtp, | 14 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); |
15 | "A host providing an IMAP Service (a mail server)"); | ||
16 | |||
17 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
18 | "The hostname of system not responsive to network requests" ); | ||
19 | |||
20 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
21 | "An invalid (not known to DNS) hostname" ); | ||
22 | 15 | ||
23 | my $t; | 16 | my $t; |
24 | 17 | ||
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; | |||
10 | 10 | ||
11 | plan tests => 10; | 11 | plan tests => 10; |
12 | 12 | ||
13 | my $host_tcp_jabber = getTestParameter( | 13 | my $host_tcp_jabber = getTestParameter("NP_HOST_TCP_JABBER", "A host providing the Jabber Service", "jabber.de"); |
14 | "NP_HOST_TCP_JABBER", | 14 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); |
15 | "A host providing the Jabber Service", | 15 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); |
16 | "jabber.org" | ||
17 | ); | ||
18 | |||
19 | my $host_nonresponsive = getTestParameter( | ||
20 | "NP_HOST_NONRESPONSIVE", | ||
21 | "The hostname of system not responsive to network requests", | ||
22 | "10.0.0.1", | ||
23 | ); | ||
24 | |||
25 | my $hostname_invalid = getTestParameter( | ||
26 | "NP_HOSTNAME_INVALID", | ||
27 | "An invalid (not known to DNS) hostname", | ||
28 | "nosuchhost", | ||
29 | ); | ||
30 | 16 | ||
31 | 17 | ||
32 | my $jabberOK = '/JABBER OK\s-\s\d+\.\d+\ssecond response time on '.$host_tcp_jabber.' port 5222/'; | 18 | 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; | |||
9 | use Test::More; | 9 | use Test::More; |
10 | use NPTest; | 10 | use NPTest; |
11 | 11 | ||
12 | my $host_tcp_ldap = getTestParameter("NP_HOST_TCP_LDAP", | 12 | my $host_tcp_ldap = getTestParameter("NP_HOST_TCP_LDAP", "A host providing the LDAP Service", "localhost"); |
13 | "A host providing the LDAP Service", | 13 | my $ldap_base_dn = getTestParameter("NP_LDAP_BASE_DN", "A base dn for the LDAP Service", "cn=admin"); |
14 | "localhost" ); | 14 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); |
15 | 15 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | |
16 | my $ldap_base_dn = getTestParameter("NP_LDAP_BASE_DN", | ||
17 | "A base dn for the LDAP Service", | ||
18 | "cn=admin" ); | ||
19 | |||
20 | my $host_nonresponsive = getTestParameter("host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
21 | "The hostname of system not responsive to network requests" ); | ||
22 | |||
23 | my $hostname_invalid = getTestParameter("hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
24 | "An invalid (not known to DNS) hostname" ); | ||
25 | 16 | ||
26 | my($result, $cmd); | 17 | my($result, $cmd); |
27 | my $command = './check_ldap'; | 18 | 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"); | |||
21 | plan tests => 15; | 21 | plan tests => 15; |
22 | 22 | ||
23 | my $bad_login_output = '/Access denied for user /'; | 23 | my $bad_login_output = '/Access denied for user /'; |
24 | my $mysqlserver = getTestParameter( | 24 | my $mysqlserver = getTestParameter("NP_MYSQL_SERVER", "A MySQL Server hostname or IP with no slaves setup"); |
25 | "NP_MYSQL_SERVER", | 25 | my $mysqlsocket = getTestParameter("NP_MYSQL_SOCKET", "Full path to a MySQL Server socket with no slaves setup"); |
26 | "A MySQL Server hostname or IP with no slaves setup" | 26 | my $mysql_login_details = getTestParameter("NP_MYSQL_LOGIN_DETAILS", "Command line parameters to specify login access (requires REPLICATION CLIENT privleges)", "-u test -ptest"); |
27 | ); | 27 | my $with_slave = getTestParameter("NP_MYSQL_WITH_SLAVE", "MySQL server with slaves setup"); |
28 | my $mysqlsocket = getTestParameter( | 28 | 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"); |
29 | "NP_MYSQL_SOCKET", | ||
30 | "Full path to a MySQL Server socket with no slaves setup" | ||
31 | ); | ||
32 | my $mysql_login_details = getTestParameter( | ||
33 | "MYSQL_LOGIN_DETAILS", | ||
34 | "Command line parameters to specify login access (requires " . | ||
35 | "REPLICATION CLIENT privleges)", | ||
36 | "-u test -ptest", | ||
37 | ); | ||
38 | my $with_slave = getTestParameter( | ||
39 | "NP_MYSQL_WITH_SLAVE", | ||
40 | "MySQL server with slaves setup" | ||
41 | ); | ||
42 | my $with_slave_login = getTestParameter( | ||
43 | "NP_MYSQL_WITH_SLAVE_LOGIN", | ||
44 | "Login details for server with slave (requires REPLICATION CLIENT " . | ||
45 | "privleges)", | ||
46 | $mysql_login_details || "-u test -ptest" | ||
47 | ); | ||
48 | 29 | ||
49 | my $result; | 30 | my $result; |
50 | 31 | ||
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); | |||
17 | 17 | ||
18 | plan skip_all => "check_mysql_query not compiled" unless (-x "check_mysql_query"); | 18 | plan skip_all => "check_mysql_query not compiled" unless (-x "check_mysql_query"); |
19 | 19 | ||
20 | my $mysqlserver = getTestParameter( | 20 | my $mysqlserver = getTestParameter("NP_MYSQL_SERVER", "A MySQL Server with no slaves setup"); |
21 | "NP_MYSQL_SERVER", | 21 | my $mysql_login_details = getTestParameter("NP_MYSQL_LOGIN_DETAILS", "Command line parameters to specify login access", "-u user -ppw -d db"); |
22 | "A MySQL Server with no slaves setup" | ||
23 | ); | ||
24 | my $mysql_login_details = getTestParameter( | ||
25 | "MYSQL_LOGIN_DETAILS", | ||
26 | "Command line parameters to specify login access", | ||
27 | "-u user -ppw -d db", | ||
28 | ); | ||
29 | my $result; | 22 | my $result; |
30 | 23 | ||
31 | if (! $mysqlserver) { | 24 | 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 { | |||
15 | 15 | ||
16 | my $res; | 16 | my $res; |
17 | 17 | ||
18 | my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost", | 18 | my $host_snmp = getTestParameter("NP_HOST_SNMP", "A host providing an SNMP Service", "localhost"); |
19 | "A host providing an SNMP Service"); | 19 | my $snmp_community = getTestParameter("NP_SNMP_COMMUNITY", "The SNMP Community string for SNMP Testing (assumes snmp v1)", "public"); |
20 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); | ||
21 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | ||
22 | my $user_snmp = getTestParameter("NP_SNMP_USER", "An SNMP user", "auth_md5"); | ||
20 | 23 | ||
21 | my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public", | ||
22 | "The SNMP Community string for SNMP Testing (assumes snmp v1)" ); | ||
23 | |||
24 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
25 | "The hostname of system not responsive to network requests" ); | ||
26 | |||
27 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
28 | "An invalid (not known to DNS) hostname" ); | ||
29 | my $user_snmp = getTestParameter( "user_snmp", "NP_SNMP_USER", "auth_md5", "An SNMP user"); | ||
30 | 24 | ||
31 | $res = NPTest->testCmd( "./check_snmp -t 1" ); | 25 | $res = NPTest->testCmd( "./check_snmp -t 1" ); |
32 | is( $res->return_code, 3, "No host name" ); | 26 | 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; | |||
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | # Required parameters | 11 | # Required parameters |
12 | my $ssh_host = getTestParameter("NP_SSH_HOST", | 12 | my $ssh_host = getTestParameter("NP_SSH_HOST", "A host providing SSH service", "localhost"); |
13 | "A host providing SSH service", | 13 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1" ); |
14 | "localhost"); | 14 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost" ); |
15 | |||
16 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", | ||
17 | "The hostname of system not responsive to network requests", | ||
18 | "10.0.0.1" ); | ||
19 | |||
20 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", | ||
21 | "An invalid (not known to DNS) hostname", | ||
22 | "nosuchhost" ); | ||
23 | 15 | ||
24 | 16 | ||
25 | plan skip_all => "SSH_HOST must be defined" unless $ssh_host; | 17 | 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 { | |||
15 | } | 15 | } |
16 | 16 | ||
17 | 17 | ||
18 | my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost", | 18 | my $host_tcp_http = getTestParameter("NP_HOST_TCP_HTTP", "A host providing the HTTP Service (a web server)", "localhost"); |
19 | "A host providing the HTTP Service (a web server)" ); | 19 | my $host_tls_http = getTestParameter("NP_HOST_TLS_HTTP", "A host providing the HTTPS Service (a tls web server)", "localhost"); |
20 | 20 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); | |
21 | my $host_tls_http = getTestParameter( "host_tls_http", "NP_HOST_TLS_HTTP", "localhost", | 21 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); |
22 | "A host providing the HTTPS Service (a tls web server)" ); | 22 | my $internet_access = getTestParameter("NP_INTERNET_ACCESS", "Is this system directly connected to the internet?", "yes"); |
23 | |||
24 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
25 | "The hostname of system not responsive to network requests" ); | ||
26 | |||
27 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
28 | "An invalid (not known to DNS) hostname" ); | ||
29 | |||
30 | my $internet_access = getTestParameter( "NP_INTERNET_ACCESS", | ||
31 | "Is this system directly connected to the internet?", | ||
32 | "yes"); | ||
33 | 23 | ||
34 | my $successOutput = '/^TCP OK\s-\s+[0-9]?\.?[0-9]+ second response time on port [0-9]+/'; | 24 | my $successOutput = '/^TCP OK\s-\s+[0-9]?\.?[0-9]+ second response time on port [0-9]+/'; |
35 | 25 | ||
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; | |||
11 | use vars qw($tests); | 11 | use vars qw($tests); |
12 | BEGIN {$tests = 8; plan tests => $tests} | 12 | BEGIN {$tests = 8; plan tests => $tests} |
13 | 13 | ||
14 | my $host_udp_time = getTestParameter( "host_udp_time", "NP_HOST_UDP_TIME", "localhost", | 14 | my $host_udp_time = getTestParameter("NP_HOST_UDP_TIME", "A host providing the UDP Time Service", "localhost"); |
15 | "A host providing the UDP Time Service" ); | 15 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); |
16 | 16 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | |
17 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
18 | "The hostname of system not responsive to network requests" ); | ||
19 | |||
20 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
21 | "An invalid (not known to DNS) hostname" ); | ||
22 | 17 | ||
23 | my $successOutput = '/^TIME OK - [0-9]+ second time difference/'; | 18 | my $successOutput = '/^TIME OK - [0-9]+ second time difference/'; |
24 | 19 | ||
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 | NTAwMTMxNlowfzELMAkGA1UEBhMCVUsxEzARBgNVBAgTCkRlcmJ5c2hpcmUxDzAN | 6 | LXBsdWdpbnMub3JnMB4XDTA4MDEwMTExMDAyNloXDTA4MDEwMjExMDAyNlowgZcx |
7 | BgNVBAcTBkJlbHBlcjEXMBUGA1UEChMOTmFnaW9zIFBsdWdpbnMxETAPBgNVBAMT | 7 | CzAJBgNVBAYTAkRFMRAwDgYDVQQIDAdCYXZhcmlhMQ8wDQYDVQQHDAZNdW5pY2gx |
8 | CFRvbiBWb29uMR4wHAYJKoZIhvcNAQkBFg90b252b29uQG1hYy5jb20wgZ8wDQYJ | 8 | GzAZBgNVBAoMEk1vbml0b3JpbmcgUGx1Z2luczEbMBkGA1UEAwwSTW9uaXRvcmlu |
9 | KoZIhvcNAQEBBQADgY0AMIGJAoGBAOQHP4JnzACi4q6quXAiK+gTSffG6yyjEV+K | 9 | ZyBQbHVnaW5zMSswKQYJKoZIhvcNAQkBFhxkZXZlbEBtb25pdG9yaW5nLXBsdWdp |
10 | iyutRgBF2MdF03X5ls0wENw/5fnMTrHynl4XoGoV/rD4CR2hGT0m7dv7Vu0MRLlP | 10 | bnMub3JnMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyeHKwKFjJWUX |
11 | J1SCiFeMuQS30zzLMJr0A7IW869qRlKQmzxs1JT6XDbSoNQuF154zoxwNsKlMjoX | 11 | YHKsisypUf9dHlIPQAISyGP1BX6UL26ZLvE6kKbx3LFQ9W2POGoQWlzFiB1soGeV |
12 | tJSHN2YpAgMBAAGjgeYwgeMwHQYDVR0OBBYEFHWjM9OQldrDLMcAfPnUVfGxlzOp | 12 | WDd0U0JtWdCKmOXWdcXpupQlTSUtRCMDQkfqLN8GR5TBTd73rezp5mz08nMfLwu0 |
13 | MIGzBgNVHSMEgaswgaiAFHWjM9OQldrDLMcAfPnUVfGxlzOpoYGEpIGBMH8xCzAJ | 13 | p5VQ191Ui8JHFgrAOalAn8Uw5De8vj4VmTXmU5NJ2UFoC0ddU/Th/lwRCayHc1cn |
14 | BgNVBAYTAlVLMRMwEQYDVQQIEwpEZXJieXNoaXJlMQ8wDQYDVQQHEwZCZWxwZXIx | 14 | MVq2F7c/uhMUUQYNBmJy0pxoHawp+j9NKl/xIYsjgQNgahQyNuswuGHjaEwhPu+7 |
15 | FzAVBgNVBAoTDk5hZ2lvcyBQbHVnaW5zMREwDwYDVQQDEwhUb24gVm9vbjEeMBwG | 15 | G03XsW4ehu+H1898M/MkSln6LQAU1syoJ8ypPM8tV+zgx4uwj7udnZ2hceN95uW7 |
16 | CSqGSIb3DQEJARYPdG9udm9vbkBtYWMuY29tggkAkhLNxfvV/mkwDAYDVR0TBAUw | 16 | 0PWg5DQyUwIDAQABo1MwUTAdBgNVHQ4EFgQUt9ps3KJ1XiMuy/ijFBjMzf6jgwkw |
17 | AwEB/zANBgkqhkiG9w0BAQQFAAOBgQDHjoXoGwBamCiNplTt93jH/TO08RATdZP5 | 17 | HwYDVR0jBBgwFoAUt9ps3KJ1XiMuy/ijFBjMzf6jgwkwDwYDVR0TAQH/BAUwAwEB |
18 | 45hlxv2+PKCjjTiFa2mjAvopFiqmYsr40XYEmpeYMiaOzOW5rBjtqBAT/JJWyfda | 18 | /zANBgkqhkiG9w0BAQsFAAOCAQEAVPBZwMHbrnHFbmhbcPuvYd5cxk0uSVNAUzsl |
19 | SCmj3swqyKus63rv/iuokIhZzBdhbB+eOJJrmwT2SEc5KdRaipH0QAGF1nZAAGzo | 19 | 2biCq5P+ZHo10VHGygXtdV4utqk/IrAt2u5qSxycWPStCtAgTd3Q8ncfjOkaHM4z |
20 | 6xW7hkzYog== | 20 | 2bxTkhLyQeU8NWPuDBqDszo2GOaFTv+lm36LEKiAfqB1tjQVePSkycdrWIhkamBV |
21 | EgMe6uHLdU7QQk1ajQfrBdakN1beqki/dKieA6gm+XF/QS4SSYINmsHB/2X5cT9U | ||
22 | b/KMB8xurCnuJQuk1P4VsSkJCOSeHjWZgK9pKNdsIJZr4wDVfhjQgU0XT6xakSf7 | ||
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 | MIIEBjCCAu6gAwIBAgIJANbQ5QQrKhUGMA0GCSqGSIb3DQEBCwUAMIGXMQswCQYD |
3 | BAYTAlVLMRMwEQYDVQQIEwpEZXJieXNoaXJlMQ8wDQYDVQQHEwZCZWxwZXIxFzAV | 3 | VQQGEwJERTEQMA4GA1UECAwHQmF2YXJpYTEPMA0GA1UEBwwGTXVuaWNoMRswGQYD |
4 | BgNVBAoTDk5hZ2lvcyBQbHVnaW5zMREwDwYDVQQDEwhUb24gVm9vbjEeMBwGCSqG | 4 | VQQKDBJNb25pdG9yaW5nIFBsdWdpbnMxGzAZBgNVBAMMEk1vbml0b3JpbmcgUGx1 |
5 | SIb3DQEJARYPdG9udm9vbkBtYWMuY29tMB4XDTA5MDMwNTIxNDEyOFoXDTE5MDMw | 5 | Z2luczErMCkGCSqGSIb3DQEJARYcZGV2ZWxAbW9uaXRvcmluZy1wbHVnaW5zLm9y |
6 | MzIxNDEyOFowfzELMAkGA1UEBhMCVUsxEzARBgNVBAgTCkRlcmJ5c2hpcmUxDzAN | 6 | ZzAeFw0xOTAyMTkxNTMxNDRaFw0yOTAyMTYxNTMxNDRaMIGXMQswCQYDVQQGEwJE |
7 | BgNVBAcTBkJlbHBlcjEXMBUGA1UEChMOTmFnaW9zIFBsdWdpbnMxETAPBgNVBAMT | 7 | RTEQMA4GA1UECAwHQmF2YXJpYTEPMA0GA1UEBwwGTXVuaWNoMRswGQYDVQQKDBJN |
8 | CFRvbiBWb29uMR4wHAYJKoZIhvcNAQkBFg90b252b29uQG1hYy5jb20wgZ8wDQYJ | 8 | b25pdG9yaW5nIFBsdWdpbnMxGzAZBgNVBAMMEk1vbml0b3JpbmcgUGx1Z2luczEr |
9 | KoZIhvcNAQEBBQADgY0AMIGJAoGBAKcWMBtNtfY8vZXk0SN6/EYTVN/LOvaOSegy | 9 | MCkGCSqGSIb3DQEJARYcZGV2ZWxAbW9uaXRvcmluZy1wbHVnaW5zLm9yZzCCASIw |
10 | oVdLoGwuwjagk+XmCzvCqHZRp8lnCLay7AO8AQI7TSN02ihCcSrgGA9OT+HciIJ1 | 10 | DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKgV2yp8pQvJuN+aJGdAe6Hd0tja |
11 | l5/kEYUAuA1PR6YKK/T713zUAlMzy2tsugx5+xSsSEwsXkmne52jJiG/wuE5CLT0 | 11 | uteCPcNIcM92WLOF69TLTSYon1XDon4tHTh4Z5d4lD8bfsGzFVBmDSgWidhAUf+v |
12 | 9pF8HQqHAgMBAAGjgeYwgeMwHQYDVR0OBBYEFGioSPQ/rdE19+zaeY2YvHTXlUDI | 12 | EqEXwbp293ej/Frc0pXCvmrz6kI1tWrLtQhL/VdbxFYxhV7JjKb+PY3SxGFpSLPe |
13 | MIGzBgNVHSMEgaswgaiAFGioSPQ/rdE19+zaeY2YvHTXlUDIoYGEpIGBMH8xCzAJ | 13 | PQ/5SwVndv7rZIwcjseL22K5Uy2TIrkgzzm2pRs/IvoxRybYr/+LGoHyrtJC6AO8 |
14 | BgNVBAYTAlVLMRMwEQYDVQQIEwpEZXJieXNoaXJlMQ8wDQYDVQQHEwZCZWxwZXIx | 14 | ylp8A/etL0gwtUvRnrnZeTQ2pA1uZ5QN3anTL8JP/ZRZYNegIkaawqMtTKbhM6pi |
15 | FzAVBgNVBAoTDk5hZ2lvcyBQbHVnaW5zMREwDwYDVQQDEwhUb24gVm9vbjEeMBwG | 15 | u3/4a3Uppvt0y7vmGfQlYejxCpICnMrvHMpw8L58zv/98AbCGjDU3UwCt6MCAwEA |
16 | CSqGSIb3DQEJARYPdG9udm9vbkBtYWMuY29tggkAvwuSk3DNh3EwDAYDVR0TBAUw | 16 | AaNTMFEwHQYDVR0OBBYEFG/UH6nGYPlVcM75UXzXBF5GZyrcMB8GA1UdIwQYMBaA |
17 | AwEB/zANBgkqhkiG9w0BAQQFAAOBgQCdqasaIO6JiV5ONFG6Tr1++85UfEdZKMUX | 17 | FG/UH6nGYPlVcM75UXzXBF5GZyrcMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcN |
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+9d81AJTM8trbLoMefsUrEhMLF5Jp3udoyYhv8LhOQi09PaRfB0KhwIDAQAB | 4 | Zg0oFonYQFH/rxKhF8G6dvd3o/xa3NKVwr5q8+pCNbVqy7UIS/1XW8RWMYVeyYym |
5 | AoGAfpxclcP8N3vteXErXURrd7pcXT0GECDgNjhvc9PV20RPXM+vYs1AA+fMeeQE | 5 | /j2N0sRhaUiz3j0P+UsFZ3b+62SMHI7Hi9tiuVMtkyK5IM85tqUbPyL6MUcm2K// |
6 | TaRqwO6x016aMRO4rz5ztYArecTBznkds1k59pkN/Ne/nsueU4tvGK8MNyS2o986 | 6 | ixqB8q7SQugDvMpafAP3rS9IMLVL0Z652Xk0NqQNbmeUDd2p0y/CT/2UWWDXoCJG |
7 | Voohqkaq4Lcy1bcHJb9su1ELjegEr1R76Mz452Hsy+uTbAECQQDcg/tZWKVeh5CQ | 7 | msKjLUym4TOqYrt/+Gt1Kab7dMu75hn0JWHo8QqSApzK7xzKcPC+fM7//fAGwhow |
8 | dOEB3YWHwfn0NDgfPm/X2i2kAZ7n7URaUy/ffdlfsrr1mBtHCfedLoOxmmlNfEpM | 8 | 1N1MArejAgMBAAECggEANuvdTwanTzC8jaNqHaq+OuemS2E9B8nwsGxtH/zFgvNR |
9 | hXAAurSHAkEAwfk7fEb0iN0Sj9gTozO7c6Ky10KwePZyjVzqSQIiJq3NX8BEaIeb | 9 | WZiMPtmrJnTkFWJcV+VPw/iMSAqN4nDHmBugVOb4Z4asxGTKK4T9shXJSnh0rqPU |
10 | 51TXxE5VxaLjjMLRkA0hWTYXClgERFZ6AQJAN7ChPqwzf08PRFwwIw911JY5cOHr | 10 | 00ZsvbmxY6z0+E5TesCJqQ+9GYTY1V357V7JchvaOxIRxWPqg9urHbru8OCtW/I5 |
11 | NoDHMCUql5vNLNdwBruxgGjBB/kUXEfgw60RusFvgt/zLh1wiii844JDawJAGQBF | 11 | Fh5HPUZlgCvlMpjlhyjydIf/oXyVA3RNsXlwe8+2cKuGIrjEzm2j9o3VF0sctTX0 |
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..0caad23d --- /dev/null +++ b/plugins/tests/check_curl.t | |||
@@ -0,0 +1,508 @@ | |||
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 | # give our webservers some time to startup | ||
130 | sleep(1); | ||
131 | } else { | ||
132 | # Child | ||
133 | #print "child\n"; | ||
134 | my $d = HTTP::Daemon->new( | ||
135 | LocalPort => $port_http, | ||
136 | LocalAddr => "127.0.0.1", | ||
137 | ) || die; | ||
138 | print "Please contact http at: <URL:", $d->url, ">\n"; | ||
139 | run_server( $d ); | ||
140 | exit; | ||
141 | } | ||
142 | |||
143 | # Run the same server on http and https | ||
144 | sub run_server { | ||
145 | my $d = shift; | ||
146 | MAINLOOP: while (my $c = $d->accept ) { | ||
147 | while (my $r = $c->get_request) { | ||
148 | if ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) { | ||
149 | $c->send_basic_header($1); | ||
150 | $c->send_crlf; | ||
151 | } elsif ($r->method eq "GET" and $r->url->path =~ m^/file/(.*)^) { | ||
152 | $c->send_basic_header; | ||
153 | $c->send_crlf; | ||
154 | $c->send_file_response("$Bin/var/$1"); | ||
155 | } elsif ($r->method eq "GET" and $r->url->path eq "/slow") { | ||
156 | $c->send_basic_header; | ||
157 | $c->send_crlf; | ||
158 | sleep 1; | ||
159 | $c->send_response("slow"); | ||
160 | } elsif ($r->url->path eq "/method") { | ||
161 | if ($r->method eq "DELETE") { | ||
162 | $c->send_error(HTTP::Status->RC_METHOD_NOT_ALLOWED); | ||
163 | } elsif ($r->method eq "foo") { | ||
164 | $c->send_error(HTTP::Status->RC_NOT_IMPLEMENTED); | ||
165 | } else { | ||
166 | $c->send_status_line(200, $r->method); | ||
167 | } | ||
168 | } elsif ($r->url->path eq "/postdata") { | ||
169 | $c->send_basic_header; | ||
170 | $c->send_crlf; | ||
171 | $c->send_response($r->method.":".$r->content); | ||
172 | } elsif ($r->url->path eq "/redirect") { | ||
173 | $c->send_redirect( "/redirect2" ); | ||
174 | } elsif ($r->url->path eq "/redir_external") { | ||
175 | $c->send_redirect(($d->isa('HTTP::Daemon::SSL') ? "https" : "http") . "://169.254.169.254/redirect2" ); | ||
176 | } elsif ($r->url->path eq "/redirect2") { | ||
177 | $c->send_basic_header; | ||
178 | $c->send_crlf; | ||
179 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' )); | ||
180 | } elsif ($r->url->path eq "/redir_timeout") { | ||
181 | $c->send_redirect( "/timeout" ); | ||
182 | } elsif ($r->url->path eq "/timeout") { | ||
183 | # Keep $c from being destroyed, but prevent severe leaks | ||
184 | unshift @persist, $c; | ||
185 | delete($persist[1000]); | ||
186 | next MAINLOOP; | ||
187 | } elsif ($r->url->path eq "/header_check") { | ||
188 | $c->send_basic_header; | ||
189 | $c->send_header('foo'); | ||
190 | $c->send_crlf; | ||
191 | } elsif ($r->url->path eq "/header_broken_check") { | ||
192 | $c->send_basic_header; | ||
193 | $c->send_header('foo'); | ||
194 | print $c "Test1:: broken\n"; | ||
195 | print $c " Test2: leading whitespace\n"; | ||
196 | $c->send_crlf; | ||
197 | } elsif ($r->url->path eq "/virtual_port") { | ||
198 | # return sent Host header | ||
199 | $c->send_basic_header; | ||
200 | $c->send_crlf; | ||
201 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host'))); | ||
202 | } else { | ||
203 | $c->send_error(HTTP::Status->RC_FORBIDDEN); | ||
204 | } | ||
205 | $c->close; | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | |||
210 | END { | ||
211 | foreach my $pid (@pids) { | ||
212 | if ($pid) { print "Killing $pid\n"; kill "INT", $pid } | ||
213 | } | ||
214 | }; | ||
215 | |||
216 | if ($ARGV[0] && $ARGV[0] eq "-d") { | ||
217 | while (1) { | ||
218 | sleep 100; | ||
219 | } | ||
220 | } | ||
221 | |||
222 | my $result; | ||
223 | my $command = "./$plugin -H 127.0.0.1"; | ||
224 | |||
225 | run_common_tests( { command => "$command -p $port_http" } ); | ||
226 | SKIP: { | ||
227 | skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https}; | ||
228 | run_common_tests( { command => "$command -p $port_https", ssl => 1 } ); | ||
229 | |||
230 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); | ||
231 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); | ||
232 | is( $result->output, "OK - Certificate 'Monitoring Plugins' will expire on Fri Feb 16 15:31:44 2029 +0000.", "output ok" ); | ||
233 | |||
234 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); | ||
235 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); | ||
236 | like( $result->output, '/WARNING - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" ); | ||
237 | |||
238 | # Expired cert tests | ||
239 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); | ||
240 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); | ||
241 | like( $result->output, '/CRITICAL - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" ); | ||
242 | |||
243 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); | ||
244 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); | ||
245 | is( $result->output, | ||
246 | 'CRITICAL - Certificate \'Monitoring Plugins\' expired on Wed Jan 2 11:00:26 2008 +0000.', | ||
247 | "output ok" ); | ||
248 | |||
249 | } | ||
250 | |||
251 | my $cmd; | ||
252 | |||
253 | # advanced checks with virtual hostname and virtual port | ||
254 | SKIP: { | ||
255 | skip "libcurl version is smaller than $required_version", 6 unless $use_advanced_checks; | ||
256 | |||
257 | # http without virtual port | ||
258 | $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$port_http\$"; | ||
259 | $result = NPTest->testCmd( $cmd ); | ||
260 | is( $result->return_code, 0, $cmd); | ||
261 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
262 | |||
263 | # http with virtual port (!= 80) | ||
264 | $cmd = "./$plugin -H $virtual_host:$virtual_port -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$virtual_port\$"; | ||
265 | $result = NPTest->testCmd( $cmd ); | ||
266 | is( $result->return_code, 0, $cmd); | ||
267 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
268 | |||
269 | # http with virtual port (80) | ||
270 | $cmd = "./$plugin -H $virtual_host:80 -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host\$"; | ||
271 | $result = NPTest->testCmd( $cmd ); | ||
272 | is( $result->return_code, 0, $cmd); | ||
273 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
274 | } | ||
275 | |||
276 | # and the same for SSL | ||
277 | SKIP: { | ||
278 | 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; | ||
279 | # https without virtual port | ||
280 | $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host:$port_https\$"; | ||
281 | $result = NPTest->testCmd( $cmd ); | ||
282 | is( $result->return_code, 0, $cmd); | ||
283 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
284 | |||
285 | # https with virtual port (!= 443) | ||
286 | $cmd = "./$plugin -H $virtual_host:$virtual_port -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host:$virtual_port\$"; | ||
287 | $result = NPTest->testCmd( $cmd ); | ||
288 | is( $result->return_code, 0, $cmd); | ||
289 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
290 | |||
291 | # https with virtual port (443) | ||
292 | $cmd = "./$plugin -H $virtual_host:443 -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host\$"; | ||
293 | $result = NPTest->testCmd( $cmd ); | ||
294 | is( $result->return_code, 0, $cmd); | ||
295 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
296 | } | ||
297 | |||
298 | |||
299 | sub run_common_tests { | ||
300 | my ($opts) = @_; | ||
301 | my $command = $opts->{command}; | ||
302 | if ($opts->{ssl}) { | ||
303 | $command .= " --ssl"; | ||
304 | } | ||
305 | |||
306 | $result = NPTest->testCmd( "$command -u /file/root" ); | ||
307 | is( $result->return_code, 0, "/file/root"); | ||
308 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second/', "Output correct" ); | ||
309 | |||
310 | $result = NPTest->testCmd( "$command -u /file/root -s Root" ); | ||
311 | is( $result->return_code, 0, "/file/root search for string"); | ||
312 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second/', "Output correct" ); | ||
313 | |||
314 | $result = NPTest->testCmd( "$command -u /file/root -s NonRoot" ); | ||
315 | is( $result->return_code, 2, "Missing string check"); | ||
316 | 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"); | ||
317 | |||
318 | $result = NPTest->testCmd( "$command -u /file/root -s NonRootWithOver30charsAndMoreFunThanAWetFish" ); | ||
319 | is( $result->return_code, 2, "Missing string check"); | ||
320 | 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"); | ||
321 | |||
322 | $result = NPTest->testCmd( "$command -u /header_check -d foo" ); | ||
323 | is( $result->return_code, 0, "header_check search for string"); | ||
324 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 96 bytes in [\d\.]+ second/', "Output correct" ); | ||
325 | |||
326 | $result = NPTest->testCmd( "$command -u /header_check -d bar" ); | ||
327 | is( $result->return_code, 2, "Missing header string check"); | ||
328 | like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - header 'bar' not found on 'https?://127\.0\.0\.1:\d+/header_check'%, "Shows search string and location"); | ||
329 | |||
330 | $result = NPTest->testCmd( "$command -u /header_broken_check" ); | ||
331 | is( $result->return_code, 0, "header_check search for string"); | ||
332 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 138 bytes in [\d\.]+ second/', "Output correct" ); | ||
333 | |||
334 | my $cmd; | ||
335 | $cmd = "$command -u /slow"; | ||
336 | $result = NPTest->testCmd( $cmd ); | ||
337 | is( $result->return_code, 0, "$cmd"); | ||
338 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
339 | $result->output =~ /in ([\d\.]+) second/; | ||
340 | cmp_ok( $1, ">", 1, "Time is > 1 second" ); | ||
341 | |||
342 | $cmd = "$command -u /statuscode/200"; | ||
343 | $result = NPTest->testCmd( $cmd ); | ||
344 | is( $result->return_code, 0, $cmd); | ||
345 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
346 | |||
347 | $cmd = "$command -u /statuscode/200 -e 200"; | ||
348 | $result = NPTest->testCmd( $cmd ); | ||
349 | is( $result->return_code, 0, $cmd); | ||
350 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - Status line output matched "200" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
351 | |||
352 | $cmd = "$command -u /statuscode/201"; | ||
353 | $result = NPTest->testCmd( $cmd ); | ||
354 | is( $result->return_code, 0, $cmd); | ||
355 | like( $result->output, '/^HTTP OK: HTTP/1.1 201 Created - \d+ bytes in [\d\.]+ second /', "Output correct: ".$result->output ); | ||
356 | |||
357 | $cmd = "$command -u /statuscode/201 -e 201"; | ||
358 | $result = NPTest->testCmd( $cmd ); | ||
359 | is( $result->return_code, 0, $cmd); | ||
360 | like( $result->output, '/^HTTP OK: HTTP/1.1 201 Created - Status line output matched "201" - \d+ bytes in [\d\.]+ second /', "Output correct: ".$result->output ); | ||
361 | |||
362 | $cmd = "$command -u /statuscode/201 -e 200"; | ||
363 | $result = NPTest->testCmd( $cmd ); | ||
364 | is( $result->return_code, 2, $cmd); | ||
365 | like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port \d+: HTTP/1.1 201 Created/', "Output correct: ".$result->output ); | ||
366 | |||
367 | $cmd = "$command -u /statuscode/200 -e 200,201,202"; | ||
368 | $result = NPTest->testCmd( $cmd ); | ||
369 | is( $result->return_code, 0, $cmd); | ||
370 | 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 ); | ||
371 | |||
372 | $cmd = "$command -u /statuscode/201 -e 200,201,202"; | ||
373 | $result = NPTest->testCmd( $cmd ); | ||
374 | is( $result->return_code, 0, $cmd); | ||
375 | 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 ); | ||
376 | |||
377 | $cmd = "$command -u /statuscode/203 -e 200,201,202"; | ||
378 | $result = NPTest->testCmd( $cmd ); | ||
379 | is( $result->return_code, 2, $cmd); | ||
380 | 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 ); | ||
381 | |||
382 | $cmd = "$command -j HEAD -u /method"; | ||
383 | $result = NPTest->testCmd( $cmd ); | ||
384 | is( $result->return_code, 0, $cmd); | ||
385 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 HEAD - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
386 | |||
387 | $cmd = "$command -j POST -u /method"; | ||
388 | $result = NPTest->testCmd( $cmd ); | ||
389 | is( $result->return_code, 0, $cmd); | ||
390 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
391 | |||
392 | $cmd = "$command -j GET -u /method"; | ||
393 | $result = NPTest->testCmd( $cmd ); | ||
394 | is( $result->return_code, 0, $cmd); | ||
395 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
396 | |||
397 | $cmd = "$command -u /method"; | ||
398 | $result = NPTest->testCmd( $cmd ); | ||
399 | is( $result->return_code, 0, $cmd); | ||
400 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
401 | |||
402 | $cmd = "$command -P foo -u /method"; | ||
403 | $result = NPTest->testCmd( $cmd ); | ||
404 | is( $result->return_code, 0, $cmd); | ||
405 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
406 | |||
407 | $cmd = "$command -j DELETE -u /method"; | ||
408 | $result = NPTest->testCmd( $cmd ); | ||
409 | is( $result->return_code, 1, $cmd); | ||
410 | like( $result->output, '/^HTTP WARNING: HTTP/1.1 405 Method Not Allowed/', "Output correct: ".$result->output ); | ||
411 | |||
412 | $cmd = "$command -j foo -u /method"; | ||
413 | $result = NPTest->testCmd( $cmd ); | ||
414 | is( $result->return_code, 2, $cmd); | ||
415 | like( $result->output, '/^HTTP CRITICAL: HTTP/1.1 501 Not Implemented/', "Output correct: ".$result->output ); | ||
416 | |||
417 | $cmd = "$command -P stufftoinclude -u /postdata -s POST:stufftoinclude"; | ||
418 | $result = NPTest->testCmd( $cmd ); | ||
419 | is( $result->return_code, 0, $cmd); | ||
420 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
421 | |||
422 | $cmd = "$command -j PUT -P stufftoinclude -u /postdata -s PUT:stufftoinclude"; | ||
423 | $result = NPTest->testCmd( $cmd ); | ||
424 | is( $result->return_code, 0, $cmd); | ||
425 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
426 | |||
427 | # To confirm that the free doesn't segfault | ||
428 | $cmd = "$command -P stufftoinclude -j PUT -u /postdata -s PUT:stufftoinclude"; | ||
429 | $result = NPTest->testCmd( $cmd ); | ||
430 | is( $result->return_code, 0, $cmd); | ||
431 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
432 | |||
433 | $cmd = "$command -u /redirect"; | ||
434 | $result = NPTest->testCmd( $cmd ); | ||
435 | is( $result->return_code, 0, $cmd); | ||
436 | like( $result->output, '/^HTTP OK: HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
437 | |||
438 | $cmd = "$command -f follow -u /redirect"; | ||
439 | $result = NPTest->testCmd( $cmd ); | ||
440 | is( $result->return_code, 0, $cmd); | ||
441 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
442 | |||
443 | $cmd = "$command -u /redirect -k 'follow: me'"; | ||
444 | $result = NPTest->testCmd( $cmd ); | ||
445 | is( $result->return_code, 0, $cmd); | ||
446 | like( $result->output, '/^HTTP OK: HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
447 | |||
448 | $cmd = "$command -f follow -u /redirect -k 'follow: me'"; | ||
449 | $result = NPTest->testCmd( $cmd ); | ||
450 | is( $result->return_code, 0, $cmd); | ||
451 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
452 | |||
453 | $cmd = "$command -f sticky -u /redirect -k 'follow: me'"; | ||
454 | $result = NPTest->testCmd( $cmd ); | ||
455 | is( $result->return_code, 0, $cmd); | ||
456 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
457 | |||
458 | $cmd = "$command -f stickyport -u /redirect -k 'follow: me'"; | ||
459 | $result = NPTest->testCmd( $cmd ); | ||
460 | is( $result->return_code, 0, $cmd); | ||
461 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
462 | |||
463 | # These tests may block | ||
464 | print "ALRM\n"; | ||
465 | |||
466 | # stickyport - on full urlS port is set back to 80 otherwise | ||
467 | $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; | ||
468 | eval { | ||
469 | local $SIG{ALRM} = sub { die "alarm\n" }; | ||
470 | alarm(2); | ||
471 | $result = NPTest->testCmd( $cmd ); | ||
472 | alarm(0); }; | ||
473 | isnt( $@, "alarm\n", $cmd ); | ||
474 | is( $result->return_code, 0, $cmd ); | ||
475 | |||
476 | # Let's hope there won't be any web server on :80 returning "redirected"! | ||
477 | $cmd = "$command -f sticky -u /redir_external -t 5 -s redirected"; | ||
478 | eval { | ||
479 | local $SIG{ALRM} = sub { die "alarm\n" }; | ||
480 | alarm(2); | ||
481 | $result = NPTest->testCmd( $cmd ); | ||
482 | alarm(0); }; | ||
483 | isnt( $@, "alarm\n", $cmd ); | ||
484 | isnt( $result->return_code, 0, $cmd ); | ||
485 | |||
486 | # Test an external address - timeout | ||
487 | SKIP: { | ||
488 | skip "This doesn't seem to work all the time", 1 unless ($ENV{HTTP_EXTERNAL}); | ||
489 | $cmd = "$command -f follow -u /redir_external -t 5"; | ||
490 | eval { | ||
491 | $result = NPTest->testCmd( $cmd, 2 ); | ||
492 | }; | ||
493 | like( $@, "/timeout in command: $cmd/", $cmd ); | ||
494 | } | ||
495 | |||
496 | $cmd = "$command -u /timeout -t 5"; | ||
497 | eval { | ||
498 | $result = NPTest->testCmd( $cmd, 2 ); | ||
499 | }; | ||
500 | like( $@, "/timeout in command: $cmd/", $cmd ); | ||
501 | |||
502 | $cmd = "$command -f follow -u /redir_timeout -t 2"; | ||
503 | eval { | ||
504 | $result = NPTest->testCmd( $cmd, 5 ); | ||
505 | }; | ||
506 | is( $@, "", $cmd ); | ||
507 | |||
508 | } | ||
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index d6d31de1..2f051fad 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t | |||
@@ -4,13 +4,15 @@ | |||
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; |
@@ -30,13 +32,16 @@ eval { | |||
30 | require HTTP::Response; | 32 | require HTTP::Response; |
31 | }; | 33 | }; |
32 | 34 | ||
35 | my $plugin = 'check_http'; | ||
36 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; | ||
37 | |||
33 | if ($@) { | 38 | if ($@) { |
34 | plan skip_all => "Missing required module for test: $@"; | 39 | plan skip_all => "Missing required module for test: $@"; |
35 | } else { | 40 | } else { |
36 | if (-x "./check_http") { | 41 | if (-x "./$plugin") { |
37 | plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests; | 42 | plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests; |
38 | } else { | 43 | } else { |
39 | plan skip_all => "No check_http compiled"; | 44 | plan skip_all => "No $plugin compiled"; |
40 | } | 45 | } |
41 | } | 46 | } |
42 | 47 | ||
@@ -185,7 +190,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") { | |||
185 | } | 190 | } |
186 | 191 | ||
187 | my $result; | 192 | my $result; |
188 | my $command = "./check_http -H 127.0.0.1"; | 193 | my $command = "./$plugin -H 127.0.0.1"; |
189 | 194 | ||
190 | run_common_tests( { command => "$command -p $port_http" } ); | 195 | run_common_tests( { command => "$command -p $port_http" } ); |
191 | SKIP: { | 196 | SKIP: { |
@@ -194,21 +199,21 @@ SKIP: { | |||
194 | 199 | ||
195 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); | 200 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); |
196 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); | 201 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); |
197 | is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:28 2019 +0000.', "output ok" ); | 202 | is( $result->output, "OK - Certificate 'Monitoring Plugins' will expire on Fri Feb 16 15:31:44 2029 +0000.", "output ok" ); |
198 | 203 | ||
199 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); | 204 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); |
200 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); | 205 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); |
201 | like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019 \+0000\)./', "output ok" ); | 206 | like( $result->output, '/WARNING - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" ); |
202 | 207 | ||
203 | # Expired cert tests | 208 | # Expired cert tests |
204 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); | 209 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); |
205 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); | 210 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); |
206 | like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019 \+0000\)./', "output ok" ); | 211 | like( $result->output, '/CRITICAL - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(Fri Feb 16 15:31:44 2029 \+0000\)./', "output ok" ); |
207 | 212 | ||
208 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); | 213 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); |
209 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); | 214 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); |
210 | is( $result->output, | 215 | is( $result->output, |
211 | 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:16 2009 +0000.', | 216 | 'CRITICAL - Certificate \'Monitoring Plugins\' expired on Wed Jan 2 11:00:26 2008 +0000.', |
212 | "output ok" ); | 217 | "output ok" ); |
213 | 218 | ||
214 | } | 219 | } |
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\"'" ); |
diff --git a/plugins/utils.c b/plugins/utils.c index 231af92b..348ec022 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -36,9 +36,6 @@ extern const char *progname; | |||
36 | #define STRLEN 64 | 36 | #define STRLEN 64 |
37 | #define TXTBLK 128 | 37 | #define TXTBLK 128 |
38 | 38 | ||
39 | unsigned int timeout_state = STATE_CRITICAL; | ||
40 | unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT; | ||
41 | |||
42 | time_t start_time, end_time; | 39 | time_t start_time, end_time; |
43 | 40 | ||
44 | /* ************************************************************************** | 41 | /* ************************************************************************** |
@@ -148,33 +145,6 @@ print_revision (const char *command_name, const char *revision) | |||
148 | command_name, revision, PACKAGE, VERSION); | 145 | command_name, revision, PACKAGE, VERSION); |
149 | } | 146 | } |
150 | 147 | ||
151 | const char * | ||
152 | state_text (int result) | ||
153 | { | ||
154 | switch (result) { | ||
155 | case STATE_OK: | ||
156 | return "OK"; | ||
157 | case STATE_WARNING: | ||
158 | return "WARNING"; | ||
159 | case STATE_CRITICAL: | ||
160 | return "CRITICAL"; | ||
161 | case STATE_DEPENDENT: | ||
162 | return "DEPENDENT"; | ||
163 | default: | ||
164 | return "UNKNOWN"; | ||
165 | } | ||
166 | } | ||
167 | |||
168 | void | ||
169 | timeout_alarm_handler (int signo) | ||
170 | { | ||
171 | if (signo == SIGALRM) { | ||
172 | printf (_("%s - Plugin timed out after %d seconds\n"), | ||
173 | state_text(timeout_state), timeout_interval); | ||
174 | exit (timeout_state); | ||
175 | } | ||
176 | } | ||
177 | |||
178 | int | 148 | int |
179 | is_numeric (char *number) | 149 | is_numeric (char *number) |
180 | { | 150 | { |
@@ -709,3 +679,18 @@ char *sperfdata_int (const char *label, | |||
709 | return data; | 679 | return data; |
710 | } | 680 | } |
711 | 681 | ||
682 | int | ||
683 | open_max (void) | ||
684 | { | ||
685 | errno = 0; | ||
686 | if (maxfd > 0) | ||
687 | return(maxfd); | ||
688 | |||
689 | if ((maxfd = sysconf (_SC_OPEN_MAX)) < 0) { | ||
690 | if (errno == 0) | ||
691 | maxfd = DEFAULT_MAXFD; /* it's indeterminate */ | ||
692 | else | ||
693 | die (STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n")); | ||
694 | } | ||
695 | return(maxfd); | ||
696 | } | ||
diff --git a/plugins/utils.h b/plugins/utils.h index a436e1ca..33a20547 100644 --- a/plugins/utils.h +++ b/plugins/utils.h | |||
@@ -29,13 +29,6 @@ suite of plugins. */ | |||
29 | void support (void); | 29 | void support (void); |
30 | void print_revision (const char *, const char *); | 30 | void print_revision (const char *, const char *); |
31 | 31 | ||
32 | /* Handle timeouts */ | ||
33 | |||
34 | extern unsigned int timeout_state; | ||
35 | extern unsigned int timeout_interval; | ||
36 | |||
37 | RETSIGTYPE timeout_alarm_handler (int); | ||
38 | |||
39 | extern time_t start_time, end_time; | 32 | extern time_t start_time, end_time; |
40 | 33 | ||
41 | /* Test input types */ | 34 | /* Test input types */ |
@@ -89,8 +82,6 @@ void usage4(const char *) __attribute__((noreturn)); | |||
89 | void usage5(void) __attribute__((noreturn)); | 82 | void usage5(void) __attribute__((noreturn)); |
90 | void usage_va(const char *fmt, ...) __attribute__((noreturn)); | 83 | void usage_va(const char *fmt, ...) __attribute__((noreturn)); |
91 | 84 | ||
92 | const char *state_text (int); | ||
93 | |||
94 | #define max(a,b) (((a)>(b))?(a):(b)) | 85 | #define max(a,b) (((a)>(b))?(a):(b)) |
95 | #define min(a,b) (((a)<(b))?(a):(b)) | 86 | #define min(a,b) (((a)<(b))?(a):(b)) |
96 | 87 | ||
@@ -106,6 +97,8 @@ char *sperfdata (const char *, double, const char *, char *, char *, | |||
106 | char *sperfdata_int (const char *, int, const char *, char *, char *, | 97 | char *sperfdata_int (const char *, int, const char *, char *, char *, |
107 | int, int, int, int); | 98 | int, int, int, int); |
108 | 99 | ||
100 | int open_max (void); | ||
101 | |||
109 | /* The idea here is that, although not every plugin will use all of these, | 102 | /* The idea here is that, although not every plugin will use all of these, |
110 | most will or should. Therefore, for consistency, these very common | 103 | most will or should. Therefore, for consistency, these very common |
111 | options should have only these meanings throughout the overall suite */ | 104 | options should have only these meanings throughout the overall suite */ |
@@ -13,10 +13,10 @@ msgstr "" | |||
13 | "PO-Revision-Date: 2004-12-23 17:46+0100\n" | 13 | "PO-Revision-Date: 2004-12-23 17:46+0100\n" |
14 | "Last-Translator: <>\n" | 14 | "Last-Translator: <>\n" |
15 | "Language-Team: English <en@li.org>\n" | 15 | "Language-Team: English <en@li.org>\n" |
16 | "Language: en\n" | ||
17 | "MIME-Version: 1.0\n" | 16 | "MIME-Version: 1.0\n" |
18 | "Content-Type: text/plain; charset=iso-8859-1\n" | 17 | "Content-Type: text/plain; charset=iso-8859-1\n" |
19 | "Content-Transfer-Encoding: 8bit\n" | 18 | "Content-Transfer-Encoding: 8bit\n" |
19 | "Language: en\n" | ||
20 | "Plural-Forms: nplurals=2; plural=(n > 1);X-Generator: KBabel 1.3.1\n" | 20 | "Plural-Forms: nplurals=2; plural=(n > 1);X-Generator: KBabel 1.3.1\n" |
21 | 21 | ||
22 | #: plugins/check_by_ssh.c:86 plugins/check_cluster.c:76 plugins/check_dig.c:88 | 22 | #: plugins/check_by_ssh.c:86 plugins/check_cluster.c:76 plugins/check_dig.c:88 |
@@ -5438,8 +5438,8 @@ msgstr "" | |||
5438 | 5438 | ||
5439 | #: plugins/negate.c:174 | 5439 | #: plugins/negate.c:174 |
5440 | msgid "" | 5440 | msgid "" |
5441 | "Ok must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer " | 5441 | "Ok must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-" |
5442 | "(0-3)." | 5442 | "3)." |
5443 | msgstr "" | 5443 | msgstr "" |
5444 | 5444 | ||
5445 | #: plugins/negate.c:180 | 5445 | #: plugins/negate.c:180 |