Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
Directory
rmtzcx
byrmtzcx, January 22, 2019
First, thanks for sharing. The script works fine when squid is running fine, however when squid is not running or you send invalid data (-d) the script doesn't return an error.
# Works fine as long as squid is up and running:
~]$ ./check_squid -H myproxy.server.tld -p 3128
SQUID OK - Squid have 12 clients and 0 ICP requests queued | 'HTTP requests'=4735c;; 'sent ICP requests'=0c;; 'received ICP requests'=0c;;
# No errors or messages when you send invalid data (-d):
~]$ ./check_squid -H myproxy.server.tld -p 3128 -d blah
~]$
# Warnings, but no errors if squid is not running:
~]$ sudo systemctl stop squid
~]$ ./check_squid -H myproxy.server.tld -p 3128
ERROR: Cannot connect to 192.168.x.x:3128
ERROR: Cannot connect to 192.168.x.x:3128
Use of uninitialized value in sprintf at /usr/share/perl5/vendor_perl/Nagios/Plugin/Performance.pm line 68.
Use of uninitialized value in sprintf at /usr/share/perl5/vendor_perl/Nagios/Plugin/Performance.pm line 68.
Use of uninitialized value in sprintf at /usr/share/perl5/vendor_perl/Nagios/Plugin/Performance.pm line 68.
Use of uninitialized value in sprintf at /usr/share/perl5/vendor_perl/Nagios/Plugin/Performance.pm line 68.
Use of uninitialized value in sprintf at /usr/share/perl5/vendor_perl/Nagios/Plugin/Performance.pm line 68.
Use of uninitialized value in sprintf at /usr/share/perl5/vendor_perl/Nagios/Plugin/Performance.pm line 68.
SQUID OK - Squid have clients and ICP requests queued | 'HTTP requests'=c;; 'sent ICP requests'=c;; 'received ICP requests'=c;;
Apply the patch below to fix both issues above:
1. Download check_squid file
1. Save the patch below as check_squid.patch
2. Apply the patch to check_squid with: patch -i check_squid.patch check_squid
--- check_squid.a 2019-01-22 08:48:59.104963842 -0600
+++ check_squid.b 2019-01-22 08:45:39.348819397 -0600
@@ -122,8 +122,11 @@
@exec = ("-h", "\Q$host", "-p", "\Q$port", "-U", "\Q$user", "-W", "\Q$password", "mgr:info");
-@result = `$squidclient @exec`;
+@result = `$squidclient @exec 2>&1`;
+if ($? != 0) {
+ $np->nagios_exit('CRITICAL', @result);
+}
my $fd_available;
my $fd_used;
@@ -286,6 +289,8 @@
}
+$np->nagios_exit('WARNING', "Invalid data (-d)");
+
# $np->nagios_exit('OK', $output);
# $np->nagios_exit('WARNING', $output);
# Works fine as long as squid is up and running:
~]$ ./check_squid -H myproxy.server.tld -p 3128
SQUID OK - Squid have 12 clients and 0 ICP requests queued | 'HTTP requests'=4735c;; 'sent ICP requests'=0c;; 'received ICP requests'=0c;;
# No errors or messages when you send invalid data (-d):
~]$ ./check_squid -H myproxy.server.tld -p 3128 -d blah
~]$
# Warnings, but no errors if squid is not running:
~]$ sudo systemctl stop squid
~]$ ./check_squid -H myproxy.server.tld -p 3128
ERROR: Cannot connect to 192.168.x.x:3128
ERROR: Cannot connect to 192.168.x.x:3128
Use of uninitialized value in sprintf at /usr/share/perl5/vendor_perl/Nagios/Plugin/Performance.pm line 68.
Use of uninitialized value in sprintf at /usr/share/perl5/vendor_perl/Nagios/Plugin/Performance.pm line 68.
Use of uninitialized value in sprintf at /usr/share/perl5/vendor_perl/Nagios/Plugin/Performance.pm line 68.
Use of uninitialized value in sprintf at /usr/share/perl5/vendor_perl/Nagios/Plugin/Performance.pm line 68.
Use of uninitialized value in sprintf at /usr/share/perl5/vendor_perl/Nagios/Plugin/Performance.pm line 68.
Use of uninitialized value in sprintf at /usr/share/perl5/vendor_perl/Nagios/Plugin/Performance.pm line 68.
SQUID OK - Squid have clients and ICP requests queued | 'HTTP requests'=c;; 'sent ICP requests'=c;; 'received ICP requests'=c;;
Apply the patch below to fix both issues above:
1. Download check_squid file
1. Save the patch below as check_squid.patch
2. Apply the patch to check_squid with: patch -i check_squid.patch check_squid
--- check_squid.a 2019-01-22 08:48:59.104963842 -0600
+++ check_squid.b 2019-01-22 08:45:39.348819397 -0600
@@ -122,8 +122,11 @@
@exec = ("-h", "\Q$host", "-p", "\Q$port", "-U", "\Q$user", "-W", "\Q$password", "mgr:info");
-@result = `$squidclient @exec`;
+@result = `$squidclient @exec 2>&1`;
+if ($? != 0) {
+ $np->nagios_exit('CRITICAL', @result);
+}
my $fd_available;
my $fd_used;
@@ -286,6 +289,8 @@
}
+$np->nagios_exit('WARNING', "Invalid data (-d)");
+
# $np->nagios_exit('OK', $output);
# $np->nagios_exit('WARNING', $output);