refacto to use hardware class

This commit is contained in:
garnier-quentin 2019-07-03 17:21:51 +02:00
parent 762d07d8df
commit 38a05ad605
23 changed files with 461 additions and 917 deletions

View File

@ -0,0 +1,74 @@
#
# Copyright 2019 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 centreon::common::radlan::mode::components::fan;
use strict;
use warnings;
my %map_states = (
1 => 'normal',
2 => 'warning',
3 => 'critical',
4 => 'shutdown',
5 => 'notPresent',
6 => 'notFunctioning',
);
my $mapping = {
rlEnvMonFanStatusDescr => { oid => '.1.3.6.1.4.1.89.83.1.1.1.2' },
rlEnvMonFanState => { oid => '.1.3.6.1.4.1.89.83.1.1.1.3', map => \%map_states },
};
my $oid_rlEnvMonFanStatusEntry = '.1.3.6.1.4.1.89.83.1.1.1';
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_rlEnvMonFanStatusEntry };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking fans');
$self->{components}->{fan} = { name => 'fans', total => 0, skip => 0 };
return if ($self->check_filter(section => 'fan'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonFanStatusEntry}})) {
next if ($oid !~ /^$mapping->{rlEnvMonFanState}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonFanStatusEntry}, instance => $instance);
next if ($self->check_filter(section => 'fan', instance => $instance, name => $result->{rlEnvMonFanStatusDescr}));
next if ($result->{rlEnvMonFanState} eq 'notPresent' &&
$self->absent_problem(section => 'fan', instance => $instance, name => $result->{rlEnvMonFanStatusDescr}));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("fan '%s' state is %s [instance: %s]",
$result->{rlEnvMonFanStatusDescr}, $result->{rlEnvMonFanState}, $instance));
my $exit = $self->get_severity(section => 'fan', value => $result->{rlEnvMonFanState});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Fan '%s' state is %s.", $result->{rlEnvMonFanStatusDescr}, $result->{rlEnvMonFanState}));
}
}
}
1;

View File

@ -0,0 +1,74 @@
#
# Copyright 2019 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 centreon::common::radlan::mode::components::psu;
use strict;
use warnings;
my %map_states = (
1 => 'normal',
2 => 'warning',
3 => 'critical',
4 => 'shutdown',
5 => 'notPresent',
6 => 'notFunctioning',
);
my $mapping = {
rlEnvMonSupplyStatusDescr => { oid => '.1.3.6.1.4.1.89.83.1.2.1' },
rlEnvMonSupplyState => { oid => '.1.3.6.1.4.1.89.83.1.2.1.3', map => \%map_states },
};
my $oid_rlEnvMonSupplyStatusEntry = '.1.3.6.1.4.1.89.83.1.2.1.2';
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_rlEnvMonSupplyStatusEntry };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking power supplies');
$self->{components}->{psu} = { name => 'psus', total => 0, skip => 0 };
return if ($self->check_filter(section => 'psu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonSupplyStatusEntry}})) {
next if ($oid !~ /^$mapping->{rlEnvMonSupplyState}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}, instance => $instance);
next if ($self->check_filter(section => 'psu', instance => $instance, name => $result->{rlEnvMonSupplyStatusDescr}));
next if ($result->{rlEnvMonSupplyState} eq 'notPresent' &&
$self->absent_problem(section => 'psu', instance => $instance, name => $result->{rlEnvMonSupplyStatusDescr}));
$self->{components}->{psu}->{total}++;
$self->{output}->output_add(long_msg => sprintf("power supply '%s' state is %s [instance: %s]",
$result->{rlEnvMonSupplyStatusDescr}, $result->{rlEnvMonSupplyState}, $instance));
my $exit = $self->get_severity(section => 'psu', value => $result->{rlEnvMonSupplyState});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Power supply '%s' state is %s.", $result->{rlEnvMonSupplyStatusDescr}, $result->{rlEnvMonSupplyState}));
}
}
}
1;

View File

