+ enhance hastate mode
+ more flexibility on triggers + choose exit status when ha doesn't work or not installed + ref https://github.com/centreon/centreon-plugins/issues/373
This commit is contained in:
parent
27459f6f29
commit
e12cad69ee
|
@ -20,16 +20,66 @@
|
||||||
|
|
||||||
package network::checkpoint::mode::hastate;
|
package network::checkpoint::mode::hastate;
|
||||||
|
|
||||||
use base qw(centreon::plugins::mode);
|
use base qw(centreon::plugins::templates::counter);
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
my %map_status = (
|
my $instance_mode;
|
||||||
0 => 'Member is UP and working',
|
|
||||||
1 => 'Problem preventing role switching',
|
sub custom_status_threshold {
|
||||||
2 => 'HA is down',
|
my ($self, %options) = @_;
|
||||||
);
|
my $status = 'ok';
|
||||||
|
my $message;
|
||||||
|
eval {
|
||||||
|
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||||||
|
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||||||
|
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
|
||||||
|
eval "$instance_mode->{option_results}->{critical_status}") {
|
||||||
|
$status = 'critical';
|
||||||
|
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
|
||||||
|
eval "$instance_mode->{option_results}->{warning_status}") {
|
||||||
|
$status = 'warning';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (defined($message)) {
|
||||||
|
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub custom_status_output {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
my $msg = "HA State: '" . $self->{result_values}->{hastate} . "' ";
|
||||||
|
$msg .= "Role: '" . $self->{result_values}->{role} . "' ";
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub custom_status_calc {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
$self->{result_values}->{hastate} = $options{new_datas}->{$self->{instance} . '_hastate'};
|
||||||
|
$self->{result_values}->{role} = $options{new_datas}->{$self->{instance} . '_role'};
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub set_counters {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->{maps_counters_type} = [
|
||||||
|
{ name => 'high_availability', type => 0 },
|
||||||
|
];
|
||||||
|
$self->{maps_counters}->{high_availability} = [
|
||||||
|
{ label => 'status', threshold => 0, set => {
|
||||||
|
key_values => [ { name => 'hastate' }, { name => 'role' } ],
|
||||||
|
closure_custom_calc => $self->can('custom_status_calc'),
|
||||||
|
closure_custom_output => $self->can('custom_status_output'),
|
||||||
|
closure_custom_perfdata => sub { return 0; },
|
||||||
|
closure_custom_threshold_check => $self->can('custom_status_threshold'),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
|
@ -37,53 +87,64 @@ sub new {
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$self->{version} = '1.0';
|
$self->{version} = '1.0';
|
||||||
|
$options{options}->add_options(arguments =>
|
||||||
|
{
|
||||||
|
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||||
|
"critical-status:s" => { name => 'critical_status', default => '%{hastate} !~ /(UP|working)/' },
|
||||||
|
"no-ha-status:s" => { name => 'no_ha_status', default => 'UNKNOWN' },
|
||||||
|
});
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub change_macros {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
foreach ('warning_status', 'critical_status') {
|
||||||
|
if (defined($self->{option_results}->{$_})) {
|
||||||
|
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub check_options {
|
sub check_options {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
$self->SUPER::init(%options);
|
$self->SUPER::check_options(%options);
|
||||||
|
|
||||||
|
$instance_mode = $self;
|
||||||
|
$self->change_macros();
|
||||||
}
|
}
|
||||||
|
|
||||||
sub run {
|
my %map_status = (
|
||||||
|
0 => 'Member is UP and working',
|
||||||
|
1 => 'Problem preventing role switching',
|
||||||
|
2 => 'HA is down',
|
||||||
|
);
|
||||||
|
|
||||||
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
$self->{snmp} = $options{snmp};
|
|
||||||
|
|
||||||
my $oid_haInstalled = '.1.3.6.1.4.1.2620.1.5.2.0';
|
my $oid_haInstalled = '.1.3.6.1.4.1.2620.1.5.2.0';
|
||||||
my $oid_haState = '.1.3.6.1.4.1.2620.1.5.6.0';
|
my $oid_haState = '.1.3.6.1.4.1.2620.1.5.6.0';
|
||||||
my $oid_haStatCode = '.1.3.6.1.4.1.2620.1.5.101.0';
|
my $oid_haStatCode = '.1.3.6.1.4.1.2620.1.5.101.0';
|
||||||
my $oid_haStarted = '.1.3.6.1.4.1.2620.1.5.5.0';
|
my $oid_haStarted = '.1.3.6.1.4.1.2620.1.5.5.0';
|
||||||
|
|
||||||
my $result = $self->{snmp}->get_leef(oids => [$oid_haInstalled, $oid_haState, $oid_haStatCode, $oid_haStarted], nothing_quit => 1);
|
$self->{high_availability} = {};
|
||||||
|
|
||||||
|
my $result = $options{snmp}->get_leef(oids => [$oid_haInstalled, $oid_haState, $oid_haStatCode, $oid_haStarted],
|
||||||
|
nothing_quit => 1);
|
||||||
|
|
||||||
if ($result->{$oid_haInstalled} < 1 or $result->{$oid_haStarted} eq "no") {
|
if ($result->{$oid_haInstalled} < 1 or $result->{$oid_haStarted} eq "no") {
|
||||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
$self->{output}->output_add(severity => $self->{option_results}->{no_ha_state},
|
||||||
short_msg => sprintf("Looks like HA is not started, or not installed .."),
|
short_msg => sprintf("Looks like HA is not started, or not installed .."),
|
||||||
long_msg => sprintf("HA Installed : '%u' HA Started : '%s'", $result->{$oid_haInstalled}, $result->{$oid_haStarted}),
|
long_msg => sprintf("HA Installed : '%u' HA Started : '%s'",
|
||||||
|
$result->{$oid_haInstalled}, $result->{$oid_haStarted}),
|
||||||
);
|
);
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
}
|
}
|
||||||
|
$self->{high_availability} = { hastate => $map_status{$result->{$oid_haStatCode}},
|
||||||
my $status = $result->{$oid_haStatCode};
|
role => $result->{$oid_haState} };
|
||||||
|
|
||||||
if ($status < 1 ) {
|
|
||||||
$self->{output}->output_add(severity => 'OK',
|
|
||||||
short_msg => sprintf("'%s'. State : '%s'", $map_status{$status}, $result->{$oid_haState}),
|
|
||||||
);
|
|
||||||
} elsif ($status == 1) {
|
|
||||||
$self->{output}->output_add(severity => 'WARNING',
|
|
||||||
short_msg => sprintf("'%s'. State : '%s'", $map_status{$status}, $result->{$oid_haState}),
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$self->{output}->output_add(severity => 'CRITICAL',
|
|
||||||
short_msg => sprintf("'%s'. State : '%s'", $map_status{$status}, $result->{$oid_haState}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->{output}->display();
|
|
||||||
$self->{output}->exit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -94,7 +155,16 @@ __END__
|
||||||
|
|
||||||
Check HA State of a Checkpoint node (chkpnt.mib).
|
Check HA State of a Checkpoint node (chkpnt.mib).
|
||||||
|
|
||||||
|
=item B<--warning-status>
|
||||||
|
|
||||||
|
Trigger warning on %{role} or %{hastate} values
|
||||||
|
e.g --warning-status '%{role} !~ /master/' will warn when failover occurs
|
||||||
|
|
||||||
|
=item B<--critical-status>
|
||||||
|
|
||||||
|
Trigger critical on %{role} or %{hastate} values
|
||||||
|
(default: '%{hastate} !~ /(UP|working)/')
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue