Debian Codegraph @

src/network/sonicwall/snmp/mode/vpn.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 network::sonicwall::snmp::mode::vpn;
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 => 'vpn', type => 1, cb_prefix_output => 'prefix_vpn_output', message_multiple => 'All VPN tunnels are OK' },
34 ];
35
36 $self->{maps_counters}->{vpn} = [
37 { label => 'traffic-in', set => {
38 key_values => [ { name => 'traffic_in', per_second => 1 }, { name => 'display' } ],
39 output_template => 'Traffic In: %s %s/s',
40 output_change_bytes => 2,
41 perfdatas => [
42 { label => 'traffic_in', template => '%.2f',
43 min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
44 ],
45 }
46 },
47 { label => 'traffic-out', set => {
48 key_values => [ { name => 'traffic_out', per_second => 1 }, { name => 'display' } ],
49 output_template => 'Traffic Out: %s %s/s',
50 output_change_bytes => 2,
51 perfdatas => [
52 { label => 'traffic_out', template => '%.2f',
53 min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
54 ],
55 }
56 }
57 ];
58 }
59
60 sub prefix_vpn_output {
61 my ($self, %options) = @_;
62
63 return "VPN '" . $options{instance_value}->{display} . "' ";
64 }
65
66 sub new {
67 my ($class, %options) = @_;
68 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
69 bless $self, $class;
70
71 $options{options}->add_options(arguments => {
72 'filter-name:s' => { name => 'filter_name' }
73 });
74
75 return $self;
76 }
77
78 sub check_options {
79 my ($self, %options) = @_;
80 $self->SUPER::check_options(%options);
81 }
82
83 my $oid_sonicSAStatEntry = '.1.3.6.1.4.1.8741.1.3.2.1.1.1';
84 my $oid_sonicSAStatUserName = '.1.3.6.1.4.1.8741.1.3.2.1.1.1.14';
85 my $oid_sonicSAStatEncryptByteCount = '.1.3.6.1.4.1.8741.1.3.2.1.1.1.9';
86 my $oid_sonicSAStatDecryptByteCount = '.1.3.6.1.4.1.8741.1.3.2.1.1.1.11';
87
88 sub manage_selection {
89 my ($self, %options) = @_;
90
91 $self->{cache_name} = "sonicwall_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
92 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
93 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
94
95 $self->{vpn} = {};
96 my $result = $options{snmp}->get_table(oid => $oid_sonicSAStatEntry, nothing_quit => 1);
97
98 foreach my $oid (sort keys %{$result}) {
99 next if ($oid !~ /^$oid_sonicSAStatUserName\.(.*)$/);
100 my $instance = $1;
101
102 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
103 $result->{$oid_sonicSAStatUserName . '.' . $instance} !~ /$self->{option_results}->{filter_name}/) {
104 $self->{output}->output_add(long_msg => "skipping '" . $result->{$oid_sonicSAStatUserName . '.' . $instance} . "': no matching filter.", debug => 1);
105 next;
106 }
107
108 $self->{vpn}->{$result->{$oid_sonicSAStatUserName . '.' . $instance}} = { traffic_in => $result->{$oid_sonicSAStatEncryptByteCount . '.' . $instance} * 8,
109 traffic_out => $result->{$oid_sonicSAStatDecryptByteCount . '.' . $instance} * 8,
110 display => $result->{$oid_sonicSAStatUserName . '.' . $instance} };
111 }
112
113 if (scalar(keys %{$self->{vpn}}) <= 0) {
114 $self->{output}->add_option_msg(short_msg => "No vpn found.");
115 $self->{output}->option_exit();
116 }
117 }
118
119 1;
120
121 __END__
122
123 =head1 MODE
124
125 Check VPN state and traffic.
126
127 =over 8
128
129 =item B<--filter-name>
130
131 Filter vpn name with regexp.
132
133 =item B<--warning-*>
134
135 Warning threshold.
136 Can be: 'traffic-in', 'traffic-out'.
137
138 =item B<--critical-*>
139
140 Critical threshold.
141 Can be: 'traffic-in', 'traffic-out'.
142
143 =back
144
145 =cut