| 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 centreon::common::cisco::standard::snmp::mode::wan3g; |
| 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 |
use Digest::MD5 qw(md5_hex); |
| 29 |
|
| 30 |
sub custom_connection_status_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
return sprintf( |
| 34 |
'connection status: %s', |
| 35 |
$self->{result_values}->{connection_status} |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
sub custom_sim_status_output { |
| 40 |
my ($self, %options) = @_; |
| 41 |
|
| 42 |
return sprintf( |
| 43 |
'sim status: %s', |
| 44 |
$self->{result_values}->{sim_status} |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
sub custom_modem_status_output { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
return sprintf( |
| 52 |
'modem status: %s [imsi: %s][imei: %s][iccid: %s]', |
| 53 |
$self->{result_values}->{modem_status}, |
| 54 |
$self->{result_values}->{imsi}, |
| 55 |
$self->{result_values}->{imei}, |
| 56 |
$self->{result_values}->{iccid} |
| 57 |
); |
| 58 |
} |
| 59 |
|
| 60 |
sub custom_radio_status_output { |
| 61 |
my ($self, %options) = @_; |
| 62 |
|
| 63 |
return sprintf( |
| 64 |
'current band: %s [channel number: %s]', |
| 65 |
$self->{result_values}->{current_band}, |
| 66 |
$self->{result_values}->{channel_number} |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 70 |
sub custom_network_status_output { |
| 71 |
my ($self, %options) = @_; |
| 72 |
|
| 73 |
return sprintf( |
| 74 |
'service status: %s', |
| 75 |
$self->{result_values}->{service_status} |
| 76 |
); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
sub modem_long_output { |
| 81 |
my ($self, %options) = @_; |
| 82 |
|
| 83 |
return "checking module '" . $options{instance_value}->{display} . "'"; |
| 84 |
} |
| 85 |
|
| 86 |
sub prefix_modem_output { |
| 87 |
my ($self, %options) = @_; |
| 88 |
|
| 89 |
return "module '" . $options{instance_value}->{display} . "' "; |
| 90 |
} |
| 91 |
|
| 92 |
sub set_counters { |
| 93 |
my ($self, %options) = @_; |
| 94 |
|
| 95 |
$self->{maps_counters_type} = [ |
| 96 |
{ name => 'modem', type => 3, cb_prefix_output => 'prefix_modem_output', cb_long_output => 'modem_long_output', |
| 97 |
indent_long_output => ' ', message_multiple => 'All cellular modems are ok', |
| 98 |
group => [ |
| 99 |
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, |
| 100 |
{ name => 'radio', type => 0, skipped_code => { -10 => 1 } }, |
| 101 |
{ name => 'network', type => 0, skipped_code => { -10 => 1 } } |
| 102 |
] |
| 103 |
} |
| 104 |
]; |
| 105 |
|
| 106 |
$self->{maps_counters}->{global} = [ |
| 107 |
{ |
| 108 |
label => 'modem-status', |
| 109 |
type => 2, |
| 110 |
unknown_default => '%{modem_status} =~ /unknown/i', |
| 111 |
warning_default => '%{modem_status} =~ /lowPowerMode/i', |
| 112 |
critical_default => '%{modem_status} =~ /offLine/i', |
| 113 |
set => { |
| 114 |
key_values => [ |
| 115 |
{ name => 'modem_status' }, { name => 'imsi' }, |
| 116 |
{ name => 'imei' }, { name => 'iccid' }, |
| 117 |
{ name => 'display' } |
| 118 |
], |
| 119 |
closure_custom_output => $self->can('custom_modem_status_output'), |
| 120 |
closure_custom_perfdata => sub { return 0; }, |
| 121 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 122 |
} |
| 123 |
}, |
| 124 |
{ |
| 125 |
label => 'connection-status', |
| 126 |
type => 2, |
| 127 |
unknown_default => '%{connection_status} =~ /unknown/i', |
| 128 |
critical_default => '%{connection_status} =~ /inactive|idle|disconnected|error/i', |
| 129 |
set => { |
| 130 |
key_values => [ { name => 'connection_status' }, { name => 'display' } ], |
| 131 |
closure_custom_output => $self->can('custom_connection_status_output'), |
| 132 |
closure_custom_perfdata => sub { return 0; }, |
| 133 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 134 |
} |
| 135 |
}, |
| 136 |
{ |
| 137 |
label => 'sim-status', |
| 138 |
type => 2, |
| 139 |
unknown_default => '%{sim_status} =~ /unknown/i', |
| 140 |
critical_default => '%{sim_status} !~ /ok|unknown/i', |
| 141 |
set => { |
| 142 |
key_values => [ { name => 'sim_status' }, { name => 'display' } ], |
| 143 |
closure_custom_output => $self->can('custom_sim_status_output'), |
| 144 |
closure_custom_perfdata => sub { return 0; }, |
| 145 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 146 |
} |
| 147 |
}, |
| 148 |
{ label => 'temperature', nlabel => 'modem.temperature.celsius', display_ok => 0, set => { |
| 149 |
key_values => [ { name => 'temperature' }, { name => 'display' } ], |
| 150 |
output_template => 'memory used: %s%s', |
| 151 |
output_change_bytes => 1, |
| 152 |
perfdatas => [ |
| 153 |
{ template => '%s', min => 0, |
| 154 |
unit => 'C', label_extra_instance => 1, instance_use => 'display' } |
| 155 |
] |
| 156 |
} |
| 157 |
} |
| 158 |
]; |
| 159 |
|
| 160 |
$self->{maps_counters}->{radio} = [ |
| 161 |
{ |
| 162 |
label => 'radio-status', |
| 163 |
type => 2, |
| 164 |
unknown_default => '%{current_band} =~ /unknown/i', |
| 165 |
critical_default => '%{current_band} =~ /invalid|none/i', |
| 166 |
set => { |
| 167 |
key_values => [ { name => 'current_band' }, { name => 'channel_number' }, { name => 'display' } ], |
| 168 |
closure_custom_output => $self->can('custom_radio_status_output'), |
| 169 |
closure_custom_perfdata => sub { return 0; }, |
| 170 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 171 |
} |
| 172 |
}, |
| 173 |
{ label => 'radio-rssi', nlabel => 'modem.radio.rssi.dbm', set => { |
| 174 |
key_values => [ { name => 'rssi' }, { name => 'display' } ], |
| 175 |
output_template => 'received signal strength: %s dBm', |
| 176 |
output_change_bytes => 1, |
| 177 |
perfdatas => [ |
| 178 |
{ template => '%s', min => 0, |
| 179 |
unit => 'dBm', label_extra_instance => 1, instance_use => 'display' } |
| 180 |
] |
| 181 |
} |
| 182 |
} |
| 183 |
]; |
| 184 |
|
| 185 |
$self->{maps_counters}->{network} = [ |
| 186 |
{ |
| 187 |
label => 'network-status', |
| 188 |
type => 2, |
| 189 |
unknown_default => '%{service_status} =~ /unknown/i', |
| 190 |
critical_default => '%{service_status} =~ /emergencyOnly|noService/i', |
| 191 |
set => { |
| 192 |
key_values => [ { name => 'service_status' }, { name => 'display' } ], |
| 193 |
closure_custom_output => $self->can('custom_network_status_output'), |
| 194 |
closure_custom_perfdata => sub { return 0; }, |
| 195 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 196 |
} |
| 197 |
}, |
| 198 |
{ label => 'traffic-in', nlabel => 'modem.traffic.in.bitspersecond', set => { |
| 199 |
key_values => [ { name => 'traffic_in', per_second => 1 }, { name => 'display' } ], |
| 200 |
output_template => 'traffic in: %s%s/s', |
| 201 |
output_change_bytes => 2, |
| 202 |
perfdatas => [ |
| 203 |
{ template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } |
| 204 |
] |
| 205 |
} |
| 206 |
}, |
| 207 |
{ label => 'traffic-out', nlabel => 'modem.traffic.out.bitspersecond', set => { |
| 208 |
key_values => [ { name => 'traffic_out', per_second => 1 }, { name => 'display' } ], |
| 209 |
output_template => 'traffic out: %s%s/s', |
| 210 |
output_change_bytes => 2, |
| 211 |
perfdatas => [ |
| 212 |
{ template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } |
| 213 |
] |
| 214 |
} |
| 215 |
} |
| 216 |
]; |
| 217 |
} |
| 218 |
|
| 219 |
sub new { |
| 220 |
my ($class, %options) = @_; |
| 221 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); |
| 222 |
bless $self, $class; |
| 223 |
|
| 224 |
$options{options}->add_options(arguments => { |
| 225 |
'filter-name:s' => { name => 'filter_name' } |
| 226 |
}); |
| 227 |
|
| 228 |
return $self; |
| 229 |
} |
| 230 |
|
| 231 |
my $map_current_band = { |
| 232 |
1 => 'unknown', 2 => 'invalid', 3 => 'none', |
| 233 |
4 => 'gsm850', 5 => 'gsm900', 6 => 'gsm1800', |
| 234 |
7 => 'gsm1900', 8 => 'wcdma800', 9 => 'wcdma850', |
| 235 |
10 => 'wcdma1900', 11 => 'wcdma2100', 12 => 'lteBand' |
| 236 |
}; |
| 237 |
my $map_modem_status = { |
| 238 |
1 => 'unknown', 2 => 'offLine', 3 => 'onLine', 4 => 'lowPowerMode' |
| 239 |
}; |
| 240 |
my $map_connection_status = { |
| 241 |
1 => 'unknown', 2 => 'error', 3 => 'connecting', |
| 242 |
4 => 'dormant', 5 => 'connected', 6 => 'disconnected', |
| 243 |
7 => 'idle', 8 => 'active', 9 => 'inactive' |
| 244 |
}; |
| 245 |
my $map_sim_status = { |
| 246 |
1 => 'unknown', 2 => 'ok', 3 => 'notInserted', |
| 247 |
4 => 'removed', 5 => 'initFailure', 6 => 'generalFailure', |
| 248 |
7 => 'locked', 8 => 'chv1Blocked', 9 => 'chv2Blocked', |
| 249 |
10 => 'chv1Rejected', 11 => 'chv2Rejected', |
| 250 |
12 => 'mepLocked', 13 => 'networkRejected' |
| 251 |
}; |
| 252 |
my $map_service_status = { |
| 253 |
1 => 'unknown', 2 => 'noService', |
| 254 |
3 => 'normal', 4 => 'emergencyOnly' |
| 255 |
}; |
| 256 |
|
| 257 |
my $mapping = { |
| 258 |
rssi => { oid => '.1.3.6.1.4.1.9.9.661.1.3.4.1.1.1' }, # c3gCurrentGsmRssi |
| 259 |
current_band => { oid => '.1.3.6.1.4.1.9.9.661.1.3.4.1.1.3', map => $map_current_band }, # c3gGsmCurrentBand |
| 260 |
channel_number => { oid => '.1.3.6.1.4.1.9.9.661.1.3.4.1.1.4' }, # c3gGsmChannelNumber |
| 261 |
imsi => { oid => '.1.3.6.1.4.1.9.9.661.1.3.1.1.1' }, # c3gImsi |
| 262 |
imei => { oid => '.1.3.6.1.4.1.9.9.661.1.3.1.1.2' }, # c3gImei |
| 263 |
iccid => { oid => '.1.3.6.1.4.1.9.9.661.1.3.1.1.3' }, # c3gIccId |
| 264 |
modem_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.1.1.6', map => $map_modem_status }, # c3gModemStatus |
| 265 |
temperature => { oid => '.1.3.6.1.4.1.9.9.661.1.1.1.12' }, # c3gModemTemperature |
| 266 |
connection_status => { oid => '.1.3.6.1.4.1.9.9.661.1.1.1.8', map => $map_connection_status }, # c3gConnectionStatus |
| 267 |
sim_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.5.1.1.2', map => $map_sim_status }, # c3gGsmSimStatus |
| 268 |
service_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.2.1.2', map => $map_service_status }, # c3gGsmCurrentServiceStatus |
| 269 |
traffic_out => { oid => '.1.3.6.1.4.1.9.9.661.1.3.2.1.19' }, # c3gGsmTotalByteTransmitted |
| 270 |
traffic_in => { oid => '.1.3.6.1.4.1.9.9.661.1.3.2.1.20' } # c3gGsmTotalByteReceived |
| 271 |
}; |
| 272 |
|
| 273 |
sub manage_selection { |
| 274 |
my ($self, %options) = @_; |
| 275 |
|
| 276 |
my $oid_entPhysicalName = '.1.3.6.1.2.1.47.1.1.1.1.7'; |
| 277 |
my $snmp_result = $options{snmp}->get_table( |
| 278 |
oid => $mapping->{connection_status}->{oid}, |
| 279 |
nothing_quit => 1 |
| 280 |
); |
| 281 |
|
| 282 |
my $instances = []; |
| 283 |
foreach (keys %$snmp_result) { |
| 284 |
/\.(\d+)$/; |
| 285 |
push @$instances, $1; |
| 286 |
} |
| 287 |
|
| 288 |
$options{snmp}->load( |
| 289 |
oids => [ $oid_entPhysicalName ], |
| 290 |
instances => $instances, |
| 291 |
instance_regexp => '^(.*)$' |
| 292 |
); |
| 293 |
$snmp_result = $options{snmp}->get_leef(); |
| 294 |
|
| 295 |
$self->{modem} = {}; |
| 296 |
foreach (keys %$snmp_result) { |
| 297 |
/\.(\d+)$/; |
| 298 |
my $instance = $1; |
| 299 |
my $name = $snmp_result->{$_}; |
| 300 |
|
| 301 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 302 |
$name !~ /$self->{option_results}->{filter_name}/) { |
| 303 |
$self->{output}->output_add(long_msg => "skipping module '" . $name . "'.", debug => 1); |
| 304 |
next; |
| 305 |
} |
| 306 |
|
| 307 |
$self->{modem}->{$instance} = { |
| 308 |
display => $name, |
| 309 |
global => { display => $name }, |
| 310 |
radio => { display => $name }, |
| 311 |
network => { display => $name } |
| 312 |
}; |
| 313 |
} |
| 314 |
|
| 315 |
return if (scalar(keys %{$self->{modem}}) <= 0); |
| 316 |
|
| 317 |
$options{snmp}->load( |
| 318 |
oids => [ map($_->{oid}, values(%$mapping)) ], |
| 319 |
instances => [ keys %{$self->{modem}} ], |
| 320 |
instance_regexp => '^(.*)$' |
| 321 |
); |
| 322 |
$snmp_result = $options{snmp}->get_leef(); |
| 323 |
foreach (keys %{$self->{modem}}) { |
| 324 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); |
| 325 |
$self->{modem}->{$_}->{global}->{modem_status} = $result->{modem_status}; |
| 326 |
$self->{modem}->{$_}->{global}->{imsi} = $result->{imsi}; |
| 327 |
$self->{modem}->{$_}->{global}->{imei} = $result->{imei}; |
| 328 |
$self->{modem}->{$_}->{global}->{iccid} = $result->{iccid}; |
| 329 |
$self->{modem}->{$_}->{global}->{connection_status} = $result->{connection_status}; |
| 330 |
$self->{modem}->{$_}->{global}->{sim_status} = $result->{sim_status}; |
| 331 |
$self->{modem}->{$_}->{global}->{temperature} = $result->{temperature}; |
| 332 |
$self->{modem}->{$_}->{radio}->{current_band} = $result->{current_band}; |
| 333 |
$self->{modem}->{$_}->{radio}->{channel_number} = $result->{channel_number}; |
| 334 |
$self->{modem}->{$_}->{radio}->{rssi} = $result->{rssi}; |
| 335 |
$self->{modem}->{$_}->{network}->{traffic_in} = $result->{traffic_in}; |
| 336 |
$self->{modem}->{$_}->{network}->{traffic_out} = $result->{traffic_out}; |
| 337 |
$self->{modem}->{$_}->{network}->{service_status} = $result->{service_status}; |
| 338 |
} |
| 339 |
|
| 340 |
$self->{cache_name} = 'cisco_standard_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . |
| 341 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . |
| 342 |
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); |
| 343 |
} |
| 344 |
|
| 345 |
1; |
| 346 |
|
| 347 |
__END__ |
| 348 |
|
| 349 |
=head1 MODE |
| 350 |
|
| 351 |
Check cellular 3G and 4G LTE WAN. |
| 352 |
|
| 353 |
=over 8 |
| 354 |
|
| 355 |
=item B<--filter-name> |
| 356 |
|
| 357 |
Filter by name (can be a regexp). |
| 358 |
|
| 359 |
=item B<--unknown-modem-status> |
| 360 |
|
| 361 |
Define the conditions to match for the status to be UNKNOWN (default: '%{modem_status} =~ /unknown/i'). |
| 362 |
You can use the following variables: %{modem_status}, %{display} |
| 363 |
|
| 364 |
=item B<--warning-modem-status> |
| 365 |
|
| 366 |
Define the conditions to match for the status to be WARNING (default: '%{modem_status} =~ /lowPowerMode/i'). |
| 367 |
You can use the following variables: %{modem_status}, %{display} |
| 368 |
|
| 369 |
=item B<--critical-modem-status> |
| 370 |
|
| 371 |
Define the conditions to match for the status to be CRITICAL (default: '%{modem_status} =~ /offLine/i'). |
| 372 |
You can use the following variables: %{modem_status}, %{display} |
| 373 |
|
| 374 |
=item B<--unknown-connection-status> |
| 375 |
|
| 376 |
Define the conditions to match for the status to be UNKNOWN (default: '%{connection_status} =~ /unknown/i'). |
| 377 |
You can use the following variables: %{connection_status}, %{display} |
| 378 |
|
| 379 |
=item B<--warning-connection-status> |
| 380 |
|
| 381 |
Define the conditions to match for the status to be WARNING. |
| 382 |
You can use the following variables: %{connection_status}, %{display} |
| 383 |
|
| 384 |
=item B<--critical-connection-status> |
| 385 |
|
| 386 |
Define the conditions to match for the status to be CRITICAL (default: '%{connection_status} =~ /inactive|idle|disconnected|error/i'). |
| 387 |
You can use the following variables: %{connection_status}, %{display} |
| 388 |
|
| 389 |
=item B<--unknown-sim-status> |
| 390 |
|
| 391 |
Define the conditions to match for the status to be UNKNOWN (default: '%{sim_status} =~ /unknown/i'). |
| 392 |
You can use the following variables: %{sim_status}, %{display} |
| 393 |
|
| 394 |
=item B<--warning-sim-status> |
| 395 |
|
| 396 |
Define the conditions to match for the status to be WARNING. |
| 397 |
You can use the following variables: %{sim_status}, %{display} |
| 398 |
|
| 399 |
=item B<--critical-sim-status> |
| 400 |
|
| 401 |
Define the conditions to match for the status to be CRITICAL (default: '%{sim_status} !~ /ok|unknown/i'). |
| 402 |
You can use the following variables: %{sim_status}, %{display} |
| 403 |
|
| 404 |
=item B<--unknown-radio-status> |
| 405 |
|
| 406 |
Define the conditions to match for the status to be UNKNOWN (default: '%{current_band} =~ /unknown/i'). |
| 407 |
You can use the following variables: %{current_band}, %{channel_number}, %{display} |
| 408 |
|
| 409 |
=item B<--warning-radio-status> |
| 410 |
|
| 411 |
Define the conditions to match for the status to be WARNING. |
| 412 |
You can use the following variables: %{current_band}, %{channel_number}, %{display} |
| 413 |
|
| 414 |
=item B<--critical-radio-status> |
| 415 |
|
| 416 |
Define the conditions to match for the status to be CRITICAL (default: '%{current_band} =~ /invalid|none/i'). |
| 417 |
You can use the following variables: %{current_band}, %{channel_number}, %{display} |
| 418 |
|
| 419 |
=item B<--unknown-network-status> |
| 420 |
|
| 421 |
Define the conditions to match for the status to be UNKNOWN (default: '%{service_status} =~ /unknown/i'). |
| 422 |
You can use the following variables: %{service_status}, %{display} |
| 423 |
|
| 424 |
=item B<--warning-network-status> |
| 425 |
|
| 426 |
Define the conditions to match for the status to be WARNING. |
| 427 |
You can use the following variables: %{service_status}, %{display} |
| 428 |
|
| 429 |
=item B<--critical-network-status> |
| 430 |
|
| 431 |
Define the conditions to match for the status to be CRITICAL (default: '%{service_status} =~ /emergencyOnly|noService/i'). |
| 432 |
You can use the following variables: %{service_status}, %{display} |
| 433 |
|
| 434 |
=item B<--warning-*> B<--critical-*> |
| 435 |
|
| 436 |
Thresholds. |
| 437 |
Can be: 'temperature', 'traffic-in', 'traffic-out'. |
| 438 |
|
| 439 |
=back |
| 440 |
|
| 441 |
=cut |