Debian Codegraph @

src/centreon/common/fortinet/fortigate/snmp/mode/ipsstats.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::ipsstats;
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 IPS domain statistics are ok' }
34 ];
35
36 $self->{maps_counters}->{domain} = [
37 { label => 'intrusions-detected', nlabel => 'domain.intrusions.detected.count', set => {
38 key_values => [ { name => 'fgIpsIntrusionsDetected', diff => 1 }, { name => 'display' } ],
39 output_template => 'Intrusions detected : %s',
40 perfdatas => [
41 { label => 'intrusions_detected', template => '%s',
42 min => 0, label_extra_instance => 1, instance_use => 'display' }
43 ]
44 }
45 },
46 { label => 'intrusions-blocked', nlabel => 'domain.intrusions.blocked.count', set => {
47 key_values => [ { name => 'fgIpsIntrusionsBlocked', diff => 1 }, { name => 'display' } ],
48 output_template => 'Intrusions blocked : %s',
49 perfdatas => [
50 { label => 'intrusions_blocked', template => '%s',
51 min => 0, label_extra_instance => 1, instance_use => 'display' }
52 ]
53 }
54 },
55 { label => 'crit-sev-detections', nlabel => 'domain.intrusions.detected.critical.severity.count', set => {
56 key_values => [ { name => 'fgIpsCritSevDetections', diff => 1 }, { name => 'display' } ],
57 output_template => 'Critical severity intrusions detected : %s',
58 perfdatas => [
59 { label => 'crit_sev_detections', template => '%s',
60 min => 0, label_extra_instance => 1, instance_use => 'display' }
61 ]
62 }
63 },
64 { label => 'high-sev-detections', nlabel => 'domain.intrusions.detected.high.severity.count', set => {
65 key_values => [ { name => 'fgIpsHighSevDetections', diff => 1 }, { name => 'display' } ],
66 output_template => 'High severity intrusions detected : %s',
67 perfdatas => [
68 { label => 'high_sev_detections', template => '%s',
69 min => 0, label_extra_instance => 1, instance_use => 'display' }
70 ]
71 }
72 },
73 { label => 'med-sev-detections', nlabel => 'domain.intrusions.detected.medium.severity.count', set => {
74 key_values => [ { name => 'fgIpsMedSevDetections', diff => 1 }, { name => 'display' } ],
75 output_template => 'Medium severity intrusions detected : %s',
76 perfdatas => [
77 { label => 'med_sev_detections', template => '%s',
78 min => 0, label_extra_instance => 1, instance_use => 'display' }
79 ]
80 }
81 },
82 { label => 'low-sev-detections', nlabel => 'domain.intrusions.detected.low.severity.count', set => {
83 key_values => [ { name => 'fgIpsLowSevDetections', diff => 1 }, { name => 'display' } ],
84 output_template => 'Low severity intrusions detected : %s',
85 perfdatas => [
86 { label => 'low_sev_detections', template => '%s',
87 min => 0, label_extra_instance => 1, instance_use => 'display' }
88 ]
89 }
90 },
91 { label => 'info-sev-detections', nlabel => 'domain.intrusions.detected.info.severity.count', set => {
92 key_values => [ { name => 'fgIpsInfoSevDetections', diff => 1 }, { name => 'display' } ],
93 output_template => 'Informational severity intrusions detected : %s',
94 perfdatas => [
95 { label => 'info_sev_detections', template => '%s',
96 min => 0, label_extra_instance => 1, instance_use => 'display' }
97 ]
98 }
99 },
100 { label => 'signature-detections', nlabel => 'domain.intrusions.detected.signature.count', set => {
101 key_values => [ { name => 'fgIpsSignatureDetections', diff => 1 }, { name => 'display' } ],
102 output_template => 'Signature intrusions detected : %s',
103 perfdatas => [
104 { label => 'signature_detection', template => '%s',
105 min => 0, label_extra_instance => 1, instance_use => 'display' }
106 ]
107 }
108 },
109 { label => 'anomaly-detections', nlabel => 'domain.intrusions.detected.anomaly.count', set => {
110 key_values => [ { name => 'fgIpsAnomalyDetections', diff => 1 }, { name => 'display' } ],
111 output_template => 'Anomaly intrusions detected : %s',
112 perfdatas => [
113 { label => 'anomaly_detections', template => '%s',
114 min => 0, label_extra_instance => 1, instance_use => 'display' }
115 ]
116 }
117 }
118 ];
119 }
120
121 sub prefix_domain_output {
122 my ($self, %options) = @_;
123
124 return "Domain '" . $options{instance_value}->{display} . "' ";
125 }
126
127 sub new {
128 my ($class, %options) = @_;
129 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
130 bless $self, $class;
131
132 $options{options}->add_options(arguments => {
133 'filter-name:s' => { name => 'filter_name' }
134 });
135
136 return $self;
137 }
138
139 my $mapping = {
140 fgIpsIntrusionsDetected => { oid => '.1.3.6.1.4.1.12356.101.9.2.1.1.1' },
141 fgIpsIntrusionsBlocked => { oid => '.1.3.6.1.4.1.12356.101.9.2.1.1.2' },
142 fgIpsCritSevDetections => { oid => '.1.3.6.1.4.1.12356.101.9.2.1.1.3' },
143 fgIpsHighSevDetections => { oid => '.1.3.6.1.4.1.12356.101.9.2.1.1.4' },
144 fgIpsMedSevDetections => { oid => '.1.3.6.1.4.1.12356.101.9.2.1.1.5' },
145 fgIpsLowSevDetections => { oid => '.1.3.6.1.4.1.12356.101.9.2.1.1.6' },
146 fgIpsInfoSevDetections => { oid => '.1.3.6.1.4.1.12356.101.9.2.1.1.7' },
147 fgIpsSignatureDetections => { oid => '.1.3.6.1.4.1.12356.101.9.2.1.1.8' },
148 fgIpsAnomalyDetections => { oid => '.1.3.6.1.4.1.12356.101.9.2.1.1.9' }
149 };
150 my $oid_fgIpsStatsEntry = '.1.3.6.1.4.1.12356.101.9.2.1.1';
151 my $oid_fgVdEntName = '.1.3.6.1.4.1.12356.101.3.2.1.1.2';
152
153 sub manage_selection {
154 my ($self, %options) = @_;
155
156 my $snmp_result = $options{snmp}->get_multiple_table(
157 oids => [
158 { oid => $oid_fgVdEntName },
159 { oid => $oid_fgIpsStatsEntry }
160 ],
161 nothing_quit => 1
162 );
163
164 $self->{domain} = {};
165 foreach my $oid (keys %{$snmp_result->{$oid_fgVdEntName}}) {
166 next if ($oid !~ /^$oid_fgVdEntName\.(.*)/);
167 my $instance = $1;
168
169 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
170 $snmp_result->{$oid_fgVdEntName}->{$oid} !~ /$self->{option_results}->{filter_name}/) {
171 $self->{output}->output_add(long_msg => "skipping '" . $snmp_result->{$oid_fgVdEntName}->{$oid} . "': no matching filter.");
172 next;
173 }
174
175 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_fgIpsStatsEntry}, instance => $instance);
176 $self->{domain}->{$instance} = $result;
177 $self->{domain}->{$instance}->{display} = $snmp_result->{$oid_fgVdEntName}->{$oid};
178 }
179
180 if (scalar(keys %{$self->{domain}}) <= 0) {
181 $self->{output}->add_option_msg(short_msg => "No domain found.");
182 $self->{output}->option_exit();
183 }
184
185 $self->{cache_name} = "fortinet_fortigate_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
186 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
187 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
188 }
189
190 1;
191
192 __END__
193
194 =head1 MODE
195
196 Check virtual domain IPS statistics.
197
198 =over 8
199
200 =item B<--warning-*> B<--critical-*>
201
202 Thresholds.
203 Can be: 'intrusions-detected', 'intrusions-blocked',
204 'crit-sev-detections', 'high-sev-detections', 'med-sev-detections',
205 'low-sev-detections', 'info-sev-detections', 'signature-detections',
206 'anomaly-detections'.
207
208 =item B<--filter-name>
209
210 Filter virtual domain name (can be a regexp).
211
212 =back
213
214 =cut