refactor ha state for citrix netscaler (Fix #1604)
This commit is contained in:
parent
cb5866f4d3
commit
dc6b442454
|
@ -20,125 +20,105 @@
|
|||
|
||||
package network::citrix::netscaler::snmp::mode::hastate;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
|
||||
|
||||
my $oid_haPeerState = '.1.3.6.1.4.1.5951.4.1.1.23.3.0';
|
||||
my $oid_haCurState = '.1.3.6.1.4.1.5951.4.1.1.23.24.0';
|
||||
sub custom_peer_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $thresholds = {
|
||||
peerstate => [
|
||||
['standalone', 'OK'],
|
||||
['primary', 'OK'],
|
||||
['secondary', 'OK'],
|
||||
['unknown', 'UNKNOWN'],
|
||||
],
|
||||
hastate => [
|
||||
['unknown', 'UNKNOWN'],
|
||||
['down|partialFail|monitorFail|completeFail|partialFailSsl|routemonitorFail', 'CRITICAL'],
|
||||
['init|up|monitorOk|dump|disabled', 'OK'],
|
||||
],
|
||||
};
|
||||
my $msg = sprintf("Peer status is '%s'", $self->{result_values}->{peer_status});
|
||||
return $msg;
|
||||
}
|
||||
|
||||
my %map_hastate_status = (
|
||||
0 => 'unknown',
|
||||
1 => 'init',
|
||||
2 => 'down',
|
||||
3 => 'up',
|
||||
4 => 'partialFail',
|
||||
5 => 'monitorFail',
|
||||
6 => 'monitorOk',
|
||||
7 => 'completeFail',
|
||||
8 => 'dumb',
|
||||
9 => 'disabled',
|
||||
10 => 'partialFailSsl',
|
||||
11 => 'routemonitorFail',
|
||||
);
|
||||
sub custom_ha_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my %map_peerstate_status = (
|
||||
0 => 'standalone',
|
||||
1 => 'primary',
|
||||
2 => 'secondary',
|
||||
3 => 'unknown',
|
||||
);
|
||||
my $msg = sprintf("High availibility status is '%s'", $self->{result_values}->{ha_status});
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, message_separator => ' - ' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'ha-status', set => {
|
||||
key_values => [ { name => 'ha_status' } ],
|
||||
closure_custom_calc => \&catalog_status_calc,
|
||||
closure_custom_output => $self->can('custom_ha_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
}
|
||||
},
|
||||
{ label => 'peer-status', set => {
|
||||
key_values => [ { name => 'peer_status' } ],
|
||||
closure_custom_calc => \&catalog_status_calc,
|
||||
closure_custom_output => $self->can('custom_peer_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"threshold-overload:s@" => { name => 'threshold_overload' },
|
||||
});
|
||||
$options{options}->add_options(arguments => {
|
||||
'unknown-ha-status:s' => { name => 'unknown_ha_status', default => '%{ha_status} =~ /unknown/i' },
|
||||
'warning-ha-status:s' => { name => 'warning_ha_status', default => '' },
|
||||
'critical-ha-status:s' => { name => 'critical_ha_status', default => '%{ha_status} =~ /down|partialFail|monitorFail|completeFail|partialFailSsl|routemonitorFail/i' },
|
||||
'unknown-peer-status:s' => { name => 'unknown_peer_status', default => '%{peer_status} =~ /unknown/i' },
|
||||
'warning-peer-status:s' => { name => 'warning_peer_status', default => '' },
|
||||
'critical-peer-status:s' => { name => 'critical_peer_status', default => '' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
$self->{overload_th} = {};
|
||||
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
|
||||
if ($val !~ /^(.*?),(.*?),(.*)$/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
my ($section, $status, $filter) = ($1, $2, $3);
|
||||
if ($self->{output}->is_litteral_status(status => $status) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
|
||||
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
|
||||
}
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => [
|
||||
'unknown_peer_status', 'warning_peer_status', 'critical_peer_status',
|
||||
'unknown_ha_status', 'warning_ha_status', 'critical_ha_status',
|
||||
]);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{snmp} = $options{snmp};
|
||||
|
||||
$self->{result} = $self->{snmp}->get_leef(oids => [$oid_haPeerState, $oid_haCurState], nothing_quit => 1);
|
||||
|
||||
my $exit = $self->get_severity(section => 'peerstate', value => $map_peerstate_status{$self->{result}->{$oid_haPeerState}});
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Peer State is '%s'",
|
||||
$map_peerstate_status{$self->{result}->{$oid_haPeerState}}
|
||||
)
|
||||
);
|
||||
$exit = $self->get_severity(section => 'hastate', value => $map_hastate_status{$self->{result}->{$oid_haCurState}});
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("High Availibility Status is '%s'",
|
||||
$map_hastate_status{$self->{result}->{$oid_haCurState}}
|
||||
)
|
||||
);
|
||||
my $map_ha_status = {
|
||||
0 => 'unknown', 1 => 'init',
|
||||
2 => 'down', 3 => 'up',
|
||||
4 => 'partialFail', 5 => 'monitorFail',
|
||||
6 => 'monitorOk', 7 => 'completeFail',
|
||||
8 => 'dumb', 9 => 'disabled',
|
||||
10 => 'partialFailSsl', 11 => 'routemonitorFail',
|
||||
};
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
my $map_peer_status = {
|
||||
0 => 'standalone', 1 => 'primary',
|
||||
2 => 'secondary', 3 => 'unknown',
|
||||
};
|
||||
|
||||
sub get_severity {
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
my $status = 'UNKNOWN'; # default
|
||||
|
||||
if (defined($self->{overload_th}->{$options{section}})) {
|
||||
foreach (@{$self->{overload_th}->{$options{section}}}) {
|
||||
if ($options{value} =~ /$_->{filter}/i) {
|
||||
$status = $_->{status};
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (@{$thresholds->{$options{section}}}) {
|
||||
if ($options{value} =~ /$$_[0]/i) {
|
||||
$status = $$_[1];
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
my $oid_haPeerState = '.1.3.6.1.4.1.5951.4.1.1.23.3.0';
|
||||
my $oid_haCurState = '.1.3.6.1.4.1.5951.4.1.1.23.24.0';
|
||||
my $snmp_result = $options{snmp}->get_leef(oids => [$oid_haPeerState, $oid_haCurState], nothing_quit => 1);
|
||||
|
||||
$self->{global} = {
|
||||
peer_status => $map_peer_status->{$snmp_result->{$oid_haPeerState}},
|
||||
ha_status => $map_ha_status->{$snmp_result->{$oid_haCurState}},
|
||||
};
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -147,15 +127,39 @@ __END__
|
|||
|
||||
=head1 MODE
|
||||
|
||||
Check High Availability Status.
|
||||
Check high availability status.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--threshold-overload>
|
||||
=item B<--unknown-ha-status>
|
||||
|
||||
Set to overload default threshold values (syntax: section,status,regexp).
|
||||
It used before default thresholds (order stays).
|
||||
Example: --threshold-overload='hastate,CRITICAL,^(?!(up)$)'
|
||||
Set warning threshold for status. (Default: '%{ha_status} =~ /unknown/i').
|
||||
Can use special variables like: %{ha_status}
|
||||
|
||||
=item B<--warning-ha-status>
|
||||
|
||||
Set warning threshold for status. (Default: '').
|
||||
Can use special variables like: %{ha_status}
|
||||
|
||||
=item B<--critical-ha-status>
|
||||
|
||||
Set critical threshold for status. (Default: '%{ha_status} =~ /down|partialFail|monitorFail|completeFail|partialFailSsl|routemonitorFail/i').
|
||||
Can use special variables like: %{ha_status}
|
||||
|
||||
=item B<--unknown-peer-status>
|
||||
|
||||
Set warning threshold for status. (Default: '%{peer_status} =~ /unknown/i').
|
||||
Can use special variables like: %{peer_status}
|
||||
|
||||
=item B<--warning-peer-status>
|
||||
|
||||
Set warning threshold for status. (Default: '').
|
||||
Can use special variables like: %{peer_status}
|
||||
|
||||
=item B<--critical-peer-status>
|
||||
|
||||
Set critical threshold for status. (Default: '').
|
||||
Can use special variables like: %{peer_status}
|
||||
|
||||
=back
|
||||
|
||||
|
|
Loading…
Reference in New Issue