From a82a8948ed785c6be8ed9c5f0abdbd9cfca2a878 Mon Sep 17 00:00:00 2001 From: tatref Date: Wed, 12 Jul 2023 15:50:03 +0200 Subject: [PATCH] validate number of proxies --- check_haproxy_stats.pl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/check_haproxy_stats.pl b/check_haproxy_stats.pl index 3b6dabf..b642ed1 100755 --- a/check_haproxy_stats.pl +++ b/check_haproxy_stats.pl @@ -251,6 +251,7 @@ sub usage { my $exitcode = 0; my $msg; my $checked = 0; +my %checked_proxies; my $perfdata = ""; # Remove excluded proxies from the list if both -p and -P options are @@ -267,6 +268,8 @@ sub usage { if (@proxies) { next unless grep {$data[$pxname] eq $_} @proxies; }; if (@no_proxies) { next if grep {$data[$pxname] eq $_} @no_proxies; }; + $checked_proxies{$data[$pxname]} = "found"; + # Is session limit enforced? if ($data[$slim]) { $perfdata .= sprintf "%s-%s=%u;%u;%u;0;%u;", $data[$pxname], $data[$svname], $data[$scur], $swarn * $data[$slim] / 100, $scrit * $data[$slim] / 100, $data[$slim]; @@ -311,6 +314,11 @@ sub usage { ++$checked; } +if (@proxies && 0+@proxies > 0+keys %checked_proxies) { + $exitcode = 2; + $msg = "Not all proxies checked for @proxies."; +} + unless ($msg) { $msg = @proxies ? sprintf("checked proxies: %s", join ', ', sort @proxies) : "checked $checked proxies."; }