| 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::cellsradio; |
| 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_signal_perfdata { |
| 30 |
my ($self) = @_; |
| 31 |
|
| 32 |
my $instances = []; |
| 33 |
foreach (@{$self->{instance_mode}->{custom_perfdata_instances}}) { |
| 34 |
push @$instances, $self->{result_values}->{$_}; |
| 35 |
} |
| 36 |
|
| 37 |
$self->{output}->perfdata_add( |
| 38 |
nlabel => $self->{nlabel}, |
| 39 |
instances => $instances, |
| 40 |
value => $self->{result_values}->{ $self->{key_values}->[0]->{name} }, |
| 41 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 42 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 43 |
min => 0 |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
sub custom_status_output { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
return sprintf( |
| 51 |
'sim status: %s [operator: %s] [imsi: %s] [interface state: %s] [simIcc: %s]', |
| 52 |
$self->{result_values}->{simStatus}, |
| 53 |
$self->{result_values}->{operator}, |
| 54 |
$self->{result_values}->{imsi}, |
| 55 |
$self->{result_values}->{interfaceState}, |
| 56 |
$self->{result_values}->{simIcc} |
| 57 |
); |
| 58 |
} |
| 59 |
|
| 60 |
sub cell_long_output { |
| 61 |
my ($self, %options) = @_; |
| 62 |
|
| 63 |
return sprintf( |
| 64 |
"checking cellular radio module '%s' interface '%s' [imei: %s] ", |
| 65 |
$options{instance_value}->{module_num}, |
| 66 |
$options{instance_value}->{interfaceType}, |
| 67 |
$options{instance_value}->{imei} |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
sub prefix_cell_output { |
| 72 |
my ($self, %options) = @_; |
| 73 |
|
| 74 |
return sprintf( |
| 75 |
"cellular radio module '%s' interface '%s' [imei: %s] ", |
| 76 |
$options{instance_value}->{module_num}, |
| 77 |
$options{instance_value}->{interfaceType}, |
| 78 |
$options{instance_value}->{imei} |
| 79 |
); |
| 80 |
} |
| 81 |
|
| 82 |
sub prefix_global_output { |
| 83 |
my ($self, %options) = @_; |
| 84 |
|
| 85 |
return 'Number of cellular radio interfaces'; |
| 86 |
} |
| 87 |
|
| 88 |
sub set_counters { |
| 89 |
my ($self, %options) = @_; |
| 90 |
|
| 91 |
$self->{maps_counters_type} = [ |
| 92 |
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, |
| 93 |
{ name => 'cells', type => 3, cb_prefix_output => 'prefix_cell_output', cb_long_output => 'cell_long_output', |
| 94 |
indent_long_output => ' ', message_multiple => 'All cellular radio interfaces are ok', |
| 95 |
group => [ |
| 96 |
{ name => 'status', type => 0, skipped_code => { -10 => 1 } }, |
| 97 |
{ name => 'signal', type => 0, skipped_code => { -10 => 1 } } |
| 98 |
] |
| 99 |
} |
| 100 |
]; |
| 101 |
|
| 102 |
$self->{maps_counters}->{global} = [ |
| 103 |
{ label => 'modules-cellradio-detected', display_ok => 0, nlabel => 'modules.cellradio.detected.count', set => { |
| 104 |
key_values => [ { name => 'detected' } ], |
| 105 |
output_template => 'detected: %s', |
| 106 |
perfdatas => [ |
| 107 |
{ template => '%s', min => 0 } |
| 108 |
] |
| 109 |
} |
| 110 |
} |
| 111 |
]; |
| 112 |
|
| 113 |
$self->{maps_counters}->{status} = [ |
| 114 |
{ |
| 115 |
label => 'status', |
| 116 |
type => 2, |
| 117 |
warning_default => '%{interfaceState} =~ /disconnect/ && %{interfaceType} =~ /data primary/', |
| 118 |
set => { |
| 119 |
key_values => [ |
| 120 |
{ name => 'module' }, { name => 'interfaceType' }, { name => 'imei' }, { name => 'simIcc' }, |
| 121 |
{ name => 'operator' }, { name => 'imsi' }, |
| 122 |
{ name => 'simStatus' }, { name => 'interfaceState' } |
| 123 |
], |
| 124 |
closure_custom_output => $self->can('custom_status_output'), |
| 125 |
closure_custom_perfdata => sub { return 0; }, |
| 126 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 127 |
} |
| 128 |
} |
| 129 |
]; |
| 130 |
|
| 131 |
$self->{maps_counters}->{signal} = [ |
| 132 |
{ label => 'module-cellradio-rsrp', nlabel => 'module.cellradio.rsrp.dbm', set => { |
| 133 |
key_values => [ { name => 'rsrp' }, { name => 'module' }, { name => 'interfaceType' }, { name => 'imei' }, { name => 'simIcc' }, { name => 'operator' } ], |
| 134 |
output_template => 'rsrp: %s dBm', |
| 135 |
closure_custom_perfdata => $self->can('custom_signal_perfdata') |
| 136 |
} |
| 137 |
}, |
| 138 |
{ label => 'module-cellradio-rsrq', nlabel => 'module.cellradio.rsrq.dbm', set => { |
| 139 |
key_values => [ { name => 'rsrq' }, { name => 'module' }, { name => 'interfaceType' }, { name => 'imei' }, { name => 'simIcc' }, { name => 'operator' } ], |
| 140 |
output_template => 'rsrq: %s dBm', |
| 141 |
closure_custom_perfdata => $self->can('custom_signal_perfdata') |
| 142 |
} |
| 143 |
}, |
| 144 |
{ label => 'module-cellradio-snr', nlabel => 'module.cellradio.snr.db', set => { |
| 145 |
key_values => [ { name => 'snr' }, { name => 'module' }, { name => 'interfaceType' }, { name => 'imei' }, { name => 'simIcc' }, { name => 'operator' } ], |
| 146 |
output_template => 'snr: %s dB', |
| 147 |
closure_custom_perfdata => $self->can('custom_signal_perfdata') |
| 148 |
} |
| 149 |
}, |
| 150 |
{ label => 'module-cellradio-rscp', nlabel => 'module.cellradio.rscp.dbm', set => { |
| 151 |
key_values => [ { name => 'rscp' }, { name => 'module' }, { name => 'interfaceType' }, { name => 'imei' }, { name => 'simIcc' }, { name => 'operator' } ], |
| 152 |
output_template => 'rscp: %s dBm', |
| 153 |
closure_custom_perfdata => $self->can('custom_signal_perfdata') |
| 154 |
} |
| 155 |
}, |
| 156 |
{ label => 'module-cellradio-csq', nlabel => 'module.cellradio.csq.dbm', set => { |
| 157 |
key_values => [ { name => 'csq' }, { name => 'module' }, { name => 'interfaceType' }, { name => 'imei' }, { name => 'simIcc' }, { name => 'operator' } ], |
| 158 |
output_template => 'csq: %s dBm', |
| 159 |
closure_custom_perfdata => $self->can('custom_signal_perfdata') |
| 160 |
} |
| 161 |
} |
| 162 |
]; |
| 163 |
} |
| 164 |
|
| 165 |
sub new { |
| 166 |
my ($class, %options) = @_; |
| 167 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 168 |
bless $self, $class; |
| 169 |
|
| 170 |
$options{options}->add_options(arguments => { |
| 171 |
'filter-module:s' => { name => 'filter_module' }, |
| 172 |
'filter-imei:s' => { name => 'filter_imei' }, |
| 173 |
'filter-interface-type:s' => { name => 'filter_interface_type' }, |
| 174 |
'custom-perfdata-instances:s' => { name => 'custom_perfdata_instances' } |
| 175 |
}); |
| 176 |
|
| 177 |
return $self; |
| 178 |
} |
| 179 |
|
| 180 |
sub check_options { |
| 181 |
my ($self, %options) = @_; |
| 182 |
$self->SUPER::check_options(%options); |
| 183 |
|
| 184 |
if (!defined($self->{option_results}->{custom_perfdata_instances}) || $self->{option_results}->{custom_perfdata_instances} eq '') { |
| 185 |
$self->{option_results}->{custom_perfdata_instances} = '%(module) %(interfaceType) %(imei)'; |
| 186 |
} |
| 187 |
|
| 188 |
$self->{custom_perfdata_instances} = $self->custom_perfdata_instances( |
| 189 |
option_name => '--custom-perfdata-instances', |
| 190 |
instances => $self->{option_results}->{custom_perfdata_instances}, |
| 191 |
labels => { module => 1, interfaceType => 1, imei => 1, imsi => 1, operator => 1, simIcc => 1} |
| 192 |
); |
| 193 |
} |
| 194 |
|
| 195 |
my $mapping_info_interface = { |
| 196 |
imei => { oid => '.1.3.6.1.4.1.2007.4.1.2.2.2.18.1.1.5' }, # teldatCellularInfoInterfaceModuleIMEI : Cellular module IMEI. |
| 197 |
imsi => { oid => '.1.3.6.1.4.1.2007.4.1.2.2.2.18.1.1.6' }, # teldatCellularInfoInterfaceModuleIMSI : Cellular module IMSI. |
| 198 |
simIcc => { oid => '.1.3.6.1.4.1.2007.4.1.2.2.2.18.1.1.8' } # teldatCellularInfoInterfaceSIMIcc : Cellular active SIM ICC. |
| 199 |
}; |
| 200 |
|
| 201 |
my $mapping_data_interface = { |
| 202 |
interfaceState => { oid => '.1.3.6.1.4.1.2007.4.1.2.2.2.18.3.1.1.2' }, # teldatCellularStateInterfaceState : Call state. |
| 203 |
techno => { oid => '.1.3.6.1.4.1.2007.4.1.2.2.2.18.3.2.1.6' }, # teldatCellularStateMobileRadioTechnology : Cellular mobile current radio access tecnology used (!GETRAT). |
| 204 |
rscp => { oid => '.1.3.6.1.4.1.2007.4.1.2.2.2.18.3.2.1.8' }, # teldatCellularStateMobileRxSignalCodePwr : Cellular mobile received signal code power (RSCP). |
| 205 |
csq => { oid => '.1.3.6.1.4.1.2007.4.1.2.2.2.18.3.2.1.10' }, # teldatCellularStateMobileSignalQuality : Cellular mobile reception signal quality (+CSQ). |
| 206 |
rsrp => { oid => '.1.3.6.1.4.1.2007.4.1.2.2.2.18.3.2.1.22' }, # teldatCellularStateMobileRxRSRP : Cellular mobile reference symbol received power (RSRP). |
| 207 |
rsrq => { oid => '.1.3.6.1.4.1.2007.4.1.2.2.2.18.3.2.1.23' }, # teldatCellularStateMobileRxRSRQ : Cellular mobile reference signal received quality (RSRQ). |
| 208 |
snr => { oid => '.1.3.6.1.4.1.2007.4.1.2.2.2.18.3.2.1.24' }, # teldatCellularStateMobileRxSINR : Cellular mobile signal versus noise ratio (SINR). |
| 209 |
simStatus => { oid => '.1.3.6.1.4.1.2007.4.1.2.2.2.18.3.2.1.26' }, # teldatCellularStateMobileSIMStatus : Cellular mobile SIM status. |
| 210 |
operator => { oid => '.1.3.6.1.4.1.2007.4.1.2.2.2.18.3.4.1.2' } |
| 211 |
}; |
| 212 |
|
| 213 |
my $oid_teldatCellularInfoInterfaceEntry = '.1.3.6.1.4.1.2007.4.1.2.2.2.18.1.1'; # teldatInfoInterfaceTable |
| 214 |
|
| 215 |
my $interface_types = { |
| 216 |
1 => 'control vocal', |
| 217 |
2 => 'data primary', |
| 218 |
3 => 'data auxiliary' |
| 219 |
}; |
| 220 |
|
| 221 |
sub manage_selection { |
| 222 |
my ($self, %options) = @_; |
| 223 |
|
| 224 |
my $snmp_result = $options{snmp}->get_table( |
| 225 |
oid => $oid_teldatCellularInfoInterfaceEntry, |
| 226 |
start => $mapping_info_interface->{imei}->{oid}, |
| 227 |
end => $mapping_info_interface->{simIcc}->{oid}, |
| 228 |
nothing_quit => 1 |
| 229 |
); |
| 230 |
|
| 231 |
$self->{global} = { detected => 0 }; |
| 232 |
$self->{cells} = {}; |
| 233 |
my $modules = {}; |
| 234 |
my $module_num = 0; |
| 235 |
my $interface_type = 0; |
| 236 |
foreach my $oid ($options{snmp}->oid_lex_sort(keys %$snmp_result)) { |
| 237 |
next if ($oid !~ /^$mapping_info_interface->{imei}->{oid}\.(.*)$/); |
| 238 |
my $instance = $1; |
| 239 |
|
| 240 |
my $result = $options{snmp}->map_instance(mapping => $mapping_info_interface, results => $snmp_result, instance => $instance); |
| 241 |
next if ($result->{imei} !~ /^[0-9]+$/); |
| 242 |
|
| 243 |
if (!defined($modules->{$module_num}) || $result->{imei} ne $modules->{$module_num}) { |
| 244 |
$module_num++; |
| 245 |
$interface_type = 0; |
| 246 |
$modules->{$module_num} = $result->{imei}; |
| 247 |
} |
| 248 |
if (defined($modules->{$module_num})) { |
| 249 |
$interface_type++; |
| 250 |
} |
| 251 |
|
| 252 |
my $module = 'module' . $module_num; |
| 253 |
|
| 254 |
next if (defined($self->{option_results}->{filter_module}) && $self->{option_results}->{filter_module} ne '' && |
| 255 |
$module !~ /$self->{option_results}->{filter_module}/); |
| 256 |
next if (defined($self->{option_results}->{filter_imei}) && $self->{option_results}->{filter_imei} ne '' && |
| 257 |
$result->{imei} !~ /$self->{option_results}->{filter_imei}/); |
| 258 |
next if (defined($self->{option_results}->{filter_interface_type}) && $self->{option_results}->{filter_interface_type} ne '' && |
| 259 |
$interface_types->{$interface_type} !~ /$self->{option_results}->{filter_interface_type}/); |
| 260 |
|
| 261 |
$self->{cells}->{$instance} = { |
| 262 |
module => $module, |
| 263 |
module_num => $module_num, |
| 264 |
interfaceType => $interface_types->{$interface_type}, |
| 265 |
imei => $result->{imei}, |
| 266 |
status => { |
| 267 |
module => $module, |
| 268 |
interfaceType => $interface_types->{$interface_type}, |
| 269 |
imei => $result->{imei}, |
| 270 |
imsi => $result->{imsi}, |
| 271 |
simIcc => $result->{simIcc} |
| 272 |
}, |
| 273 |
signal => { |
| 274 |
module => $module, |
| 275 |
interfaceType => $interface_types->{$interface_type}, |
| 276 |
imei => $result->{imei}, |
| 277 |
imsi => $result->{imsi}, |
| 278 |
simIcc => $result->{simIcc} |
| 279 |
} |
| 280 |
}; |
| 281 |
|
| 282 |
$self->{global}->{detected}++; |
| 283 |
} |
| 284 |
|
| 285 |
if (scalar(keys %{$self->{cells}}) <= 0 && |
| 286 |
(defined($self->{option_results}->{filter_module}) && $self->{option_results}->{filter_module} ne '') || |
| 287 |
(defined($self->{option_results}->{filter_imei}) && $self->{option_results}->{filter_imei} ne '')) { |
| 288 |
$self->{output}->add_option_msg(short_msg => 'No interfaces found matching with filter'); |
| 289 |
$self->{output}->option_exit(); |
| 290 |
} |
| 291 |
|
| 292 |
$options{snmp}->load( |
| 293 |
oids => [ map($_->{oid}, values(%$mapping_data_interface)) ], |
| 294 |
instances => [ map($_, keys(%{$self->{cells}})) ], |
| 295 |
instance_regexp => '^(.*)$' |
| 296 |
); |
| 297 |
$snmp_result = $options{snmp}->get_leef(); |
| 298 |
|
| 299 |
foreach (keys %{$self->{cells}}) { |
| 300 |
my $result = $options{snmp}->map_instance(mapping => $mapping_data_interface, results => $snmp_result, instance => $_); |
| 301 |
|
| 302 |
$self->{cells}->{$_}->{status}->{simStatus} = $result->{simStatus}; |
| 303 |
$self->{cells}->{$_}->{status}->{interfaceState} = $result->{interfaceState}; |
| 304 |
$self->{cells}->{$_}->{status}->{operator} = $result->{operator}; |
| 305 |
$self->{cells}->{$_}->{signal}->{operator} = $result->{operator}; |
| 306 |
|
| 307 |
next if ($self->{cells}->{$_}->{status}->{simIcc} eq ''); |
| 308 |
|
| 309 |
$self->{cells}->{$_}->{signal}->{rsrp} = $result->{rsrp} if ($result->{rsrp} ne '' && $result->{rsrp} != 0); |
| 310 |
$self->{cells}->{$_}->{signal}->{rsrq} = $result->{rsrq} if ($result->{rsrq} ne '' && $result->{rsrq} != 0); |
| 311 |
$self->{cells}->{$_}->{signal}->{snr} = $result->{snr} if ($result->{snr} ne '' && $result->{snr} != 0); |
| 312 |
$self->{cells}->{$_}->{signal}->{rscp} = $result->{rscp} if ($result->{rscp} ne '' && $result->{rscp} != 0); |
| 313 |
$self->{cells}->{$_}->{signal}->{csq} = $result->{csq} if ($result->{csq} ne '' && $result->{csq} != 0); |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
1; |
| 318 |
|
| 319 |
__END__ |
| 320 |
|
| 321 |
=head1 MODE |
| 322 |
|
| 323 |
Check cellular radio interfaces. |
| 324 |
|
| 325 |
=over 8 |
| 326 |
|
| 327 |
=item B<--filter-module> |
| 328 |
|
| 329 |
Filter cellular radio interfaces by module. |
| 330 |
|
| 331 |
=item B<--filter-imei> |
| 332 |
|
| 333 |
Filter cellular radio interfaces by IMEI. |
| 334 |
|
| 335 |
=item B<--filter-interface-type> |
| 336 |
|
| 337 |
Filter cellular radio interfaces by type. |
| 338 |
|
| 339 |
=item B<--custom-perfdata-instances> |
| 340 |
|
| 341 |
Customize the name composition rule for the instances the metrics will be attached to (default: '%(module) %(interfaceType) %(imei)'). |
| 342 |
You can use the following variables: %(module), %(interfaceType), %(imei), %(operator), %(simIcc) |
| 343 |
|
| 344 |
=item B<--unknown-status> |
| 345 |
|
| 346 |
Define the conditions to match for the status to be UNKNOWN. |
| 347 |
You can use the following variables: %{module}, %{interfaceType}, %{imei}, %{operator}, %{imsi}, %{simIcc}, %{simStatus}, %{interfaceState} |
| 348 |
|
| 349 |
=item B<--warning-status> |
| 350 |
|
| 351 |
Define the conditions to match for the status to be WARNING (default: '%{interfaceState} =~ /disconnect/ && %{interfaceType} =~ /data primary/'). |
| 352 |
You can use the following variables: %{module}, %{interfaceType}, %{imei}, %{operator}, %{imsi}, %{simIcc}, %{simStatus}, %{interfaceState} |
| 353 |
|
| 354 |
=item B<--critical-status> |
| 355 |
|
| 356 |
Define the conditions to match for the status to be CRITICAL. |
| 357 |
You can use the following variables: %{module}, %{interfaceType}, %{imei}, %{operator}, %{imsi}, %{simIcc}, %{simStatus}, %{interfaceState} |
| 358 |
|
| 359 |
=item B<--warning-*> B<--critical-*> |
| 360 |
|
| 361 |
Thresholds. |
| 362 |
Can be: 'modules-cellradio-detected', 'module-cellradio-rsrp', ''module-cellradio-rsrq', 'module-cellradio-rscp', 'module-cellradio-csq' |
| 363 |
'module-cellradio-snr'. |
| 364 |
|
| 365 |
=back |
| 366 |
|
| 367 |
=cut |