Debian Codegraph @

src/centreon/common/fortinet/fortigate/snmp/mode/virus.pm

raw
1 #
2 # Copyright 2024 Centreon (http://www.centreon.com/)
3 #
4 # Centreon is a full-fledged industry-strength solution that meets
5 # the needs in IT infrastructure and application monitoring for
6 # service performance.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 package centreon::common::fortinet::fortigate::snmp::mode::virus;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28
29 sub set_counters {
30 my ($self, %options) = @_;
31
32 $self->{maps_counters_type} = [
33 { name => 'domain', type => 1, cb_prefix_output => 'prefix_domain_output', message_multiple => 'All virtualdomains virus stats are ok' }
34 ];
35
36 $self->{maps_counters}->{domain} = [
37 { label => 'virus-detected', nlabel => 'domain.virus.detected.count', set => {
38 key_values => [ { name => 'fgAvVirusDetected', diff => 1 }, { name => 'display' } ],
39 output_template => 'virus detected: %s',
40 perfdatas => [
41 { label => 'virus_detected', template => '%s',
42 min => 0, label_extra_instance => 1, instance_use => 'display' }
43 ]
44 }
45 },
46 { label => 'virus-detected-psec', nlabel => 'domain.virus.detected.persecond', display_ok => 0, set => {
47 key_values => [ { name => 'fgAvVirusDetected', per_second => 1 }, { name => 'display' } ],
48 output_template => 'virus detected: %.2f/s',
49 perfdatas => [
50 { label => 'domain.virus.detected.persecond', template => '%.2f',
51 unit => '/s', min => 0, label_extra_instance => 1, instance_use => 'display' }
52 ]
53 }
54 },
55 { label => 'virus-blocked', nlabel => 'domain.virus.blocked.count', set => {
56 key_values => [ { name => 'fgAvVirusBlocked', diff => 1 }, { name => 'display' } ],
57 output_template => 'virus blocked: %s',
58 perfdatas => [
59 { label => 'virus_blocked', template => '%s',
60 min => 0, label_extra_instance => 1, instance_use => 'display' }
61 ]
62 }
63 },
64 { label => 'virus-blocked-psec', nlabel => 'domain.virus.blocked.persecond', display_ok => 0, set => {
65 key_values => [ { name => 'fgAvVirusBlocked', per_second => 1 }, { name => 'display' } ],
66 output_template => 'virus blocked: %.2f/s',
67 perfdatas => [
68 { label => 'domain.virus.blocked.persecond', template => '%.2f',
69 unit => '/s', min => 0, label_extra_instance => 1, instance_use => 'display' }
70 ]
71 }
72 }
73 ];
74 }
75
76 sub prefix_domain_output {
77 my ($self, %options) = @_;
78
79 return "Domain '" . $options{instance_value}->{display} . "' ";
80 }
81
82 sub new {
83 my ($class, %options) = @_;
84 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
85 bless $self, $class;
86
87 $options{options}->add_options(arguments => {
88 'filter-name:s' => { name => 'filter_name' }
89 });
90
91 return $self;
92 }
93
94 my $mapping = {
95 fgAvVirusDetected => { oid => '.1.3.6.1.4.1.12356.101.8.2.1.1.1' },
96 fgAvVirusBlocked => { oid => '.1.3.6.1.4.1.12356.101.8.2.1.1.2' },
97 };
98 my $oid_fgAvStatsEntry = '.1.3.6.1.4.1.12356.101.8.2.1.1';
99 my $oid_fgVdEntName = '.1.3.6.1.4.1.12356.101.3.2.1.1.2';
100
101 sub manage_selection {
102 my ($self, %options) = @_;
103
104 my $snmp_result = $options{snmp}->get_multiple_table(
105 oids => [
106 { oid => $oid_fgVdEntName },
107 { oid => $oid_fgAvStatsEntry, end => $mapping->{fgAvVirusBlocked}->{oid} }
108 ],
109 nothing_quit => 1
110 );
111
112 $self->{domain} = {};
113 foreach my $oid (keys %{$snmp_result->{$oid_fgVdEntName}}) {
114 next if ($oid !~ /^$oid_fgVdEntName\.(.*)/);
115 my $instance = $1;
116
117 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
118 $snmp_result->{$oid_fgVdEntName}->{$oid} !~ /$self->{option_results}->{filter_name}/) {
119 $self->{output}->output_add(long_msg => "skipping '" . $snmp_result->{$oid_fgVdEntName}->{$oid} . "': no matching filter.");
120 next;
121 }
122
123 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_fgAvStatsEntry}, instance => $instance);
124
125 $self->{domain}->{$instance} = $result;
126 $self->{domain}->{$instance}->{display} = $snmp_result->{$oid_fgVdEntName}->{$oid};
127 }
128
129 if (scalar(keys %{$self->{domain}}) <= 0) {
130 $self->{output}->add_option_msg(short_msg => 'no domain found.');
131 $self->{output}->option_exit();
132 }
133
134 $self->{cache_name} = "fortinet_fortigate_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
135 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
136 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
137 }
138
139 1;
140
141 __END__
142
143 =head1 MODE
144
145 Check virus blocked and detected.
146
147 =over 8
148
149 =item B<--warning-*> B<--critical-*>
150
151 Thresholds.
152 Can be: 'virus-detected', ''virus-detected-psec',
153 'virus-blocked', 'virus-blocked-psec'.
154
155 =item B<--filter-name>
156
157 Filter virtual domain name (can be a regexp).
158
159 =back
160
161 =cut
162