Debian Codegraph @

src/centreon/common/fortinet/fortigate/snmp/mode/sdwan.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::sdwan;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
28 use Digest::MD5 qw(md5_hex);
29
30 sub prefix_traffic_output {
31 my ($self, %options) = @_;
32
33 return 'traffic ';
34 }
35
36 sub sdwan_long_output {
37 my ($self, %options) = @_;
38
39 return sprintf(
40 "checking sd-wan '%s' [vdom: %s] [interface: %s]",
41 $options{instance_value}->{name},
42 $options{instance_value}->{vdom},
43 $options{instance_value}->{ifName}
44 );
45 }
46
47 sub prefix_sdwan_output {
48 my ($self, %options) = @_;
49
50 return sprintf(
51 "sd-wan '%s' [vdom: %s] [interface: %s] ",
52 $options{instance_value}->{name},
53 $options{instance_value}->{vdom},
54 $options{instance_value}->{ifName}
55 );
56 }
57
58 sub set_counters {
59 my ($self, %options) = @_;
60
61 $self->{maps_counters_type} = [
62 { name => 'sdwan', type => 3, cb_prefix_output => 'prefix_sdwan_output', cb_long_output => 'sdwan_long_output',
63 indent_long_output => ' ', message_multiple => 'All sd-wan links are ok',
64 group => [
65 { name => 'status', type => 0, skipped_code => { -10 => 1 } },
66 { name => 'traffic', type => 0, cb_prefix_output => 'prefix_traffic_output', skipped_code => { -10 => 1 } },
67 { name => 'latency', type => 0, skipped_code => { -10 => 1 } },
68 { name => 'jitter', type => 0, skipped_code => { -10 => 1 } },
69 { name => 'packetloss', type => 0, skipped_code => { -10 => 1 } }
70 ]
71 }
72 ];
73
74 $self->{maps_counters}->{status} = [
75 {
76 label => 'status',
77 type => 2,
78 critical_default => '%{state} eq "down"',
79 set => {
80 key_values => [ { name => 'state' }, { name => 'vdom' }, { name => 'ifName' }, { name => 'name' }, { name => 'id' } ],
81 output_template => 'state: %s',
82 closure_custom_perfdata => sub { return 0; },
83 closure_custom_threshold_check => \&catalog_status_threshold_ng
84 }
85 }
86 ];
87
88 $self->{maps_counters}->{traffic} = [
89 { label => 'traffic-in', nlabel => 'sdwan.traffic.in.bitspersecond', set => {
90 key_values => [ { name => 'in', per_second => 1 }, { name => 'vdom' }, { name => 'name' }, { name => 'ifName' } ],
91 output_template => 'in: %s %s/s',
92 output_change_bytes => 2,
93 closure_custom_perfdata => sub {
94 my ($self, %options) = @_;
95
96 $self->{output}->perfdata_add(
97 nlabel => $self->{nlabel},
98 unit => 'b/s',
99 instances => [$self->{result_values}->{vdom}, $self->{result_values}->{name}, $self->{result_values}->{ifName}],
100 value => sprintf('%.2f', $self->{result_values}->{in}),
101 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
102 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
103 min => 0
104 );
105 }
106 }
107 },
108 { label => 'traffic-out', nlabel => 'sdwan.traffic.out.bitspersecond', set => {
109 key_values => [ { name => 'out', per_second => 1 }, { name => 'vdom' }, { name => 'name' }, { name => 'ifName' } ],
110 output_template => 'out: %s %s/s',
111 output_change_bytes => 2,
112 closure_custom_perfdata => sub {
113 my ($self, %options) = @_;
114
115 $self->{output}->perfdata_add(
116 nlabel => $self->{nlabel},
117 unit => 'b/s',
118 instances => [$self->{result_values}->{vdom}, $self->{result_values}->{name}, $self->{result_values}->{ifName}],
119 value => sprintf('%.2f', $self->{result_values}->{out}),
120 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
121 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
122 min => 0
123 );
124 }
125 }
126 },
127 { label => 'traffic-bi', nlabel => 'sdwan.traffic.bi.bitspersecond', set => {
128 key_values => [ { name => 'bi', per_second => 1 }, { name => 'vdom' }, { name => 'name' }, { name => 'ifName' } ],
129 output_template => 'bi: %s %s/s',
130 output_change_bytes => 2,
131 closure_custom_perfdata => sub {
132 my ($self, %options) = @_;
133
134 $self->{output}->perfdata_add(
135 nlabel => $self->{nlabel},
136 unit => 'b/s',
137 instances => [$self->{result_values}->{vdom}, $self->{result_values}->{name}, $self->{result_values}->{ifName}],
138 value => sprintf('%.2f', $self->{result_values}->{bi}),
139 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
140 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
141 min => 0
142 );
143 }
144 }
145 }
146 ];
147
148 $self->{maps_counters}->{latency} = [
149 { label => 'latency', nlabel => 'sdwan.latency.milliseconds', set => {
150 key_values => [ { name => 'latency' }, { name => 'vdom' }, { name => 'name' }, { name => 'ifName' } ],
151 output_template => 'latency: %sms',
152 closure_custom_perfdata => sub {
153 my ($self, %options) = @_;
154
155 $self->{output}->perfdata_add(
156 nlabel => $self->{nlabel},
157 unit => 'ms',
158 instances => [$self->{result_values}->{vdom}, $self->{result_values}->{name}, $self->{result_values}->{ifName}],
159 value => sprintf('%.2f', $self->{result_values}->{latency}),
160 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
161 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
162 min => 0
163 );
164 }
165 }
166 }
167 ];
168
169 $self->{maps_counters}->{jitter} = [
170 { label => 'jitter', nlabel => 'sdwan.jitter.milliseconds', set => {
171 key_values => [ { name => 'jitter' }, { name => 'vdom' }, { name => 'name' }, { name => 'ifName' } ],
172 output_template => 'jitter: %sms',
173 closure_custom_perfdata => sub {
174 my ($self, %options) = @_;
175
176 $self->{output}->perfdata_add(
177 nlabel => $self->{nlabel},
178 unit => 'ms',
179 instances => [$self->{result_values}->{vdom}, $self->{result_values}->{name}, $self->{result_values}->{ifName}],
180 value => sprintf('%.2f', $self->{result_values}->{jitter}),
181 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
182 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
183 min => 0
184 );
185 }
186 }
187 }
188 ];
189
190 $self->{maps_counters}->{packetloss} = [
191 { label => 'packetloss', nlabel => 'sdwan.packetloss.percentage', set => {
192 key_values => [ { name => 'packet_loss' }, { name => 'vdom' }, { name => 'name' }, { name => 'ifName' } ],
193 output_template => 'packet loss: %.3f%%',
194 closure_custom_perfdata => sub {
195 my ($self, %options) = @_;
196
197 $self->{output}->perfdata_add(
198 nlabel => $self->{nlabel},
199 unit => '%',
200 instances => [$self->{result_values}->{vdom}, $self->{result_values}->{name}, $self->{result_values}->{ifName}],
201 value => sprintf('%.3f', $self->{result_values}->{packet_loss}),
202 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
203 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
204 min => 0,
205 max => 100
206 );
207 }
208 }
209 }
210 ];
211 }
212
213 sub new {
214 my ($class, %options) = @_;
215 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
216 bless $self, $class;
217
218 $options{options}->add_options(arguments => {
219 'filter-id:s' => { name => 'filter_id' },
220 'filter-name:s' => { name => 'filter_name' },
221 'filter-vdom:s' => { name => 'filter_vdom' }
222 });
223
224 return $self;
225 }
226
227 my $mapping_status = { 0 => 'up', 1 => 'down' };
228
229 my $mapping = {
230 state => { oid => '.1.3.6.1.4.1.12356.101.4.9.2.1.4', map => $mapping_status }, # fgVWLHealthCheckLinkState
231 latency => { oid => '.1.3.6.1.4.1.12356.101.4.9.2.1.5' }, # fgVWLHealthCheckLinkLatency
232 jitter => { oid => '.1.3.6.1.4.1.12356.101.4.9.2.1.6' }, # fgVWLHealthCheckLinkJitter
233 packet_loss => { oid => '.1.3.6.1.4.1.12356.101.4.9.2.1.9' }, # fgVWLHealthCheckLinkPacketLoss
234 vdom => { oid => '.1.3.6.1.4.1.12356.101.4.9.2.1.10' }, # fgVWLHealthCheckLinkVdom
235 traffic_in => { oid => '.1.3.6.1.4.1.12356.101.4.9.2.1.11' }, # fgVWLHealthCheckLinkBandwidthIn
236 traffic_out => { oid => '.1.3.6.1.4.1.12356.101.4.9.2.1.12' }, # fgVWLHealthCheckLinkBandwidthOut
237 traffic_bi => { oid => '.1.3.6.1.4.1.12356.101.4.9.2.1.13' }, # fgVWLHealthCheckLinkBandwidthBi
238 ifName => { oid => '.1.3.6.1.4.1.12356.101.4.9.2.1.14' } # fgVWLHealthCheckLinkIfName
239 };
240
241 sub manage_selection {
242 my ($self, %options) = @_;
243
244 $self->{cache_name} = 'fortinet_fortigate_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
245 md5_hex(
246 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : 'all') . '_' .
247 (defined($self->{option_results}->{filter_id}) ? md5_hex($self->{option_results}->{filter_id}) : 'all') . '_' .
248 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : 'all') . '_' .
249 (defined($self->{option_results}->{filter_vdom}) ? md5_hex($self->{option_results}->{filter_vdom}) : 'all')
250 );
251
252 if ($options{snmp}->is_snmpv1()) {
253 $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
254 $self->{output}->option_exit();
255 }
256
257 my $oid_name = '.1.3.6.1.4.1.12356.101.4.9.2.1.2'; # fgVWLHealthCheckLinkName
258 my $snmp_result = $options{snmp}->get_table(
259 oid => $oid_name,
260 nothing_quit => 1
261 );
262
263 $self->{sdwan} = {};
264 foreach (keys %$snmp_result) {
265 /^$oid_name\.(.*)$/;
266 my $id = $1;
267
268 if (defined($self->{option_results}->{filter_id}) && $self->{option_results}->{filter_id} ne '' &&
269 $id !~ /$self->{option_results}->{filter_id}/) {
270 $self->{output}->output_add(long_msg => "skipping sd-wan '" . $snmp_result->{$_} . "'.", debug => 1);
271 next;
272 }
273 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
274 $snmp_result->{$_} !~ /$self->{option_results}->{filter_name}/) {
275 $self->{output}->output_add(long_msg => "skipping sd-wan '" . $snmp_result->{$_} . "'.", debug => 1);
276 next;
277 }
278
279 $self->{sdwan}->{ $id } = {
280 id => $id,
281 name => $snmp_result->{$_}
282 };
283 }
284
285 return if (scalar(keys %{$self->{sdwan}}) <= 0);
286
287 $options{snmp}->load(
288 oids => [ map($_->{oid}, values(%$mapping)) ],
289 instances => [ map($_, keys(%{$self->{sdwan}})) ],
290 instance_regexp => '^(.*)$'
291 );
292 $snmp_result = $options{snmp}->get_leef();
293 foreach (keys %{$self->{sdwan}}) {
294 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
295
296 if (defined($self->{option_results}->{filter_vdom}) && $self->{option_results}->{filter_vdom} ne '' &&
297 $result->{vdom} !~ /$self->{option_results}->{filter_vdom}/) {
298 $self->{output}->output_add(long_msg => "skipping sd-wan '" . $self->{sdwan}->{$_}->{name} . "'.", debug => 1);
299 next;
300 }
301
302 $self->{sdwan}->{$_}->{vdom} = $result->{vdom};
303 $self->{sdwan}->{$_}->{ifName} = $result->{ifName};
304
305 $self->{sdwan}->{$_}->{status} = {
306 state => $result->{state},
307 name => $self->{sdwan}->{$_}->{name},
308 id => $self->{sdwan}->{$_}->{id},
309 vdom => $result->{vdom},
310 ifName => $result->{ifName}
311 };
312
313 $self->{sdwan}->{$_}->{traffic} = {
314 name => $self->{sdwan}->{$_}->{name},
315 vdom => $result->{vdom},
316 ifName => $result->{ifName},
317 in => $result->{traffic_in} * 1000,
318 out => $result->{traffic_out} * 1000,
319 bi => $result->{traffic_bi} * 1000,
320 };
321
322 $self->{sdwan}->{$_}->{jitter} = {
323 name => $self->{sdwan}->{$_}->{name},
324 vdom => $result->{vdom},
325 ifName => $result->{ifName},
326 jitter => $result->{jitter}
327 };
328 $self->{sdwan}->{$_}->{latency} = {
329 name => $self->{sdwan}->{$_}->{name},
330 vdom => $result->{vdom},
331 ifName => $result->{ifName},
332 latency => $result->{latency}
333 };
334 $self->{sdwan}->{$_}->{packetloss} = {
335 name => $self->{sdwan}->{$_}->{name},
336 vdom => $result->{vdom},
337 ifName => $result->{ifName},
338 packet_loss => $result->{packet_loss}
339 };
340 }
341 }
342
343 1;
344
345 __END__
346
347 =head1 MODE
348
349 Check sd-wan links.
350
351 =over 8
352
353 =item B<--filter-id>
354
355 Filter sd-wan links by ID (can be a regexp).
356
357 =item B<--filter-name>
358
359 Filter sd-wan links by name (can be a regexp).
360
361 =item B<--filter-vdom>
362
363 Filter sd-wan links by vdom name (can be a regexp).
364
365 =item B<--unknown-status>
366
367 Define the conditions to match for the status to be UNKNOWN.
368 You can use the following variables: %{state}, %{vdom}, %{id}, %{name}, %{ifName}
369
370 =item B<--warning-status>
371
372 Define the conditions to match for the status to be WARNING.
373 You can use the following variables: %{state}, %{vdom}, %{id}, %{name}, %{ifName}
374
375 =item B<--critical-status>
376
377 Define the conditions to match for the status to be CRITICAL (default: '%{state} eq "down"').
378 You can use the following variables: %{state}, %{vdom}, %{id}, %{name}, %{ifName}
379
380 =item B<--warning-*> B<--critical-*>
381
382 Thresholds.
383 Can be: 'traffic-in', 'traffic-out', 'traffic-bi',
384 'latency', 'jitter', 'packetloss'.
385
386 =back
387
388 =cut