refactor ha state for citrix netscaler (Fix #1604)

This commit is contained in:
garnier-quentin 2019-08-27 15:44:37 +02:00
parent cb5866f4d3
commit dc6b442454
1 changed files with 104 additions and 100 deletions

View File

@ -20,125 +20,105 @@
package network::citrix::netscaler::snmp::mode::hastate; package network::citrix::netscaler::snmp::mode::hastate;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; 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'; sub custom_peer_status_output {
my $oid_haCurState = '.1.3.6.1.4.1.5951.4.1.1.23.24.0'; my ($self, %options) = @_;
my $thresholds = { my $msg = sprintf("Peer status is '%s'", $self->{result_values}->{peer_status});
peerstate => [ return $msg;
['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 %map_hastate_status = ( sub custom_ha_status_output {
0 => 'unknown', my ($self, %options) = @_;
1 => 'init',
2 => 'down',
3 => 'up',
4 => 'partialFail',
5 => 'monitorFail',
6 => 'monitorOk',
7 => 'completeFail',
8 => 'dumb',
9 => 'disabled',
10 => 'partialFailSsl',
11 => 'routemonitorFail',
);
my %map_peerstate_status = ( my $msg = sprintf("High availibility status is '%s'", $self->{result_values}->{ha_status});
0 => 'standalone', return $msg;
1 => 'primary', }
2 => 'secondary',
3 => 'unknown', 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 { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'unknown-ha-status:s' => { name => 'unknown_ha_status', default => '%{ha_status} =~ /unknown/i' },
"threshold-overload:s@" => { name => 'threshold_overload' }, '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; return $self;
} }
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::init(%options); $self->SUPER::check_options(%options);
$self->{overload_th} = {}; $self->change_macros(macros => [
foreach my $val (@{$self->{option_results}->{threshold_overload}}) { 'unknown_peer_status', 'warning_peer_status', 'critical_peer_status',
if ($val !~ /^(.*?),(.*?),(.*)$/) { 'unknown_ha_status', 'warning_ha_status', 'critical_ha_status',
$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};
}
} }
sub run { my $map_ha_status = {
my ($self, %options) = @_; 0 => 'unknown', 1 => 'init',
$self->{snmp} = $options{snmp}; 2 => 'down', 3 => 'up',
4 => 'partialFail', 5 => 'monitorFail',
$self->{result} = $self->{snmp}->get_leef(oids => [$oid_haPeerState, $oid_haCurState], nothing_quit => 1); 6 => 'monitorOk', 7 => 'completeFail',
8 => 'dumb', 9 => 'disabled',
my $exit = $self->get_severity(section => 'peerstate', value => $map_peerstate_status{$self->{result}->{$oid_haPeerState}}); 10 => 'partialFailSsl', 11 => 'routemonitorFail',
$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}}
)
);
$self->{output}->display(); my $map_peer_status = {
$self->{output}->exit(); 0 => 'standalone', 1 => 'primary',
} 2 => 'secondary', 3 => 'unknown',
};
sub get_severity { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $status = 'UNKNOWN'; # default
if (defined($self->{overload_th}->{$options{section}})) { my $oid_haPeerState = '.1.3.6.1.4.1.5951.4.1.1.23.3.0';
foreach (@{$self->{overload_th}->{$options{section}}}) { my $oid_haCurState = '.1.3.6.1.4.1.5951.4.1.1.23.24.0';
if ($options{value} =~ /$_->{filter}/i) { my $snmp_result = $options{snmp}->get_leef(oids => [$oid_haPeerState, $oid_haCurState], nothing_quit => 1);
$status = $_->{status};
return $status; $self->{global} = {
} peer_status => $map_peer_status->{$snmp_result->{$oid_haPeerState}},
} ha_status => $map_ha_status->{$snmp_result->{$oid_haCurState}},
} };
foreach (@{$thresholds->{$options{section}}}) {
if ($options{value} =~ /$$_[0]/i) {
$status = $$_[1];
return $status;
}
}
return $status;
} }
1; 1;
@ -147,15 +127,39 @@ __END__
=head1 MODE =head1 MODE
Check High Availability Status. Check high availability status.
=over 8 =over 8
=item B<--threshold-overload> =item B<--unknown-ha-status>
Set to overload default threshold values (syntax: section,status,regexp). Set warning threshold for status. (Default: '%{ha_status} =~ /unknown/i').
It used before default thresholds (order stays). Can use special variables like: %{ha_status}
Example: --threshold-overload='hastate,CRITICAL,^(?!(up)$)'
=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 =back