From a2f5e5ed1051e8157bf3a85044717acb5a592f7f Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Sun, 12 Jun 2016 15:24:42 +0200 Subject: [PATCH] check_nginx_status: Updating to 0.20 --- check_nginx_status/check_nginx_status | 56 +++++++++++++++++++++++---- check_nginx_status/control | 2 +- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/check_nginx_status/check_nginx_status b/check_nginx_status/check_nginx_status index 5188d73..24091ee 100644 --- a/check_nginx_status/check_nginx_status +++ b/check_nginx_status/check_nginx_status @@ -1,12 +1,11 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl -w # check_nginx_status.pl -# Version : 0.10 # Author : regis.leroy at makina-corpus.com # Licence : GPL - http://www.fsf.org/licenses/gpl.txt # # help : ./check_nginx_status.pl -h # -# issues & updates: http://github.com/regilero/check_inginx_status +# issues & updates: http://github.com/regilero/check_nginx_status use strict; use Getopt::Long; use LWP::UserAgent; @@ -20,7 +19,7 @@ use lib $FindBin::Bin; use utils qw($TIMEOUT); # Globals -my $Version='0.9'; +my $Version='0.20'; my $Name=$0; my $o_host = undef; # hostname @@ -43,6 +42,7 @@ my $o_crit_thresold= undef; # critical thresolds entry my $o_debug= undef; # debug mode my $o_servername= undef; # ServerName (host header in http request) my $o_https= undef; # SSL (HTTPS) mode +my $o_disable_sslverifyhostname = 0; my $TempPath = '/tmp/'; # temp path my $MaxTimeDif = 60*30; # Maximum uptime difference (seconds), default 30 minutes @@ -98,6 +98,8 @@ sub help { ServerName, (host header of HTTP request) use it if you specified an IP in -H to match the good Virtualhost in your target -S, --ssl Wether we should use HTTPS instead of HTTP +--disable-sslverifyhostname + Disable SSL hostname verification -U, --user=user Username for basic auth -P, --pass=PASS @@ -158,6 +160,7 @@ sub check_options { 'w:s' => \$o_warn_thresold,'warn:s' => \$o_warn_thresold, 'c:s' => \$o_crit_thresold,'critical:s' => \$o_crit_thresold, 't:i' => \$o_timeout, 'timeout:i' => \$o_timeout, + 'disable-sslverifyhostname' => \$o_disable_sslverifyhostname, ); if (defined ($o_help)) { @@ -207,6 +210,11 @@ my $ua = LWP::UserAgent->new( protocols_allowed => ['http', 'https'], timeout => $o_timeout ); + +if ( $o_disable_sslverifyhostname ) { + $ua->ssl_opts( 'verify_hostname' => 0 ); +} + # we need to enforce the HTTP request is made on the Nagios Host IP and # not on the DNS related IP for that domain @LWP::Protocol::http::EXTRA_SOCK_OPTS = ( PeerAddr => $override_ip ); @@ -381,7 +389,8 @@ if ($response->is_success) { } # check only if the counters may have been incremented # but not if it may have been too much incremented - if ( ($elapsed < $MaxTimeDif) && ($elapsed != 0) ) { + # if nginx was restarted ($NbRequests is now lower than previous value), just skip + if ( ($elapsed < $MaxTimeDif) && ($elapsed != 0) && ($NbRequests >= $LastNbRequests) ) { $ConnPerSec = ($AcceptedConn-$LastAcceptedConn)/$elapsed; $RequestsNew = $NbRequests-$LastNbRequests; $ReqPerSec = $RequestsNew/$elapsed; @@ -399,10 +408,41 @@ if ($response->is_success) { $InfoData = sprintf (" %.3f sec. response time, Active: %d (Writing: %d Reading: %d Waiting: %d)" . " ReqPerSec: %.3f ConnPerSec: %.3f ReqPerConn: %.3f" ,$timeelapsed,$ActiveConn,$Writing,$Reading,$Waiting,$ReqPerSec,$ConnPerSec,$ReqPerConn); - $PerfData = sprintf ("Writing=%d;;;; Reading=%d;;;; Waiting=%d;;;; Active=%d;;;; " - . "ReqPerSec=%f;;;; ConnPerSec=%f;;;; ReqPerConn=%f;;;;" + + # Manage warn and crit values for the perfdata + my $p_warn_a_level = "$o_warn_a_level"; + my $p_crit_a_level = "$o_crit_a_level"; + my $p_warn_rps_level = "$o_warn_rps_level"; + my $p_crit_rps_level = "$o_crit_rps_level"; + my $p_warn_cps_level = "$o_warn_cps_level"; + my $p_crit_cps_level = "$o_crit_cps_level"; + + if ($p_warn_a_level == "-1") { + $p_warn_a_level = ""; + } + if ($p_crit_a_level == "-1") { + $p_crit_a_level = ""; + } + if ($p_warn_rps_level == "-1") { + $p_warn_rps_level = ""; + } + if ($p_crit_rps_level == "-1") { + $p_crit_rps_level = ""; + } + if ($p_warn_cps_level == "-1") { + $p_warn_cps_level = ""; + } + if ($p_crit_cps_level == "-1") { + $p_crit_cps_level = ""; + } + + $PerfData = sprintf ("Writing=%d;;;; Reading=%d;;;; Waiting=%d;;;; Active=%d;%s;%s;; " + . "ReqPerSec=%f;%s;%s;; ConnPerSec=%f;%s;%s;; ReqPerConn=%f;;;;" ,($Writing),($Reading),($Waiting),($ActiveConn) - ,($ReqPerSec),($ConnPerSec),($ReqPerConn)); + ,($p_warn_a_level),($p_crit_a_level) + ,($ReqPerSec),($p_warn_rps_level),($p_crit_rps_level) + ,($ConnPerSec),($p_warn_cps_level),($p_crit_cps_level) + ,($ReqPerConn)); # first all critical exists by priority if (defined($o_crit_a_level) && (-1!=$o_crit_a_level) && ($ActiveConn >= $o_crit_a_level)) { nagios_exit($nginx,"CRITICAL", "Active Connections are critically high " . $InfoData,$PerfData); diff --git a/check_nginx_status/control b/check_nginx_status/control index 2bd53d0..afe2adb 100644 --- a/check_nginx_status/control +++ b/check_nginx_status/control @@ -1,7 +1,7 @@ Homepage: https://raw.github.com/regilero/check_nginx_status/master/check_nginx_status.pl Watch: https://raw.github.com/regilero/check_nginx_status/master/check_nginx_status.pl \$Version\=\'([0-9.]+)' Recommends: libwww-perl, monitoring-plugins-common | nagios-plugins-common -Version: 0.10 +Version: 0.20 Uploaders: Jan Wagner Description: plugin checking the nginx_status page report from nginx Tracking Active connections processes, request per second, connections per