This commit is contained in:
garnier-quentin 2020-04-20 17:53:03 +02:00
parent 094767f041
commit 1fa79d31a6
4 changed files with 100 additions and 112 deletions

View File

@ -214,15 +214,18 @@ sub get_performance {
$encoded = encode_json($json_request); $encoded = encode_json($json_request);
}; };
if ($@) { if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot encode json request"); $self->{output}->add_option_msg(short_msg => 'Cannot encode json request');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->settings(); $self->settings();
my $content = $self->{http}->request(url_path => '/api/' . $self->{freebox_api_version} . '/' . $options{path}, my $content = $self->{http}->request(
method => 'POST', query_form_post => $encoded, url_path => '/api/' . $self->{freebox_api_version} . '/' . $options{path},
critical_status => '', warning_status => '', unknown_status => ''); method => 'POST', query_form_post => $encoded,
critical_status => '', warning_status => '', unknown_status => ''
);
my $decoded = $self->manage_response(content => $content); my $decoded = $self->manage_response(content => $content);
my ($datas, $total) = ({}, 0); my ($datas, $total) = ({}, 0);
foreach my $data (@{$decoded->{result}->{data}}) { foreach my $data (@{$decoded->{result}->{data}}) {
foreach my $label (keys %$data) { foreach my $label (keys %$data) {
@ -233,9 +236,7 @@ sub get_performance {
$total++; $total++;
} }
foreach (keys %$datas) { $datas->{$_} = $datas->{$_} / $total / 100 foreach (keys %$datas);
$datas->{$_} /= $total;
}
return $datas; return $datas;
} }

View File

@ -27,7 +27,7 @@ use warnings;
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0 }, { name => 'global', type => 0 },
]; ];
@ -38,9 +38,9 @@ sub set_counters {
output_template => 'Dsl available upload bandwidth : %.2f %s/s', output_template => 'Dsl available upload bandwidth : %.2f %s/s',
output_change_bytes => 2, output_change_bytes => 2,
perfdatas => [ perfdatas => [
{ label => 'rate_up', value => 'rate_up_absolute', template => '%.2f', { label => 'rate_up', value => 'rate_up_absolute', template => '%s',
unit => 'b/s', min => 0 }, unit => 'b/s', min => 0 }
], ]
} }
}, },
{ label => 'rate-down', set => { { label => 'rate-down', set => {
@ -48,9 +48,9 @@ sub set_counters {
output_template => 'Dsl available download bandwidth : %.2f %s/s', output_template => 'Dsl available download bandwidth : %.2f %s/s',
output_change_bytes => 2, output_change_bytes => 2,
perfdatas => [ perfdatas => [
{ label => 'rate_down', value => 'rate_down_absolute', template => '%.2f', { label => 'rate_down', value => 'rate_down_absolute', template => '%s',
unit => 'b/s', min => 0 }, unit => 'b/s', min => 0 }
], ]
} }
}, },
{ label => 'snr-up', set => { { label => 'snr-up', set => {
@ -59,8 +59,8 @@ sub set_counters {
output_change_bytes => 2, output_change_bytes => 2,
perfdatas => [ perfdatas => [
{ label => 'snr_up', value => 'snr_up_absolute', template => '%.2f', { label => 'snr_up', value => 'snr_up_absolute', template => '%.2f',
unit => 'dB' }, unit => 'dB' }
], ]
} }
}, },
{ label => 'snr-down', set => { { label => 'snr-down', set => {
@ -69,10 +69,10 @@ sub set_counters {
output_change_bytes => 2, output_change_bytes => 2,
perfdatas => [ perfdatas => [
{ label => 'snr_down', value => 'snr_down_absolute', template => '%.2f', { label => 'snr_down', value => 'snr_down_absolute', template => '%.2f',
unit => 'dB' }, unit => 'dB' }
], ]
} }
}, }
]; ];
} }
@ -80,21 +80,23 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ });
});
return $self; return $self;
} }
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $result = $options{custom}->get_performance(db => 'dsl', path => 'rrd/'); $self->{global} = $options{custom}->get_performance(db => 'dsl', path => 'rrd/');
$result->{snr_up} *= 10 if (defined($result->{snr_up})); $self->{global}->{snr_up} *= 10 if (defined($self->{global}->{snr_up}));
$result->{snr_down} *= 10 if (defined($result->{snr_down})); $self->{global}->{snr_down} *= 10 if (defined($self->{global}->{snr_down}));
$self->{global} = { %{$result} }; $self->{global}->{rate_up} *= int($self->{global}->{rate_up} * 8)
if (defined($self->{global}->{rate_up}));
$self->{global}->{rate_down} *= int($self->{global}->{rate_down} * 8)
if (defined($self->{global}->{rate_down}));
} }
1; 1;
@ -112,14 +114,9 @@ Check dsl usage.
Only display some counters (regexp can be used). Only display some counters (regexp can be used).
Example: --filter-counters='^rate-up$' Example: --filter-counters='^rate-up$'
=item B<--warning-*> =item B<--warning-*> B<--critical-*>
Threshold warning. Thresholds.
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'. Can be: 'rate-up', 'rate-down', 'snr-up', 'snr-down'.
=back =back

