| 1 |
# |
| 2 |
# Copyright 2018 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::teltonika::snmp::mode::modem; |
| 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_status_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
return sprintf( |
| 34 |
"connection state is '%s' [pin state: '%s'] [net state: '%s'][sim state: '%s']", |
| 35 |
$self->{result_values}->{connectionState}, |
| 36 |
$self->{result_values}->{pinState}, |
| 37 |
$self->{result_values}->{netState}, |
| 38 |
$self->{result_values}->{simState} |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
sub prefix_modem_output { |
| 43 |
my ($self, %options) = @_; |
| 44 |
|
| 45 |
return sprintf( |
| 46 |
"modem imsi '%s' [operator: %s] ", |
| 47 |
$options{instance_value}->{imsi}, |
| 48 |
$options{instance_value}->{operator} |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
sub set_counters { |
| 53 |
my ($self, %options) = @_; |
| 54 |
|
| 55 |
$self->{maps_counters_type} = [ |
| 56 |
{ name => 'modems', type => 1, cb_prefix_output => 'prefix_modem_output', message_multiple => 'All modems are ok', skipped_code => { -10 => 1, -11 => 1 } } |
| 57 |
]; |
| 58 |
|
| 59 |
$self->{maps_counters}->{modems} = [ |
| 60 |
{ label => 'status', type => 2, critical_default => '%{connectionState} !~ /connected/i', set => { |
| 61 |
key_values => [ { name => 'simState' }, { name => 'pinState' }, { name => 'netState' }, { name => 'connectionState' } ], |
| 62 |
closure_custom_output => $self->can('custom_status_output'), |
| 63 |
closure_custom_perfdata => sub { return 0; }, |
| 64 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 65 |
} |
| 66 |
}, |
| 67 |
{ label => 'signal-strength', nlabel => 'modem.signal.strength.dbm', display_ok => 0, set => { |
| 68 |
key_values => [ { name => 'signal' }, { name => 'imsi' }, { name => 'operator' } ], |
| 69 |
output_template => 'signal strength: %s dBm', |
| 70 |
closure_custom_perfdata => sub { |
| 71 |
my ($self, %options) = @_; |
| 72 |
|
| 73 |
$self->{output}->perfdata_add( |
| 74 |
nlabel => $self->{nlabel}, |
| 75 |
unit => 'dBm', |
| 76 |
instances => [$self->{result_values}->{imsi}, $self->{result_values}->{operator}], |
| 77 |
value => sprintf('%s', $self->{result_values}->{signal}), |
| 78 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 79 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}) |
| 80 |
); |
| 81 |
} |
| 82 |
} |
| 83 |
}, |
| 84 |
{ label => 'temperature', nlabel => 'modem.temperature.celsius', display_ok => 0, set => { |
| 85 |
key_values => [ { name => 'temperature' }, { name => 'imsi' }, { name => 'operator' } ], |
| 86 |
output_template => 'temperature: %s C', |
| 87 |
closure_custom_perfdata => sub { |
| 88 |
my ($self, %options) = @_; |
| 89 |
|
| 90 |
$self->{output}->perfdata_add( |
| 91 |
nlabel => $self->{nlabel}, |
| 92 |
unit => 'C', |
| 93 |
instances => [$self->{result_values}->{imsi}, $self->{result_values}->{operator}], |
| 94 |
value => sprintf('%s', $self->{result_values}->{temperature}), |
| 95 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 96 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 97 |
); |
| 98 |
} |
| 99 |
} |
| 100 |
}, |
| 101 |
{ label => 'traffic-in', nlabel => 'modem.traffic.in.bitspersecond', display_ok => 0, set => { |
| 102 |
key_values => [ { name => 'received', per_second => 1 }, { name => 'imsi' }, { name => 'operator' } ], |
| 103 |
output_template => 'traffic in: %s %s/s', |
| 104 |
output_change_bytes => 2, |
| 105 |
closure_custom_perfdata => sub { |
| 106 |
my ($self, %options) = @_; |
| 107 |
|
| 108 |
$self->{output}->perfdata_add( |
| 109 |
nlabel => $self->{nlabel}, |
| 110 |
unit => 'b/s', |
| 111 |
instances => [$self->{result_values}->{imsi}, $self->{result_values}->{operator}], |
| 112 |
value => sprintf('%s', $self->{result_values}->{received}), |
| 113 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 114 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 115 |
min => 0 |
| 116 |
); |
| 117 |
} |
| 118 |
} |
| 119 |
}, |
| 120 |
{ label => 'traffic-out', nlabel => 'modem.traffic.out.bitspersecond', display_ok => 0, set => { |
| 121 |
key_values => [ { name => 'sent', per_second => 1 }, { name => 'imsi' }, { name => 'operator' } ], |
| 122 |
output_template => 'traffic out: %s %s/s', |
| 123 |
output_change_bytes => 2, |
| 124 |
closure_custom_perfdata => sub { |
| 125 |
my ($self, %options) = @_; |
| 126 |
|
| 127 |
$self->{output}->perfdata_add( |
| 128 |
nlabel => $self->{nlabel}, |
| 129 |
unit => 'b/s', |
| 130 |
instances => [$self->{result_values}->{imsi}, $self->{result_values}->{operator}], |
| 131 |
value => sprintf('%s', $self->{result_values}->{sent}), |
| 132 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 133 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 134 |
min => 0 |
| 135 |
); |
| 136 |
} |
| 137 |
} |
| 138 |
}, |
| 139 |
{ label => 'signal-receive-power', nlabel => 'modem.signal.receive.power.dbm', display_ok => 0, set => { |
| 140 |
key_values => [ { name => 'rsrp' }, { name => 'imsi' }, { name => 'operator' } ], |
| 141 |
output_template => 'signal receive power: %s dBm', |
| 142 |
closure_custom_perfdata => sub { |
| 143 |
my ($self, %options) = @_; |
| 144 |
|
| 145 |
$self->{output}->perfdata_add( |
| 146 |
nlabel => $self->{nlabel}, |
| 147 |
unit => 'dBm', |
| 148 |
instances => [$self->{result_values}->{imsi}, $self->{result_values}->{operator}], |
| 149 |
value => sprintf('%s', $self->{result_values}->{rsrp}), |
| 150 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 151 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}) |
| 152 |
); |
| 153 |
} |
| 154 |
} |
| 155 |
}, |
| 156 |
{ label => 'signal-receive-quality', nlabel => 'modem.signal.receive.quality.dbm', display_ok => 0, set => { |
| 157 |
key_values => [ { name => 'rsrq' }, { name => 'imsi' }, { name => 'operator' } ], |
| 158 |
output_template => 'signal receive quality: %s dBm', |
| 159 |
closure_custom_perfdata => sub { |
| 160 |
my ($self, %options) = @_; |
| 161 |
|
| 162 |
$self->{output}->perfdata_add( |
| 163 |
nlabel => $self->{nlabel}, |
| 164 |
unit => 'dBm', |
| 165 |
instances => [$self->{result_values}->{imsi}, $self->{result_values}->{operator}], |
| 166 |
value => sprintf('%s', $self->{result_values}->{rsrq}), |
| 167 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 168 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}) |
| 169 |
); |
| 170 |
} |
| 171 |
} |
| 172 |
} |
| 173 |
]; |
| 174 |
} |
| 175 |
|
| 176 |
sub new { |
| 177 |
my ($class, %options) = @_; |
| 178 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); |
| 179 |
bless $self, $class; |
| 180 |
|
| 181 |
$options{options}->add_options(arguments => {}); |
| 182 |
|
| 183 |
return $self; |
| 184 |
} |
| 185 |
|
| 186 |
sub teltonika_legacy { |
| 187 |
my ($self, %options) = @_; |
| 188 |
|
| 189 |
my $mapping = { |
| 190 |
imsi => { oid => '.1.3.6.1.4.1.48690.1.6' }, |
| 191 |
simState => { oid => '.1.3.6.1.4.1.48690.2.1' }, |
| 192 |
pinState => { oid => '.1.3.6.1.4.1.48690.2.2' }, |
| 193 |
netState => { oid => '.1.3.6.1.4.1.48690.2.3' }, |
| 194 |
signal => { oid => '.1.3.6.1.4.1.48690.2.4' }, |
| 195 |
operator => { oid => '.1.3.6.1.4.1.48690.2.5' }, |
| 196 |
connectionState => { oid => '.1.3.6.1.4.1.48690.2.7' }, |
| 197 |
temperature => { oid => '.1.3.6.1.4.1.48690.2.9' }, |
| 198 |
sent => { oid => '.1.3.6.1.4.1.48690.2.19' }, |
| 199 |
received => { oid => '.1.3.6.1.4.1.48690.2.20' }, |
| 200 |
rsrp => { oid => '.1.3.6.1.4.1.48690.2.23' }, |
| 201 |
rsrq => { oid => '.1.3.6.1.4.1.48690.2.24' } |
| 202 |
}; |
| 203 |
|
| 204 |
my $snmp_result = $options{snmp}->get_leef( |
| 205 |
oids => [ map($_->{oid} . '.0', values(%$mapping)) ], |
| 206 |
nothing_quit => 1 |
| 207 |
); |
| 208 |
|
| 209 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0); |
| 210 |
$result->{simState} = defined($result->{simState}) ? $result->{simState} : '-'; |
| 211 |
$result->{pinState} = defined($result->{pinState}) ? $result->{pinState} : '-'; |
| 212 |
$result->{netState} = defined($result->{netState}) ? $result->{netState} : '-'; |
| 213 |
$result->{temperature} = $result->{temperature} / 10; |
| 214 |
$result->{sent} = $result->{sent} * 8; |
| 215 |
$result->{received} = $result->{received} * 8; |
| 216 |
|
| 217 |
$self->{modems} = { 0 => $result }; |
| 218 |
} |
| 219 |
|
| 220 |
sub teltonika_trb14x { |
| 221 |
my ($self, %options) = @_; |
| 222 |
|
| 223 |
my $mapping = { |
| 224 |
imsi => { oid => '.1.3.6.1.4.1.48690.2.2.1.8' }, |
| 225 |
simState => { oid => '.1.3.6.1.4.1.48690.2.2.1.9' }, |
| 226 |
pinState => { oid => '.1.3.6.1.4.1.48690.2.2.1.10' }, |
| 227 |
netState => { oid => '.1.3.6.1.4.1.48690.2.2.1.11' }, |
| 228 |
signal => { oid => '.1.3.6.1.4.1.48690.2.2.1.12' }, |
| 229 |
operator => { oid => '.1.3.6.1.4.1.48690.2.2.1.13' }, |
| 230 |
connectionState => { oid => '.1.3.6.1.4.1.48690.2.2.1.15' }, |
| 231 |
temperature => { oid => '.1.3.6.1.4.1.48690.2.2.1.17' }, |
| 232 |
rsrp => { oid => '.1.3.6.1.4.1.48690.2.2.1.20' }, |
| 233 |
rsrq => { oid => '.1.3.6.1.4.1.48690.2.2.1.21' }, |
| 234 |
sent => { oid => '.1.3.6.1.4.1.48690.2.2.1.22' }, |
| 235 |
received => { oid => '.1.3.6.1.4.1.48690.2.2.1.23' } |
| 236 |
}; |
| 237 |
|
| 238 |
my $oid_modemEntry = '.1.3.6.1.4.1.48690.2.2.1'; |
| 239 |
my $snmp_result = $options{snmp}->get_table( |
| 240 |
oid => $oid_modemEntry, |
| 241 |
nothing_quit => 1 |
| 242 |
); |
| 243 |
|
| 244 |
$self->{modems} = {}; |
| 245 |
foreach my $oid (keys %$snmp_result) { |
| 246 |
next if ($oid !~ /^$mapping->{imsi}->{oid}\.(.*)$/); |
| 247 |
my $instance = $1; |
| 248 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 249 |
|
| 250 |
$result->{simState} = defined($result->{simState}) ? $result->{simState} : '-'; |
| 251 |
$result->{pinState} = defined($result->{pinState}) ? $result->{pinState} : '-'; |
| 252 |
$result->{netState} = defined($result->{netState}) ? $result->{netState} : '-'; |
| 253 |
$result->{temperature} = $result->{temperature} / 10; |
| 254 |
$result->{sent} = $result->{sent} * 8; |
| 255 |
$result->{received} = $result->{received} * 8; |
| 256 |
|
| 257 |
$self->{modems}->{$instance} = $result; |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
sub manage_selection { |
| 262 |
my ($self, %options) = @_; |
| 263 |
|
| 264 |
my $oid_hardwareRevision = '.1.3.6.1.4.1.48690.1.10.0'; # legacy |
| 265 |
my $oid_fwVersion = '.1.3.6.1.4.1.48690.1.6.0'; |
| 266 |
|
| 267 |
my $snmp_result = $options{snmp}->get_leef( |
| 268 |
oids => [ $oid_hardwareRevision, $oid_fwVersion ], |
| 269 |
nothing_quit => 1 |
| 270 |
); |
| 271 |
|
| 272 |
if (defined($snmp_result->{$oid_hardwareRevision})) { |
| 273 |
$self->teltonika_legacy(snmp => $options{snmp}); |
| 274 |
} else { |
| 275 |
$self->teltonika_trb14x(snmp => $options{snmp}); |
| 276 |
} |
| 277 |
|
| 278 |
$self->{cache_name} = 'teltonika_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . |
| 279 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); |
| 280 |
} |
| 281 |
|
| 282 |
1; |
| 283 |
|
| 284 |
__END__ |
| 285 |
|
| 286 |
=head1 MODE |
| 287 |
|
| 288 |
Check modem. |
| 289 |
|
| 290 |
=over 8 |
| 291 |
|
| 292 |
=item B<--filter-counters> |
| 293 |
|
| 294 |
Only display some counters (regexp can be used). |
| 295 |
Example: --filter-counters='status' |
| 296 |
|
| 297 |
=item B<--warning-status> |
| 298 |
|
| 299 |
Define the conditions to match for the status to be WARNING. |
| 300 |
You can use the following variables: %{simState}, %{pinState}, %{netState}, %{connectionState} |
| 301 |
|
| 302 |
=item B<--critical-status> |
| 303 |
|
| 304 |
Define the conditions to match for the status to be CRITICAL (default: '%{connectionState} !~ /connected/i'). |
| 305 |
You can use the following variables: %{simState}, %{pinState}, %{netState}, %{connectionState} |
| 306 |
|
| 307 |
=item B<--warning-*> B<--critical-*> |
| 308 |
|
| 309 |
Thresholds. |
| 310 |
Can be: 'signal-strength', 'temperature', 'traffic-in', 'traffic-out' |
| 311 |
'signal-receive-power', 'signal-receive-quality'. |
| 312 |
|
| 313 |
=back |
| 314 |
|
| 315 |
=cut |