Debian Codegraph @

src/network/athonet/epc/snmp/mode/interfacesgtpc.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::interfacesgtpc;
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
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 'status: %s',
34 $self->{result_values}->{status}
35 );
36 }
37
38 sub prefix_interface_output {
39 my ($self, %options) = @_;
40
41 return sprintf(
42 "Gtp control interface source '%s' destination '%s' [type: %s] [owner: %s] ",
43 $options{instance_value}->{source_address},
44 $options{instance_value}->{destination_address},
45 $options{instance_value}->{type},
46 $options{instance_value}->{owner}
47 );
48 }
49
50 sub set_counters {
51 my ($self, %options) = @_;
52
53 $self->{maps_counters_type} = [
54 { name => 'global', type => 0 },
55 { name => 'interfaces', type => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All Gtp control interfaces are ok' }
56 ];
57
58 $self->{maps_counters}->{global} = [
59 { label => 'total', nlabel => 'gtpc.interfaces.total.count', display_ok => 0, set => {
60 key_values => [ { name => 'total' } ],
61 output_template => 'total interfaces: %s',
62 perfdatas => [
63 { template => '%s', min => 0 }
64 ]
65 }
66 }
67 ];
68
69 $self->{maps_counters}->{interfaces} = [
70 {
71 label => 'status', type => 2, critical_default => '%{status} =~ /down/i',
72 set => {
73 key_values => [ { name => 'status' }, { name => 'source_address' }, { name => 'destination_address' } ],
74 closure_custom_output => $self->can('custom_status_output'),
75 closure_custom_perfdata => sub { return 0; },
76 closure_custom_threshold_check => \&catalog_status_threshold_ng
77 }
78 }
79 ];
80 }
81
82 sub new {
83 my ($class, %options) = @_;
84 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
85 bless $self, $class;
86
87 $options{options}->add_options(arguments => {
88 'filter-source-address:s' => { name => 'filter_source_address' },
89 'filter-destination-address:s' => { name => 'filter_destination_address' },
90 'filter-type:s' => { name => 'filter_type' }
91 });
92
93 return $self;
94 }
95
96 my $map_status = { 0 => 'down', 1 => 'up' };
97 my $map_type = { 1 => 'gTPv1', 2 => 'gTPv2', 11 => 'gTPPrime' };
98 my $map_owner = {
99 0 => 'unknown', 1 => 'mme', 2 => 'msc', 3 => 'sgsn',
100 4 => 'fgw', 5 => 'wifi', 6 => 'sgw', 7 => 'pgw', 8 => 'hlr-hss'
101 };
102
103 my $mapping = {
104 owner => { oid => '.1.3.6.1.4.1.35805.10.2.12.9.1.8', map => $map_owner } # gTPcOwner
105 };
106
107 sub manage_selection {
108 my ($self, %options) = @_;
109
110 my $oid_status = '.1.3.6.1.4.1.35805.10.2.12.9.1.6'; # gTPcState
111 my $snmp_result = $options{snmp}->get_table(
112 oid => $oid_status,
113 nothing_quit => 1
114 );
115
116 $self->{interfaces} = {};
117 foreach (keys %$snmp_result) {
118 /^$oid_status\.(.*)$/;
119 my $instance = $1;
120 my @indexes = split(/\./, $instance);
121
122 my $source_address = $self->{output}->decode(join('', map(chr($_), splice(@indexes, 0, shift(@indexes)) )));
123 my $destination_address = $self->{output}->decode(join('', map(chr($_), splice(@indexes, 0, shift(@indexes)) )));
124 my $type = $map_type->{ $indexes[0] };
125
126 if (defined($self->{option_results}->{filter_source_address}) && $self->{option_results}->{filter_source_address} ne '' &&
127 $source_address !~ /$self->{option_results}->{filter_source_address}/) {
128 $self->{output}->output_add(long_msg => "skipping '" . $source_address . "': no matching filter.", debug => 1);
129 next;
130 }
131 if (defined($self->{option_results}->{filter_destination_address}) && $self->{option_results}->{filter_destination_address} ne '' &&
132 $destination_address !~ /$self->{option_results}->{filter_destination_address}/) {
133 $self->{output}->output_add(long_msg => "skipping '" . $destination_address . "': no matching filter.", debug => 1);
134 next;
135 }
136 if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
137 $type !~ /$self->{option_results}->{filter_type}/) {
138 $self->{output}->output_add(long_msg => "skipping '" . $type . "': no matching filter.", debug => 1);
139 next;
140 }
141
142 $self->{interfaces}->{$instance} = {
143 source_address => $source_address,
144 destination_address => $destination_address,
145 type => $type,
146 status => $map_status->{ $snmp_result->{$_} }
147 };
148 }
149
150 $self->{global} = { total => scalar(keys %{$self->{interfaces}}) };
151 return if (scalar(keys %{$self->{interfaces}}) <= 0);
152
153 $options{snmp}->load(oids => [
154 map($_->{oid}, values(%$mapping))
155 ],
156 instances => [keys %{$self->{interfaces}}],
157 instance_regexp => '^(.*)$'
158 );
159 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
160
161 foreach (keys %{$self->{interfaces}}) {
162 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
163 $self->{interfaces}->{$_} = { %{$self->{interfaces}->{$_}}, %$result };
164 }
165 }
166
167 1;
168
169 __END__
170
171 =head1 MODE
172
173 Check GTP control interfaces.
174
175 =over 8
176
177 =item B<--filter-source-address>
178
179 Filter interfaces by source address (can be a regexp).
180
181 =item B<--filter-destination-address>
182
183 Filter interfaces by destination address (can be a regexp).
184
185 =item B<--filter-type>
186
187 Filter interfaces by type (can be a regexp).
188
189 =item B<--unknown-status>
190
191 Define the conditions to match for the status to be UNKNOWN.
192 You can use the following variables: %{status}, %{source_address}, %{destination_address}
193
194 =item B<--warning-status>
195
196 Define the conditions to match for the status to be WARNING.
197 You can use the following variables: %{status}, %{source_address}, %{destination_address}
198
199 =item B<--critical-status>
200
201 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /down/i').
202 You can use the following variables: %{status}, %{source_address}, %{destination_address}
203
204 =item B<--warning-*> B<--critical-*>
205
206 Thresholds.
207 Can be: 'total'.
208
209 =back
210
211 =cut