| 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::cisco::meraki::cloudcontroller::restapi::mode::devices; |
| 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 'status: ' . $self->{result_values}->{status}; |
| 34 |
} |
| 35 |
|
| 36 |
sub custom_link_status_output { |
| 37 |
my ($self, %options) = @_; |
| 38 |
|
| 39 |
return 'status: ' . $self->{result_values}->{link_status}; |
| 40 |
} |
| 41 |
|
| 42 |
sub custom_port_status_output { |
| 43 |
my ($self, %options) = @_; |
| 44 |
|
| 45 |
return 'status: ' . $self->{result_values}->{port_status} . ' [enabled: ' . $self->{result_values}->{port_enabled} . ']'; |
| 46 |
} |
| 47 |
|
| 48 |
sub device_long_output { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
return "checking device '" . $options{instance_value}->{display} . "'"; |
| 52 |
} |
| 53 |
|
| 54 |
sub prefix_device_output { |
| 55 |
my ($self, %options) = @_; |
| 56 |
|
| 57 |
return "Device '" . $options{instance_value}->{display} . "' "; |
| 58 |
} |
| 59 |
|
| 60 |
sub prefix_global_output { |
| 61 |
my ($self, %options) = @_; |
| 62 |
|
| 63 |
return 'Devices '; |
| 64 |
} |
| 65 |
|
| 66 |
sub prefix_connection_output { |
| 67 |
my ($self, %options) = @_; |
| 68 |
|
| 69 |
return 'connection '; |
| 70 |
} |
| 71 |
|
| 72 |
sub prefix_traffic_output { |
| 73 |
my ($self, %options) = @_; |
| 74 |
|
| 75 |
return 'traffic '; |
| 76 |
} |
| 77 |
|
| 78 |
sub prefix_link_output { |
| 79 |
my ($self, %options) = @_; |
| 80 |
|
| 81 |
return "link '" . $options{instance_value}->{display} . "' "; |
| 82 |
} |
| 83 |
|
| 84 |
sub prefix_port_output { |
| 85 |
my ($self, %options) = @_; |
| 86 |
|
| 87 |
return "port '" . $options{instance_value}->{display} . "' "; |
| 88 |
} |
| 89 |
|
| 90 |
sub set_counters { |
| 91 |
my ($self, %options) = @_; |
| 92 |
|
| 93 |
$self->{maps_counters_type} = [ |
| 94 |
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } }, |
| 95 |
{ name => 'devices', type => 3, cb_prefix_output => 'prefix_device_output', cb_long_output => 'device_long_output', indent_long_output => ' ', message_multiple => 'All devices are ok', |
| 96 |
group => [ |
| 97 |
{ name => 'device_status', type => 0, skipped_code => { -10 => 1 } }, |
| 98 |
{ name => 'device_performance', type => 0, skipped_code => { -10 => 1 } }, |
| 99 |
{ name => 'device_connections', type => 0, cb_prefix_output => 'prefix_connection_output', skipped_code => { -10 => 1 } }, |
| 100 |
{ name => 'device_traffic', type => 0, cb_prefix_output => 'prefix_traffic_output', skipped_code => { -10 => 1, -11 => 1 } }, |
| 101 |
{ name => 'device_links_counters', type => 0, skipped_code => { -10 => 1, -11 => 1 } }, |
| 102 |
{ name => 'device_links', display_long => 1, cb_prefix_output => 'prefix_link_output', message_multiple => 'All links are ok', type => 1, skipped_code => { -10 => 1 } }, |
| 103 |
{ name => 'device_ports', display_long => 1, cb_prefix_output => 'prefix_port_output', message_multiple => 'All ports are ok', type => 1, skipped_code => { -10 => 1 } } |
| 104 |
] |
| 105 |
} |
| 106 |
]; |
| 107 |
|
| 108 |
$self->{maps_counters}->{global} = [ |
| 109 |
{ label => 'total-online', nlabel => 'devices.total.online.count', display_ok => 0, set => { |
| 110 |
key_values => [ { name => 'online' }, { name => 'total' } ], |
| 111 |
output_template => 'online: %s', |
| 112 |
perfdatas => [ |
| 113 |
{ template => '%s', min => 0, max => 'total' } |
| 114 |
] |
| 115 |
} |
| 116 |
}, |
| 117 |
{ label => 'total-online-prct', nlabel => 'devices.total.online.percentage', display_ok => 0, set => { |
| 118 |
key_values => [ { name => 'online_prct' } ], |
| 119 |
output_template => 'online: %.2f%%', |
| 120 |
perfdatas => [ |
| 121 |
{ template => '%.2f', unit => '%', min => 0, max => 100 } |
| 122 |
] |
| 123 |
} |
| 124 |
}, |
| 125 |
{ label => 'total-offline', nlabel => 'devices.total.offline.count', display_ok => 0, set => { |
| 126 |
key_values => [ { name => 'offline' }, { name => 'total' } ], |
| 127 |
output_template => 'offline: %s', |
| 128 |
perfdatas => [ |
| 129 |
{ template => '%s', min => 0, max => 'total' } |
| 130 |
] |
| 131 |
} |
| 132 |
}, |
| 133 |
{ label => 'total-offline-prct', nlabel => 'devices.total.offline.percentage', display_ok => 0, set => { |
| 134 |
key_values => [ { name => 'offline_prct' } ], |
| 135 |
output_template => 'offline: %.2f%%', |
| 136 |
perfdatas => [ |
| 137 |
{ template => '%.2f', unit => '%', min => 0, max => 100 } |
| 138 |
] |
| 139 |
} |
| 140 |
}, |
| 141 |
{ label => 'total-alerting', nlabel => 'devices.total.alerting.count', display_ok => 0, set => { |
| 142 |
key_values => [ { name => 'alerting' }, { name => 'total' } ], |
| 143 |
output_template => 'alerting: %s', |
| 144 |
perfdatas => [ |
| 145 |
{ template => '%s', min => 0, max => 'total' } |
| 146 |
] |
| 147 |
} |
| 148 |
} |
| 149 |
]; |
| 150 |
|
| 151 |
$self->{maps_counters}->{device_status} = [ |
| 152 |
{ label => 'status', type => 2, critical_default => '%{status} =~ /alerting/i', set => { |
| 153 |
key_values => [ { name => 'status' }, { name => 'display' } ], |
| 154 |
closure_custom_output => $self->can('custom_status_output'), |
| 155 |
closure_custom_perfdata => sub { return 0; }, |
| 156 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 157 |
} |
| 158 |
} |
| 159 |
]; |
| 160 |
|
| 161 |
$self->{maps_counters}->{device_performance} = [ |
| 162 |
{ label => 'load', nlabel => 'device.load.count', set => { |
| 163 |
key_values => [ { name => 'perfscore' } ], |
| 164 |
output_template => 'load: %s', |
| 165 |
perfdatas => [ |
| 166 |
{ template => '%d', min => 0, max => 100, label_extra_instance => 1 } |
| 167 |
] |
| 168 |
} |
| 169 |
} |
| 170 |
]; |
| 171 |
|
| 172 |
$self->{maps_counters}->{device_connections} = [ |
| 173 |
{ label => 'connections-success', nlabel => 'device.connections.success.count', set => { |
| 174 |
key_values => [ { name => 'success' } ], |
| 175 |
output_template => 'success: %s', |
| 176 |
perfdatas => [ |
| 177 |
{ template => '%d', min => 0, label_extra_instance => 1 } |
| 178 |
] |
| 179 |
} |
| 180 |
}, |
| 181 |
{ label => 'connections-auth', nlabel => 'device.connections.auth.count', display_ok => 0, set => { |
| 182 |
key_values => [ { name => 'auth' } ], |
| 183 |
output_template => 'auth: %s', |
| 184 |
perfdatas => [ |
| 185 |
{ template => '%d', min => 0, label_extra_instance => 1 } |
| 186 |
] |
| 187 |
} |
| 188 |
}, |
| 189 |
{ label => 'connections-assoc', nlabel => 'device.connections.assoc.count', display_ok => 0, set => { |
| 190 |
key_values => [ { name => 'assoc' } ], |
| 191 |
output_template => 'assoc: %s', |
| 192 |
perfdatas => [ |
| 193 |
{ template => '%d', min => 0, label_extra_instance => 1 } |
| 194 |
] |
| 195 |
} |
| 196 |
}, |
| 197 |
{ label => 'connections-dhcp', nlabel => 'device.connections.dhcp.count', display_ok => 0, set => { |
| 198 |
key_values => [ { name => 'dhcp' } ], |
| 199 |
output_template => 'dhcp: %s', |
| 200 |
perfdatas => [ |
| 201 |
{ template => '%d', min => 0, label_extra_instance => 1 } |
| 202 |
] |
| 203 |
} |
| 204 |
}, |
| 205 |
{ label => 'connections-dns', nlabel => 'device.connections.dns.count', display_ok => 0, set => { |
| 206 |
key_values => [ { name => 'dns' } ], |
| 207 |
output_template => 'dns: %s', |
| 208 |
perfdatas => [ |
| 209 |
{ template => '%d', min => 0, label_extra_instance => 1 } |
| 210 |
] |
| 211 |
} |
| 212 |
} |
| 213 |
]; |
| 214 |
|
| 215 |
$self->{maps_counters}->{device_traffic} = [ |
| 216 |
{ label => 'traffic-in', nlabel => 'device.traffic.in.bitspersecond', set => { |
| 217 |
key_values => [ { name => 'traffic_in', per_second => 1 }, { name => 'display' } ], |
| 218 |
output_template => 'in: %s %s/s', |
| 219 |
output_change_bytes => 2, |
| 220 |
perfdatas => [ |
| 221 |
{ template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1 } |
| 222 |
] |
| 223 |
} |
| 224 |
}, |
| 225 |
{ label => 'traffic-out', nlabel => 'device.traffic.out.bitspersecond', set => { |
| 226 |
key_values => [ { name => 'traffic_out', per_second => 1 }, { name => 'display' } ], |
| 227 |
output_template => 'out: %s %s/s', |
| 228 |
output_change_bytes => 2, |
| 229 |
perfdatas => [ |
| 230 |
{ template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1 } |
| 231 |
] |
| 232 |
} |
| 233 |
} |
| 234 |
]; |
| 235 |
|
| 236 |
$self->{maps_counters}->{device_links_counters} = [ |
| 237 |
{ label => 'links-ineffective', nlabel => 'device.links.ineffective.count', display_ok => 0, set => { |
| 238 |
key_values => [ { name => 'ineffective' } ], |
| 239 |
output_template => 'links ineffective: %s', |
| 240 |
perfdatas => [ |
| 241 |
{ template => '%s', min => 0, label_extra_instance => 1 } |
| 242 |
] |
| 243 |
} |
| 244 |
} |
| 245 |
]; |
| 246 |
|
| 247 |
$self->{maps_counters}->{device_links} = [ |
| 248 |
{ label => 'link-status', type => 2, critical_default => '%{link_status} =~ /failed/i', set => { |
| 249 |
key_values => [ { name => 'link_status' }, { name => 'display' } ], |
| 250 |
closure_custom_output => $self->can('custom_link_status_output'), |
| 251 |
closure_custom_perfdata => sub { return 0; }, |
| 252 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 253 |
} |
| 254 |
}, |
| 255 |
{ label => 'link-latency', nlabel => 'device.link.latency.milliseconds', set => { |
| 256 |
key_values => [ { name => 'latency_ms' } ], |
| 257 |
output_template => 'latency: %.2f ms', |
| 258 |
perfdatas => [ |
| 259 |
{ template => '%.2f', min => 0, unit => 'ms', label_extra_instance => 1 } |
| 260 |
] |
| 261 |
} |
| 262 |
}, |
| 263 |
{ label => 'link-loss', nlabel => 'device.link.loss.percentage', set => { |
| 264 |
key_values => [ { name => 'loss_percent' } ], |
| 265 |
output_template => 'loss: %.2f %%', |
| 266 |
perfdatas => [ |
| 267 |
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } |
| 268 |
] |
| 269 |
} |
| 270 |
} |
| 271 |
]; |
| 272 |
|
| 273 |
$self->{maps_counters}->{device_ports} = [ |
| 274 |
{ label => 'port-status', type => 2, critical_default => '%{port_enabled} == 1 and %{port_status} !~ /^connected/i', set => { |
| 275 |
key_values => [ { name => 'port_status' }, { name => 'port_enabled' }, { name => 'display' } ], |
| 276 |
closure_custom_output => $self->can('custom_port_status_output'), |
| 277 |
closure_custom_perfdata => sub { return 0; }, |
| 278 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 279 |
} |
| 280 |
}, |
| 281 |
{ label => 'port-traffic-in', nlabel => 'device.port.traffic.in.bitspersecond', set => { |
| 282 |
key_values => [ { name => 'traffic_in' } ], |
| 283 |
output_template => 'traffic in: %s %s/s', |
| 284 |
output_change_bytes => 2, |
| 285 |
perfdatas => [ |
| 286 |
{ template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1 } |
| 287 |
] |
| 288 |
} |
| 289 |
}, |
| 290 |
{ label => 'port-traffic-out', nlabel => 'device.port.traffic.out.bitspersecond', set => { |
| 291 |
key_values => [ { name => 'traffic_out' } ], |
| 292 |
output_template => 'traffic out: %s %s/s', |
| 293 |
output_change_bytes => 2, |
| 294 |
perfdatas => [ |
| 295 |
{ template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1 } |
| 296 |
] |
| 297 |
} |
| 298 |
} |
| 299 |
]; |
| 300 |
} |
| 301 |
|
| 302 |
sub new { |
| 303 |
my ($class, %options) = @_; |
| 304 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); |
| 305 |
bless $self, $class; |
| 306 |
|
| 307 |
$options{options}->add_options(arguments => { |
| 308 |
'filter-device-name:s' => { name => 'filter_device_name' }, |
| 309 |
'filter-network-id:s' => { name => 'filter_network_id' }, |
| 310 |
'filter-organization-name:s' => { name => 'filter_organization_name' }, |
| 311 |
'filter-organization-id:s' => { name => 'filter_organization_id' }, |
| 312 |
'filter-tags:s' => { name => 'filter_tags' }, |
| 313 |
'add-switch-ports' => { name => 'add_switch_ports' }, |
| 314 |
'filter-switch-port:s' => { name => 'filter_switch_port' }, |
| 315 |
'filter-link-name:s' => { name => 'filter_link_name' }, |
| 316 |
'skip-traffic-disconnect-port' => { name => 'skip_traffic_disconnect_port' }, |
| 317 |
'skip-clients' => { name => 'skip_clients' }, |
| 318 |
'skip-performance' => { name => 'skip_performance' }, |
| 319 |
'skip-connections' => { name => 'skip_connections' } |
| 320 |
}); |
| 321 |
|
| 322 |
return $self; |
| 323 |
} |
| 324 |
|
| 325 |
sub add_connection_stats { |
| 326 |
my ($self, %options) = @_; |
| 327 |
|
| 328 |
my $connections = $options{custom}->get_network_device_connection_stats( |
| 329 |
serial => $options{serial}, |
| 330 |
network_id => $options{network_id} |
| 331 |
); |
| 332 |
|
| 333 |
$self->{devices}->{ $options{serial} }->{device_connections} = { |
| 334 |
assoc => defined($connections->{assoc}) ? $connections->{assoc} : 0, |
| 335 |
auth => defined($connections->{auth}) ? $connections->{auth} : 0, |
| 336 |
dhcp => defined($connections->{dhcp}) ? $connections->{dhcp} : 0, |
| 337 |
dns => defined($connections->{dns}) ? $connections->{dns} : 0, |
| 338 |
success => defined($connections->{success}) ? $connections->{success} : 0 |
| 339 |
}; |
| 340 |
} |
| 341 |
|
| 342 |
sub add_clients { |
| 343 |
my ($self, %options) = @_; |
| 344 |
|
| 345 |
my $clients = $options{custom}->get_device_clients( |
| 346 |
serial => $options{serial} |
| 347 |
); |
| 348 |
|
| 349 |
$self->{devices}->{ $options{serial} }->{device_traffic} = { |
| 350 |
display => $options{name}, |
| 351 |
traffic_in => 0, |
| 352 |
traffic_out => 0 |
| 353 |
}; |
| 354 |
|
| 355 |
if (defined($clients)) { |
| 356 |
foreach (@$clients) { |
| 357 |
$self->{devices}->{ $options{serial} }->{device_traffic}->{traffic_in} += $_->{usage}->{recv} * 8; |
| 358 |
$self->{devices}->{ $options{serial} }->{device_traffic}->{traffic_out} += $_->{usage}->{sent} * 8; |
| 359 |
} |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
sub add_uplink { |
| 364 |
my ($self, %options) = @_; |
| 365 |
|
| 366 |
my $links = $options{custom}->get_network_device_uplink( |
| 367 |
serial => $options{serial}, |
| 368 |
orgId => $options{orgId} |
| 369 |
); |
| 370 |
|
| 371 |
if (defined($links)) { |
| 372 |
$self->{devices}->{ $options{serial} }->{device_links_counters} = { ineffective => 0 }; |
| 373 |
|
| 374 |
foreach (@$links) { |
| 375 |
my $interface = lc($_->{interface}); |
| 376 |
$interface =~ s/\s+//g; |
| 377 |
|
| 378 |
next if (defined($self->{option_results}->{filter_link_name}) && $self->{option_results}->{filter_link_name} ne '' && |
| 379 |
$interface !~ /$self->{option_results}->{filter_link_name}/); |
| 380 |
|
| 381 |
$self->{devices}->{ $options{serial} }->{device_links}->{$interface} = { |
| 382 |
display => $interface, |
| 383 |
link_status => lc($_->{status}) |
| 384 |
}; |
| 385 |
$self->{devices}->{ $options{serial} }->{device_links_counters}->{ineffective}++ |
| 386 |
if ($_->{status} =~ /failed|Not Connected/i); |
| 387 |
} |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
sub add_uplink_loss_latency { |
| 392 |
my ($self, %options) = @_; |
| 393 |
|
| 394 |
my $links = $options{custom}->get_organization_uplink_loss_and_latency( |
| 395 |
serial => $options{serial}, |
| 396 |
orgId => $options{orgId} |
| 397 |
); |
| 398 |
|
| 399 |
return if (!defined($links)); |
| 400 |
|
| 401 |
foreach (values %$links) { |
| 402 |
my $interface = lc($_->{uplink}); |
| 403 |
$interface =~ s/\s+//g; |
| 404 |
|
| 405 |
next if (!defined($self->{devices}->{ $options{serial} }->{device_links}->{$interface})); |
| 406 |
next if (defined($self->{option_results}->{filter_link_name}) && $self->{option_results}->{filter_link_name} ne '' && |
| 407 |
$interface !~ /$self->{option_results}->{filter_link_name}/); |
| 408 |
|
| 409 |
my ($latency, $loss, $count) = (0, 0, 0); |
| 410 |
foreach my $ts (@{$_->{timeSeries}}) { |
| 411 |
next if (!defined($ts->{latencyMs})); |
| 412 |
$latency += $ts->{latencyMs}; |
| 413 |
$loss += $ts->{lossPercent}; |
| 414 |
$count++; |
| 415 |
} |
| 416 |
|
| 417 |
if ($count > 0) { |
| 418 |
$latency /= $count; |
| 419 |
$loss /= $count; |
| 420 |
} |
| 421 |
|
| 422 |
$self->{devices}->{ $options{serial} }->{device_links}->{$interface}->{loss_percent} = $loss; |
| 423 |
$self->{devices}->{ $options{serial} }->{device_links}->{$interface}->{latency_ms} = $latency; |
| 424 |
} |
| 425 |
} |
| 426 |
|
| 427 |
sub add_performance { |
| 428 |
my ($self, %options) = @_; |
| 429 |
|
| 430 |
my $perf = $options{custom}->get_network_device_performance( |
| 431 |
serial => $options{serial}, |
| 432 |
network_id => $options{network_id} |
| 433 |
); |
| 434 |
|
| 435 |
if (defined($perf) && defined($perf->{perfScore})) { |
| 436 |
$self->{devices}->{ $options{serial} }->{device_performance} = { |
| 437 |
perfscore => $perf->{perfScore} |
| 438 |
}; |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
sub add_switch_port_statuses { |
| 443 |
my ($self, %options) = @_; |
| 444 |
|
| 445 |
my $ports = $options{custom}->get_device_switch_port_statuses( |
| 446 |
serial => $options{serial} |
| 447 |
); |
| 448 |
|
| 449 |
foreach (@$ports) { |
| 450 |
next if (defined($self->{option_results}->{filter_switch_port}) && $_->{portId} !~ /$self->{option_results}->{filter_switch_port}/i |
| 451 |
&& $self->{option_results}->{filter_switch_port} ne '' ); |
| 452 |
|
| 453 |
$self->{devices}->{ $options{serial} }->{device_ports}->{ $_->{portId} } = { |
| 454 |
display => $_->{portId}, |
| 455 |
port_status => lc($_->{status}), |
| 456 |
port_enabled => $_->{enabled} =~ /True|1/i ? 1 : 0 |
| 457 |
}; |
| 458 |
|
| 459 |
next if (defined($self->{option_results}->{skip_traffic_disconnect_port}) && $_->{status} =~ /disconnected/i); |
| 460 |
|
| 461 |
$self->{devices}->{ $options{serial} }->{device_ports}->{ $_->{portId} }->{traffic_in} = $_->{usageInKb}->{recv} * 1000 * 8, |
| 462 |
$self->{devices}->{ $options{serial} }->{device_ports}->{ $_->{portId} }->{traffic_out} = $_->{usageInKb}->{sent} * 1000 * 8; |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
sub manage_selection { |
| 467 |
my ($self, %options) = @_; |
| 468 |
|
| 469 |
$self->{cache_name} = 'meraki_' . $self->{mode} . '_' . $options{custom}->get_token() . '_' . |
| 470 |
md5_hex( |
| 471 |
(defined($self->{option_results}->{filter_counters}) ? $self->{option_results}->{filter_counters} : 'all') . '_' . |
| 472 |
(defined($self->{option_results}->{filter_device_name}) ? $self->{option_results}->{filter_device_name} : 'all') . '_' . |
| 473 |
(defined($self->{option_results}->{filter_network_id}) ? $self->{option_results}->{filter_network_id} : 'all') . '_' . |
| 474 |
(defined($self->{option_results}->{filter_organization_id}) ? $self->{option_results}->{filter_organization_id} : 'all') . '_' . |
| 475 |
(defined($self->{option_results}->{filter_organization_name}) ? $self->{option_results}->{filter_organization_name} : 'all') . '_' . |
| 476 |
(defined($self->{option_results}->{filter_tags}) ? $self->{option_results}->{filter_tags} : 'all') |
| 477 |
); |
| 478 |
|
| 479 |
# | /clients | /connectionStats | /performance | /uplink | /uplinksLossAndLatency | /switchPortStatuses |
| 480 |
#-------------------|----------|---------------------------------|---------|------------------------|----------------------- |
| 481 |
# MV [camera] | | | | X | | |
| 482 |
# MS [switch] | X | | | X | | X |
| 483 |
# MG [cellullar gw] | X | X | | X | | |
| 484 |
# MX [appliance] | X | | X | X | X | |
| 485 |
# MR [wireless] | X | X | | X | | |
| 486 |
|
| 487 |
my $datas = $options{custom}->get_datas(); |
| 488 |
|
| 489 |
$self->{global} = { total => 0, online => 0, offline => 0, alerting => 0, offline_prct => 0, online_prct => 0 }; |
| 490 |
$self->{devices} = {}; |
| 491 |
foreach my $serial (keys %{$datas->{devices}}) { |
| 492 |
next if (defined($self->{option_results}->{filter_device_name}) && $self->{option_results}->{filter_device_name} ne '' && |
| 493 |
$datas->{devices}->{$serial}->{name} !~ /$self->{option_results}->{filter_device_name}/); |
| 494 |
next if (defined($self->{option_results}->{filter_network_id}) && $self->{option_results}->{filter_network_id} ne '' && |
| 495 |
$datas->{devices}->{$serial}->{networkId} !~ /$self->{option_results}->{filter_network_id}/); |
| 496 |
|
| 497 |
if (defined($self->{option_results}->{filter_tags}) && $self->{option_results}->{filter_tags} ne '') { |
| 498 |
my $tags; |
| 499 |
$tags = join(' ', @{$datas->{devices}->{$serial}->{tags}}) if (defined($datas->{devices}->{$serial}->{tags})); |
| 500 |
if (!defined($tags) || $tags !~ /$self->{option_results}->{filter_tags}/) { |
| 501 |
next; |
| 502 |
} |
| 503 |
} |
| 504 |
next if (defined($self->{option_results}->{filter_organization_id}) && $self->{option_results}->{filter_organization_id} ne '' && |
| 505 |
$datas->{devices}->{$serial}->{orgId} !~ /$self->{option_results}->{filter_organization_id}/); |
| 506 |
next if (defined($self->{option_results}->{filter_organization_name}) && $self->{option_results}->{filter_organization_name} ne '' && |
| 507 |
$datas->{orgs}->{ $datas->{devices}->{$serial}->{orgId} }->{name} !~ /$self->{option_results}->{filter_organization_name}/); |
| 508 |
|
| 509 |
$self->{devices}->{$serial} = { |
| 510 |
display => $datas->{devices}->{$serial}->{name}, |
| 511 |
device_status => { |
| 512 |
display => $datas->{devices}->{$serial}->{name}, |
| 513 |
status => $datas->{devices_status}->{$serial}->{status} |
| 514 |
}, |
| 515 |
device_links => {}, |
| 516 |
device_ports => {} |
| 517 |
}; |
| 518 |
|
| 519 |
if (!defined($self->{option_results}->{skip_connections}) && $datas->{devices}->{$serial}->{model} =~ /^(?:MG|MR)/) { |
| 520 |
$self->add_connection_stats( |
| 521 |
custom => $options{custom}, |
| 522 |
serial => $serial, |
| 523 |
name => $datas->{devices}->{$serial}->{name}, |
| 524 |
network_id => $datas->{devices}->{$serial}->{networkId} |
| 525 |
); |
| 526 |
} |
| 527 |
if (!defined($self->{option_results}->{skip_clients}) && $datas->{devices}->{$serial}->{model} =~ /^(?:MS|MG|MR|MX)/) { |
| 528 |
$self->add_clients( |
| 529 |
custom => $options{custom}, |
| 530 |
serial => $serial, |
| 531 |
name => $datas->{devices}->{$serial}->{name} |
| 532 |
); |
| 533 |
} |
| 534 |
if ($datas->{devices}->{$serial}->{model} =~ /^(?:MV|MS|MG|MR|MX)/) { |
| 535 |
$self->add_uplink( |
| 536 |
custom => $options{custom}, |
| 537 |
serial => $serial, |
| 538 |
name => $datas->{devices}->{$serial}->{name}, |
| 539 |
orgId => $datas->{devices}->{$serial}->{orgId} |
| 540 |
); |
| 541 |
} |
| 542 |
if (defined($self->{option_results}->{add_switch_ports}) && $datas->{devices}->{$serial}->{model} =~ /^MS/) { |
| 543 |
$self->add_switch_port_statuses( |
| 544 |
custom => $options{custom}, |
| 545 |
serial => $serial |
| 546 |
); |
| 547 |
} |
| 548 |
if ($datas->{devices}->{$serial}->{model} =~ /^MX/) { |
| 549 |
$self->add_performance( |
| 550 |
custom => $options{custom}, |
| 551 |
serial => $serial, |
| 552 |
name => $datas->{devices}->{$serial}->{name}, |
| 553 |
network_id => $datas->{devices}->{$serial}->{networkId} |
| 554 |
) if (!defined($self->{option_results}->{skip_performance})); |
| 555 |
|
| 556 |
$self->add_uplink_loss_latency( |
| 557 |
custom => $options{custom}, |
| 558 |
serial => $serial, |
| 559 |
orgId => $datas->{devices}->{$serial}->{orgId} |
| 560 |
); |
| 561 |
} |
| 562 |
|
| 563 |
$self->{global}->{total}++; |
| 564 |
$self->{global}->{ lc($datas->{devices_status}->{$serial}->{status}) }++ |
| 565 |
if (defined($self->{global}->{ lc($datas->{devices_status}->{$serial}->{status}) })); |
| 566 |
} |
| 567 |
|
| 568 |
if (scalar(keys %{$self->{devices}}) <= 0) { |
| 569 |
$self->{output}->output_add(short_msg => 'no devices found'); |
| 570 |
} |
| 571 |
|
| 572 |
if ($self->{global}->{total} > 0) { |
| 573 |
$self->{global}->{online_prct} = $self->{global}->{online} * 100 / $self->{global}->{total}; |
| 574 |
$self->{global}->{offline_prct} = $self->{global}->{offline} * 100 / $self->{global}->{total}; |
| 575 |
} |
| 576 |
} |
| 577 |
|
| 578 |
1; |
| 579 |
|
| 580 |
__END__ |
| 581 |
|
| 582 |
=head1 MODE |
| 583 |
|
| 584 |
Check devices. |
| 585 |
|
| 586 |
=over 8 |
| 587 |
|
| 588 |
=item B<--filter-device-name> |
| 589 |
|
| 590 |
Filter devices by name (can be a regexp). |
| 591 |
|
| 592 |
=item B<--filter-link-name> |
| 593 |
|
| 594 |
Filter VPN links by name (can be a regexp). |
| 595 |
|
| 596 |
=item B<--filter-network-id> |
| 597 |
|
| 598 |
Filter devices by network ID (can be a regexp). |
| 599 |
|
| 600 |
=item B<--filter-organization-id> |
| 601 |
|
| 602 |
Filter devices by organization ID (can be a regexp). |
| 603 |
|
| 604 |
=item B<--filter-organization-name> |
| 605 |
|
| 606 |
Filter devices by organization name (can be a regexp). |
| 607 |
|
| 608 |
=item B<--filter-tags> |
| 609 |
|
| 610 |
Filter devices by tags (can be a regexp). |
| 611 |
|
| 612 |
=item B<--add-switch-ports> |
| 613 |
|
| 614 |
Add switch port statuses and traffic. |
| 615 |
|
| 616 |
=item B<--filter-switch-port> |
| 617 |
|
| 618 |
Filter switch port (can be a regexp). |
| 619 |
|
| 620 |
=item B<--skip-clients> |
| 621 |
|
| 622 |
Don't monitor clients traffic on device. |
| 623 |
|
| 624 |
=item B<--skip-performance> |
| 625 |
|
| 626 |
Don't monitor appliance performance score. |
| 627 |
|
| 628 |
=item B<--skip-connections> |
| 629 |
|
| 630 |
Don't monitor connection stats. |
| 631 |
|
| 632 |
=item B<--skip-traffic-disconnect-port> |
| 633 |
|
| 634 |
Skip port traffic counters if port status is disconnected. |
| 635 |
|
| 636 |
=item B<--unknown-status> |
| 637 |
|
| 638 |
Define the conditions to match for the status to be UNKNOWN. |
| 639 |
You can use the following variables: %{status}, %{display} |
| 640 |
|
| 641 |
=item B<--warning-status> |
| 642 |
|
| 643 |
Define the conditions to match for the status to be WARNING. |
| 644 |
You can use the following variables: %{status}, %{display} |
| 645 |
|
| 646 |
=item B<--critical-status> |
| 647 |
|
| 648 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /alerting/i'). |
| 649 |
You can use the following variables: %{status}, %{display} |
| 650 |
|
| 651 |
=item B<--unknown-link-status> |
| 652 |
|
| 653 |
Define the conditions to match for the status to be UNKNOWN. |
| 654 |
You can use the following variables: %{link_status}, %{display} |
| 655 |
|
| 656 |
=item B<--warning-link-status> |
| 657 |
|
| 658 |
Define the conditions to match for the status to be WARNING. |
| 659 |
You can use the following variables: %{link_status}, %{display} |
| 660 |
|
| 661 |
=item B<--critical-link-status> |
| 662 |
|
| 663 |
Define the conditions to match for the status to be CRITICAL (default: '%{link_status} =~ /failed/i'). |
| 664 |
You can use the following variables: %{link_status}, %{display} |
| 665 |
|
| 666 |
=item B<--unknown-port-status> |
| 667 |
|
| 668 |
Define the conditions to match for the status to be UNKNOWN. |
| 669 |
You can use the following variables: %{port_status}, %{port_enabled}, %{display} |
| 670 |
|
| 671 |
=item B<--warning-port-status> |
| 672 |
|
| 673 |
Define the conditions to match for the status to be WARNING. |
| 674 |
You can use the following variables: %{port_status}, %{port_enabled}, %{display} |
| 675 |
|
| 676 |
=item B<--critical-port-status> |
| 677 |
|
| 678 |
Define the conditions to match for the status to be CRITICAL (default: '%{port_enabled} == 1 and %{port_status} !~ /^connected/i'). |
| 679 |
You can use the following variables: %{port_status}, %{port_enabled}, %{display} |
| 680 |
|
| 681 |
=item B<--warning-*> B<--critical-*> |
| 682 |
|
| 683 |
Thresholds. |
| 684 |
Can be: 'total-online', 'total-online-prct', 'total-offline', 'total-offline-prct', 'total-alerting', |
| 685 |
'traffic-in', 'traffic-out', 'connections-success', 'connections-auth', |
| 686 |
'connections-assoc', 'connections-dhcp', 'connections-dns', |
| 687 |
'load', 'links-ineffective', 'link-latency' (ms), ''link-loss' (%), |
| 688 |
'port-traffic-in', 'port-traffic-out'. |
| 689 |
|
| 690 |
=back |
| 691 |
|
| 692 |
=cut |