+ WIP : cisco prime wifi

This commit is contained in:
garnier-quentin 2016-11-29 14:57:30 +01:00
parent 86a5ac9b95
commit be0b418843
2 changed files with 71 additions and 50 deletions

View File

@ -95,8 +95,8 @@ sub check_options {
# return 0 = no hostname left # return 0 = no hostname left
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? shift(@{$self->{option_results}->{hostname}}) : undef; $self->{hostname} = (defined($self->{option_results}->{hostname})) ? shift(@{$self->{option_results}->{hostname}}) : undef;
$self->{port} = (defined($self->{option_results}->{port})) ? shift(@{$self->{option_results}->{port}}) : 80; $self->{port} = (defined($self->{option_results}->{port})) ? shift(@{$self->{option_results}->{port}}) : 443;
$self->{proto} = (defined($self->{option_results}->{proto})) ? shift(@{$self->{option_results}->{proto}}) : 'http'; $self->{proto} = (defined($self->{option_results}->{proto})) ? shift(@{$self->{option_results}->{proto}}) : 'https';
$self->{url_path} = (defined($self->{option_results}->{url_path})) ? shift(@{$self->{option_results}->{url_path}}) : '/webacs/api/v1/data/'; $self->{url_path} = (defined($self->{option_results}->{url_path})) ? shift(@{$self->{option_results}->{url_path}}) : '/webacs/api/v1/data/';
$self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : ''; $self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : '';
$self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : ''; $self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : '';
@ -142,19 +142,13 @@ sub cache_ap {
my $timestamp_cache = $options{statefile}->get(name => 'last_timestamp'); my $timestamp_cache = $options{statefile}->get(name => 'last_timestamp');
my $ap = $options{statefile}->get(name => 'ap'); my $ap = $options{statefile}->get(name => 'ap');
if ($has_cache_file == 0 || !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($options{reload_cache_time}) * 60))) { if ($has_cache_file == 0 || !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($options{reload_cache_time}) * 60))) {
$ap = {}; $ap = $self->get(function => 'AccessPoints', object => 'accessPointsDTO', key => 'name',
my $datas = { last_timestamp => time(), ap => $ap };
my $result = $self->get(function => 'AccessPoints', object => 'accessPointsDTO', key => 'name',
fields => ['adminStatus', 'clientCount', 'controllerName', 'lwappUpTime', 'status', 'upTime']); fields => ['adminStatus', 'clientCount', 'controllerName', 'lwappUpTime', 'status', 'upTime']);
if (defined($result->{result}->{rows})) { my $datas = { last_timestamp => time(), ap => $ap };
foreach (@{$result->{result}->{rows}}) {
$environments->{$_->{id}} = $_->{name};
}
}
$options{statefile}->write(data => $datas); $options{statefile}->write(data => $datas);
} }
return $environments; return $ap;
} }
sub get { sub get {
@ -164,7 +158,7 @@ sub get {
my ($result, $first_result, $max_results) = ({}, 0, 1000); my ($result, $first_result, $max_results) = ({}, 0, 1000);
while (1) { while (1) {
my $response = $self->{http}->request(url_path => $self->{option_results}->{url_path} . $options{function} .'.json?.full=true&.sort=' . $options{key} . '&.firstResult=' . $firstResult . '&.maxResults=' . $max_results, my $response = $self->{http}->request(url_path => $self->{url_path} . $options{function} .'.json?.full=true&.sort=' . $options{key} . '&.firstResult=' . $first_result . '&.maxResults=' . $max_results,
critical_status => '', warning_status => ''); critical_status => '', warning_status => '');
my $content; my $content;
eval { eval {
@ -184,9 +178,9 @@ sub get {
} }
foreach (@{$content->{queryResponse}->{entity}}) { foreach (@{$content->{queryResponse}->{entity}}) {
$result->{$_->{$options{key}} = {}; $result->{$_->{$options{object}}->{$options{key}}} = {};
foreach my $field (@{$options{fields}}) { foreach my $field (@{$options{fields}}) {
$result->{$_->{$options{key}}->{$field} = $_->{$options{object}}>{$field} $result->{$_->{$options{object}}->{$options{key}}}->{$field} = $_->{$options{object}}->{$field}
if (defined($_->{$options{object}}->{$field})); if (defined($_->{$options{object}}->{$field}));
} }
} }
@ -219,11 +213,11 @@ Cisco Prime hostname.
=item B<--port> =item B<--port>
Port used (Default: 80) Port used (Default: 443)
=item B<--proto> =item B<--proto>
Specify https if needed (Default: 'http') Specify https if needed (Default: 'https')
=item B<--url-path> =item B<--url-path>

View File

@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc;
use centreon::plugins::statefile; use centreon::plugins::statefile;
my $instance_mode; my $instance_mode;
@ -37,11 +38,11 @@ sub custom_status_threshold {
local $SIG{__WARN__} = sub { $message = $_[0]; }; local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; }; local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && if (defined($instance_mode->{option_results}->{critical_ap_status}) && $instance_mode->{option_results}->{critical_ap_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") { eval "$instance_mode->{option_results}->{critical_ap_status}") {
$status = 'critical'; $status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && } elsif (defined($instance_mode->{option_results}->{warning_ap_status}) && $instance_mode->{option_results}->{warning_ap_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") { eval "$instance_mode->{option_results}->{warning_ap_status}") {
$status = 'warning'; $status = 'warning';
} }
}; };
@ -54,10 +55,7 @@ sub custom_status_threshold {
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = 'status : ' . $self->{result_values}->{status}; my $msg = 'status : ' . $self->{result_values}->{status} . '(admin: ' . $self->{result_values}->{admin_status} . ')';
if ($self->{result_values}->{information} ne '') {
$msg .= ' [information: ' . $self->{result_values}->{information} . ']';
}
return $msg; return $msg;
} }
@ -67,15 +65,26 @@ sub custom_status_calc {
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'}; $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
$self->{result_values}->{environment} = $options{new_datas}->{$self->{instance} . '_environment'}; $self->{result_values}->{controller} = $options{new_datas}->{$self->{instance} . '_controller'};
$self->{result_values}->{application} = $options{new_datas}->{$self->{instance} . '_application'}; $self->{result_values}->{admin_status} = $options{new_datas}->{$self->{instance} . '_admin_status'};
$self->{result_values}->{exit_code} = $options{new_datas}->{$self->{instance} . '_exit_code'};
$self->{result_values}->{family} = $options{new_datas}->{$self->{instance} . '_family'};
$self->{result_values}->{information} = $options{new_datas}->{$self->{instance} . '_information'};
return 0; return 0;
} }
sub custom_uptime_output {
my ($self, %options) = @_;
my $msg = 'uptime started since : ' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{uptime});
return $msg;
}
sub custom_lwappuptime_output {
my ($self, %options) = @_;
my $msg = 'uptime started since : ' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{lwapp_uptime});
return $msg;
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -86,8 +95,7 @@ sub set_counters {
$self->{maps_counters}->{ap} = [ $self->{maps_counters}->{ap} = [
{ label => 'ap-status', threshold => 0, set => { { label => 'ap-status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'name' }, { name => 'environment' }, key_values => [ { name => 'status' }, { name => 'name' }, { name => 'controller' }, { name => 'admin_status' } ],
{ name => 'application' }, { name => 'exit_code' }, { name => 'family' }, { name => 'information' } ],
closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
@ -95,11 +103,29 @@ sub set_counters {
} }
}, },
{ label => 'ap-clients', set => { { label => 'ap-clients', set => {
key_values => [ { name => 'error' }, { name => 'total' } ], key_values => [ { name => 'client_count' }, { name => 'name' } ],
output_template => 'Error : %s', output_template => 'Clients : %s',
perfdatas => [ perfdatas => [
{ label => 'total_error', value => 'error_absolute', template => '%s', { label => 'ap_clients', value => 'client_count_absolute', template => '%s',
min => 0, max => 'total_absolute' }, min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'ap-uptime', set => {
key_values => [ { name => 'uptime' }, { name => 'name' } ],
closure_custom_output => $self->can('custom_uptime_output'),
perfdatas => [
{ label => 'ap_uptime', value => 'uptime_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'ap-lwappuptime', set => {
key_values => [ { name => 'lwapp_uptime' }, { name => 'name' } ],
closure_custom_output => $self->can('custom_lwappuptime_output'),
perfdatas => [
{ label => 'ap_lwappuptime', value => 'lwapp_uptime_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
], ],
} }
}, },
@ -107,11 +133,11 @@ sub set_counters {
$self->{maps_counters}->{ctrl} = [ $self->{maps_counters}->{ctrl} = [
{ label => 'ctrl-ap-count', set => { { label => 'ctrl-ap-count', set => {
key_values => [ { name => 'error' }, { name => 'total' } ], key_values => [ { name => 'ap_count' }, { name => 'name' } ],
output_template => 'Error : %s', output_template => 'Number of access points : %s',
perfdatas => [ perfdatas => [
{ label => 'total_error', value => 'error_absolute', template => '%s', { label => 'ctrl_ap_count', value => 'ap_count_absolute', template => '%s',
min => 0, max => 'total_absolute' }, min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
], ],
} }
}, },
@ -128,8 +154,8 @@ sub new {
{ {
"filter-controller:s" => { name => 'filter_controller' }, "filter-controller:s" => { name => 'filter_controller' },
"filter-ap:s" => { name => 'filter_ap' }, "filter-ap:s" => { name => 'filter_ap' },
"warning-status:s" => { name => 'warning_status' }, "warning-ap-status:s" => { name => 'warning_ap_status', default => '%{admin_status} =~ /enable/i && %{status} =~ /minor|warning/i' },
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Error/i' }, "critical-ap-status:s" => { name => 'critical_ap_status', default => '%{admin_status} =~ /enable/i && %{status} =~ /major|critical/i' },
"reload-cache-time:s" => { name => 'reload_cache_time', default => 180 }, "reload-cache-time:s" => { name => 'reload_cache_time', default => 180 },
}); });
$self->{statefile_cache_ap} = centreon::plugins::statefile->new(%options); $self->{statefile_cache_ap} = centreon::plugins::statefile->new(%options);
@ -161,7 +187,7 @@ sub prefix_ap_output {
sub change_macros { sub change_macros {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach (('warning_status', 'critical_status')) { foreach (('warning_ap_status', 'critical_ap_status')) {
if (defined($self->{option_results}->{$_})) { if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
} }
@ -196,6 +222,9 @@ sub manage_selection {
lwapp_uptime => $access_points->{$ap_name}->{lwappUpTime}, lwapp_uptime => $access_points->{$ap_name}->{lwappUpTime},
uptime => $access_points->{$ap_name}->{upTime}, uptime => $access_points->{$ap_name}->{upTime},
}; };
$self->{ctrl}->{$access_points->{$ap_name}->{controllerName}} = { ap_count => 0 }
if (!defined($self->{ctrl}->{$access_points->{$ap_name}->{controllerName}}));
$self->{ctrl}->{$access_points->{$ap_name}->{controllerName}}->{ap_count}++;
} }
if (scalar(keys %{$self->{ap}}) <= 0) { if (scalar(keys %{$self->{ap}}) <= 0) {
@ -239,17 +268,15 @@ Threshold critical.
Can be: 'total-error', 'total-running', 'total-unplanned', Can be: 'total-error', 'total-running', 'total-unplanned',
'total-finished', 'total-coming'. 'total-finished', 'total-coming'.
=item B<--warning-status> =item B<--warning-ap-status>
Set warning threshold for status (Default: -) Set warning threshold for status (Default: '%{admin_status} =~ /enable/i && %{status} =~ /minor|warning/i')
Can used special variables like: %{name}, %{status}, Can used special variables like: %{name}, %{status}, %{controller}, %{admin_status}
%{exit_code}, %{family}, %{information}, %{environment}, %{application}
=item B<--critical-status> =item B<--critical-ap-status>
Set critical threshold for status (Default: '%{exit_code} =~ /Error/i'). Set critical threshold for status (Default: '%{admin_status} =~ /enable/i && %{status} =~ /major|critical/i').
Can used special variables like: %{name}, %{status}, Can used special variables like: %{name}, %{status}, %{controller}, %{admin_status}
%{exit_code}, %{family}, %{information}, %{environment}, %{application}
=item B<--reload-cache-time> =item B<--reload-cache-time>