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);
};
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->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 => '', unknown_status => '');
my $content = $self->{http}->request(
url_path => '/api/' . $self->{freebox_api_version} . '/' . $options{path},
method => 'POST', query_form_post => $encoded,
critical_status => '', warning_status => '', unknown_status => ''
);
my $decoded = $self->manage_response(content => $content);
my ($datas, $total) = ({}, 0);
foreach my $data (@{$decoded->{result}->{data}}) {
foreach my $label (keys %$data) {
@ -233,9 +236,7 @@ sub get_performance {
$total++;
}
foreach (keys %$datas) {
$datas->{$_} /= $total;
}
$datas->{$_} = $datas->{$_} / $total / 100 foreach (keys %$datas);
return $datas;
}

View File

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

View File

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

View File

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