Commit 453da0bb authored by Cyril Feraudet's avatar Cyril Feraudet
Browse files

- Passes through and reports errors from squidclient, making it easier

  to figure out the correct command syntax and perform diagnostics.
- More useful output text for reporting FileDescriptors data.
- Various minor spelling and grammar corrections.
- Version number increased from 1.00 to 1.01.
parent 796f607a
#!/usr/bin/perl
###################################################################
# check_squid is developped with GPL Licence 2.0
# check_squid is developed with GPL Licence 2.0
#
# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
#
# Developped by : Cyril Feraudet
# Developed by: Cyril Feraudet
# Contributors :
# - Nicolad Rofort
# - James Turner
# - MakleKing
# - Thomas Beinicke
# - Jeremy Jacquier-Roux
#
###################################################################
# This program is free software; you can redistribute it and/or
......@@ -17,17 +23,18 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# For information : cyril@feraudet.com
# For information: cyril@feraudet.com
####################################################################
my $VERSION = "1.0";
my $VERSION = "1.01";
$|;
use Nagios::Plugin;
# todo : use strict;
$np = Nagios::Plugin->new(usage => "Usage: %s [ -v|--verbose ] [ -H <host> ] [ -d <data> ] [ -p <port> ] [ -t <timeout>] [ -c <threshold> ] [ -w <threshold> ]", version => $VERSION);
$np = Nagios::Plugin->new(
usage => "Usage: %s [ -v|--verbose ] [ -H <host> ] [ -d <data> ] [ -p <port> ] [ -t <timeout>] [ -c <threshold> ] [ -w <threshold> ]",
version => $VERSION);
$np->add_arg(
spec => 'host|H=s',
......@@ -39,8 +46,8 @@ $np->add_arg(
$np->add_arg( # Connections Cache Resources Memory FileDescriptors
spec => 'data|d=s',
help => "-d, --data=<data>\n"
. " Optional data to fetch (default: Connections)"
. " available data : Connections Cache Resources Memory FileDescriptors",
. " Optional data to fetch (default: Connections)\n"
. " Available data: Connections Cache Resources Memory FileDescriptors",
required => 0
);
......@@ -109,7 +116,6 @@ my $critical = $np->opts->critical;
my $warning = $np->opts->warning;
my $squidclient = $np->opts->squidclient;
$host = 'localhost' if (!defined($host) or $host eq '');
$port = 3128 if (!defined($port) or $port eq '');
$data = 'Connections' if (!defined($data) or $data eq '');
......@@ -126,10 +132,12 @@ $np->set_thresholds(critical => $critical, warning => $warning);
@exec = ("-h", "\Q$host", "-p", "\Q$port", "-U", "\Q$user", "-W", "\Q$password", "mgr:info");
if (! -x $squidclient) {
die "$squidclient not found !";
die "$squidclient not found";
}
@result = `$squidclient @exec`;
@result = `$squidclient @exec 2>&1`;
if($? > 0) { $np->nagios_exit("CRITICAL",$result[0]); }
my $fd_available;
my $fd_used;
......@@ -235,7 +243,7 @@ if($data =~ /Connections/i) # Connections Cache Resources Memory FileDescriptor
$np->add_perfdata( label => "HTTP requests", value => $connection_nbhttpreceived, uom => "c");
$np->add_perfdata( label => "sent ICP requests", value => $connection_nbicpsent, uom => "c");
$np->add_perfdata( label => "received ICP requests", value => $connection_nbicpreceived, uom => "c");
$np->nagios_exit('OK', "Squid have $connection_nbclient clients and $connection_nbicpqueued ICP requests queued");
$np->nagios_exit('OK', "$connection_nbclient clients, $connection_nbicpqueued queued ICP requests");
}
if($data =~ /Cache/i)
{
......@@ -257,20 +265,12 @@ if($data =~ /Memory/i)
my $t = Nagios::Plugin::Threshold->set_thresholds(warning => $warning, critical => $critical);
$np->add_perfdata( label => "Memory used", value => $memory_used, uom => "KB", threshold => $t);
$np->add_perfdata( label => "Memory available", value => $memory_available, uom => "KB");
$np->nagios_exit($np->check_threshold($memory_used), "Squid use $memory_used KB of memory");
$np->nagios_exit($np->check_threshold($memory_used), "Using $memory_used KB of memory");
}
if($data =~ /FileDescriptors/i)
{
my $t = Nagios::Plugin::Threshold->set_thresholds(warning => $warning, critical => $critical);
$np->add_perfdata( label => "Max FD", value => $fd_available);
$np->add_perfdata( label => "Cur FD", value => $fd_used, threshold => $t);
$np->nagios_exit($np->check_threshold($fd_used), 'Squid work fine.');
$np->nagios_exit($np->check_threshold($fd_used), "Using $fd_used file descriptors. (Maximum: $fd_available)");
}
# $np->nagios_exit('OK', $output);
# $np->nagios_exit('WARNING', $output);
# $np->nagios_exit('CRITICAL', $output);
# $np->nagios_exit('UNKNOWN', $output);
# $np->nagios_exit('DEPENDENT', $output);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment