226 lines
7.5 KiB
Perl
226 lines
7.5 KiB
Perl
|
#
|
||
|
# 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::system;
|
||
|
|
||
|
use base qw(centreon::plugins::templates::counter);
|
||
|
|
||
|
use strict;
|
||
|
use warnings;
|
||
|
my $instance_mode;
|
||
|
|
||
|
sub set_counters {
|
||
|
my ($self, %options) = @_;
|
||
|
|
||
|
$self->{maps_counters_type} = [
|
||
|
{ name => 'global', type => 0 },
|
||
|
];
|
||
|
|
||
|
$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' },
|
||
|
],
|
||
|
}
|
||
|
},
|
||
|
{ label => 'temperature-cpub', set => {
|
||
|
key_values => [ { name => 'temp_cpub' } ],
|
||
|
output_template => 'Temperature cpub : %s C',
|
||
|
perfdatas => [
|
||
|
{ label => 'temp_cpub', value => 'temp_cpub_absolute', template => '%s',
|
||
|
unit => 'C' },
|
||
|
],
|
||
|
}
|
||
|
},
|
||
|
{ label => 'temperature-switch', set => {
|
||
|
key_values => [ { name => 'temp_sw' } ],
|
||
|
output_template => 'Temperature switch : %s C',
|
||
|
perfdatas => [
|
||
|
{ label => 'temp_sw', value => 'temp_sw_absolute', template => '%s',
|
||
|
unit => 'C' },
|
||
|
],
|
||
|
}
|
||
|
},
|
||
|
{ label => 'fan-speed', set => {
|
||
|
key_values => [ { name => 'fan_rpm' } ],
|
||
|
output_template => 'fan speed : %s rpm',
|
||
|
perfdatas => [
|
||
|
{ label => 'fan_rpm', value => 'fan_rpm_absolute', template => '%s',
|
||
|
min => 0, unit => 'rpm' },
|
||
|
],
|
||
|
}
|
||
|
},
|
||
|
{ label => 'disk-status', threshold => 0, set => {
|
||
|
key_values => [ { name => 'disk_status' } ],
|
||
|
closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc_extra_options => { label_ref => 'disk' },
|
||
|
closure_custom_output => $self->can('custom_status_output'),
|
||
|
closure_custom_perfdata => sub { return 0; },
|
||
|
closure_custom_threshold_check => $self->can('custom_status_threshold'),
|
||
|
}
|
||
|
},
|
||
|
{ label => 'wifi-status', threshold => 0, set => {
|
||
|
key_values => [ { name => 'wifi_status' } ],
|
||
|
closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc_extra_options => { label_ref => 'wifi' },
|
||
|
closure_custom_output => $self->can('custom_status_output'),
|
||
|
closure_custom_perfdata => sub { return 0; },
|
||
|
closure_custom_threshold_check => $self->can('custom_status_threshold'),
|
||
|
}
|
||
|
},
|
||
|
];
|
||
|
}
|
||
|
|
||
|
sub custom_status_threshold {
|
||
|
my ($self, %options) = @_;
|
||
|
my $status = 'ok';
|
||
|
my $message;
|
||
|
|
||
|
eval {
|
||
|
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
||
|
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
||
|
|
||
|
my $label = $self->{label};
|
||
|
$label =~ s/-/_/g;
|
||
|
if (defined($instance_mode->{option_results}->{'critical_' . $label}) && $instance_mode->{option_results}->{'critical_' . $label} ne '' &&
|
||
|
eval "$instance_mode->{option_results}->{'critical_' . $label}") {
|
||
|
$status = 'critical';
|
||
|
} elsif (defined($instance_mode->{option_results}->{'warning_' . $label}) && $instance_mode->{option_results}->{'warning_' . $label} ne '' &&
|
||
|
eval "$instance_mode->{option_results}->{'warning_' . $label}") {
|
||
|
$status = 'warning';
|
||
|
}
|
||
|
};
|
||
|
if (defined($message)) {
|
||
|
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
||
|
}
|
||
|
|
||
|
return $status;
|
||
|
}
|
||
|
|
||
|
sub custom_status_output {
|
||
|
my ($self, %options) = @_;
|
||
|
my $msg = ucfirst($self->{result_values}->{label}) . ' status : ' . $self->{result_values}->{status};
|
||
|
|
||
|
return $msg;
|
||
|
}
|
||
|
|
||
|
sub custom_status_calc {
|
||
|
my ($self, %options) = @_;
|
||
|
|
||
|
$self->{result_values}->{label} = $options{extra_options}->{label_ref};
|
||
|
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{label} . '_status'};
|
||
|
return 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 =>
|
||
|
{
|
||
|
"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;
|
||
|
}
|
||
|
|
||
|
sub check_options {
|
||
|
my ($self, %options) = @_;
|
||
|
$self->SUPER::check_options(%options);
|
||
|
|
||
|
$instance_mode = $self;
|
||
|
$self->change_macros();
|
||
|
}
|
||
|
|
||
|
sub change_macros {
|
||
|
my ($self, %options) = @_;
|
||
|
|
||
|
foreach (('warning_wifi_status', 'critical_wifi_status', 'warning_disk_status', 'critical_disk_status')) {
|
||
|
if (defined($self->{option_results}->{$_})) {
|
||
|
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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->{global}->{wifi_status} = $result->{status}->{state};
|
||
|
}
|
||
|
|
||
|
1;
|
||
|
|
||
|
__END__
|
||
|
|
||
|
=head1 MODE
|
||
|
|
||
|
Check system.
|
||
|
|
||
|
=over 8
|
||
|
|
||
|
=item B<--filter-counters>
|
||
|
|
||
|
Only display some counters (regexp can be used).
|
||
|
Example: --filter-counters='^temperature-cpum$'
|
||
|
|
||
|
=item B<--warning-wifi-status>
|
||
|
|
||
|
Set warning threshold for wifi status (Default: '%{status} =~ /bad_param/i').
|
||
|
Can used special variables like: %{status}
|
||
|
|
||
|
=item B<--critical-wifi-status>
|
||
|
|
||
|
Set critical threshold for wifi status (Default: '%{status} =~ /failed/i').
|
||
|
Can used special variables like: %{status}
|
||
|
|
||
|
=item B<--warning-disk-status>
|
||
|
|
||
|
Set warning threshold for disk status.
|
||
|
Can used special variables like: %{status}
|
||
|
|
||
|
=item B<--critical-disk-status>
|
||
|
|
||
|
Set critical threshold for disk status (Default: '%{status} =~ /error/i').
|
||
|
Can used special variables like: %{status}
|
||
|
|
||
|
=item B<--warning-*>
|
||
|
|
||
|
Threshold warning.
|
||
|
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'.
|
||
|
|
||
|
=back
|
||
|
|
||
|
=cut
|