Debian Codegraph @

src/apps/pfsense/snmp/mode/pfinterfaces.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 apps::pfsense::snmp::mode::pfinterfaces;
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 => 'pfint', type => 1, cb_prefix_output => 'prefix_pfint_output', message_multiple => 'All pfInterfaes are ok' }
34 ];
35
36 $self->{maps_counters}->{pfint} = [
37 { label => 'traffic-in-pass', nlabel => 'pfinterface.pass.traffic.in.bitspersecond', set => {
38 key_values => [ { name => 'pfInterfacesIf4BytesInPass', per_second => 1 }, { name => 'display' } ],
39 output_change_bytes => 2,
40 output_template => 'Traffic In Pass : %s %s/s',
41 perfdatas => [
42 { label => 'traffic_in_pass', template => '%.2f',
43 min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
44 ]
45 }
46 },
47 { label => 'traffic-out-pass', nlabel => 'pfinterface.pass.traffic.out.bitspersecond', set => {
48 key_values => [ { name => 'pfInterfacesIf4BytesOutPass', per_second => 1 }, { name => 'display' } ],
49 output_change_bytes => 2,
50 output_template => 'Traffic Out Pass : %s %s/s',
51 perfdatas => [
52 { label => 'traffic_out_pass', template => '%.2f',
53 min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
54 ]
55 }
56 },
57 { label => 'traffic-in-block', nlabel => 'pfinterface.block.traffic.in.bitspersecond', set => {
58 key_values => [ { name => 'pfInterfacesIf4BytesInBlock', per_second => 1 }, { name => 'display' } ],
59 output_change_bytes => 2,
60 output_template => 'Traffic In Block : %s %s/s',
61 perfdatas => [
62 { label => 'traffic_in_block', template => '%.2f',
63 min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
64 ]
65 }
66 },
67 { label => 'traffic-out-block', nlabel => 'pfinterface.block.traffic.out.bitspersecond', set => {
68 key_values => [ { name => 'pfInterfacesIf4BytesOutBlock', per_second => 1 }, { name => 'display' } ],
69 output_change_bytes => 2,
70 output_template => 'Traffic Out Block : %s %s/s',
71 perfdatas => [
72 { label => 'traffic_out_block', template => '%.2f',
73 min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
74 ]
75 }
76 }
77 ];
78 }
79
80 sub prefix_pfint_output {
81 my ($self, %options) = @_;
82
83 return "pfInterface '" . $options{instance_value}->{display} . "' ";
84 }
85
86 sub new {
87 my ($class, %options) = @_;
88 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
89 bless $self, $class;
90
91 $options{options}->add_options(arguments => {
92 'filter-name:s' => { name => 'filter_name' }
93 });
94
95 return $self;
96 }
97
98 my $oid_pfInterfacesIfDescr = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.2';
99 my $mapping = {
100 pfInterfacesIf4BytesInPass => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.7' },
101 pfInterfacesIf4BytesInBlock => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.8' },
102 pfInterfacesIf4BytesOutPass => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.9' },
103 pfInterfacesIf4BytesOutBlock => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.10' }
104 };
105
106 sub manage_selection {
107 my ($self, %options) = @_;
108
109 if ($options{snmp}->is_snmpv1()) {
110 $self->{output}->add_option_msg(short_msg => "Can't check SNMP 64 bits counters with SNMPv1.");
111 $self->{output}->option_exit();
112 }
113 my $snmp_result = $options{snmp}->get_table(oid => $oid_pfInterfacesIfDescr, nothing_quit => 1);
114
115 $self->{pfint} = {};
116 foreach my $oid (keys %{$snmp_result}) {
117 $oid =~ /^$oid_pfInterfacesIfDescr\.(.*)$/;
118 my $instance = $1;
119
120 my $name = $snmp_result->{$oid};
121 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
122 $name !~ /$self->{option_results}->{filter_name}/) {
123 $self->{output}->output_add(long_msg => "skipping pfInterface '" . $name . "'.", debug => 1);
124 next;
125 }
126
127 $self->{pfint}->{$instance} = { display => $name };
128 }
129
130 $options{snmp}->load(
131 oids => [
132 $mapping->{pfInterfacesIf4BytesInPass}->{oid}, $mapping->{pfInterfacesIf4BytesOutPass}->{oid},
133 $mapping->{pfInterfacesIf4BytesInBlock}->{oid}, $mapping->{pfInterfacesIf4BytesOutBlock}->{oid},
134 ],
135 instances => [keys %{$self->{pfint}}],
136 instance_regexp => '^(.*)$'
137 );
138 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
139
140 foreach my $instance (keys %{$self->{pfint}}) {
141 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
142
143 foreach (keys %$mapping) {
144 $self->{pfint}->{$instance}->{$_} = $result->{$_} * 8;
145 }
146 }
147
148 if (scalar(keys %{$self->{pfint}}) <= 0) {
149 $self->{output}->add_option_msg(short_msg => "No pfInterface found.");
150 $self->{output}->option_exit();
151 }
152
153 $self->{cache_name} = 'pfsense_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
154 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
155 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
156 }
157
158 1;
159
160 __END__
161
162 =head1 MODE
163
164 Check pfInterfaces.
165
166 =over 8
167
168 =item B<--warning-*>
169
170 Warning threshold.
171 Can be: 'traffic-in-pass', 'traffic-out-pass', 'traffic-in-block', 'traffic-out-block'.
172
173 =item B<--critical-*>
174
175 Critical threshold.
176 Can be: 'traffic-in-pass', 'traffic-out-pass', 'traffic-in-block', 'traffic-out-block'.
177
178 =item B<--filter-name>
179
180 Filter by interface name (can be a regexp).
181
182 =back
183
184 =cut