enh(fortimanager/snmp): mode device-status - add policy packages (#3252)

This commit is contained in:
qgarnier 2021-11-15 15:27:56 +01:00 committed by GitHub
parent 042796d9e2
commit b26398b90c
2 changed files with 147 additions and 108 deletions

View File

@ -25,68 +25,96 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use Digest::MD5 qw(md5_hex); use Digest::MD5 qw(md5_hex);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
return $self->{result_values}->{output_label} . ': ' . $self->{result_values}->{status};
}
sub device_long_output {
my ($self, %options) = @_;
return "checking device '" . $options{instance_value}->{name} . "'";
}
sub prefix_device_output {
my ($self, %options) = @_;
return "Device '" . $options{instance_value}->{name} . "' ";
}
sub prefix_pp_output {
my ($self, %options) = @_;
return "policy package '" . $options{instance_value}->{package_name} . "' ";
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'device', type => 1, cb_prefix_output => 'prefix_device_output', message_multiple => 'All devices are ok' } { name => 'devices', type => 3, cb_prefix_output => 'prefix_device_output', cb_long_output => 'device_long_output', indent_long_output => ' ', message_multiple => 'All devices are ok',
group => [
{ name => 'status', type => 0, skipped_code => { -10 => 1 } },
{ name => 'con_status', type => 0, skipped_code => { -10 => 1 } },
{ name => 'db_status', type => 0, skipped_code => { -10 => 1 } },
{ name => 'config_status', type => 0, skipped_code => { -10 => 1 } },
{ name => 'packages', display_long => 1, cb_prefix_output => 'prefix_pp_output', message_multiple => 'policy packages are ok', type => 1, skipped_code => { -10 => 1 } }
]
}
]; ];
$self->{maps_counters}->{device} = [ $self->{maps_counters}->{status} = [
{ label => 'device-status', threshold => 0, set => { { label => 'device-status', type => 2, set => {
key_values => [ { name => 'fmDeviceEntState' }, { name => 'display' } ], key_values => [ { name => 'status' }, { name => 'name' } ],
closure_custom_calc => $self->can('custom_status_calc'), output_template => 'status: %s',
closure_custom_calc_extra_options => { output_label => 'Status', name_status => 'fmDeviceEntState' },
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'device-con-status', threshold => 0, set => {
key_values => [ { name => 'fmDeviceEntConnectState' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_calc_extra_options => { output_label => 'Connection Status', name_status => 'fmDeviceEntConnectState' },
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
}
},
{ label => 'device-db-status', threshold => 0, set => {
key_values => [ { name => 'fmDeviceEntDbState' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_calc_extra_options => { output_label => 'DB Status', name_status => 'fmDeviceEntDbState' },
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
}
},
{ label => 'device-config-status', threshold => 0, set => {
key_values => [ { name => 'fmDeviceEntConfigState' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_calc_extra_options => { output_label => 'Configuration Status', name_status => 'fmDeviceEntConfigState' },
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
} }
} }
]; ];
}
sub custom_status_output { $self->{maps_counters}->{con_status} = [
my ($self, %options) = @_; { label => 'device-con-status', type => 2, critical_default => '%{status} =~ /down/i', set => {
key_values => [ { name => 'status' }, { name => 'name' } ],
output_template => 'connection status: %s',
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
return $self->{result_values}->{output_label} . ' : ' . $self->{result_values}->{status}; $self->{maps_counters}->{db_status} = [
} { label => 'device-db-status', type => 2, set => {
key_values => [ { name => 'status' }, { name => 'name' } ],
output_template => 'db status: %s',
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
sub custom_status_calc { $self->{maps_counters}->{config_status} = [
my ($self, %options) = @_; { label => 'device-config-status', type => 2, set => {
key_values => [ { name => 'status' }, { name => 'name' } ],
output_template => 'configuration status: %s',
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
$self->{result_values}->{output_label} = $options{extra_options}->{output_label}; $self->{maps_counters}->{packages} = [
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{name_status}}; { label => 'device-policy-package-status', type => 2, set => {
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; key_values => [ { name => 'status' }, { name => 'package_name' } ],
return 0; output_template => 'status: %s',
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
} }
sub new { sub new {
@ -95,36 +123,12 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' }
'warning-device-status:s' => { name => 'warning_device_status', default => '' },
'critical-device-status:s' => { name => 'critical_device_status', default => '' },
'warning-device-con-status:s' => { name => 'warning_device_con_status', default => '' },
'critical-device-con-status:s' => { name => 'critical_device_con_status', default => '%{status} =~ /down/i' },
'warning-device-db-status:s' => { name => 'warning_device_db_status', default => '' },
'critical-device-db-status:s' => { name => 'critical_device_db_status', default => '' },
'warning-device-config-status:s' => { name => 'warning_device_config_status', default => '' },
'critical-device-config-status:s' => { name => 'critical_device_config_status', default => '' }
}); });
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => [
'warning_device_status', 'critical_device_status', 'warning_device_con_status', 'critical_device_con_status',
'warning_device_db_status', 'critical_device_db_status', 'warning_device_config_status', 'critical_device_config_status'
]);
}
sub prefix_device_output {
my ($self, %options) = @_;
return "Device '" . $options{instance_value}->{display} . "' ";
}
my %map_connection_state = (0 => 'unknown', 1 => 'up', 2 => 'down'); my %map_connection_state = (0 => 'unknown', 1 => 'up', 2 => 'down');
my %map_db_state = (0 => 'unknown', 1 => 'not-modified', 2 => 'modified'); my %map_db_state = (0 => 'unknown', 1 => 'not-modified', 2 => 'modified');
my %map_config_state = (0 => 'unknown', 1 => 'in-sync', 2 => 'out-of-sync'); my %map_config_state = (0 => 'unknown', 1 => 'in-sync', 2 => 'out-of-sync');
@ -136,48 +140,73 @@ my %map_device_state = (
); );
my $mapping = { my $mapping = {
fmDeviceEntConnectState => { oid => '.1.3.6.1.4.1.12356.103.6.2.1.12', map => \%map_connection_state }, connectState => { oid => '.1.3.6.1.4.1.12356.103.6.2.1.12', map => \%map_connection_state }, # fmDeviceEntConnectState
fmDeviceEntDbState => { oid => '.1.3.6.1.4.1.12356.103.6.2.1.13', map => \%map_db_state }, dbState => { oid => '.1.3.6.1.4.1.12356.103.6.2.1.13', map => \%map_db_state }, # fmDeviceEntDbState
fmDeviceEntConfigState => { oid => '.1.3.6.1.4.1.12356.103.6.2.1.14', map => \%map_config_state }, configState => { oid => '.1.3.6.1.4.1.12356.103.6.2.1.14', map => \%map_config_state }, # fmDeviceEntConfigState
fmDeviceEntState => { oid => '.1.3.6.1.4.1.12356.103.6.2.1.15', map => \%map_device_state }, state => { oid => '.1.3.6.1.4.1.12356.103.6.2.1.15', map => \%map_device_state }, # fmDeviceEntState
policyPackageState => { oid => '.1.3.6.1.4.1.12356.103.6.2.1.23' } # fmDeviceEntPolicyPackageState
}; };
my $oid_fmDeviceEntName = '.1.3.6.1.4.1.12356.103.6.2.1.2'; my $oid_fmDeviceEntName = '.1.3.6.1.4.1.12356.103.6.2.1.2';
my $oid_fmDeviceEntry = '.1.3.6.1.4.1.12356.103.6.2.1';
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $snmp_result = $options{snmp}->get_multiple_table( my $snmp_result = $options{snmp}->get_table(
oids => [ oid => $oid_fmDeviceEntName,
{ oid => $oid_fmDeviceEntName },
{ oid => $oid_fmDeviceEntry, start => $mapping->{fmDeviceEntConnectState}->{oid}, end => $mapping->{fmDeviceEntState}->{oid} },
],
nothing_quit => 1 nothing_quit => 1
); );
$self->{device} = {}; $self->{devices} = {};
foreach my $oid (keys %{$snmp_result->{ $oid_fmDeviceEntName }}) { foreach my $oid (keys %$snmp_result) {
$oid =~ /^$oid_fmDeviceEntName\.(.*)$/; $oid =~ /^$oid_fmDeviceEntName\.(.*)$/;
my $instance = $1; my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{ $oid_fmDeviceEntry }, instance => $instance);
my $name = $snmp_result->{ $oid_fmDeviceEntName }->{$oid}; my $name = $snmp_result->{$oid};
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$name !~ /$self->{option_results}->{filter_name}/) { $name !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
next; next;
} }
$self->{device}->{$instance} = { $self->{devices}->{$instance} = {
display => $name, %$result name => $name,
status => { name => $name },
con_status => { name => $name },
db_status => { name => $name },
config_status => { name => $name },
packages => {}
}; };
} }
if (scalar(keys %{$self->{device}}) <= 0) { if (scalar(keys %{$self->{devices}}) <= 0) {
$self->{output}->add_option_msg(short_msg => 'No device found.'); $self->{output}->add_option_msg(short_msg => 'No device found.');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$options{snmp}->load(oids => [
map($_->{oid}, values(%$mapping))
],
instances => [ map($_, keys(%{$self->{devices}})) ],
instance_regexp => '^(.*)$'
);
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
foreach (keys %{$self->{devices}}) {
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
$self->{devices}->{$_}->{status}->{status} = $result->{state};
$self->{devices}->{$_}->{con_status}->{status} = $result->{connectState};
$self->{devices}->{$_}->{config_status}->{status} = $result->{configState};
$self->{devices}->{$_}->{db_status}->{status} = $result->{dbState};
if (defined($result->{policyPackageState}) && $result->{policyPackageState}) {
foreach my $entry (split(/\|/, $result->{policyPackageState})) {
next if ($entry !~ /\s*(.*?)\[(.*?)\]/);
$self->{devices}->{$_}->{packages}->{$1} = {
package_name => $1,
status => $2
};
}
}
}
} }
1; 1;
@ -197,42 +226,52 @@ Filter by device name (can be a regexp).
=item B<--warning-device-status> =item B<--warning-device-status>
Set warning threshold for device status. Set warning threshold for device status.
Can used special variables like: %{status}, %{display} Can used special variables like: %{status}, %{name}
=item B<--critical-device-status> =item B<--critical-device-status>
Set critical threshold for device status Set critical threshold for device status
Can used special variables like: %{status}, %{display} Can used special variables like: %{status}, %{name}
=item B<--warning-device-con-status> =item B<--warning-device-con-status>
Set warning threshold for device connection status. Set warning threshold for device connection status.
Can used special variables like: %{status}, %{display} Can used special variables like: %{status}, %{name}
=item B<--critical-device-con-status> =item B<--critical-device-con-status>
Set critical threshold for device connection status (Default: '%{status} =~ /down/i'). Set critical threshold for device connection status (Default: '%{status} =~ /down/i').
Can used special variables like: %{status}, %{display} Can used special variables like: %{status}, %{name}
=item B<--warning-device-db-status> =item B<--warning-device-db-status>
Set warning threshold for device DB status. Set warning threshold for device DB status.
Can used special variables like: %{status}, %{display} Can used special variables like: %{status}, %{name}
=item B<--critical-device-db-status> =item B<--critical-device-db-status>
Set critical threshold for device DB status. Set critical threshold for device DB status.
Can used special variables like: %{status}, %{display} Can used special variables like: %{status}, %{name}
=item B<--warning-device-config-status> =item B<--warning-device-config-status>
Set warning threshold for device configuration status. Set warning threshold for device configuration status.
Can used special variables like: %{status}, %{display} Can used special variables like: %{status}, %{name}
=item B<--critical-device-config-status> =item B<--critical-device-config-status>
Set critical threshold for device configuration status. Set critical threshold for device configuration status.
Can used special variables like: %{status}, %{display} Can used special variables like: %{status}, %{name}
=item B<--warning-device-policy-package-status>
Set warning threshold for device policy package status.
Can used special variables like: %{status}, %{package_name}
=item B<--critical-device-policy-package-status>
Set critical threshold for device policy package status.
Can used special variables like: %{status}, %{package_name}
=back =back

View File

@ -30,12 +30,12 @@ sub new {
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
%{$self->{modes}} = ( $self->{modes} = {
'cpu' => 'network::fortinet::fortimanager::snmp::mode::cpu', 'cpu' => 'network::fortinet::fortimanager::snmp::mode::cpu',
'device-status' => 'network::fortinet::fortimanager::snmp::mode::devicestatus', 'device-status' => 'network::fortinet::fortimanager::snmp::mode::devicestatus',
'disk' => 'network::fortinet::fortimanager::snmp::mode::disk', 'disk' => 'network::fortinet::fortimanager::snmp::mode::disk',
'memory' => 'network::fortinet::fortimanager::snmp::mode::memory', 'memory' => 'network::fortinet::fortimanager::snmp::mode::memory'
); };
return $self; return $self;
} }