freebox plugin: wip
This commit is contained in:
parent
d9b4e82be2
commit
d108499020
|
@ -49,7 +49,7 @@ sub new {
|
|||
"freebox-api-version:s@" => { name => 'freebox_api_version', },
|
||||
"proxyurl:s@" => { name => 'proxyurl' },
|
||||
"timeout:s@" => { name => 'timeout' },
|
||||
"precision:s@" => { name => 'precision' },
|
||||
"resolution:s@" => { name => 'resolution' },
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
|
||||
|
@ -208,7 +208,40 @@ sub get_data {
|
|||
sub get_performance {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($self->{session_token})) {
|
||||
$self->get_session();
|
||||
}
|
||||
|
||||
my $json_request = { db => $options{db}, date_start => time() - $self->{resolution}, precision => 100 };
|
||||
my $encoded;
|
||||
eval {
|
||||
$encoded = encode_json($json_request);
|
||||
};
|
||||
if ($@) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot encode json request");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->settings();
|
||||
my $content = $self->{http}->request(url_path => '/api/' . $self->{freebox_api_version} . '/' . $options{path},
|
||||
method => 'POST', query_form_post => $encoded,
|
||||
critical_status => '', warning_status => '');
|
||||
my $decoded = $self->manage_response(content => $content);
|
||||
my ($datas, $total) = ({}, 0);
|
||||
foreach my $data (@{$decoded->{result}->{datas}}) {
|
||||
foreach my $label (keys %$data) {
|
||||
next if ($label eq 'time');
|
||||
$datas->{label} = 0 if (!defined($datas->{$label}));
|
||||
$datas->{label} += $datas->{$label};
|
||||
}
|
||||
$total++;
|
||||
}
|
||||
|
||||
foreach (keys %$datas) {
|
||||
$datas->{$_} /= $total;
|
||||
}
|
||||
|
||||
return $datas;
|
||||
}
|
||||
|
||||
sub DESTROY {
|
||||
|
@ -259,7 +292,7 @@ Proxy URL if any.
|
|||
|
||||
Set HTTP timeout in seconds (Default: '10').
|
||||
|
||||
=item B<--precision>
|
||||
=item B<--resolution>
|
||||
|
||||
Selected data performance resolution in seconds (Default: '300').
|
||||
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
#
|
||||
# Copyright 2017 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package network::freebox::restapi::mode::dslusage;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0 },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'rate-up', set => {
|
||||
key_values => [ { name => 'rate_up' } ],
|
||||
output_template => 'Dsl available upload bandwidth : %.2f %s/s',
|
||||
output_change_bytes => 2,
|
||||
perfdatas => [
|
||||
{ label => 'rate_up', value => 'rate_up_absolute', template => '%.2f',
|
||||
unit => 'b/s', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'rate-down', set => {
|
||||
key_values => [ { name => 'rate_down' } ],
|
||||
output_template => 'Dsl available download bandwidth : %.2f %s/s',
|
||||
output_change_bytes => 2,
|
||||
perfdatas => [
|
||||
{ label => 'rate_down', value => 'rate_down_absolute', template => '%.2f',
|
||||
unit => 'b/s', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'snr-up', set => {
|
||||
key_values => [ { name => 'snr_up' } ],
|
||||
output_template => 'Dsl upload signal/noise ratio : %.2f dB',
|
||||
output_change_bytes => 2,
|
||||
perfdatas => [
|
||||
{ label => 'snr_up', value => 'snr_up_absolute', template => '%.2f',
|
||||
unit => 'dB' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'snr-down', set => {
|
||||
key_values => [ { name => 'snr_down' } ],
|
||||
output_template => 'Dsl download signal/noise ratio : %.2f dB',
|
||||
output_change_bytes => 2,
|
||||
perfdatas => [
|
||||
{ label => 'snr_down', value => 'snr_down_absolute', template => '%.2f',
|
||||
unit => 'dB' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $result = $options{custom}->get_performance(db => 'dsl', path => 'rrd/');
|
||||
$result->{snr_up} *= 10 if (defined($result->{snr_up}));
|
||||
$result->{snr_down} *= 10 if (defined($result->{snr_down}));
|
||||
$self->{global} = { %{$result} };
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check dsl usage.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-counters>
|
||||
|
||||
Only display some counters (regexp can be used).
|
||||
Example: --filter-counters='^rate-up$'
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'rate-up', 'rate-down', 'snr-up', 'snr-down'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'rate-up', 'rate-down', 'snr-up', 'snr-down'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,146 @@
|
|||
#
|
||||
# Copyright 2017 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package network::freebox::restapi::mode::netusage;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0 },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'bw-up', set => {
|
||||
key_values => [ { name => 'bw_up' } ],
|
||||
output_template => 'Upload available bandwidth : %.2f %s/s',
|
||||
output_change_bytes => 2,
|
||||
perfdatas => [
|
||||
{ label => 'bw_up', value => 'bw_up_absolute', template => '%.2f',
|
||||
unit => 'b/s', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'bw-down', set => {
|
||||
key_values => [ { name => 'bw_down' } ],
|
||||
output_template => 'Download available bandwidth : %.2f %s/s',
|
||||
output_change_bytes => 2,
|
||||
perfdatas => [
|
||||
{ label => 'bw_down', value => 'bw_down_absolute', template => '%.2f',
|
||||
unit => 'b/s', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'rate-up', set => {
|
||||
key_values => [ { name => 'rate_up' } ],
|
||||
output_template => 'Upload rate : %.2f %s/s',
|
||||
output_change_bytes => 2,
|
||||
perfdatas => [
|
||||
{ label => 'rate_up', value => 'rate_up_absolute', template => '%.2f',
|
||||
unit => 'b/s', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'rate-down', set => {
|
||||
key_values => [ { name => 'rate_down' } ],
|
||||
output_template => 'Download rate : %.2f %s/s',
|
||||
output_change_bytes => 2,
|
||||
perfdatas => [
|
||||
{ label => 'rate_down', value => 'rate_down_absolute', template => '%.2f',
|
||||
unit => 'b/s', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'vpn-rate-up', set => {
|
||||
key_values => [ { name => 'vpn_rate_up' } ],
|
||||
output_template => 'Vpn client upload rate : %.2f %s/s',
|
||||
output_change_bytes => 2,
|
||||
perfdatas => [
|
||||
{ label => 'vpn_rate_up', value => 'vpn_rate_up_absolute', template => '%.2f',
|
||||
unit => 'b/s', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'vpn-rate-down', set => {
|
||||
key_values => [ { name => 'vpn_rate_down' } ],
|
||||
output_template => 'Vpn client download rate : %.2f %s/s',
|
||||
output_change_bytes => 2,
|
||||
perfdatas => [
|
||||
{ label => 'vpn_rate_down', value => 'vpn_rate_down_absolute', template => '%.2f',
|
||||
unit => 'b/s', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $result = $options{custom}->get_performance(db => 'net', path => 'rrd/');
|
||||
$self->{global} = { %{$result} };
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check network usage.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-counters>
|
||||
|
||||
Only display some counters (regexp can be used).
|
||||
Example: --filter-counters='^bw-up$'
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'bw-up', 'bw-down', 'rate-up', 'rate-down', 'vpn-rate-up', 'vpn-rate-down'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'bw-up', 'bw-down', 'rate-up', 'rate-down', 'vpn-rate-up', 'vpn-rate-down'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -31,8 +31,10 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
%{$self->{modes}} = (
|
||||
'system' => 'network::freebox::restapi::mode::system',
|
||||
);
|
||||
'dsl-usage' => 'network::freebox::restapi::mode::dslusage',
|
||||
'net-usage' => 'network::freebox::restapi::mode::netusage',
|
||||
'system' => 'network::freebox::restapi::mode::system',
|
||||
);
|
||||
|
||||
$self->{custom_modes}{api} = 'network::freebox::restapi::custom::api';
|
||||
return $self;
|
||||
|
|
Loading…
Reference in New Issue