@ -20,20 +20,20 @@
package centreon::common::radlan::mode::environment;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
my $oid_rlEnvMonFanStatusEntry = '.1.3.6.1.4.1.89.83.1.1.1';
my $oid_rlEnvMonFanStatusDescr = '.1.3.6.1.4.1.89.83.1.1.1.2';
my $oid_rlEnvMonFanState = '.1.3.6.1.4.1.89.83.1.1.1.3';
my $oid_rlEnvMonSupplyStatusEntry = '.1.3.6.1.4.1.89.83.1.2.1';
my $oid_rlEnvMonSupplyStatusDescr = '.1.3.6.1.4.1.89.83.1.2.1.2';
my $oid_rlEnvMonSupplyState = '.1.3.6.1.4.1.89.83.1.2.1.3';
sub set_system {
my ($self, %options) = @_;
my $thresholds = {
psu => [
$self->{regexp_threshold_overload_check_section_option} = '^fan|psu$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
default => [
['shutdown', 'WARNING'],
['warning', 'WARNING'],
['critical', 'CRITICAL'],
@ -41,235 +41,36 @@ my $thresholds = {
['notPresent', 'OK'],
['normal', 'OK'],
],
fan => [
['shutdown', 'WARNING'],
['warning', 'WARNING'],
['critical', 'CRITICAL'],
['notFunctioning', 'CRITICAL'],
['notPresent', 'OK'],
['normal', 'OK'],
],
};
};
my %map_states = (
1 => 'normal',
2 => 'warning',
3 => 'critical',
4 => 'shutdown',
5 => 'notPresent',
6 => 'notFunctioning',
);
$self->{components_path} = 'centreon::common::radlan::mode::components';
$self->{components_module} = ['fan', 'psu'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"exclude:s" => { name => 'exclude' },
"component:s" => { name => 'component', default => 'all' },
"absent-problem:s" => { name => 'absent' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
});
$options{options}->add_options(arguments => {});
$self->{components} = {};
$self->{no_components} = undef;
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{no_component})) {
if ($self->{option_results}->{no_component} ne '') {
$self->{no_components} = $self->{option_results}->{no_component};
} else {
$self->{no_components} = 'critical';
}
}
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
if ($val !~ /^(.*?),(.*?),(.*)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $status, $filter) = ($1, $2, $3);
if ($self->{output}->is_litteral_status(status => $status) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
$self->{output}->option_exit();
}
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
}
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
# There is a bug with get_leef and snmpv1.
$self->{results} = $self->{snmp}->get_multiple_table(oids => [
{ oid => $oid_rlEnvMonFanStatusEntry },
{ oid => $oid_rlEnvMonSupplyStatusEntry },
]);
if ($self->{option_results}->{component} eq 'all') {
$self->check_fan();
$self->check_psu();
} elsif ($self->{option_results}->{component} eq 'fan') {
$self->check_fan();
} elsif ($self->{option_results}->{component} eq 'psu') {
$self->check_psu();
} else {
$self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'.");
$self->{output}->option_exit();
}
my $total_components = 0;
my $display_by_component = '';
my $display_by_component_append = '';
foreach my $comp (sort(keys %{$self->{components}})) {
# Skipping short msg when no components
next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0);
$total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
$display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name};
$display_by_component_append = ', ';
}
$self->{output}->output_add(severity => 'OK',
short_msg => sprintf("All %s components are ok [%s].",
$total_components,
$display_by_component)
);
if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
$self->{output}->output_add(severity => $self->{no_components},
short_msg => 'No components are checked.');
}
$self->{output}->display();
$self->{output}->exit();
}
sub check_exclude {
my ($self, %options) = @_;
if (defined($options{instance})) {
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) {
$self->{components}->{$options{section}}->{skip}++;
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
return 1;
}
} elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
return 1;
}
return 0;
}
sub absent_problem {
my ($self, %options) = @_;
if (defined($self->{option_results}->{absent}) &&
$self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) {
$self->{output}->output_add(severity => 'CRITICAL',
short_msg => sprintf("Component '%s' instance '%s' is not present",
$options{section}, $options{instance}));
}
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)"));
$self->{components}->{$options{section}}->{skip}++;
return 1;
}
sub get_severity {
my ($self, %options) = @_;
my $status = 'UNKNOWN'; # default
if (defined($self->{overload_th}->{$options{section}})) {
foreach (@{$self->{overload_th}->{$options{section}}}) {
if ($options{value} =~ /$_->{filter}/i) {
$status = $_->{status};
return $status;
}
}
}
foreach (@{$thresholds->{$options{section}}}) {
if ($options{value} =~ /$$_[0]/i) {
$status = $$_[1];
return $status;
}
}
return $status;
}
sub check_fan {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking fans");
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
return if ($self->check_exclude(section => 'fan'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonFanStatusEntry}})) {
next if ($oid !~ /^$oid_rlEnvMonFanStatusDescr\.(.*)/);
my $instance = $self->{results}->{$oid_rlEnvMonFanStatusEntry}->{$oid};
my $fan_state = $self->{results}->{$oid_rlEnvMonFanStatusEntry}->{$oid_rlEnvMonFanState . '.' . $1};
next if ($self->check_exclude(section => 'fan', instance => $instance));
next if ($map_states{$fan_state} eq 'notPresent' &&
$self->absent_problem(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Fan '%s' state is %s.",
$instance, $map_states{$fan_state}));
my $exit = $self->get_severity(section => 'fan', value => $map_states{$fan_state});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Fan '%s' state is %s.", $instance, $map_states{$fan_state}));
}
}
}
sub check_psu {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking power supplies");
$self->{components}->{psu} = {name => 'psus', total => 0, skip => 0};
return if ($self->check_exclude(section => 'psu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonSupplyStatusEntry}})) {
next if ($oid !~ /^$oid_rlEnvMonSupplyStatusDescr\.(.*)/);
my $instance = $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}->{$oid};
my $psu_state = $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}->{$oid_rlEnvMonSupplyState . '.' . $1};
next if ($self->check_exclude(section => 'psu', instance => $instance));
next if ($map_states{$psu_state} eq 'notPresent' &&
$self->absent_problem(section => 'psu', instance => $instance));
$self->{components}->{psu}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Power supply '%s' state is %s.",
$instance, $map_states{$psu_state}));
my $exit = $self->get_severity(section => 'psu', value => $map_states{$psu_state});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Power supply '%s' state is %s.", $instance, $map_states{$psu_state}));
}
}
}
1;
__END__
=head1 MODE
Check environment (RADLAN-HWENVIROMENT) (Fans, Power Supplies).
Check environment (RADLAN-HWENVIROMENT).
=over 8
@ -278,10 +79,10 @@ Check environment (RADLAN-HWENVIROMENT) (Fans, Power Supplies).
Which component to check (Default: 'all').
Can be: 'psu', 'fan'.
=item B<--exclude>
=item B<--filter>
Exclude some parts (comma seperated list) (Example: --exclude=psu)
Can also exclude specific instance: --exclude='fan#fan2_unit1#'
Exclude some parts (comma seperated list) (Example: --filter=psu)
Can also exclude specific instance: --filter=fan,1
=item B<--absent-problem>

View File

