+ enhance cisco asa failover mode (WIP)
This commit is contained in:
parent
25501609aa
commit
b055c75ac0
|
@ -20,33 +20,97 @@
|
|||
|
||||
package network::cisco::asa::mode::failover;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my %map_failover = (
|
||||
1 => 'other',
|
||||
2 => 'up', # for '.4' index
|
||||
3 => 'down', # can be
|
||||
4 => 'error', # maybe
|
||||
5 => 'overTemp',
|
||||
6 => 'busy',
|
||||
7 => 'noMedia',
|
||||
8 => 'backup',
|
||||
9 => 'active', # can be
|
||||
10 => 'standby' # can be
|
||||
);
|
||||
my $instance_mode;
|
||||
|
||||
sub custom_status_threshold {
|
||||
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_change_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf("Primary unit is '%s' [details: '%s'], Secondary unit is '%s' [details : '%s']",
|
||||
$self->{result_values}->{primaryState}, $self->{result_values}->{primaryDetails},
|
||||
$self->{result_values}->{secondaryState}, $self->{result_values}->{secondaryDetails});
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_change_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{primaryStateLast} = $options{old_datas}->{$self->{instance} . '_primary_state'};
|
||||
$self->{result_values}->{primaryState} = $options{new_datas}->{$self->{instance} . '_primary_state'};
|
||||
$self->{result_values}->{secondaryStateLast} = $options{old_datas}->{$self->{instance} . '_secondary_state'};
|
||||
$self->{result_values}->{secondaryState} = $options{new_datas}->{$self->{instance} . '_secondary_state'};
|
||||
$self->{result_values}->{primaryDetails} = $options{new_datas}->{$self->{instance} . '_primary_details'};
|
||||
$self->{result_values}->{secondaryDetails} = $options{new_datas}->{$self->{instance} . '_secondary_details'};
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, message_separator => ' - ' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'active-units', set => {
|
||||
key_values => [ { name => 'active_units' } ],
|
||||
output_template => 'Active units : %s',
|
||||
perfdatas => [
|
||||
{ label => 'active_units', value => 'active_units_absolute', template => '%s',
|
||||
min => 0, max => 2 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
key_values => [ { name => 'primary_state', diff => 1 }, { name => 'secondary_state', diff => 1 }, { name => 'primary_details' }, { name => 'secondary_details' } ],
|
||||
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 {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"dont-warn-notstandby" => { name => 'dont_warn_notstandby' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -54,7 +118,20 @@ sub new {
|
|||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$instance_mode = $self;
|
||||
$self->change_macros();
|
||||
}
|
||||
|
||||
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 run {
|
||||
|
@ -63,20 +140,9 @@ sub run {
|
|||
|
||||
my $active_units = 0;
|
||||
my $exit = 'ok';
|
||||
# primary is '.6' index and secondary is '.7' index (it's like that. '.4' is the global interface)
|
||||
my $oid_cfwHardwareStatusValue_primary = '.1.3.6.1.4.1.9.9.147.1.2.1.1.1.3.6';
|
||||
my $oid_cfwHardwareStatusValue_secondary = '.1.3.6.1.4.1.9.9.147.1.2.1.1.1.3.7';
|
||||
my $oid_cfwHardwareStatusDetail_primary = '.1.3.6.1.4.1.9.9.147.1.2.1.1.1.4.6';
|
||||
my $oid_cfwHardwareStatusDetail_secondary = '.1.3.6.1.4.1.9.9.147.1.2.1.1.1.4.7';
|
||||
my $result = $self->{snmp}->get_leef(oids => [$oid_cfwHardwareStatusValue_primary, $oid_cfwHardwareStatusValue_secondary,
|
||||
$oid_cfwHardwareStatusDetail_primary, $oid_cfwHardwareStatusDetail_secondary], nothing_quit => 1);
|
||||
|
||||
if ($result->{$oid_cfwHardwareStatusValue_primary} == 9 || $result->{$oid_cfwHardwareStatusValue_primary} == 10 ) {
|
||||
$active_units++;
|
||||
}
|
||||
if ($result->{$oid_cfwHardwareStatusValue_secondary} == 9 || $result->{$oid_cfwHardwareStatusValue_secondary} == 10 ) {
|
||||
$active_units++;
|
||||
}
|
||||
|
||||
|
||||
if ($active_units == 0) {
|
||||
$exit = 'critical';
|
||||
} elsif ($active_units == 1 && !defined($self->{option_results}->{dont_warn_notstandby})) {
|
||||
|
@ -97,6 +163,45 @@ sub run {
|
|||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my %map_failover = (
|
||||
1 => 'other',
|
||||
2 => 'up', # for '.4' index
|
||||
3 => 'down', # can be
|
||||
4 => 'error', # maybe
|
||||
5 => 'overTemp',
|
||||
6 => 'busy',
|
||||
7 => 'noMedia',
|
||||
8 => 'backup',
|
||||
9 => 'active', # can be
|
||||
10 => 'standby' # can be
|
||||
);
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{global} = {};
|
||||
|
||||
# primary is '.6' index and secondary is '.7' index (it's like that. '.4' is the global interface)
|
||||
my $oid_cfwHardwareStatusValue_primary = '.1.3.6.1.4.1.9.9.147.1.2.1.1.1.3.6';
|
||||
my $oid_cfwHardwareStatusValue_secondary = '.1.3.6.1.4.1.9.9.147.1.2.1.1.1.3.7';
|
||||
my $oid_cfwHardwareStatusDetail_primary = '.1.3.6.1.4.1.9.9.147.1.2.1.1.1.4.6';
|
||||
my $oid_cfwHardwareStatusDetail_secondary = '.1.3.6.1.4.1.9.9.147.1.2.1.1.1.4.7';
|
||||
my $result = $options{snmp}->get_leef(oids => [$oid_cfwHardwareStatusValue_primary, $oid_cfwHardwareStatusValue_secondary,
|
||||
$oid_cfwHardwareStatusDetail_primary, $oid_cfwHardwareStatusDetail_secondary], nothing_quit => 1);
|
||||
|
||||
$self->{global}->{primary_state} = $map_failover{$result->{$oid_cfwHardwareStatusValue_primary}};
|
||||
$self->{global}->{primary_details} = $result->{$oid_cfwHardwareStatusDetail_primary};
|
||||
$self->{global}->{secondary_state} = $map_failover{$result->{$oid_cfwHardwareStatusValue_secondary}};
|
||||
$self->{global}->{secondary_details} = $result->{$oid_cfwHardwareStatusDetail_secondary};
|
||||
my $active_units = 0;
|
||||
$active_units++ if ($result->{$oid_cfwHardwareStatusValue_primary} == 9 || $result->{$oid_cfwHardwareStatusValue_primary} == 10);
|
||||
$active_units++ if ($result->{$oid_cfwHardwareStatusValue_secondary} == 9 || $result->{$oid_cfwHardwareStatusValue_secondary} == 10);
|
||||
$self->{global}->{active_units} = $active_units;
|
||||
|
||||
$self->{cache_name} = "cisco_asa_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
@ -107,9 +212,30 @@ Check failover status on Cisco ASA (CISCO-UNIFIED-FIREWALL-MIB).
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--dont-warn-notstandby>
|
||||
=item B<--filter-counters>
|
||||
|
||||
Don't return warning if a unit is active and the other unit is not in standby status.
|
||||
Only display some counters (regexp can be used).
|
||||
Example: --filter-counters='^status$'
|
||||
|
||||
=item B<--warning-status>
|
||||
|
||||
Set warning threshold for status.
|
||||
Can used special variables like: %{primaryStateLast}, %{secondaryStateLast}, %{primaryState}, %{secondaryState}
|
||||
|
||||
=item B<--critical-status>
|
||||
|
||||
Set critical threshold for status.
|
||||
Can used special variables like: %{primaryStateLast}, %{secondaryStateLast}, %{primaryState}, %{secondaryState}
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'active-units'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'active-units'.
|
||||
|
||||
=back
|
||||
|
||||
|
|
Loading…
Reference in New Issue