Skip to content

Commit

Permalink
src - Add option to HA to report all warn as crit
Browse files Browse the repository at this point in the history
* Add option to HA check to report all WARNING states as CRITICAL
  • Loading branch information
phibos committed Dec 15, 2023
1 parent 965b40d commit 0525e5b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions check_sophos_xg_ha.pl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ BEGIN
default => [],
);

$mp->add_arg(
spec => 'warning-is-critical',
help => 'The plugin reports all WARNING states as CRITICAL. Use it if everything not OK should be reported as CRITICAL. If the device does not respond to SNMP requests the check will still report UNKOWN.',
default => 0,

);

$mp->getopts;


Expand Down Expand Up @@ -164,6 +171,7 @@ sub check
my $sfosDevicePeerHAState = $sfosXGHAStats . '.5.0';
my $sfosDeviceHAConfigMode = $sfosXGHAStats . '.6.0';
my $sfosDeviceLoadBalancing = $sfosXGHAStats . '.7.0';
my $warning_or_critical = ($mp->opts->{'warning-is-critical'}) ? CRITICAL : WARNING;

my %HaStatusType = (
0 => 'disabled',
Expand Down Expand Up @@ -199,7 +207,7 @@ sub check
}

if ($result->{$sfosHAStatus} != 1) {
my $state = WARNING;
my $state = $warning_or_critical;
my $message = 'HA is disabled but it should be enabled';
if ($mp->opts->{'disabled-ok'}) {
# Exit with OK if a disabled HA mode is OK
Expand All @@ -219,15 +227,15 @@ sub check
if ($result->{$sfosDeviceCurrentHAState} == 3 or $result->{$sfosDevicePeerHAState} == 3) {
$mp->add_message(OK, $message);
} elsif ($result->{$sfosDeviceCurrentHAState} == 2) {
$mp->add_message(WARNING, 'No primary peer found, but running in standalone mode: ' . $message);
$mp->add_message($warning_or_critical, 'No primary peer found, but running in standalone mode: ' . $message);
} else {
$mp->add_message(CRITICAL, 'No primary peer found: ' . $message);
}

if(@{$mp->opts->{'expected-mode'}} > 0) {
if (!grep(/^$result->{$sfosDeviceHAConfigMode}$/, @{$mp->opts->{'expected-mode'}})) {
$mp->add_message(
WARNING,
$warning_or_critical,
sprintf(
'Mode is "%s" but expected "%s"',
$result->{$sfosDeviceHAConfigMode},
Expand Down

0 comments on commit 0525e5b

Please sign in to comment.