@ -50,9 +50,9 @@ my $mapping = {
my $oid_sensorProbeHumidityEntry = '.1.3.6.1.4.1.3854.1.2.2.1.17.1';
sub load {
my (%options) = @_;
my ($self) = @_;
push @{$options{request}}, { oid => $oid_sensorProbeHumidityEntry, end => $mapping->{sensorProbeHumidityLowCritical}->{oid} };
push @{$self->{request}}, { oid => $oid_sensorProbeHumidityEntry, end => $mapping->{sensorProbeHumidityLowCritical}->{oid} };
}
sub check {
@ -60,14 +60,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking humidity");
$self->{components}->{humidity} = {name => 'humidity', total => 0, skip => 0};
return if ($self->check_exclude(section => 'humidity'));
return if ($self->check_filter(section => 'humidity'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensorProbeHumidityEntry}})) {
next if ($oid !~ /^$mapping->{sensorProbeHumidityPercent}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensorProbeHumidityEntry}, instance => $instance);
next if ($self->check_exclude(section => 'humidity', instance => $instance));
next if ($self->check_filter(section => 'humidity', instance => $instance));
if ($result->{sensorProbeHumidityOnline} =~ /Offline/i) {
$self->absent_problem(section => 'humidity', instance => $instance);
next;

View File

@ -33,23 +33,24 @@ my %map_sp_status = (
my $oid_spStatus = '.1.3.6.1.4.1.3854.1.1.2';
sub load {
my (%options) = @_;
my ($self) = @_;
push @{$options{request}}, { oid => $oid_spStatus };
push @{$self->{request}}, { oid => $oid_spStatus };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking sp");
$self->{components}->{sp} = {name => 'sp', total => 0, skip => 0};
return if ($self->check_exclude(section => 'sp'));
$self->{components}->{sp} = { name => 'sp', total => 0, skip => 0 };
return if ($self->check_filter(section => 'sp'));
return if (scalar(keys %{$self->{results}->{$oid_spStatus}}) <= 0);
my $instance = 0;
my $sp_status = defined($map_sp_status{$self->{results}->{$oid_spStatus}->{$oid_spStatus . '.' . $instance}}) ?
$map_sp_status{$self->{results}->{$oid_spStatus}->{$oid_spStatus . '.' . $instance}} : 'unknown';
return if ($self->check_exclude(section => 'sp', instance => $instance));
return if ($self->check_filter(section => 'sp', instance => $instance));
return if ($sp_status =~ /noStatus/i &&
$self->absent_problem(section => 'sp', instance => $instance));

View File

@ -45,9 +45,9 @@ my $mapping = {
my $oid_sensorProbeSwitchEntry = '.1.3.6.1.4.1.3854.1.2.2.1.18.1';
sub load {
my (%options) = @_;
my ($self) = @_;
push @{$options{request}}, { oid => $oid_sensorProbeSwitchEntry, end => $mapping->{sensorProbeSwitchOnline}->{oid} };
push @{$self->{request}}, { oid => $oid_sensorProbeSwitchEntry, end => $mapping->{sensorProbeSwitchOnline}->{oid} };
}
sub check {
@ -55,14 +55,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking switch");
$self->{components}->{switch} = {name => 'switch', total => 0, skip => 0};
return if ($self->check_exclude(section => 'switch'));
return if ($self->check_filter(section => 'switch'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensorProbeSwitchEntry}})) {
next if ($oid !~ /^$mapping->{sensorProbeSwitchStatus}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensorProbeSwitchEntry}, instance => $instance);
next if ($self->check_exclude(section => 'switch', instance => $instance));
next if ($self->check_filter(section => 'switch', instance => $instance));
if ($result->{sensorProbeSwitchOnline} =~ /Offline/i) {
$self->absent_problem(section => 'switch', instance => $instance);
next;

View File

@ -50,9 +50,9 @@ my $mapping = {
my $oid_sensorProbeTempEntry = '.1.3.6.1.4.1.3854.1.2.2.1.16.1';
sub load {
my (%options) = @_;
my ($self) = @_;
push @{$options{request}}, { oid => $oid_sensorProbeTempEntry, end => $mapping->{sensorProbeTempLowCritical}->{oid} };
push @{$self->{request}}, { oid => $oid_sensorProbeTempEntry, end => $mapping->{sensorProbeTempLowCritical}->{oid} };
}
sub check {
@ -60,14 +60,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking temperatures");
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
return if ($self->check_exclude(section => 'temperature'));
return if ($self->check_filter(section => 'temperature'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensorProbeTempEntry}})) {
next if ($oid !~ /^$mapping->{sensorProbeTempDegree}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensorProbeTempEntry}, instance => $instance);
next if ($self->check_exclude(section => 'temperature', instance => $instance));
next if ($self->check_filter(section => 'temperature', instance => $instance));
if ($result->{sensorProbeTempOnline} =~ /Offline/i) {
$self->absent_problem(section => 'temperature', instance => $instance);
next;

View File

@ -20,13 +20,20 @@
package hardware::sensors::sensorip::snmp::mode::sensors;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
use centreon::plugins::misc;
my $thresholds = {
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^sp|temperature|humidity|switch$';
$self->{regexp_threshold_numeric_check_section_option} = '^humidity|temperature$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
sp => [
['noStatus', 'UNKNOWN'],
['normal', 'OK'],
@ -43,220 +50,36 @@ my $thresholds = {
['relayOn', 'OK'],
['relayOff', 'OK'],
],
};
};
$self->{components_path} = 'hardware::sensors::sensorip::snmp::mode::components';
$self->{components_module} = ['sp', 'temperature', 'humidity', 'switch'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"exclude:s" => { name => 'exclude' },
"component:s" => { name => 'component', default => '.*' },
"absent-problem:s" => { name => 'absent' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
"warning:s@" => { name => 'warning' },
"critical:s@" => { name => 'critical' },
});
$options{options}->add_options(arguments => {});
$self->{components} = {};
$self->{no_components} = undef;
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{no_component})) {
if ($self->{option_results}->{no_component} ne '') {
$self->{no_components} = $self->{option_results}->{no_component};
} else {
$self->{no_components} = 'critical';
}
}
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
if ($val !~ /^(.*?),(.*?),(.*)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $status, $filter) = ($1, $2, $3);
if ($self->{output}->is_litteral_status(status => $status) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
$self->{output}->option_exit();
}
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
}
$self->{numeric_threshold} = {};
foreach my $option (('warning', 'critical')) {
foreach my $val (@{$self->{option_results}->{$option}}) {
if ($val !~ /^(.*?),(.*?),(.*)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $regexp, $value) = ($1, $2, $3);
if ($section !~ /(humidity|temperature)/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: battery or temperature).");
$self->{output}->option_exit();
}
my $position = 0;
if (defined($self->{numeric_threshold}->{$section})) {
$position = scalar(@{$self->{numeric_threshold}->{$section}});
}
if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'.");
$self->{output}->option_exit();
}
$self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section}));
push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, regexp => $regexp };
}
}
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
my $snmp_request = [];
my @components = ('sp', 'temperature', 'humidity', 'switch');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "hardware::sensors::sensorip::snmp::mode::components::$_";
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name,
error_msg => "Cannot load module '$mod_name'.");
my $func = $mod_name->can('load');
$func->(request => $snmp_request);
}
}
if (scalar(@{$snmp_request}) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'.");
$self->{output}->option_exit();
}
$self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request);
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "hardware::sensors::sensorip::snmp::mode::components::$_";
my $func = $mod_name->can('check');
$func->($self);
}
}
my $total_components = 0;
my $display_by_component = '';
my $display_by_component_append = '';
foreach my $comp (sort(keys %{$self->{components}})) {
# Skipping short msg when no components
next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0);
$total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
$display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name};
$display_by_component_append = ', ';
}
$self->{output}->output_add(severity => 'OK',
short_msg => sprintf("All %s components are ok [%s].",
$total_components,
$display_by_component)
);
if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
$self->{output}->output_add(severity => $self->{no_components},
short_msg => 'No components are checked.');
}
$self->{output}->display();
$self->{output}->exit();
}
sub check_exclude {
my ($self, %options) = @_;
if (defined($options{instance})) {
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) {
$self->{components}->{$options{section}}->{skip}++;
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
return 1;
}
} elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
return 1;
}
return 0;
}
sub absent_problem {
my ($self, %options) = @_;
if (defined($self->{option_results}->{absent}) &&
$self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) {
$self->{output}->output_add(severity => 'CRITICAL',
short_msg => sprintf("Component '%s' instance '%s' is not present",
$options{section}, $options{instance}));
}
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)"));
$self->{components}->{$options{section}}->{skip}++;
return 1;
}
sub get_severity_numeric {
my ($self, %options) = @_;
my $status = 'OK'; # default
my $thresholds = { warning => undef, critical => undef };
my $checked = 0;
if (defined($self->{numeric_threshold}->{$options{section}})) {
my $exits = [];
foreach (@{$self->{numeric_threshold}->{$options{section}}}) {
if ($options{instance} =~ /$_->{regexp}/) {
push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]);
$thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label});
$checked = 1;
}
}
$status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0);
}
return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked);
}
sub get_severity {
my ($self, %options) = @_;
my $status = 'UNKNOWN'; # default
if (defined($self->{overload_th}->{$options{section}})) {
foreach (@{$self->{overload_th}->{$options{section}}}) {
if ($options{value} =~ /$_->{filter}/i) {
$status = $_->{status};
return $status;
}
}
}
foreach (@{$thresholds->{$options{section}}}) {
if ($options{value} =~ /$$_[0]/i) {
$status = $$_[1];
return $status;
}
}
return $status;
}
1;
__END__
=head1 MODE
Check sensor components (Sensor Probe status, Temperatures, Humidity, Switch).
Check sensor components.
=over 8
@ -265,10 +88,10 @@ Check sensor components (Sensor Probe status, Temperatures, Humidity, Switch).
Which component to check (Default: '.*').
Can be: 'sp', 'temperature', 'humidity', 'switch'.
=item B<--exclude>
=item B<--filter>
Exclude some parts (comma seperated list) (Example: --exclude=psu)
Can also exclude specific instance: --exclude='humidty#0#'
Exclude some parts (comma seperated list) (Example: --filter=psu)
Can also exclude specific instance: --filter=humidty,0
=item B<--absent-problem>

