Debian Codegraph @

src/apps/pfsense/snmp/mode/packetstats.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::packetstats;
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 => 'global', type => 0, message_separator => ' - ' }
34 ];
35
36 $self->{maps_counters}->{global} = [
37 { label => 'match', nlabel => 'packets.matched.persecond', set => {
38 key_values => [ { name => 'pfCounterMatch', per_second => 1 } ],
39 output_template => 'Packets Matched Filter Rule : %.2f/s',
40 perfdatas => [
41 { label => 'match', template => '%.2f', unit => '/s', min => 0 }
42 ]
43 }
44 },
45 { label => 'badoffset', nlabel => 'packets.badoffset.persecond', set => {
46 key_values => [ { name => 'pfCounterBadOffset', per_second => 1 } ],
47 output_template => 'Bad Offset Packets : %.2f/s',
48 perfdatas => [
49 { label => 'bad_offset', template => '%.2f', unit => '/s', min => 0 }
50 ]
51 }
52 },
53 { label => 'fragment', nlabel => 'packets.fragmented.persecond', set => {
54 key_values => [ { name => 'pfCounterFragment', per_second => 1 } ],
55 output_template => 'Fragmented Packets : %.2f/s',
56 perfdatas => [
57 { label => 'fragment', template => '%.2f', unit => '/s', min => 0 }
58 ]
59 }
60 },
61 { label => 'short', nlabel => 'packets.short.persecond', set => {
62 key_values => [ { name => 'pfCounterShort', per_second => 1 } ],
63 output_template => 'Short Packets : %.2f/s',
64 perfdatas => [
65 { label => 'short', template => '%.2f', unit => '/s', min => 0 }
66 ]
67 }
68 },
69 { label => 'normalize', nlabel => 'packets.normalized.persecond',set => {
70 key_values => [ { name => 'pfCounterNormalize', per_second => 1 } ],
71 output_template => 'Normalized Packets : %.2f/s',
72 perfdatas => [
73 { label => 'normalize', template => '%.2f', unit => '/s', min => 0 },
74 ],
75 }
76 },
77 { label => 'memdrop', nlabel => 'packets.memorydropped.persecond',set => {
78 key_values => [ { name => 'pfCounterMemDrop', per_second => 1 } ],
79 output_template => 'Dropped Packets Due To Memory : %.2f/s',
80 perfdatas => [
81 { label => 'memdrop', template => '%.2f', unit => '/s', min => 0 }
82 ]
83 }
84 }
85 ];
86 }
87
88 sub new {
89 my ($class, %options) = @_;
90 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
91 bless $self, $class;
92
93 $options{options}->add_options(arguments => {
94 });
95
96 return $self;
97 }
98
99 sub manage_selection {
100 my ($self, %options) = @_;
101
102 if ($options{snmp}->is_snmpv1()) {
103 $self->{output}->add_option_msg(short_msg => "Can't check SNMP 64 bits counters with SNMPv1.");
104 $self->{output}->option_exit();
105 }
106 my %oids = (
107 pfCounterMatch => '.1.3.6.1.4.1.12325.1.200.1.2.1.0',
108 pfCounterBadOffset => '.1.3.6.1.4.1.12325.1.200.1.2.2.0',
109 pfCounterFragment => '.1.3.6.1.4.1.12325.1.200.1.2.3.0',
110 pfCounterShort => '.1.3.6.1.4.1.12325.1.200.1.2.4.0',
111 pfCounterNormalize => '.1.3.6.1.4.1.12325.1.200.1.2.5.0',
112 pfCounterMemDrop => '.1.3.6.1.4.1.12325.1.200.1.2.6.0'
113 );
114 my $snmp_result = $options{snmp}->get_leef(oids => [values %oids], nothing_quit => 1);
115 $self->{global} = {};
116 foreach (keys %oids) {
117 $self->{global}->{$_} = $snmp_result->{$oids{$_}};
118 }
119
120 $self->{cache_name} = "pfsense_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
121 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
122 }
123
124 1;
125
126 __END__
127
128 =head1 MODE
129
130 Check global packet statistics.
131
132 =over 8
133
134 =item B<--filter-counters>
135
136 Only display some counters (regexp can be used).
137 Example: --filter-counters='^match$'
138
139 =item B<--warning-*>
140
141 Warning threshold.
142 Can be: 'match', 'badoffset', 'fragment', 'short',
143 'normalize', 'memdrop'.
144
145 =item B<--critical-*>
146
147 Critical threshold.
148 Can be: 'match', 'badoffset', 'fragment', 'short',
149 'normalize', 'memdrop'.
150
151 =back
152
153 =cut