Debian Codegraph @

src/network/teldat/snmp/mode/listcellsradio.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::teldat::snmp::mode::listcellsradio;
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 $mapping = {
44 imei => { oid => '.1.3.6.1.4.1.2007.4.1.2.2.2.18.1.1.5' }, # teldatCellularInfoInterfaceModuleIMEI : Cellular module IMEI.
45 imsi => { oid => '.1.3.6.1.4.1.2007.4.1.2.2.2.18.1.1.6' }, # teldatCellularInfoInterfaceModuleIMSI : Cellular module IMSI.
46 simIcc => { oid => '.1.3.6.1.4.1.2007.4.1.2.2.2.18.1.1.8' } # teldatCellularInfoInterfaceSIMIcc : Cellular active SIM ICC.
47 };
48 my $oid_teldatCellularInfoInterfaceEntry = '.1.3.6.1.4.1.2007.4.1.2.2.2.18.1.1'; # teldatInfoInterfaceTable
49
50 my $interface_types = {
51 1 => 'control vocal',
52 2 => 'data primary',
53 3 => 'data auxiliary'
54 };
55
56 sub manage_selection {
57 my ($self, %options) = @_;
58
59 my $snmp_result = $options{snmp}->get_table(
60 oid => $oid_teldatCellularInfoInterfaceEntry,
61 start => $mapping->{imei}->{oid},
62 end => $mapping->{simIcc}->{oid},
63 nothing_quit => 1
64 );
65
66 my $results = {};
67 my $modules = {};
68 my $module_num = 0;
69 my $interface_type = 0;
70 foreach my $oid ($options{snmp}->oid_lex_sort(keys %$snmp_result)) {
71 next if ($oid !~ /^$mapping->{imei}->{oid}\.(.*)$/);
72 my $instance = $1;
73
74 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
75 next if ($result->{imei} !~ /^[0-9]+$/);
76
77 if (!defined($modules->{$module_num}) || $result->{imei} ne $modules->{$module_num}) {
78 $module_num++;
79 $interface_type = 0;
80 $modules->{$module_num} = $result->{imei};
81 }
82 if (defined($modules->{$module_num})) {
83 $interface_type++;
84 }
85
86 my $module = 'module' . $module_num;
87
88 $results->{$instance} = {
89 module => $module,
90 moduleNum => $module_num,
91 interfaceType => $interface_types->{$interface_type},
92 imei => $result->{imei},
93 imsi => $result->{imsi},
94 simIcc => $result->{simIcc}
95 };
96 }
97
98 return $results;
99 }
100
101 sub run {
102 my ($self, %options) = @_;
103
104 my $results = $self->manage_selection(snmp => $options{snmp});
105 foreach my $name (sort keys %$results) {
106 $self->{output}->output_add(long_msg =>
107 '[module = ' . $results->{$name}->{module} . ']' .
108 '[moduleNum = ' . $results->{$name}->{moduleNum} . ']' .
109 '[interfaceType = ' . $results->{$name}->{interfaceType} . ']' .
110 join('', map("[$_ = " . $results->{$name}->{$_} . ']', keys(%$mapping)))
111 );
112 }
113
114 $self->{output}->output_add(
115 severity => 'OK',
116 short_msg => 'List cellular radio interfaces:'
117 );
118 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
119 $self->{output}->exit();
120 }
121
122 sub disco_format {
123 my ($self, %options) = @_;
124
125 $self->{output}->add_disco_format(elements => ['module', 'moduleNum', 'interfaceType', keys %$mapping]);
126 }
127
128 sub disco_show {
129 my ($self, %options) = @_;
130
131 my $results = $self->manage_selection(snmp => $options{snmp});
132 foreach (sort keys %$results) {
133 $self->{output}->add_disco_entry(
134 %{$results->{$_}}
135 );
136 }
137 }
138
139 1;
140
141 __END__
142
143 =head1 MODE
144
145 List cellular radio interfaces.
146
147 =over 8
148
149 =back
150
151 =cut