View File

@ -28,7 +28,7 @@ sub check {
$self->{output}->output_add(long_msg => "Checking disks");
$self->{components}->{disk} = {name => 'disks', total => 0, skip => 0};
return if ($self->check_exclude(section => 'disk'));
return if ($self->check_filter(section => 'disk'));
if ($self->{stdout} =~ /^System Disks.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) {
#Disk Status Service OK2RM
@ -41,7 +41,7 @@ sub check {
my $disk_status = defined($2) ? $2 : 'unknown';
my $disk_name = defined($1) ? $1 : 'unknown';
next if ($self->check_exclude(section => 'disk', instance => $disk_name));
next if ($self->check_filter(section => 'disk', instance => $disk_name));
$self->{components}->{disk}->{total}++;
$self->{output}->output_add(long_msg => "Disk Status '" . $disk_name . "' is " . $disk_status);

View File

@ -28,7 +28,7 @@ sub check {
$self->{output}->output_add(long_msg => "Checking fans");
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
return if ($self->check_exclude(section => 'fan'));
return if ($self->check_filter(section => 'fan'));
if ($self->{stdout} =~ /^Fans.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) {
#Sensor Status Speed Warn Low
@ -41,7 +41,7 @@ sub check {
my $fan_status = defined($2) ? $2 : 'unknown';
my $fan_name = defined($1) ? $1 : 'unknown';
next if ($self->check_exclude(section => 'fan', instance => $fan_name));
next if ($self->check_filter(section => 'fan', instance => $fan_name));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => "Fan Sensor Status '" . $fan_name . "' is " . $fan_status);

View File

@ -28,7 +28,7 @@ sub check {
$self->{output}->output_add(long_msg => "Checking power supplies");
$self->{components}->{psu} = {name => 'psus', total => 0, skip => 0};
return if ($self->check_exclude(section => 'psu'));
return if ($self->check_filter(section => 'psu'));
if ($self->{stdout} =~ /^Power Supplies.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) {
#Supply Status Underspeed Overtemp Overvolt Undervolt Overcurrent
@ -40,7 +40,7 @@ sub check {
my $ps_status = defined($2) ? $2 : 'unknown';
my $ps_name = defined($1) ? $1 : 'unknown';
next if ($self->check_exclude(section => 'psu', instance => $ps_name));
next if ($self->check_filter(section => 'psu', instance => $ps_name));
$self->{components}->{psu}->{total}++;
$self->{output}->output_add(long_msg => "Power Supplies Sensor Status '" . $ps_name . "' is " . $ps_status);

View File

@ -1,63 +0,0 @@
#
# Copyright 2019 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 hardware::server::sun::mgmt_cards::components::showenvironment::resources;
use strict;
use warnings;
use Exporter;
our $thresholds;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw($thresholds);
$thresholds = {
temperature => [
['^(?!(OK)$)', 'CRITICAL'],
['^OK$', 'OK'],
],
si => [
['^(?!(OFF)$)', 'CRITICAL'],
['^OFF$', 'OK'],
],
disk => [
['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'],
['^OK|NOT PRESENT$', 'OK'],
],
fan => [
['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'],
['^OK|NOT PRESENT$', 'OK'],
],
voltage => [
['^(?!(OK)$)', 'CRITICAL'],
['^OK$', 'OK'],
],
psu => [
['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'],
['^OK|NOT PRESENT$', 'OK'],
],
sensors => [
['^(?!(OK)$)', 'CRITICAL'],
['^OK$', 'OK'],
],
};
1;

View File

@ -28,7 +28,7 @@ sub check {
$self->{output}->output_add(long_msg => "Checking sensors");
$self->{components}->{sensors} = {name => 'sensors', total => 0, skip => 0};
return if ($self->check_exclude(section => 'sensors'));
return if ($self->check_filter(section => 'sensors'));
if ($self->{stdout} =~ /^Current sensors.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) {
#Sensor Status
@ -40,7 +40,7 @@ sub check {
my $sensor_status = defined($2) ? $2 : 'unknown';
my $sensor_name = defined($1) ? $1 : 'unknown';
next if ($self->check_exclude(section => 'sensors', instance => $sensor_name));
next if ($self->check_filter(section => 'sensors', instance => $sensor_name));
$self->{components}->{sensors}->{total}++;
$self->{output}->output_add(long_msg => "Current Sensor status '" . $sensor_name . "' is " . $sensor_status);

View File

@ -28,7 +28,7 @@ sub check {
$self->{output}->output_add(long_msg => "Checking system indicator");
$self->{components}->{si} = {name => 'system indicator', total => 0, skip => 0};
return if ($self->check_exclude(section => 'si'));
return if ($self->check_filter(section => 'si'));
#--------------------------------------------------------
#System Indicator Status:
@ -55,7 +55,7 @@ sub check {
my $si_name = defined($1) ? $1 : 'unknown';
my $si_status = defined($2) ? $2 : 'unknown';
next if ($self->check_exclude(section => 'si', instance => $si_name));
next if ($self->check_filter(section => 'si', instance => $si_name));
$self->{components}->{si}->{total}++;
$self->{output}->output_add(long_msg => "System Indicator Status '$si_name' is " . $si_status);

View File

@ -28,7 +28,7 @@ sub check {
$self->{output}->output_add(long_msg => "Checking temperatures");
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
return if ($self->check_exclude(section => 'temperature'));
return if ($self->check_filter(section => 'temperature'));
if ($self->{stdout} =~ /^System Temperatures.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) {
#Sensor Status Temp LowHard LowSoft LowWarn HighWarn HighSoft HighHard
@ -40,7 +40,7 @@ sub check {
my $sensor_status = defined($2) ? $2 : 'unknown';
my $sensor_name = defined($1) ? $1 : 'unknown';
next if ($self->check_exclude(section => 'temperature', instance => $sensor_name));
next if ($self->check_filter(section => 'temperature', instance => $sensor_name));
$self->{components}->{temperature}->{total}++;
$self->{output}->output_add(long_msg => "System Temperature Sensor '" . $sensor_name . "' is " . $sensor_status);

View File

@ -28,7 +28,7 @@ sub check {
$self->{output}->output_add(long_msg => "Checking voltages");
$self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0};
return if ($self->check_exclude(section => 'voltage'));
return if ($self->check_filter(section => 'voltage'));
if ($self->{stdout} =~ /^Voltage sensors.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) {
#Sensor Status Voltage LowSoft LowWarn HighWarn HighSoft
@ -41,7 +41,7 @@ sub check {
my $voltage_status = defined($2) ? $2 : 'unknown';
my $voltage_name = defined($1) ? $1 : 'unknown';
next if ($self->check_exclude(section => 'voltage', instance => $voltage_name));
next if ($self->check_filter(section => 'voltage', instance => $voltage_name));
$self->{components}->{voltage}->{total}++;
$self->{output}->output_add(long_msg => "Voltage Sensor status '" . $voltage_name . "' is " . $voltage_status);

View File

@ -20,47 +20,78 @@
package hardware::server::sun::mgmt_cards::mode::showenvironment;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
use centreon::plugins::misc;
use hardware::server::sun::mgmt_cards::components::showenvironment::resources qw($thresholds);
use hardware::server::sun::mgmt_cards::components::showenvironment::psu;
use hardware::server::sun::mgmt_cards::components::showenvironment::fan;
use hardware::server::sun::mgmt_cards::components::showenvironment::temperature;
use hardware::server::sun::mgmt_cards::components::showenvironment::sensors;
use hardware::server::sun::mgmt_cards::components::showenvironment::voltage;
use hardware::server::sun::mgmt_cards::components::showenvironment::si;
use hardware::server::sun::mgmt_cards::components::showenvironment::disk;
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} =
'^temperature|si|disk|fan|voltage|psu|sensors$';
$self->{cb_hook2} = 'execute_command';
$self->{components_exec_load} = 0;
$self->{thresholds} = {
temperature => [
['^(?!(OK)$)', 'CRITICAL'],
['^OK$', 'OK'],
],
si => [
['^(?!(OFF)$)', 'CRITICAL'],
['^OFF$', 'OK'],
],
disk => [
['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'],
['^OK|NOT PRESENT$', 'OK'],
],
fan => [
['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'],
['^OK|NOT PRESENT$', 'OK'],
],
voltage => [
['^(?!(OK)$)', 'CRITICAL'],
['^OK$', 'OK'],
],
psu => [
['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'],
['^OK|NOT PRESENT$', 'OK'],
],
sensors => [
['^(?!(OK)$)', 'CRITICAL'],
['^OK$', 'OK'],
],
};
$self->{components_path} = 'hardware::server::sun::mgmt_cards::components::showenvironment';
$self->{components_module} = ['temperature', 'si', 'disk', 'fan', 'voltage', 'psu', 'sensors'];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1, no_absent => 1);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => 23 },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"timeout:s" => { name => 'timeout', default => 30 },
"command-plink:s" => { name => 'command_plink', default => 'plink' },
"ssh" => { name => 'ssh' },
"exclude:s" => { name => 'exclude' },
"component:s" => { name => 'component', default => 'all' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
$options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port', default => 23 },
'username:s' => { name => 'username' },
'password:s' => { name => 'password' },
'timeout:s' => { name => 'timeout', default => 30 },
'command-plink:s' => { name => 'command_plink', default => 'plink' },
'ssh' => { name => 'ssh' },
});
$self->{components} = {};
$self->{no_components} = undef;
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{hostname})) {
$self->{output}->add_option_msg(short_msg => "Need to specify a hostname.");
@ -78,29 +109,6 @@ sub check_options {
if (!defined($self->{option_results}->{ssh})) {
require hardware::server::sun::mgmt_cards::lib::telnet;
}
if (defined($self->{option_results}->{no_component})) {
if ($self->{option_results}->{no_component} ne '') {
$self->{no_components} = $self->{option_results}->{no_component};
} else {
$self->{no_components} = 'critical';
}
}
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
if ($val !~ /^(.*?),(.*?),(.*)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $status, $filter) = ($1, $2, $3);
if ($self->{output}->is_litteral_status(status => $status) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
$self->{output}->option_exit();
}
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
}
}
sub ssh_command {
@ -113,6 +121,7 @@ sub ssh_command {
timeout => $self->{option_results}->{timeout},
wait_exit => 1
);
$stdout =~ s/\r//g;
if ($lerror <= -1000) {
$self->{output}->output_add(severity => 'UNKNOWN',
@ -139,42 +148,7 @@ sub ssh_command {
return $stdout;
}
sub global {
my ($self, %options) = @_;
hardware::server::sun::mgmt_cards::components::showenvironment::psu::check($self);
hardware::server::sun::mgmt_cards::components::showenvironment::fan::check($self);
hardware::server::sun::mgmt_cards::components::showenvironment::temperature::check($self);
hardware::server::sun::mgmt_cards::components::showenvironment::sensors::check($self);
hardware::server::sun::mgmt_cards::components::showenvironment::voltage::check($self);
hardware::server::sun::mgmt_cards::components::showenvironment::si::check($self);
hardware::server::sun::mgmt_cards::components::showenvironment::disk::check($self);
}
sub component {
my ($self, %options) = @_;
if ($self->{option_results}->{component} eq 'si') {
hardware::server::sun::mgmt_cards::components::showenvironment::si::check($self);
} elsif ($self->{option_results}->{component} eq 'psu') {
hardware::server::sun::mgmt_cards::components::showenvironment::psu::check($self);
} elsif ($self->{option_results}->{component} eq 'fan') {
hardware::server::sun::mgmt_cards::components::showenvironment::fan::check($self);
} elsif ($self->{option_results}->{component} eq 'temperature') {
hardware::server::sun::mgmt_cards::components::showenvironment::temperature::check($self);
} elsif ($self->{option_results}->{component} eq 'sensors') {
hardware::server::sun::mgmt_cards::components::showenvironment::sensors::check($self);
} elsif ($self->{option_results}->{component} eq 'voltage') {
hardware::server::sun::mgmt_cards::components::showenvironment::voltage::check($self);
} elsif ($self->{option_results}->{component} eq 'disk') {
hardware::server::sun::mgmt_cards::components::showenvironment::disk::check($self);
} else {
$self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'.");
$self->{output}->option_exit();
}
}
sub run {
sub execute_command {
my ($self, %options) = @_;
if (defined($self->{option_results}->{ssh})) {
@ -186,81 +160,12 @@ sub run {
hostname => $self->{option_results}->{hostname},
port => $self->{option_results}->{port},
timeout => $self->{option_results}->{timeout},
output => $self->{output});
output => $self->{output}
);
my @lines = $telnet_handle->cmd("showenvironment");
$self->{stdout} = join("", @lines);
}
$self->{stdout} =~ s/\r//msg;
if ($self->{option_results}->{component} eq 'all') {
$self->global();
} else {
$self->component();
}
my $total_components = 0;
my $display_by_component = '';
my $display_by_component_append = '';
foreach my $comp (sort(keys %{$self->{components}})) {
# Skipping short msg when no components
next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0);
$total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
$display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name};
$display_by_component_append = ', ';
}
$self->{output}->output_add(severity => 'OK',
short_msg => sprintf("All %s components [%s] are ok.",
$total_components,
$display_by_component)
);
if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
$self->{output}->output_add(severity => $self->{no_components},
short_msg => 'No components are checked.');
}
$self->{output}->display();
$self->{output}->exit();
}
sub check_exclude {
my ($self, %options) = @_;
if (defined($options{instance})) {
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) {
$self->{components}->{$options{section}}->{skip}++;
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
return 1;
}
} elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
return 1;
}
return 0;
}
sub get_severity {
my ($self, %options) = @_;
my $status = 'UNKNOWN'; # default
if (defined($self->{overload_th}->{$options{section}})) {
foreach (@{$self->{overload_th}->{$options{section}}}) {
if ($options{value} =~ /$_->{filter}/i) {
$status = $_->{status};
return $status;
}
}
}
foreach (@{$thresholds->{$options{section}}}) {
if ($options{value} =~ /$$_[0]/i) {
$status = $$_[1];
return $status;
}
}
return $status;
}
1;
@ -303,13 +208,13 @@ Use ssh (with plink) instead of telnet.
=item B<--component>
Which component to check (Default: 'all').
Which component to check (Default: '.*').
Can be: 'temperature', 'si', 'disk', 'fan', 'voltage', 'psu', 'sensors'.
=item B<--exclude>
=item B<--filter>
Exclude some parts (comma seperated list) (Example: --exclude=fan)
Can also exclude specific instance: --exclude=fan#F1.RS#
Exclude some parts (comma seperated list) (Example: --filter=fan)
Can also exclude specific instance: --filter=fan,F1.RS
=item B<--no-component>

View File

@ -20,129 +20,64 @@
package os::solaris::local::mode::lomv120;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
use centreon::plugins::misc;
use os::solaris::local::mode::lomv120components::fan;
use os::solaris::local::mode::lomv120components::psu;
use os::solaris::local::mode::lomv120components::voltage;
use os::solaris::local::mode::lomv120components::sf;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'lom' },
"command-path:s" => { name => 'command_path', default => '/usr/sbin' },
"command-options:s" => { name => 'command_options', default => '-fpv 2>&1'},
"exclude:s" => { name => 'exclude' },
"component:s" => { name => 'component', default => 'all' },
"no-component:s" => { name => 'no_component' },
});
$self->{components} = {};
$self->{no_components} = undef;
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{no_component})) {
if ($self->{option_results}->{no_component} ne '') {
$self->{no_components} = $self->{option_results}->{no_component};
} else {
$self->{no_components} = 'critical';
}
}
}
sub component {
sub set_system {
my ($self, %options) = @_;
if ($self->{option_results}->{component} eq 'all') {
os::solaris::local::mode::lomv120components::fan::check($self);
os::solaris::local::mode::lomv120components::psu::check($self);
os::solaris::local::mode::lomv120components::voltage::check($self);
os::solaris::local::mode::lomv120components::sf::check($self);
} elsif ($self->{option_results}->{component} eq 'fan') {
os::solaris::local::mode::lomv120components::fan::check($self);
} elsif ($self->{option_results}->{component} eq 'psu') {
os::solaris::local::mode::lomv120components::psu::check($self);
} elsif ($self->{option_results}->{component} eq 'voltage') {
os::solaris::local::mode::lomv120components::voltage::check($self);
} elsif ($self->{option_results}->{component} eq 'sf') {
os::solaris::local::mode::lomv120components::sf::check($self);
} else {
$self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'.");
$self->{output}->option_exit();
}
$self->{regexp_threshold_overload_check_section_option} = '^fan|psu|voltage|sf$';
my $total_components = 0;
my $display_by_component = '';
my $display_by_component_append = '';
foreach my $comp (sort(keys %{$self->{components}})) {
# Skipping short msg when no components
next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0);
$total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
$display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name};
$display_by_component_append = ', ';
}
$self->{cb_hook2} = 'command_execute';
$self->{output}->output_add(severity => 'OK',
short_msg => sprintf("All %s components [%s] are ok.",
$total_components,
$display_by_component)
);
$self->{thresholds} = {
default => [
['^(?!(OK)$)' => 'CRITICAL'],
],
};
if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
$self->{output}->output_add(severity => $self->{no_components},
short_msg => 'No components are checked.');
}
$self->{components_exec_load} = 0;
$self->{components_path} = 'os::solaris::local::mode::lomv120components';
$self->{components_module} = ['fan', 'psu', 'voltage', 'sf'];
}
sub run {
sub command_execute {
my ($self, %options) = @_;
($self->{stdout}) = centreon::plugins::misc::execute(output => $self->{output},
($self->{stdout}) = centreon::plugins::misc::execute(
output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options},
no_quit => 1);
$self->component();
$self->{output}->display();
$self->{output}->exit();
no_quit => 1
);
}
sub check_exclude {
my ($self, %options) = @_;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1);
bless $self, $class;
if (defined($options{instance})) {
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) {
$self->{components}->{$options{section}}->{skip}++;
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
return 1;
}
} elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
return 1;
}
return 0;
$options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' },
'remote' => { name => 'remote' },
'ssh-option:s@' => { name => 'ssh_option' },
'ssh-path:s' => { name => 'ssh_path' },
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
'timeout:s' => { name => 'timeout', default => 30 },
'sudo' => { name => 'sudo' },
'command:s' => { name => 'command', default => 'lom' },
'command-path:s' => { name => 'command_path', default => '/usr/sbin' },
'command-options:s' => { name => 'command_options', default => '-fpv 2>&1'},
});
return $self;
}
1;
@ -198,19 +133,25 @@ Command options (Default: '-fpv 2>&1').
=item B<--component>
Which component to check (Default: 'all').
Which component to check (Default: '.*').
Can be: 'fan', 'psu', 'voltage', 'sf'.
=item B<--exclude>
=item B<--filter>
Exclude some parts (comma seperated list) (Example: --exclude=fan,sf)
Can also exclude specific instance: --exclude=fan#1#,sf
Exclude some parts (comma seperated list) (Example: --filter=fan)
Can also exclude specific instance: --filter=fan,1
=item B<--no-component>
Return an error if no compenents are checked.
If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='psu,WARNING,^(?!(ok)$)'
=back
=cut

