mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-29 16:45:04 +02:00
enh cisco meraki rest api (#2640)
This commit is contained in:
parent
d2bda2f196
commit
9052f4a45c
@ -52,7 +52,8 @@ sub new {
|
|||||||
'ignore-permission-errors' => { name => 'ignore_permission_errors' },
|
'ignore-permission-errors' => { name => 'ignore_permission_errors' },
|
||||||
'use-extra-cache' => { name => 'use_extra_cache' },
|
'use-extra-cache' => { name => 'use_extra_cache' },
|
||||||
'reload-extra-cache-time:s' => { name => 'reload_extra_cache_time' },
|
'reload-extra-cache-time:s' => { name => 'reload_extra_cache_time' },
|
||||||
'trace-api:s' => { name => 'trace_api' }
|
'trace-api:s' => { name => 'trace_api' },
|
||||||
|
'api-requests-disabled' => { name => 'api_requests_disabled' }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
|
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
|
||||||
@ -67,7 +68,9 @@ sub new {
|
|||||||
uplink_statuses => {},
|
uplink_statuses => {},
|
||||||
uplinks_loss_latency => {},
|
uplinks_loss_latency => {},
|
||||||
devices_statuses => {},
|
devices_statuses => {},
|
||||||
devices_connection_stats => {}
|
devices_connection_stats => {},
|
||||||
|
devices_performance => {},
|
||||||
|
devices_clients => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
@ -225,6 +228,8 @@ sub settings {
|
|||||||
sub request_api {
|
sub request_api {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return undef if (defined($self->{option_results}->{api_requests_disabled}));
|
||||||
|
|
||||||
$self->settings();
|
$self->settings();
|
||||||
|
|
||||||
my $hostname = $self->{hostname};
|
my $hostname = $self->{hostname};
|
||||||
@ -290,7 +295,6 @@ sub cache_meraki_entities {
|
|||||||
$self->{cache_devices} = $self->{cache}->get(name => 'devices');
|
$self->{cache_devices} = $self->{cache}->get(name => 'devices');
|
||||||
|
|
||||||
if ($has_cache_file == 0 || !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{reload_cache_time}) * 60))) {
|
if ($has_cache_file == 0 || !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{reload_cache_time}) * 60))) {
|
||||||
$self->{cache_organizations} = {};
|
|
||||||
$self->{cache_organizations} = $self->get_organizations(
|
$self->{cache_organizations} = $self->get_organizations(
|
||||||
disable_cache => 1
|
disable_cache => 1
|
||||||
);
|
);
|
||||||
@ -319,7 +323,9 @@ sub get_organizations {
|
|||||||
return $self->{cache_organizations} if (!defined($options{disable_cache}) || $options{disable_cache} == 0);
|
return $self->{cache_organizations} if (!defined($options{disable_cache}) || $options{disable_cache} == 0);
|
||||||
my $datas = $self->request_api(endpoint => '/organizations');
|
my $datas = $self->request_api(endpoint => '/organizations');
|
||||||
my $results = {};
|
my $results = {};
|
||||||
$results->{$_->{id}} = $_ foreach (@$datas);
|
if (defined($datas)) {
|
||||||
|
$results->{$_->{id}} = $_ foreach (@$datas);
|
||||||
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
@ -336,7 +342,9 @@ sub get_networks {
|
|||||||
endpoint => '/organizations/' . $id . '/networks',
|
endpoint => '/organizations/' . $id . '/networks',
|
||||||
hostname => $self->get_shard_hostname(organization_id => $id)
|
hostname => $self->get_shard_hostname(organization_id => $id)
|
||||||
);
|
);
|
||||||
$results->{$_->{id}} = $_ foreach (@$datas);
|
if (defined($datas)) {
|
||||||
|
$results->{ $_->{id} } = $_ foreach (@$datas);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
@ -354,7 +362,9 @@ sub get_devices {
|
|||||||
endpoint => '/organizations/' . $id . '/devices',
|
endpoint => '/organizations/' . $id . '/devices',
|
||||||
hostname => $self->get_shard_hostname(organization_id => $id)
|
hostname => $self->get_shard_hostname(organization_id => $id)
|
||||||
);
|
);
|
||||||
$results->{$_->{serial}} = $_ foreach (@$datas);
|
if (defined($datas)) {
|
||||||
|
$results->{ $_->{serial} } = $_ foreach (@$datas);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
@ -512,13 +522,23 @@ sub get_device_clients {
|
|||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->cache_meraki_entities();
|
$self->cache_meraki_entities();
|
||||||
|
$self->load_extra_cache();
|
||||||
my $timespan = defined($options{timespan}) ? $options{timespan} : 300;
|
my $timespan = defined($options{timespan}) ? $options{timespan} : 300;
|
||||||
$timespan = 1 if ($timespan <= 0);
|
$timespan = 1 if ($timespan <= 0);
|
||||||
|
|
||||||
return $self->request_api(
|
if (!defined($self->{cached}->{devices_clients}->{ $options{serial} })) {
|
||||||
endpoint => '/devices/' . $options{serial} . '/clients?timespan=' . $options{timespan},
|
$self->{cached}->{updated} = 1;
|
||||||
hostname => $self->get_shard_hostname(serial => $options{serial})
|
# 400 = feature not supported. 204 = no content
|
||||||
);
|
$self->{cached}->{devices_clients}->{ $options{serial} } = {
|
||||||
|
update_time => time(),
|
||||||
|
data => $self->request_api(
|
||||||
|
endpoint => '/devices/' . $options{serial} . '/clients?timespan=' . $options{timespan},
|
||||||
|
hostname => $self->get_shard_hostname(serial => $options{serial})
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return $self->{cached}->{devices_clients}->{ $options{serial} }->{data};
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_device_switch_port_statuses {
|
sub get_device_switch_port_statuses {
|
||||||
@ -538,13 +558,22 @@ sub get_network_device_performance {
|
|||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->cache_meraki_entities();
|
$self->cache_meraki_entities();
|
||||||
|
$self->load_extra_cache();
|
||||||
|
|
||||||
# 400 = feature not supported. 204 = no content
|
if (!defined($self->{cached}->{devices_performance}->{ $options{serial} })) {
|
||||||
return $self->request_api(
|
$self->{cached}->{updated} = 1;
|
||||||
endpoint => '/devices/' . $options{serial} . '/appliance/performance',
|
# 400 = feature not supported. 204 = no content
|
||||||
hostname => $self->get_shard_hostname(network_id => $options{network_id}),
|
$self->{cached}->{devices_performance}->{ $options{serial} } = {
|
||||||
ignore_codes => { 400 => 1, 204 => 1 }
|
update_time => time(),
|
||||||
);
|
data => $self->request_api(
|
||||||
|
endpoint => '/devices/' . $options{serial} . '/appliance/performance',
|
||||||
|
hostname => $self->get_shard_hostname(network_id => $options{network_id}),
|
||||||
|
ignore_codes => { 400 => 1, 204 => 1 }
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return $self->{cached}->{devices_performance}->{ $options{serial} }->{data};
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_organization_uplink_loss_and_latency {
|
sub get_organization_uplink_loss_and_latency {
|
||||||
@ -593,7 +622,7 @@ sub load_extra_cache {
|
|||||||
$self->{cached}->{devices_statuses} = {};
|
$self->{cached}->{devices_statuses} = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $entry (('uplink_statuses', 'uplinks_loss_latency', 'devices_connection_stats')) {
|
foreach my $entry (('uplink_statuses', 'uplinks_loss_latency', 'devices_connection_stats', 'devices_performance', 'devices_clients')) {
|
||||||
next if (!defined($self->{cached}->{$entry}));
|
next if (!defined($self->{cached}->{$entry}));
|
||||||
|
|
||||||
foreach (keys %{$self->{cached}->{$entry}}) {
|
foreach (keys %{$self->{cached}->{$entry}}) {
|
||||||
|
@ -301,7 +301,8 @@ sub new {
|
|||||||
'add-switch-ports' => { name => 'add_switch_ports' },
|
'add-switch-ports' => { name => 'add_switch_ports' },
|
||||||
'skip-traffic-disconnect-port' => { name => 'skip_traffic_disconnect_port' },
|
'skip-traffic-disconnect-port' => { name => 'skip_traffic_disconnect_port' },
|
||||||
'skip-clients' => { name => 'skip_clients' },
|
'skip-clients' => { name => 'skip_clients' },
|
||||||
'skip-performance' => { name => 'skip_performance' }
|
'skip-performance' => { name => 'skip_performance' },
|
||||||
|
'skip-connections' => { name => 'skip_connections' }
|
||||||
});
|
});
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
@ -512,7 +513,7 @@ sub manage_selection {
|
|||||||
device_ports => {}
|
device_ports => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
if ($devices->{$serial}->{model} =~ /^(?:MG|MR)/) {
|
if (!defined($self->{option_results}->{skip_connections}) && $devices->{$serial}->{model} =~ /^(?:MG|MR)/) {
|
||||||
$self->add_connection_stats(
|
$self->add_connection_stats(
|
||||||
custom => $options{custom},
|
custom => $options{custom},
|
||||||
timespan => $timespan,
|
timespan => $timespan,
|
||||||
@ -618,6 +619,10 @@ Don't monitor clients traffic on device.
|
|||||||
|
|
||||||
Don't monitor appliance perfscore.
|
Don't monitor appliance perfscore.
|
||||||
|
|
||||||
|
=item B<--skip-connections>
|
||||||
|
|
||||||
|
Don't monitor connection stats.
|
||||||
|
|
||||||
=item B<--skip-traffic-disconnect-port>
|
=item B<--skip-traffic-disconnect-port>
|
||||||
|
|
||||||
Skip port traffic counters if port status is disconnected.
|
Skip port traffic counters if port status is disconnected.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user