Debian Codegraph @

src/network/athonet/epc/snmp/mode/apns.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::athonet::epc::snmp::mode::apns;
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 prefix_apn_output {
30 my ($self, %options) = @_;
31
32 return 'apn ';
33 }
34
35 sub apn_long_output {
36 my ($self, %options) = @_;
37
38 return sprintf(
39 "checking apn '%s'",
40 $options{instance_value}->{name}
41 );;
42 }
43
44 sub prefix_traffic_output {
45 my ($self, %options) = @_;
46
47 return 'traffic ';
48 }
49
50 sub set_counters {
51 my ($self, %options) = @_;
52
53 $self->{maps_counters_type} = [
54 {
55 name => 'apns', type => 3, cb_prefix_output => 'prefix_apn_output', cb_long_output => 'apn_long_output',
56 indent_long_output => ' ', message_multiple => 'All access point names are ok',
57 group => [
58 { name => 'traffic', type => 0, cb_prefix_output => 'prefix_traffic_output', skipped_code => { -10 => 1 } },
59 { name => 'pdp', type => 0, skipped_code => { -10 => 1 } }
60 ]
61 }
62 ];
63
64 $self->{maps_counters}->{traffic} = [
65 { label => 'traffic-in', nlabel => 'apn.traffic.in.bytespersecond', set => {
66 key_values => [ { name => 'traffic_in', per_second => 1 } ],
67 output_template => 'in: %.2f %s/s',
68 output_change_bytes => 1,
69 perfdatas => [
70 { template => '%.2f', unit => 'B/s', min => 0, label_extra_instance => 1 }
71 ]
72 }
73 },
74 { label => 'traffic-out', nlabel => 'apn.traffic.out.bytespersecond', set => {
75 key_values => [ { name => 'traffic_out', per_second => 1 } ],
76 output_template => 'out: %.2f %s/s',
77 output_change_bytes => 1,
78 perfdatas => [
79 { template => '%.2f', unit => 'B/s', min => 0, label_extra_instance => 1 }
80 ]
81 }
82 }
83 ];
84
85 $self->{maps_counters}->{pdp} = [
86 { label => 'pdp-contexts', nlabel => 'apn.pdp_contexts.count', set => {
87 key_values => [ { name => 'contexts' } ],
88 output_template => 'pdp contexts: %s',
89 perfdatas => [
90 { template => '%s', min => 0, label_extra_instance => 1 }
91 ]
92 }
93 }
94 ];
95 }
96
97 sub new {
98 my ($class, %options) = @_;
99 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
100 bless $self, $class;
101
102 $options{options}->add_options(arguments => {
103 'filter-name:s' => { name => 'filter_name' }
104 });
105
106 return $self;
107 }
108
109 my $mapping = {
110 traffic_in => { oid => '.1.3.6.1.4.1.35805.10.2.99.14.1.2' }, # aPNRowDownlinkBytes
111 traffic_out => { oid => '.1.3.6.1.4.1.35805.10.2.99.14.1.3' }, # aPNRowUplinkBytes
112 pdp_contexts => { oid => '.1.3.6.1.4.1.35805.10.2.99.14.1.4' } # aPNRowPdpContexts
113 };
114
115 sub manage_selection {
116 my ($self, %options) = @_;
117
118 $self->{cache_name} = 'athonet_epc_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
119 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
120
121 my $oid_apn_name = '.1.3.6.1.4.1.35805.10.2.99.14.1.1'; # aPNRowApnKey
122 my $snmp_result = $options{snmp}->get_table(
123 oid => $oid_apn_name,
124 nothing_quit => 1
125 );
126
127 $self->{apns} = {};
128 foreach (keys %$snmp_result) {
129 /^$oid_apn_name\.(.*)$/;
130 my $instance = $1;
131 my $name = $self->{output}->decode($snmp_result->{$_});
132
133 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
134 $name !~ /$self->{option_results}->{filter_name}/) {
135 $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
136 next;
137 }
138
139 $self->{apns}->{$name} = {
140 instance => $instance,
141 name => $name,
142 traffic => {},
143 context => {}
144 };
145 }
146
147 $self->{global}->{total} = scalar(keys %{$self->{apns}});
148 return if (scalar(keys %{$self->{apns}}) <= 0);
149
150 $options{snmp}->load(oids => [
151 map($_->{oid}, values(%$mapping))
152 ],
153 instances => [ map($_->{instance}, values(%{$self->{apns}})) ],
154 instance_regexp => '^(.*)$'
155 );
156 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
157
158 foreach (keys %{$self->{apns}}) {
159 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $self->{apns}->{$_}->{instance});
160 $self->{apns}->{$_}->{traffic}->{traffic_in} = $result->{traffic_in};
161 $self->{apns}->{$_}->{traffic}->{traffic_out} = $result->{traffic_out};
162 $self->{apns}->{$_}->{pdp}->{contexts} = $result->{pdp_contexts};
163 }
164 }
165
166 1;
167
168 __END__
169
170 =head1 MODE
171
172 Check access point names.
173
174 =over 8
175
176 =item B<--filter-counters>
177
178 Only display some counters (regexp can be used).
179 Example: --filter-counters='traffic'
180
181 =item B<--filter-name>
182
183 Filter APN by name (can be a regexp).
184
185 =item B<--warning-*> B<--critical-*>
186
187 Thresholds.
188 Can be: 'traffic-in', 'traffic-out', 'pdp-contexts'.
189
190 =back
191
192 =cut