View File

@ -27,9 +27,9 @@ use warnings;
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, { name => 'global', type => 0, skipped_code => { -10 => 1 } }
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
@ -38,9 +38,9 @@ sub set_counters {
output_template => 'Upload available bandwidth : %.2f %s/s', output_template => 'Upload available bandwidth : %.2f %s/s',
output_change_bytes => 2, output_change_bytes => 2,
perfdatas => [ perfdatas => [
{ label => 'bw_up', value => 'bw_up_absolute', template => '%.2f', { label => 'bw_up', value => 'bw_up_absolute', template => '%s',
unit => 'b/s', min => 0 }, unit => 'b/s', min => 0 }
], ]
} }
}, },
{ label => 'bw-down', set => { { label => 'bw-down', set => {
@ -48,9 +48,9 @@ sub set_counters {
output_template => 'Download available bandwidth : %.2f %s/s', output_template => 'Download available bandwidth : %.2f %s/s',
output_change_bytes => 2, output_change_bytes => 2,
perfdatas => [ perfdatas => [
{ label => 'bw_down', value => 'bw_down_absolute', template => '%.2f', { label => 'bw_down', value => 'bw_down_absolute', template => '%s',
unit => 'b/s', min => 0 }, unit => 'b/s', min => 0 }
], ]
} }
}, },
{ label => 'rate-up', set => { { label => 'rate-up', set => {
@ -58,9 +58,9 @@ sub set_counters {
output_template => 'Upload rate : %.2f %s/s', output_template => 'Upload rate : %.2f %s/s',
output_change_bytes => 2, output_change_bytes => 2,
perfdatas => [ perfdatas => [
{ label => 'rate_up', value => 'rate_up_absolute', template => '%.2f', { label => 'rate_up', value => 'rate_up_absolute', template => '%s',
unit => 'b/s', min => 0 }, unit => 'b/s', min => 0 }
], ]
} }
}, },
{ label => 'rate-down', set => { { label => 'rate-down', set => {
@ -68,9 +68,9 @@ sub set_counters {
output_template => 'Download rate : %.2f %s/s', output_template => 'Download rate : %.2f %s/s',
output_change_bytes => 2, output_change_bytes => 2,
perfdatas => [ perfdatas => [
{ label => 'rate_down', value => 'rate_down_absolute', template => '%.2f', { label => 'rate_down', value => 'rate_down_absolute', template => '%s',
unit => 'b/s', min => 0 }, unit => 'b/s', min => 0 }
], ]
} }
}, },
{ label => 'vpn-rate-up', set => { { label => 'vpn-rate-up', set => {
@ -78,21 +78,21 @@ sub set_counters {
output_template => 'Vpn client upload rate : %.2f %s/s', output_template => 'Vpn client upload rate : %.2f %s/s',
output_change_bytes => 2, output_change_bytes => 2,
perfdatas => [ perfdatas => [
{ label => 'vpn_rate_up', value => 'vpn_rate_up_absolute', template => '%.2f', { label => 'vpn_rate_up', value => 'vpn_rate_up_absolute', template => '%s',
unit => 'b/s', min => 0 }, unit => 'b/s', min => 0 }
], ]
} }
}, },
{ label => 'vpn-rate-down', set => { { label => 'vpn-rate-down', set => {
key_values => [ { name => 'vpn_rate_down' } ], key_values => [ { name => 'vpn_rate_down' } ],
output_template => 'Vpn client download rate : %.2f %s/s', output_template => 'Vpn client download rate : %.2f %s/s',
output_change_bytes => 2, output_change_bytes => 2,
perfdatas => [ perfdatas => [
{ label => 'vpn_rate_down', value => 'vpn_rate_down_absolute', template => '%.2f', { label => 'vpn_rate_down', value => 'vpn_rate_down_absolute', template => '%s',
unit => 'b/s', min => 0 }, unit => 'b/s', min => 0 }
], ]
} }
}, }
]; ];
} }
@ -100,19 +100,18 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ });
});
return $self; return $self;
} }
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $result = $options{custom}->get_performance(db => 'net', path => 'rrd/'); $self->{global} = $options{custom}->get_performance(db => 'net', path => 'rrd/');
$self->{global} = { %{$result} }; $self->{global}->{$_} = int($self->{global}->{$_} * 8) foreach (keys %{$self->{global}});
} }
1; 1;
@ -130,14 +129,9 @@ Check network usage.
Only display some counters (regexp can be used). Only display some counters (regexp can be used).
Example: --filter-counters='^bw-up$' Example: --filter-counters='^bw-up$'
=item B<--warning-*> =item B<--warning-*> B<--critical-*>
Threshold warning. Thresholds.
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'. Can be: 'bw-up', 'bw-down', 'rate-up', 'rate-down', 'vpn-rate-up', 'vpn-rate-down'.
=back =back

