enh fortinet fortigate cluster status (#1238)

* enh fortinet fortigate cluster status

* add old option for compatibility
This commit is contained in:
Colin Gagnaire 2018-11-22 10:10:40 +01:00 committed by GitHub
parent 3c72e86988
commit a47c151fd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 144 additions and 72 deletions

View File

@ -20,26 +20,81 @@
package centreon::common::fortinet::fortigate::mode::clusterstatus;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
my $oid_fgHaSystemMode = '.1.3.6.1.4.1.12356.101.13.1.1'; # '.0' to have the mode
my $oid_fgHaStatsSerial = '.1.3.6.1.4.1.12356.101.13.2.1.1.2';
my $oid_fgHaStatsMasterSerial = '.1.3.6.1.4.1.12356.101.13.2.1.1.16';
my $oid_fgHaStatsSyncStatus = '.1.3.6.1.4.1.12356.101.13.2.1.1.12';
my $instance_mode;
my %maps_ha_mode = (
1 => 'standalone',
2 => 'activeActive',
3 => 'activePassive',
);
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);
}
my %maps_sync_status = (
0 => 'not synchronized',
1 => 'synchronized',
);
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("status is '%s' [Hostname: %s] [Role: %s]",
$self->{result_values}->{sync_status},
$self->{result_values}->{hostname},
$self->{result_values}->{role});
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{serial} = $options{new_datas}->{$self->{instance} . '_serial'};
$self->{result_values}->{hostname} = $options{new_datas}->{$self->{instance} . '_hostname'};
$self->{result_values}->{sync_status} = $options{new_datas}->{$self->{instance} . '_sync_status'};
$self->{result_values}->{role} = $options{new_datas}->{$self->{instance} . '_role'};
return 0;
}
sub prefix_status_output {
my ($self, %options) = @_;
return "Node '" . $options{instance_value}->{serial} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'nodes', type => 1, cb_prefix_output => 'prefix_status_output', message_multiple => 'All cluster nodes status are ok' },
];
$self->{maps_counters}->{nodes} = [
{ label => 'node', threshold => 0, set => {
key_values => [ { name => 'serial' }, { name => 'hostname' }, { name => 'sync_status' }, { 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 {
my ($class, %options) = @_;
@ -49,7 +104,9 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"one-node-status:s" => { name => 'one_node_status', default => 'critical' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{sync_status} !~ /synchronized/' },
"one-node-status:s" => { name => 'one_node_status' }, # not used, use --opt-exit instead
});
return $self;
@ -57,68 +114,76 @@ sub new {
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
$self->SUPER::check_options(%options);
if ($self->{output}->is_litteral_status(status => $self->{option_results}->{one_node_status}) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong one-node-status status option '" . $self->{option_results}->{one_node_status} . "'.");
$self->{output}->option_exit();
$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 {
my %map_ha_mode = (
1 => 'standalone',
2 => 'activeActive',
3 => 'activePassive',
);
my %map_sync_status = (
0 => 'not synchronized',
1 => 'synchronized',
);
my $mapping = {
fgHaStatsSerial => { oid => '.1.3.6.1.4.1.12356.101.13.2.1.1.2' },
fgHaStatsHostname => { oid => '.1.3.6.1.4.1.12356.101.13.2.1.1.11' },
fgHaStatsSyncStatus => { oid => '.1.3.6.1.4.1.12356.101.13.2.1.1.12', map => \%map_sync_status },
fgHaStatsMasterSerial => { oid => '.1.3.6.1.4.1.12356.101.13.2.1.1.16' },
};
my $oid_fgHaStatsEntry = '.1.3.6.1.4.1.12356.101.13.2.1.1';
my $oid_fgHaSystemMode = '.1.3.6.1.4.1.12356.101.13.1.1.0';
sub manage_selection {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{result} = $self->{snmp}->get_multiple_table(oids => [
{ oid => $oid_fgHaSystemMode },
{ oid => $oid_fgHaStatsMasterSerial },
{ oid => $oid_fgHaStatsSerial },
{ oid => $oid_fgHaStatsSyncStatus },
],
nothing_quit => 1);
# Check if mode cluster
my $ha_mode = $self->{result}->{$oid_fgHaSystemMode}->{$oid_fgHaSystemMode . '.0'};
my $ha_output = defined($maps_ha_mode{$ha_mode}) ? $maps_ha_mode{$ha_mode} : 'unknown';
$self->{output}->output_add(long_msg => 'High availabily mode is ' . $ha_output . '.');
if ($ha_mode == 1) {
$self->{output}->output_add(severity => 'ok',
short_msg => sprintf("No cluster configuration (standalone mode)."));
} else {
$self->{output}->output_add(severity => 'ok',
short_msg => sprintf("Cluster status is ok."));
foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$self->{result}->{$oid_fgHaStatsSerial}})) {
next if ($key !~ /^$oid_fgHaStatsSerial\.([0-9]+)$/);
if ($ha_mode == 3) {
my $state = $self->{result}->{$oid_fgHaStatsMasterSerial}->{$oid_fgHaStatsMasterSerial . '.' . $1} eq '' ?
'master' : 'slave';
$self->{output}->output_add(long_msg => sprintf("Node '%s' is %s.",
$self->{result}->{$oid_fgHaStatsSerial}->{$key}, $state));
}
my $sync_status = $self->{result}->{$oid_fgHaStatsSyncStatus}->{$oid_fgHaStatsSyncStatus . '.' . $1};
next if (!defined($sync_status));
$self->{output}->output_add(long_msg => sprintf("Node '%s' sync-status is %s.",
$self->{result}->{$oid_fgHaStatsSerial}->{$key}, $maps_sync_status{$sync_status}));
if ($sync_status == 0) {
$self->{output}->output_add(severity => 'critical',
short_msg => sprintf("Node '%s' sync-status is %s.",
$self->{result}->{$oid_fgHaStatsSerial}->{$key}, $maps_sync_status{$sync_status}));
}
}
if (scalar(keys %{$self->{result}->{$oid_fgHaStatsSerial}}) == 1 &&
!$self->{output}->is_status(value => $self->{option_results}->{one_node_status}, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $self->{option_results}->{one_node_status},
short_msg => sprintf("Cluster with one node only"));
}
$self->{nodes} = {};
my $mode = $self->{snmp}->get_leef(oids => [ $oid_fgHaSystemMode ], nothing_quit => 1);
if ($map_ha_mode{$mode->{$oid_fgHaSystemMode}} =~ /standalone/) {
$self->{output}->add_option_msg(short_msg => "No cluster configuration (standalone mode)");
$self->{output}->option_exit();
}
$self->{output}->display();
$self->{output}->exit();
$self->{results} = $options{snmp}->get_table(oid => $oid_fgHaStatsEntry,
nothing_quit => 1);
foreach my $oid (keys %{$self->{results}}) {
next if($oid !~ /^$mapping->{fgHaStatsSerial}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance);
$self->{nodes}->{$instance} = {
serial => $result->{fgHaStatsSerial},
hostname => $result->{fgHaStatsHostname},
sync_status => $result->{fgHaStatsSyncStatus},
role => ($result->{fgHaStatsMasterSerial} eq '') ? "master" : "slave",
};
}
if (scalar(keys %{$self->{nodes}}) <= 0) {
$self->{output}->add_option_msg(short_msg => 'No cluster nodes found');
$self->{output}->option_exit();
}
}
1;
@ -131,10 +196,17 @@ Check cluster status (FORTINET-FORTIGATE-MIB).
=over 8
=item B<--one-node-status>
=item B<--warning-status>
Status if only one node (default: 'critical').
Set warning threshold for status (Default: '').
Can used special variables like: %{serial}, %{hostname}, %{sync_status}, %{role}
=item B<--critical-status>
Set critical threshold for status (Default: '%{sync_status} !~ /synchronized/').
Can used special variables like: %{serial}, %{hostname}, %{sync_status}, %{role}
=back
=cut
=cut