centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/virus.pm

163 lines
5.9 KiB
Perl
Raw Normal View History

2014-01-31 17:52:26 +01:00
#
2020-01-06 15:19:23 +01:00
# Copyright 2020 Centreon (http://www.centreon.com/)
2015-07-21 11:51:02 +02:00
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
2014-01-31 17:52:26 +01:00
package centreon::common::fortinet::fortigate::snmp::mode::virus;
2014-01-31 17:52:26 +01:00
2020-01-14 11:33:05 +01:00
use base qw(centreon::plugins::templates::counter);
2014-01-31 17:52:26 +01:00
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
2020-01-14 11:33:05 +01:00
sub set_counters {
my ($self, %options) = @_;
2020-01-14 11:33:05 +01:00
$self->{maps_counters_type} = [
{ name => 'domain', type => 1, cb_prefix_output => 'prefix_domain_output', message_multiple => 'All virtualdomains virus stats are ok' }
];
2020-01-14 11:33:05 +01:00
$self->{maps_counters}->{domain} = [
{ label => 'virus-detected', nlabel => 'domain.virus.detected.count', set => {
key_values => [ { name => 'fgAvVirusDetected', diff => 1 }, { name => 'display' } ],
output_template => 'virus detected: %s',
perfdatas => [
2020-05-13 14:18:28 +02:00
{ label => 'virus_detected', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' },
2020-01-14 11:33:05 +01:00
],
}
},
{ label => 'virus-detected-psec', nlabel => 'domain.virus.detected.persecond', display_ok => 0, set => {
2020-05-13 14:18:28 +02:00
key_values => [ { name => 'fgAvVirusDetected', per_second => 1 }, { name => 'display' } ],
2020-01-14 11:33:05 +01:00
output_template => 'virus detected: %.2f/s',
perfdatas => [
2020-05-13 14:18:28 +02:00
{ label => 'domain.virus.detected.persecond', template => '%.2f',
unit => '/s', min => 0, label_extra_instance => 1, instance_use => 'display' },
2020-01-14 11:33:05 +01:00
],
}
},
{ label => 'virus-blocked', nlabel => 'domain.virus.blocked.count', set => {
key_values => [ { name => 'fgAvVirusBlocked', diff => 1 }, { name => 'display' } ],
output_template => 'virus blocked: %s',
perfdatas => [
2020-05-13 14:18:28 +02:00
{ label => 'virus_blocked', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' },
2020-01-14 11:33:05 +01:00
],
}
},
{ label => 'virus-blocked-psec', nlabel => 'domain.virus.blocked.persecond', display_ok => 0, set => {
2020-05-13 14:18:28 +02:00
key_values => [ { name => 'fgAvVirusBlocked', per_second => 1 }, { name => 'display' } ],
2020-01-14 11:33:05 +01:00
output_template => 'virus blocked: %.2f/s',
perfdatas => [
2020-05-13 14:18:28 +02:00
{ label => 'domain.virus.blocked.persecond', template => '%.2f',
unit => '/s', min => 0, label_extra_instance => 1, instance_use => 'display' },
2020-01-14 11:33:05 +01:00
],
}
}
];
2014-01-31 17:52:26 +01:00
}
2020-01-14 11:33:05 +01:00
sub prefix_domain_output {
2014-01-31 17:52:26 +01:00
my ($self, %options) = @_;
2020-01-14 11:33:05 +01:00
return "Domain '" . $options{instance_value}->{display} . "' ";
2014-01-31 17:52:26 +01:00
}
2020-01-14 11:33:05 +01:00
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
2014-01-31 17:52:26 +01:00
2020-01-14 11:33:05 +01:00
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
});
2014-01-31 17:52:26 +01:00
2020-01-14 11:33:05 +01:00
return $self;
2014-01-31 17:52:26 +01:00
}
2020-01-14 11:33:05 +01:00
my $mapping = {
fgAvVirusDetected => { oid => '.1.3.6.1.4.1.12356.101.8.2.1.1.1' },
fgAvVirusBlocked => { oid => '.1.3.6.1.4.1.12356.101.8.2.1.1.2' },
};
my $oid_fgAvStatsEntry = '.1.3.6.1.4.1.12356.101.8.2.1.1';
my $oid_fgVdEntName = '.1.3.6.1.4.1.12356.101.3.2.1.1.2';
sub manage_selection {
2014-01-31 17:52:26 +01:00
my ($self, %options) = @_;
2020-01-14 11:33:05 +01:00
my $snmp_result = $options{snmp}->get_multiple_table(
oids => [
{ oid => $oid_fgVdEntName },
{ oid => $oid_fgAvStatsEntry, end => $mapping->{fgAvVirusBlocked}->{oid} },
],
nothing_quit => 1
);
$self->{domain} = {};
foreach my $oid (keys %{$snmp_result->{$oid_fgVdEntName}}) {
next if ($oid !~ /^$oid_fgVdEntName\.(.*)/);
my $instance = $1;
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$snmp_result->{$oid_fgVdEntName}->{$oid} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $snmp_result->{$oid_fgVdEntName}->{$oid} . "': no matching filter.");
2014-01-31 17:52:26 +01:00
next;
}
2020-01-14 11:33:05 +01:00
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_fgAvStatsEntry}, instance => $instance);
2014-01-31 17:52:26 +01:00
2020-01-14 11:33:05 +01:00
$self->{domain}->{$instance} = $result;
$self->{domain}->{$instance}->{display} = $snmp_result->{$oid_fgVdEntName}->{$oid};
2014-01-31 17:52:26 +01:00
}
2020-01-14 11:33:05 +01:00
if (scalar(keys %{$self->{domain}}) <= 0) {
$self->{output}->add_option_msg(short_msg => 'no domain found.');
$self->{output}->option_exit();
2014-01-31 17:52:26 +01:00
}
2020-01-14 11:33:05 +01:00
$self->{cache_name} = "fortinet_fortigate_" . $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')) . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
2014-01-31 17:52:26 +01:00
}
1;
__END__
=head1 MODE
2014-03-21 17:09:20 +01:00
Check virus blocked and detected.
2014-01-31 17:52:26 +01:00
=over 8
2020-01-14 11:33:05 +01:00
=item B<--warning-*> B<--critical-*>
2014-01-31 17:52:26 +01:00
2020-01-14 11:33:05 +01:00
Thresholds.
Can be: 'virus-detected', ''virus-detected-psec',
'virus-blocked', 'virus-blocked-psec'.
2014-01-31 17:52:26 +01:00
2020-01-14 11:33:05 +01:00
=item B<--filter-name>
2014-01-31 17:52:26 +01:00
2020-01-14 11:33:05 +01:00
Filter virtual domain name (can be a regexp).
2014-01-31 17:52:26 +01:00
=back
=cut
2020-01-14 11:33:05 +01:00