View File

@ -23,16 +23,12 @@ package os::solaris::local::mode::lomv120components::fan;
use strict;
use warnings;
my %conditions = (
1 => ['^(?!(OK)$)' => 'CRITICAL'],
);
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking fans");
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
return if ($self->check_exclude(section => 'fan'));
return if ($self->check_filter(section => 'fan'));
#Fans:
#1 FAULT speed 0%
@ -48,19 +44,20 @@ sub check {
next if ($line !~ /^\s*(\S+)\s+(\S+)/);
my ($instance, $status) = ($1, $2);
next if ($self->check_exclude(section => 'fan', instance => $instance));
next if ($self->check_filter(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("fan '%s' status is %s.",
$instance, $status)
$self->{output}->output_add(
long_msg => sprintf(
"fan '%s' status is %s.",
$instance, $status
)
);
foreach (keys %conditions) {
if ($status =~ /${$conditions{$_}}[0]/i) {
$self->{output}->output_add(severity => ${$conditions{$_}}[1],
my $exit = $self->get_severity(label => 'default', section => 'fan', value => $status);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("fan '%s' status is %s",
$instance, $status));
last;
}
}
}
}

View File

@ -23,16 +23,12 @@ package os::solaris::local::mode::lomv120components::psu;
use strict;
use warnings;
my %conditions = (
1 => ['^(?!(OK)$)' => 'CRITICAL'],
);
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking power supplies");
$self->{components}->{psu} = {name => 'psus', total => 0, skip => 0};
return if ($self->check_exclude(section => 'psu'));
return if ($self->check_filter(section => 'psu'));
#PSUs:
#1 OK
@ -44,19 +40,20 @@ sub check {
next if ($line !~ /^\s*(\S+)\s+(\S+)/);
my ($instance, $status) = ($1, $2);
next if ($self->check_exclude(section => 'psu', instance => $instance));
next if ($self->check_filter(section => 'psu', instance => $instance));
$self->{components}->{psu}->{total}++;
$self->{output}->output_add(long_msg => sprintf("psu '%s' status is %s.",
$instance, $status)
$self->{output}->output_add(
long_msg => sprintf(
"psu '%s' status is %s.",
$instance, $status
)
);
foreach (keys %conditions) {
if ($status =~ /${$conditions{$_}}[0]/i) {
$self->{output}->output_add(severity => ${$conditions{$_}}[1],
my $exit = $self->get_severity(label => 'default', section => 'psu', value => $status);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("psu '%s' status is %s",
$instance, $status));
last;
}
}
}
}

View File

@ -24,16 +24,12 @@ use strict;
use warnings;
use centreon::plugins::misc;
my %conditions = (
1 => ['^(?!(ok)$)' => 'CRITICAL'],
);
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking system flag");
$self->{components}->{sf} = {name => 'system flag', total => 0, skip => 0};
return if ($self->check_exclude(section => 'sf'));
return if ($self->check_filter(section => 'sf'));
#System status flags:
# 1 SCSI-Term status=ok
@ -48,19 +44,20 @@ sub check {
next if ($line !~ /^\s*(\S+).*?status=(.*)/);
my ($instance, $status) = ($1, $2);
next if ($self->check_exclude(section => 'sf', instance => $instance));
next if ($self->check_filter(section => 'sf', instance => $instance));
$self->{components}->{sf}->{total}++;
$self->{output}->output_add(long_msg => sprintf("System flag '%s' status is %s.",
$instance, $status)
$self->{output}->output_add(
long_msg => sprintf(
"system flag '%s' status is %s.",
$instance, $status
)
);
foreach (keys %conditions) {
if ($status =~ /${$conditions{$_}}[0]/i) {
$self->{output}->output_add(severity => ${$conditions{$_}}[1],
short_msg => sprintf("System flag '%s' status is %s",
my $exit = $self->get_severity(label => 'default', section => 'sf', value => $status);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("system flag '%s' status is %s",
$instance, $status));
last;
}
}
}
}

View File

@ -24,16 +24,12 @@ use strict;
use warnings;
use centreon::plugins::misc;
my %conditions = (
1 => ['^(?!(ok)$)' => 'CRITICAL'],
);
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking supply voltages");
$self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0};
return if ($self->check_exclude(section => 'voltage'));
return if ($self->check_filter(section => 'voltage'));
#Supply voltages:
#1 5V status=ok
@ -48,19 +44,20 @@ sub check {
next if ($line !~ /^\s*(\S+).*?status=(.*)/);
my ($instance, $status) = ($1, $2);
next if ($self->check_exclude(section => 'voltage', instance => $instance));
next if ($self->check_filter(section => 'voltage', instance => $instance));
$self->{components}->{voltage}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Supply voltage '%s' status is %s.",
$instance, $status)
$self->{output}->output_add(
long_msg => sprintf(
"Supply voltage '%s' status is %s.",
$instance, $status
)
);
foreach (keys %conditions) {
if ($status =~ /${$conditions{$_}}[0]/i) {
$self->{output}->output_add(severity => ${$conditions{$_}}[1],
short_msg => sprintf("Supply voltage '%s' status is %s",
my $exit = $self->get_severity(label => 'default', section => 'voltage', value => $status);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("supply voltage '%s' status is %s",
$instance, $status));
last;
}
}
}
}