View File

@ -28,20 +28,20 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0 }, { name => 'global', type => 0 },
{ name => 'wifi', type => 1, cb_prefix_output => 'prefix_wifi_output', message_multiple => 'All wifis are ok' } { name => 'wifi', type => 1, cb_prefix_output => 'prefix_wifi_output', message_multiple => 'All wifis are ok' }
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'temperature-cpum', set => { { label => 'temperature-cpum', set => {
key_values => [ { name => 'temp_cpum' } ], key_values => [ { name => 'temp_cpum' } ],
output_template => 'Temperature cpum : %s C', output_template => 'Temperature cpum : %s C',
perfdatas => [ perfdatas => [
{ label => 'temp_cpum', value => 'temp_cpum_absolute', template => '%s', { label => 'temp_cpum', value => 'temp_cpum_absolute', template => '%s',
unit => 'C' }, unit => 'C' }
], ]
} }
}, },
{ label => 'temperature-cpub', set => { { label => 'temperature-cpub', set => {
@ -49,8 +49,8 @@ sub set_counters {
output_template => 'Temperature cpub : %s C', output_template => 'Temperature cpub : %s C',
perfdatas => [ perfdatas => [
{ label => 'temp_cpub', value => 'temp_cpub_absolute', template => '%s', { label => 'temp_cpub', value => 'temp_cpub_absolute', template => '%s',
unit => 'C' }, unit => 'C' }
], ]
} }
}, },
{ label => 'temperature-switch', set => { { label => 'temperature-switch', set => {
@ -58,8 +58,8 @@ sub set_counters {
output_template => 'Temperature switch : %s C', output_template => 'Temperature switch : %s C',
perfdatas => [ perfdatas => [
{ label => 'temp_sw', value => 'temp_sw_absolute', template => '%s', { label => 'temp_sw', value => 'temp_sw_absolute', template => '%s',
unit => 'C' }, unit => 'C' }
], ]
} }
}, },
{ label => 'fan-speed', set => { { label => 'fan-speed', set => {
@ -67,8 +67,8 @@ sub set_counters {
output_template => 'fan speed : %s rpm', output_template => 'fan speed : %s rpm',
perfdatas => [ perfdatas => [
{ label => 'fan_rpm', value => 'fan_rpm_absolute', template => '%s', { label => 'fan_rpm', value => 'fan_rpm_absolute', template => '%s',
min => 0, unit => 'rpm' }, min => 0, unit => 'rpm' }
], ]
} }
}, },
{ label => 'disk-status', threshold => 0, set => { { label => 'disk-status', threshold => 0, set => {
@ -76,10 +76,9 @@ sub set_counters {
closure_custom_calc => $self->can('custom_disk_status_calc'), closure_custom_calc => $self->can('custom_disk_status_calc'),
closure_custom_output => $self->can('custom_disk_status_output'), closure_custom_output => $self->can('custom_disk_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold
} }
}, }
]; ];
$self->{maps_counters}->{wifi} = [ $self->{maps_counters}->{wifi} = [
@ -88,17 +87,16 @@ sub set_counters {
closure_custom_calc => $self->can('custom_wifi_status_calc'), closure_custom_calc => $self->can('custom_wifi_status_calc'),
closure_custom_output => $self->can('custom_wifi_status_output'), closure_custom_output => $self->can('custom_wifi_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold
} }
}, }
]; ];
} }
sub custom_disk_status_output { sub custom_disk_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = 'Disk status : ' . $self->{result_values}->{status};
return $msg; return 'Disk status : ' . $self->{result_values}->{status};
} }
sub custom_disk_status_calc { sub custom_disk_status_calc {
@ -110,9 +108,8 @@ sub custom_disk_status_calc {
sub custom_wifi_status_output { sub custom_wifi_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = "Wifi '" . $self->{result_values}->{display} . "' status : " . $self->{result_values}->{status};
return $msg; return "Wifi '" . $self->{result_values}->{display} . "' status : " . $self->{result_values}->{status};
} }
sub custom_wifi_status_calc { sub custom_wifi_status_calc {
@ -127,15 +124,14 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'warning-wifi-status:s' => { name => 'warning_wifi_status', default => '%{status} =~ /bad_param/i' },
"warning-wifi-status:s" => { name => 'warning_wifi_status', default => '%{status} =~ /bad_param/i' }, 'critical-wifi-status:s' => { name => 'critical_wifi_status', default => '%{status} =~ /failed/i' },
"critical-wifi-status:s" => { name => 'critical_wifi_status', default => '%{status} =~ /failed/i' }, 'warning-disk-status:s' => { name => 'warning_disk_status', default => '' },
"warning-disk-status:s" => { name => 'warning_disk_status', default => '' }, 'critical-disk-status:s' => { name => 'critical_disk_status', default => '%{status} =~ /error/i' },
"critical-disk-status:s" => { name => 'critical_disk_status', default => '%{status} =~ /error/i' }, });
});
return $self; return $self;
} }
@ -143,18 +139,23 @@ sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::check_options(%options); $self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_wifi_status', 'critical_wifi_status', 'warning_disk_status', 'critical_disk_status']); $self->change_macros(
macros => [
'warning_wifi_status', 'critical_wifi_status',
'warning_disk_status', 'critical_disk_status'
]
);
} }
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $result = $options{custom}->get_data(path => 'system/'); my $result = $options{custom}->get_data(path => 'system/');
$self->{global} = { %{$result} }; $self->{global} = { %{$result} };
$result = $options{custom}->get_data(path => 'wifi/ap/'); $result = $options{custom}->get_data(path => 'wifi/ap/');
$self->{wifi} = {}; $self->{wifi} = {};
$result = [$result] if (ref($result) ne 'ARRAY'); $result = [$result] if (ref($result) ne 'ARRAY');
foreach (@$result) { foreach (@$result) {
$self->{wifi}->{$_->{id}} = { $self->{wifi}->{$_->{id}} = {
@ -199,14 +200,9 @@ Can used special variables like: %{status}
Set critical threshold for disk status (Default: '%{status} =~ /error/i'). Set critical threshold for disk status (Default: '%{status} =~ /error/i').
Can used special variables like: %{status} Can used special variables like: %{status}
=item B<--warning-*> =item B<--warning-*> B<--critical-*>
Threshold warning. Thresholds.
Can be: 'temperature-cpum', 'temperature-cpub', 'temperature-switch', 'fan-speed'.
=item B<--critical-*>
Threshold critical.
Can be: 'temperature-cpum', 'temperature-cpub', 'temperature-switch', 'fan-speed'. Can be: 'temperature-cpum', 'temperature-cpub', 'temperature-switch', 'fan-speed'.
=back =back