Debian Codegraph @

src/network/athonet/epc/snmp/mode/interfacesdiameter.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::interfacesdiameter;
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 custom_transport_status_output {
39 my ($self, %options) = @_;
40
41 return sprintf(
42 'transport status: %s [type: %s]',
43 $self->{result_values}->{transport_status},
44 $self->{result_values}->{transport_type}
45 );
46 }
47
48 sub prefix_interface_output {
49 my ($self, %options) = @_;
50
51 return sprintf(
52 "Diameter interface '%s' [local: %s] [peer: %s]%s%s ",
53 $options{instance_value}->{name},
54 $options{instance_value}->{local_hostname},
55 $options{instance_value}->{peer_hostname},
56 (defined($options{instance_value}->{secondary_local_addr}) && $options{instance_value}->{secondary_local_addr} ne '') ?
57 ' [secondary local: ' . $options{instance_value}->{secondary_local_addr} . ']' : '',
58 (defined($options{instance_value}->{secondary_peer_addr}) && $options{instance_value}->{secondary_peer_addr} ne '') ?
59 ' [secondary peer: ' . $options{instance_value}->{secondary_peer_addr} . ']' : '',
60 );
61 }
62
63 sub set_counters {
64 my ($self, %options) = @_;
65
66 $self->{maps_counters_type} = [
67 { name => 'global', type => 0 },
68 { name => 'interfaces', type => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All diameter interfaces are ok' }
69 ];
70
71 $self->{maps_counters}->{global} = [
72 { label => 'total', nlabel => 'diameter.interfaces.total.count', display_ok => 0, set => {
73 key_values => [ { name => 'total' } ],
74 output_template => 'total interfaces: %s',
75 perfdatas => [
76 { template => '%s', min => 0 }
77 ]
78 }
79 }
80 ];
81
82 $self->{maps_counters}->{interfaces} = [
83 {
84 label => 'status', type => 2, critical_default => '%{status} =~ /down/i',
85 set => {
86 key_values => [
87 { name => 'status' }, { name => 'name' }, { name => 'owner' }
88 ],
89 closure_custom_output => $self->can('custom_status_output'),
90 closure_custom_perfdata => sub { return 0; },
91 closure_custom_threshold_check => \&catalog_status_threshold_ng
92 }
93 },
94 {
95 label => 'transport-status', type => 2, critical_default => '%{transport_status} =~ /down/i',
96 set => {
97 key_values => [ { name => 'transport_status' }, { name => 'transport_type' }, { name => 'name' } ],
98 closure_custom_output => $self->can('custom_transport_status_output'),
99 closure_custom_perfdata => sub { return 0; },
100 closure_custom_threshold_check => \&catalog_status_threshold_ng
101 }
102 }
103 ];
104 }
105
106 sub new {
107 my ($class, %options) = @_;
108 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
109 bless $self, $class;
110
111 $options{options}->add_options(arguments => {
112 'filter-name:s' => { name => 'filter_name' },
113 'filter-owner:s' => { name => 'filter_owner' }
114 });
115
116 return $self;
117 }
118
119 my $map_status = { 0 => 'down', 1 => 'up' };
120 my $map_transport_type = { 0 => 'sctp', 1 => 'tcp', 2 => 'udp' };
121 my $map_owner = {
122 0 => 'unknown', 1 => 'mme', 2 => 'msc', 3 => 'sgsn',
123 4 => 'fgw', 5 => 'wifi', 6 => 'spgw', 7 => 'hlr-hss',
124 8 => 'sgw', 9 => 'pgw', 10 => 'pcrf', 11 => 'dpiaf',
125 12 => 'aaa', 13 => 'ocs'
126 };
127
128 my $mapping = {
129 peer_hostname => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.4' }, # iDiameterPeerHostName
130 transport_type => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.8', map => $map_transport_type }, # iDiameterTransportType
131 transport_status => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.9', map => $map_status }, # iDiameterTransportState
132 status => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.10', map => $map_status }, # iDiameterState
133 owner => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.11', map => $map_owner }, # iDiameterOwner
134 secondary_local_addr => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.12' }, # iDiameterSecondaryLocalAddress
135 secondary_peer_addr => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.13' } # iDiameterSecondaryPeerAddress
136 };
137
138 sub manage_selection {
139 my ($self, %options) = @_;
140
141 my $oid_local_hostname = '.1.3.6.1.4.1.35805.10.2.12.2.1.2'; # iDiameterLocalHostName
142 my $snmp_result = $options{snmp}->get_table(
143 oid => $oid_local_hostname,
144 nothing_quit => 1
145 );
146
147 $self->{interfaces} = {};
148 foreach (keys %$snmp_result) {
149 /^$oid_local_hostname\.(\d+\.(.*))$/;
150 my $instance = $1;
151 my $name = $self->{output}->decode(join('', map(chr($_), split(/\./, $2))));
152
153 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
154 $name !~ /$self->{option_results}->{filter_name}/) {
155 $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
156 next;
157 }
158
159 $self->{interfaces}->{$instance} = {
160 name => $name,
161 local_hostname => $snmp_result->{$_}
162 };
163 }
164
165 $self->{global} = { total => 0 };
166
167 return if (scalar(keys %{$self->{interfaces}}) <= 0);
168
169 $options{snmp}->load(oids => [
170 map($_->{oid}, values(%$mapping))
171 ],
172 instances => [keys %{$self->{interfaces}}],
173 instance_regexp => '^(.*)$'
174 );
175 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
176
177 foreach (keys %{$self->{interfaces}}) {
178 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
179
180 if (defined($self->{option_results}->{filter_owner}) && $self->{option_results}->{filter_owner} ne '' &&
181 $result->{owner} !~ /$self->{option_results}->{filter_owner}/) {
182 $self->{output}->output_add(long_msg => "skipping '" . $self->{interfaces}->{$_}->{name} . "': no matching filter.", debug => 1);
183 delete $self->{interfaces}->{$_};
184 next;
185 }
186
187 $self->{interfaces}->{$_} = { %{$self->{interfaces}->{$_}}, %$result };
188 }
189
190 $self->{global}->{total} = scalar(keys %{$self->{interfaces}});
191 }
192
193 1;
194
195 __END__
196
197 =head1 MODE
198
199 Check diameter interfaces.
200
201 =over 8
202
203 =item B<--filter-counters>
204
205 Only display some counters (regexp can be used).
206 Example: --filter-counters='transport'
207
208 =item B<--filter-name>
209
210 Filter interfaces by name (can be a regexp).
211
212 =item B<--filter-owner>
213
214 Filter interfaces by owner (can be a regexp).
215
216 =item B<--unknown-status>
217
218 Define the conditions to match for the status to be UNKNOWN.
219 You can use the following variables: %{status}, %{name}, %{owner}
220
221 =item B<--warning-status>
222
223 Define the conditions to match for the status to be WARNING.
224 You can use the following variables: %{status}, %{name}, %{owner}
225
226 =item B<--critical-status>
227
228 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /down/i').
229 You can use the following variables: %{status}, %{name}, %{owner}
230
231 =item B<--unknown-transport-status>
232
233 Define the conditions to match for the status to be UNKNOWN.
234 You can use the following variables: %{transport_status}, %{transport_type}, %{name}
235
236 =item B<--warning-transport-status>
237
238 Define the conditions to match for the status to be WARNING.
239 You can use the following variables: %{transport_status}, %{transport_type}, %{name}
240
241 =item B<--critical-transport-status>
242
243 Define the conditions to match for the status to be CRITICAL (default: '%{transport_status} =~ /down/i').
244 You can use the following variables: %{transport_status}, %{transport_type}, %{name}
245
246 =item B<--warning-*> B<--critical-*>
247
248 Thresholds.
249 Can be: 'total'.
250
251 =back
252
253 =cut