From ec537bc4636459970b8bdc7fd7563f08c945699b Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Thu, 15 Aug 2013 17:28:49 +0200 Subject: cleanup after check_http patch (fixes #50) - cleanup whitespace - added test cases - print time_ssl only if ssl is in use - updated news and thanks file diff --git a/NEWS b/NEWS index 41ea0a2..849341f 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ This file documents the major additions and syntax changes between releases. Allow for building the plugins in parallel Add --without-{dbi,ldap,radius} options to ./configure Made Verbose output of check_sensors compliant (Gabriele Tozzi) + New switch -E/--extended-perfdata for check_http to print additional performance data (Sebastian Nohn) FIXES Change the MAIL FROM command generated by check_smtp to be RFC compliant diff --git a/THANKS.in b/THANKS.in index 08c5bcc..54315af 100644 --- a/THANKS.in +++ b/THANKS.in @@ -284,3 +284,4 @@ Vaclav Ovsik Roman Fiedler Fabio Rueda Gabriele Tozzi +Sebastian Nohn diff --git a/plugins/check_http.c b/plugins/check_http.c index ce26ff4..6db38e8 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -1,34 +1,34 @@ /***************************************************************************** -* +* * Nagios check_http plugin -* +* * License: GPL * Copyright (c) 1999-2013 Nagios Plugins Development Team -* +* * Description: -* +* * This file contains the check_http plugin -* +* * This plugin tests the HTTP service on the specified host. It can test * normal (http) and secure (https) servers, follow redirects, search for * strings and regular expressions, check connection times, and report on * certificate expiration times. -* -* +* +* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with this program. If not, see . -* -* +* +* *****************************************************************************/ /* splint -I. -I../../plugins -I../../lib/ -I/usr/kerberos/include/ ../../plugins/check_http.c */ @@ -1145,24 +1145,24 @@ check_http (void) /* check elapsed time */ if (show_extended_perfdata) xasprintf (&msg, - _("%s - %d bytes in %.3f second response time %s|%s %s %s %s %s %s %s"), - msg, page_len, elapsed_time, - (display_html ? "" : ""), - perfd_time (elapsed_time), - perfd_size (page_len), - perfd_time_connect (elapsed_time_connect), - perfd_time_ssl (elapsed_time_ssl), - perfd_time_headers (elapsed_time_headers), - perfd_time_firstbyte (elapsed_time_firstbyte), - perfd_time_transfer (elapsed_time_transfer)); + _("%s - %d bytes in %.3f second response time %s|%s %s %s %s %s %s %s"), + msg, page_len, elapsed_time, + (display_html ? "" : ""), + perfd_time (elapsed_time), + perfd_size (page_len), + perfd_time_connect (elapsed_time_connect), + use_ssl == TRUE ? perfd_time_ssl (elapsed_time_ssl) : "", + perfd_time_headers (elapsed_time_headers), + perfd_time_firstbyte (elapsed_time_firstbyte), + perfd_time_transfer (elapsed_time_transfer)); else xasprintf (&msg, - _("%s - %d bytes in %.3f second response time %s|%s %s"), - msg, page_len, elapsed_time, - (display_html ? "" : ""), - perfd_time (elapsed_time), - perfd_size (page_len)); - + _("%s - %d bytes in %.3f second response time %s|%s %s"), + msg, page_len, elapsed_time, + (display_html ? "" : ""), + perfd_time (elapsed_time), + perfd_size (page_len)); + result = max_state_alt(get_status(elapsed_time, thlds), result); die (result, "HTTP %s: %s\n", state_text(result), msg); @@ -1364,7 +1364,7 @@ char *perfd_time_headers (double elapsed_time_headers) { return fperfdata ("time_headers", elapsed_time_headers, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); } - + char *perfd_time_firstbyte (double elapsed_time_firstbyte) { return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index 6299791..9948c53 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t @@ -8,22 +8,22 @@ use strict; use Test::More; use NPTest; -plan tests => 27; +plan tests => 30; my $successOutput = '/OK.*HTTP.*second/'; my $res; -my $host_tcp_http = getTestParameter( "NP_HOST_TCP_HTTP", - "A host providing the HTTP Service (a web server)", +my $host_tcp_http = getTestParameter( "NP_HOST_TCP_HTTP", + "A host providing the HTTP Service (a web server)", "localhost" ); -my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", +my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1" ); -my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", - "An invalid (not known to DNS) hostname", +my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", + "An invalid (not known to DNS) hostname", "nosuchhost"); my $internet_access = getTestParameter( "NP_INTERNET_ACCESS", @@ -32,8 +32,8 @@ my $internet_access = getTestParameter( "NP_INTERNET_ACCESS", my $host_tcp_http2; if ($internet_access eq "no") { - $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2", - "A host providing an index page containing the string 'nagios'", + $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2", + "A host providing an index page containing the string 'nagios'", "www.nagios.com" ); } @@ -118,6 +118,10 @@ SKIP: { $res = NPTest->testCmd( "./check_http www.verisign.com -C 1" ); cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works"); + $res = NPTest->testCmd( "./check_http --ssl www.verisign.com -E" ); + like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); + like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); + $res = NPTest->testCmd( "./check_http --ssl www.e-paycobalt.com" ); @@ -126,4 +130,7 @@ SKIP: { $res = NPTest->testCmd( "./check_http -H www.mozilla.com -u /firefox -f follow" ); is( $res->return_code, 0, "Redirection based on location is okay"); + + $res = NPTest->testCmd( "./check_http -H www.mozilla.com --extended-perfdata" ); + like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); } -- cgit v0.10-9-g596f