Debian Codegraph @

src/network/athonet/epc/snmp/mode/listinterfacesdiameter.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::listinterfacesdiameter;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 sub new {
29 my ($class, %options) = @_;
30 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
31 bless $self, $class;
32
33 $options{options}->add_options(arguments => {
34 });
35 return $self;
36 }
37
38 sub check_options {
39 my ($self, %options) = @_;
40 $self->SUPER::init(%options);
41 }
42
43 my $map_status = { 0 => 'down', 1 => 'up' };
44 my $map_transport_type = { 0 => 'sctp', 1 => 'tcp', 2 => 'udp' };
45 my $map_owner = {
46 0 => 'unknown', 1 => 'mme', 2 => 'msc', 3 => 'sgsn',
47 4 => 'fgw', 5 => 'wifi', 6 => 'spgw', 7 => 'hlr-hss',
48 8 => 'sgw', 9 => 'pgw', 10 => 'pcrf', 11 => 'dpiaf',
49 12 => 'aaa', 13 => 'ocs'
50 };
51
52 my $mapping = {
53 local_hostname => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.2' }, # iDiameterLocalHostName
54 local_realmname => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.3' }, # iDiameterLocalRealmName
55 peer_hostname => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.4' }, # iDiameterPeerHostName
56 peer_realmname => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.5' }, # iDiameterPeerRealmName
57 local_address => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.6' }, # iDiameterLocalAddress
58 peer_address => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.7' }, # iDiameterPeerAddress
59 transport_type => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.8', map => $map_transport_type }, # iDiameterTransportType
60 transport_status => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.9', map => $map_status }, # iDiameterTransportState
61 status => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.10', map => $map_status }, # iDiameterState
62 owner => { oid => '.1.3.6.1.4.1.35805.10.2.12.2.1.11', map => $map_owner } # iDiameterOwner
63 };
64 my $oid_diameterInterfacesEntry = '.1.3.6.1.4.1.35805.10.2.12.2.1';
65
66 sub manage_selection {
67 my ($self, %options) = @_;
68
69 my $snmp_result = $options{snmp}->get_table(
70 oid => $oid_diameterInterfacesEntry,
71 start => $mapping->{local_hostname}->{oid},
72 end => $mapping->{owner}->{oid},
73 nothing_quit => 1
74 );
75
76 my $results = {};
77 foreach (keys %$snmp_result) {
78 next if (! /^$mapping->{local_hostname}->{oid}\.(\d+\.(.*))$/);
79 my $instance = $1;
80 my $name = $self->{output}->decode(join('', map(chr($_), split(/\./, $2))));
81
82 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
83 $results->{$name} = $result;
84 }
85
86 return $results;
87 }
88
89 sub run {
90 my ($self, %options) = @_;
91
92 my $results = $self->manage_selection(snmp => $options{snmp});
93 foreach my $name (sort keys %$results) {
94 $self->{output}->output_add(long_msg =>
95 '[name = ' . $name . ']' . join('', map("[$_ = " . $results->{$name}->{$_} . ']', keys(%$mapping)))
96 );
97 }
98
99 $self->{output}->output_add(
100 severity => 'OK',
101 short_msg => 'List diameter interfaces:'
102 );
103 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
104 $self->{output}->exit();
105 }
106
107 sub disco_format {
108 my ($self, %options) = @_;
109
110 $self->{output}->add_disco_format(elements => ['name', keys %$mapping]);
111 }
112
113 sub disco_show {
114 my ($self, %options) = @_;
115
116 my $results = $self->manage_selection(snmp => $options{snmp});
117 foreach (sort keys %$results) {
118 $self->{output}->add_disco_entry(
119 name => $_,
120 %{$results->{$_}}
121 );
122 }
123 }
124
125 1;
126
127 __END__
128
129 =head1 MODE
130
131 List diameter interfaces.
132
133 =over 8
134
135 =back
136
137 =cut