+ update: refactoring with hardware template class

This commit is contained in:
garnier-quentin 2016-01-08 14:29:55 +01:00
parent 2b1880531c
commit 27d9d58848
44 changed files with 562 additions and 2190 deletions

View File

@ -32,7 +32,6 @@ sub set_system {
$self->{cb_hook2} = 'snmp_execute'; $self->{cb_hook2} = 'snmp_execute';
#Example for threshold:
$self->{thresholds} = { $self->{thresholds} = {
psu => [ psu => [
['not operational', 'CRITICAL'], ['not operational', 'CRITICAL'],

View File

@ -44,9 +44,9 @@ my $mapping = {
my $oid_deviceDiskValueEntry = '.1.3.6.1.4.1.3417.2.2.1.1.1.1'; my $oid_deviceDiskValueEntry = '.1.3.6.1.4.1.3417.2.2.1.1.1.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_deviceDiskValueEntry }; push @{$self->{request}}, { oid => $oid_deviceDiskValueEntry };
} }
sub check { sub check {

View File

@ -66,9 +66,9 @@ my $mapping = {
my $oid_deviceSensorValueEntry = '.1.3.6.1.4.1.3417.2.1.1.1.1.1'; my $oid_deviceSensorValueEntry = '.1.3.6.1.4.1.3417.2.1.1.1.1.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_deviceSensorValueEntry }; push @{$self->{request}}, { oid => $oid_deviceSensorValueEntry };
} }
sub check { sub check {

View File

@ -20,13 +20,24 @@
package network::bluecoat::snmp::mode::hardware; package network::bluecoat::snmp::mode::hardware;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::hardware);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc;
my $thresholds = { my $thresholds = {
};
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(sensor|disk|sensor_opstatus)$';
$self->{regexp_threshold_numeric_check_section_option} = '^sensor$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
sensor_opstatus => [ sensor_opstatus => [
['ok', 'OK'], ['ok', 'OK'],
['unavailable', 'UNKNOWN'], ['unavailable', 'UNKNOWN'],
@ -61,7 +72,18 @@ my $thresholds = {
['unusable', 'CRITICAL'], ['unusable', 'CRITICAL'],
['unknown', 'UNKNOWN'], ['unknown', 'UNKNOWN'],
], ],
}; };
$self->{components_path} = 'network::bluecoat::snmp::mode::components';
$self->{components_module} = ['sensor', 'disk'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
@ -71,240 +93,11 @@ sub new {
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"filter:s@" => { name => 'filter' },
"absent-problem:s@" => { name => 'absent_problem' },
"component:s" => { name => 'component', default => '.*' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
"warning:s@" => { name => 'warning' },
"critical:s@" => { name => 'critical' },
}); });
$self->{components} = {};
$self->{no_components} = undef;
return $self; 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->{filter} = [];
foreach my $val (@{$self->{option_results}->{filter}}) {
next if (!defined($val) || $val eq '');
my @values = split (/,/, $val);
push @{$self->{filter}}, { filter => $values[0], instance => $values[1] };
}
$self->{absent_problem} = [];
foreach my $val (@{$self->{option_results}->{absent_problem}}) {
next if (!defined($val) || $val eq '');
my @values = split (/,/, $val);
push @{$self->{absent_problem}}, { filter => $values[0], instance => $values[1] };
}
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
next if (!defined($val) || $val eq '');
my @values = split (/,/, $val);
if (scalar(@values) < 3) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $instance, $status, $filter);
if (scalar(@values) == 3) {
($section, $status, $filter) = @values;
$instance = '.*';
} else {
($section, $instance, $status, $filter) = @values;
}
if ($section !~ /^sensor|disk|sensor_opstatus$/) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload section '" . $val . "'.");
$self->{output}->option_exit();
}
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, instance => $instance };
}
$self->{numeric_threshold} = {};
foreach my $option (('warning', 'critical')) {
foreach my $val (@{$self->{option_results}->{$option}}) {
next if (!defined($val) || $val eq '');
if ($val !~ /^(.*?),(.*?),(.*)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $instance, $value) = ($1, $2, $3);
if ($section !~ /^sensor$/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'.");
$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, instance => $instance };
}
}
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
my $snmp_request = [];
my @components = ('sensor', 'disk');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "network::bluecoat::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 = "network::bluecoat::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 absent_problem {
my ($self, %options) = @_;
foreach (@{$self->{absent_problem}}) {
if ($options{section} =~ /$_->{filter}/) {
if (!defined($_->{instance}) || $options{instance} =~ /$_->{instance}/) {
$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;
}
}
}
return 0;
}
sub check_filter {
my ($self, %options) = @_;
foreach (@{$self->{filter}}) {
if ($options{section} =~ /$_->{filter}/) {
if (!defined($options{instance}) && !defined($_->{instance})) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
return 1;
} elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
return 1;
}
}
}
return 0;
}
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} =~ /$_->{instance}/) {
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 &&
(!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) {
$status = $_->{status};
return $status;
}
}
}
my $label = defined($options{label}) ? $options{label} : $options{section};
foreach (@{$thresholds->{$label}}) {
if ($options{value} =~ /$$_[0]/i) {
$status = $$_[1];
return $status;
}
}
return $status;
}
1; 1;
__END__ __END__

View File

@ -37,9 +37,9 @@ my $mapping = {
my $oid_fanSpeedSensorEntry = '.1.3.6.1.4.1.2620.1.6.7.8.2.1'; my $oid_fanSpeedSensorEntry = '.1.3.6.1.4.1.2620.1.6.7.8.2.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_fanSpeedSensorEntry, start => $mapping->{fanSpeedSensorName}->{oid}, end => $mapping->{fanSpeedSensorStatus}->{oid} }; push @{$self->{request}}, { oid => $oid_fanSpeedSensorEntry, start => $mapping->{fanSpeedSensorName}->{oid}, end => $mapping->{fanSpeedSensorStatus}->{oid} };
} }
sub check { sub check {
@ -47,14 +47,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking fans"); $self->{output}->output_add(long_msg => "Checking fans");
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
return if ($self->check_exclude(section => 'fan')); return if ($self->check_filter(section => 'fan'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fanSpeedSensorEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fanSpeedSensorEntry}})) {
next if ($oid !~ /^$mapping->{fanSpeedSensorStatus}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{fanSpeedSensorStatus}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fanSpeedSensorEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fanSpeedSensorEntry}, instance => $instance);
next if ($self->check_exclude(section => 'fan', instance => $instance)); next if ($self->check_filter(section => 'fan', instance => $instance));
next if ($result->{fanSpeedSensorName} !~ /^[0-9a-zA-Z ]+$/); # sometimes there is some wrong values in hex next if ($result->{fanSpeedSensorName} !~ /^[0-9a-zA-Z ]+$/); # sometimes there is some wrong values in hex
$self->{components}->{fan}->{total}++; $self->{components}->{fan}->{total}++;

View File

@ -29,9 +29,9 @@ my $mapping = {
my $oid_powerSupplyStatus = '.1.3.6.1.4.1.2620.1.6.7.9.1.1.2'; my $oid_powerSupplyStatus = '.1.3.6.1.4.1.2620.1.6.7.9.1.1.2';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_powerSupplyStatus }; push @{$self->{request}}, { oid => $oid_powerSupplyStatus };
} }
sub check { sub check {
@ -39,14 +39,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking power supplies"); $self->{output}->output_add(long_msg => "Checking power supplies");
$self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0};
return if ($self->check_exclude(section => 'psu')); return if ($self->check_filter(section => 'psu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_powerSupplyStatus}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_powerSupplyStatus}})) {
next if ($oid !~ /^$mapping->{powerSupplyStatus}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{powerSupplyStatus}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_powerSupplyStatus}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_powerSupplyStatus}, instance => $instance);
next if ($self->check_exclude(section => 'psu', instance => $instance)); next if ($self->check_filter(section => 'psu', instance => $instance));
$self->{components}->{psu}->{total}++; $self->{components}->{psu}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s'", $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s'",

View File

@ -37,9 +37,9 @@ my $mapping = {
my $oid_tempertureSensorEntry = '.1.3.6.1.4.1.2620.1.6.7.8.1.1'; my $oid_tempertureSensorEntry = '.1.3.6.1.4.1.2620.1.6.7.8.1.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_tempertureSensorEntry, start => $mapping->{tempertureSensorName}->{oid}, end => $mapping->{tempertureSensorStatus}->{oid} }; push @{$self->{request}}, { oid => $oid_tempertureSensorEntry, start => $mapping->{tempertureSensorName}->{oid}, end => $mapping->{tempertureSensorStatus}->{oid} };
} }
sub check { sub check {
@ -47,14 +47,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking temperatures"); $self->{output}->output_add(long_msg => "Checking temperatures");
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; $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_tempertureSensorEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_tempertureSensorEntry}})) {
next if ($oid !~ /^$mapping->{tempertureSensorStatus}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{tempertureSensorStatus}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_tempertureSensorEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_tempertureSensorEntry}, instance => $instance);
next if ($self->check_exclude(section => 'temperature', instance => $instance)); next if ($self->check_filter(section => 'temperature', instance => $instance));
next if ($result->{tempertureSensorName} !~ /^[0-9a-zA-Z ]+$/); # sometimes there is some wrong values in hex next if ($result->{tempertureSensorName} !~ /^[0-9a-zA-Z ]+$/); # sometimes there is some wrong values in hex
$self->{components}->{temperature}->{total}++; $self->{components}->{temperature}->{total}++;

View File

@ -37,9 +37,9 @@ my $mapping = {
my $oid_voltageSensorEntry = '.1.3.6.1.4.1.2620.1.6.7.8.3.1'; my $oid_voltageSensorEntry = '.1.3.6.1.4.1.2620.1.6.7.8.3.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_voltageSensorEntry, start => $mapping->{voltageSensorName}->{oid}, end => $mapping->{voltageSensorStatus}->{oid} }; push @{$self->{request}}, { oid => $oid_voltageSensorEntry, start => $mapping->{voltageSensorName}->{oid}, end => $mapping->{voltageSensorStatus}->{oid} };
} }
sub check { sub check {
@ -47,14 +47,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking voltages"); $self->{output}->output_add(long_msg => "Checking voltages");
$self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0}; $self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0};
return if ($self->check_exclude(section => 'voltage')); return if ($self->check_filter(section => 'voltage'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_voltageSensorEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_voltageSensorEntry}})) {
next if ($oid !~ /^$mapping->{voltageSensorStatus}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{voltageSensorStatus}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_voltageSensorEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_voltageSensorEntry}, instance => $instance);
next if ($self->check_exclude(section => 'voltage', instance => $instance)); next if ($self->check_filter(section => 'voltage', instance => $instance));
next if ($result->{voltageSensorName} !~ /^[0-9a-zA-Z ]+$/); # sometimes there is some wrong values in hex next if ($result->{voltageSensorName} !~ /^[0-9a-zA-Z ]+$/); # sometimes there is some wrong values in hex
$self->{components}->{voltage}->{total}++; $self->{components}->{voltage}->{total}++;

View File

@ -20,12 +20,19 @@
package network::checkpoint::mode::hardware; package network::checkpoint::mode::hardware;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::hardware);
use strict; use strict;
use warnings; use warnings;
my $thresholds = { sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(temperature|voltage|fan|psu)$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
temperature => [ temperature => [
['true', 'CRITICAL'], ['true', 'CRITICAL'],
['reading error', 'CRITICAL'], ['reading error', 'CRITICAL'],
@ -46,150 +53,32 @@ my $thresholds = {
['down', 'CRITICAL'], ['down', 'CRITICAL'],
['.*', 'UNKNOWN'], ['.*', 'UNKNOWN'],
], ],
}; };
$self->{components_path} = 'network::checkpoint::mode::components';
$self->{components_module} = ['voltage', 'fan', 'temperature', 'psu'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
sub new { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"exclude:s" => { name => 'exclude' },
"component:s" => { name => 'component', default => '.*' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
}); });
$self->{components} = {};
$self->{no_components} = undef;
return $self; 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 treshold-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 treshold-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) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
my $snmp_request = [];
my @components = ('voltage', 'fan', 'temperature', 'psu');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "network::checkpoint::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 = "network::checkpoint::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 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; 1;
__END__ __END__
@ -205,15 +94,10 @@ Check hardware (fans, power supplies, temperatures, voltages).
Which component to check (Default: '.*'). Which component to check (Default: '.*').
Can be: 'psu', 'fan', 'temperature', 'voltage'. Can be: 'psu', 'fan', 'temperature', 'voltage'.
=item B<--exclude> =item B<--filter>
Exclude some parts (comma seperated list) (Example: --exclude=psu) Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu)
Can also exclude specific instance: --exclude='psu#1#' Can also exclude specific instance: --filter=psu,1
=item B<--absent-problem>
Return an error if an entity is not 'present' (default is skipping) (comma seperated list)
Can be specific or global: --absent-problem=fan#1#
=item B<--no-component> =item B<--no-component>
@ -222,7 +106,7 @@ If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload> =item B<--threshold-overload>
Set to overload default threshold values (syntax: section,status,regexp) Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays). It used before default thresholds (order stays).
Example: --threshold-overload='fan,CRITICAL,^(?!(false)$)' Example: --threshold-overload='fan,CRITICAL,^(?!(false)$)'

View File

@ -30,9 +30,9 @@ my $mapping = {
my $oid_fanEntry = '.1.3.6.1.4.1.15497.1.1.1.10.1'; my $oid_fanEntry = '.1.3.6.1.4.1.15497.1.1.1.10.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_fanEntry, start => $mapping->{fanRPMs}->{oid} }; push @{$self->{request}}, { oid => $oid_fanEntry, start => $mapping->{fanRPMs}->{oid} };
} }
sub check { sub check {
@ -40,14 +40,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking fans"); $self->{output}->output_add(long_msg => "Checking fans");
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
return if ($self->check_exclude(section => 'fan')); return if ($self->check_filter(section => 'fan'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fanEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fanEntry}})) {
next if ($oid !~ /^$mapping->{fanRPMs}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{fanRPMs}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fanEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fanEntry}, instance => $instance);
next if ($self->check_exclude(section => 'fan', instance => $instance)); next if ($self->check_filter(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++; $self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Fan '%s' is '%s' rpm [instance = %s]", $self->{output}->output_add(long_msg => sprintf("Fan '%s' is '%s' rpm [instance = %s]",

View File

@ -37,9 +37,9 @@ my $mapping = {
my $oid_powerSupplyEntry = '.1.3.6.1.4.1.15497.1.1.1.8.1'; my $oid_powerSupplyEntry = '.1.3.6.1.4.1.15497.1.1.1.8.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_powerSupplyEntry, start => $mapping->{powerSupplyStatus}->{oid} }; push @{$self->{request}}, { oid => $oid_powerSupplyEntry, start => $mapping->{powerSupplyStatus}->{oid} };
} }
sub check { sub check {
@ -47,14 +47,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking power supplies"); $self->{output}->output_add(long_msg => "Checking power supplies");
$self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0}; $self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0};
return if ($self->check_exclude(section => 'psu')); return if ($self->check_filter(section => 'psu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_powerSupplyEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_powerSupplyEntry}})) {
next if ($oid !~ /^$mapping->{powerSupplyStatus}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{powerSupplyStatus}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_powerSupplyEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_powerSupplyEntry}, instance => $instance);
next if ($self->check_exclude(section => 'psu', instance => $instance)); next if ($self->check_filter(section => 'psu', instance => $instance));
if ($result->{powerSupplyStatus} =~ /powerSupplyNotInstalled/i) { if ($result->{powerSupplyStatus} =~ /powerSupplyNotInstalled/i) {
$self->absent_problem(section => 'psu', instance => $instance); $self->absent_problem(section => 'psu', instance => $instance);
next; next;

View File

@ -36,9 +36,9 @@ my $mapping = {
my $oid_raidEntry = '.1.3.6.1.4.1.15497.1.1.1.18.1'; my $oid_raidEntry = '.1.3.6.1.4.1.15497.1.1.1.18.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_raidEntry, start => $mapping->{raidStatus}->{oid} }; push @{$self->{request}}, { oid => $oid_raidEntry, start => $mapping->{raidStatus}->{oid} };
} }
sub check { sub check {
@ -46,14 +46,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking raids"); $self->{output}->output_add(long_msg => "Checking raids");
$self->{components}->{raid} = {name => 'raids', total => 0, skip => 0}; $self->{components}->{raid} = {name => 'raids', total => 0, skip => 0};
return if ($self->check_exclude(section => 'raid')); return if ($self->check_filter(section => 'raid'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_raidEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_raidEntry}})) {
next if ($oid !~ /^$mapping->{raidStatus}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{raidStatus}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_raidEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_raidEntry}, instance => $instance);
next if ($self->check_exclude(section => 'raid', instance => $instance)); next if ($self->check_filter(section => 'raid', instance => $instance));
$self->{components}->{raid}->{total}++; $self->{components}->{raid}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Raid '%s' status is '%s' [instance = %s]", $self->{output}->output_add(long_msg => sprintf("Raid '%s' status is '%s' [instance = %s]",

View File

@ -44,9 +44,9 @@ my $mapping = {
my $oid_temperatureEntry = '.1.3.6.1.4.1.15497.1.1.1.9.1'; my $oid_temperatureEntry = '.1.3.6.1.4.1.15497.1.1.1.9.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_temperatureEntry, start => $mapping->{degreesCelsius}->{oid} }; push @{$self->{request}}, { oid => $oid_temperatureEntry, start => $mapping->{degreesCelsius}->{oid} };
} }
sub check { sub check {
@ -54,14 +54,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking temperatures"); $self->{output}->output_add(long_msg => "Checking temperatures");
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; $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_temperatureEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_temperatureEntry}})) {
next if ($oid !~ /^$mapping->{degreesCelsius}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{degreesCelsius}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_temperatureEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_temperatureEntry}, instance => $instance);
next if ($self->check_exclude(section => 'temperature', instance => $instance)); next if ($self->check_filter(section => 'temperature', instance => $instance));
$self->{components}->{temperature}->{total}++; $self->{components}->{temperature}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Temperature '%s' is '%s' degree centigrade [instance = %s]", $self->{output}->output_add(long_msg => sprintf("Temperature '%s' is '%s' degree centigrade [instance = %s]",

View File

@ -20,12 +20,20 @@
package network::cisco::ironport::snmp::mode::hardware; package network::cisco::ironport::snmp::mode::hardware;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::hardware);
use strict; use strict;
use warnings; use warnings;
my $thresholds = { sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(raid|psu)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(temperature|fan)$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
psu => [ psu => [
['powerSupplyNotInstalled', 'OK'], ['powerSupplyNotInstalled', 'OK'],
['powerSupplyHealthy', 'OK'], ['powerSupplyHealthy', 'OK'],
@ -37,7 +45,18 @@ my $thresholds = {
['driveFailure', 'CRITICAL'], ['driveFailure', 'CRITICAL'],
['driveRebuild', 'WARNING'], ['driveRebuild', 'WARNING'],
], ],
}; };
$self->{components_path} = 'network::cisco::ironport::snmp::mode::components';
$self->{components_module} = ['fan', 'temperature', 'psu', 'raid'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
@ -47,206 +66,11 @@ sub new {
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"exclude:s" => { name => 'exclude' },
"absent-problem:s" => { name => 'absent' },
"component:s" => { name => 'component', default => '.*' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
"warning:s@" => { name => 'warning' },
"critical:s@" => { name => 'critical' },
}); });
$self->{components} = {};
$self->{no_components} = undef;
return $self; 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 !~ /(temperature|fan)/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: temperature or fan).");
$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) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
my $snmp_request = [];
my @components = ('fan', 'temperature', 'psu', 'raid');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "network::cisco::ironport::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 = "network::cisco::ironport::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; 1;
__END__ __END__
@ -262,10 +86,10 @@ Check Hardware (Fans, Power Supplies, Temperatures, Raids).
Which component to check (Default: '.*'). Which component to check (Default: '.*').
Can be: 'fan', 'temperature', 'psu', 'raid'. Can be: 'fan', 'temperature', 'psu', 'raid'.
=item B<--exclude> =item B<--filter>
Exclude some parts (comma seperated list) (Example: --exclude=fan,temperature) Exclude some parts (comma seperated list) (Example: --filter=fan --filter=temperature)
Can also exclude specific instance: --exclude=fan#1#,temperature#2# Can also exclude specific instance: --filter=fan,1
=item B<--absent-problem> =item B<--absent-problem>
@ -279,7 +103,7 @@ If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload> =item B<--threshold-overload>
Set to overload default threshold values (syntax: section,status,regexp) Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays). It used before default thresholds (order stays).
Example: --threshold-overload='psu,CRITICAL,^(?!(powerSupplyHealthy)$)' Example: --threshold-overload='psu,CRITICAL,^(?!(powerSupplyHealthy)$)'

View File

@ -40,9 +40,9 @@ my $mapping = {
my $oid_rlEnvMonFanStatusEntry = '.1.3.6.1.4.1.171.10.94.89.89.83.1.1.1'; my $oid_rlEnvMonFanStatusEntry = '.1.3.6.1.4.1.171.10.94.89.89.83.1.1.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_rlEnvMonFanStatusEntry }; push @{$self->{request}}, { oid => $oid_rlEnvMonFanStatusEntry };
} }
sub check { sub check {
@ -50,14 +50,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking fans"); $self->{output}->output_add(long_msg => "Checking fans");
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
return if ($self->check_exclude(section => 'fan')); return if ($self->check_filter(section => 'fan'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonFanStatusEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonFanStatusEntry}})) {
next if ($oid !~ /^$mapping->{rlEnvMonFanStatusDescr}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{rlEnvMonFanStatusDescr}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonFanStatusEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonFanStatusEntry}, instance => $instance);
next if ($self->check_exclude(section => 'fan', instance => $result->{rlEnvMonFanStatusDescr})); next if ($self->check_filter(section => 'fan', instance => $result->{rlEnvMonFanStatusDescr}));
next if ($result->{rlEnvMonFanState} eq 'notPresent' && next if ($result->{rlEnvMonFanState} eq 'notPresent' &&
$self->absent_problem(section => 'fan', instance => $result->{rlEnvMonFanStatusDescr})); $self->absent_problem(section => 'fan', instance => $result->{rlEnvMonFanStatusDescr}));
$self->{components}->{fan}->{total}++; $self->{components}->{fan}->{total}++;

View File

@ -40,9 +40,9 @@ my $mapping = {
my $oid_rlEnvMonSupplyStatusEntry = '.1.3.6.1.4.1.171.10.94.89.89.83.1.2.1'; my $oid_rlEnvMonSupplyStatusEntry = '.1.3.6.1.4.1.171.10.94.89.89.83.1.2.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_rlEnvMonSupplyStatusEntry }; push @{$self->{request}}, { oid => $oid_rlEnvMonSupplyStatusEntry };
} }
sub check { sub check {
@ -50,14 +50,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking power supplies"); $self->{output}->output_add(long_msg => "Checking power supplies");
$self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0};
return if ($self->check_exclude(section => 'psu')); return if ($self->check_filter(section => 'psu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonSupplyStatusEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonSupplyStatusEntry}})) {
next if ($oid !~ /^$mapping->{rlEnvMonSupplyStatusDescr}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{rlEnvMonSupplyStatusDescr}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}, instance => $instance);
next if ($self->check_exclude(section => 'psu', instance => $result->{rlEnvMonSupplyStatusDescr})); next if ($self->check_filter(section => 'psu', instance => $result->{rlEnvMonSupplyStatusDescr}));
next if ($result->{rlEnvMonSupplyState} eq 'notPresent' && next if ($result->{rlEnvMonSupplyState} eq 'notPresent' &&
$self->absent_problem(section => 'psu', instance => $result->{rlEnvMonSupplyStatusDescr})); $self->absent_problem(section => 'psu', instance => $result->{rlEnvMonSupplyStatusDescr}));
$self->{components}->{psu}->{total}++; $self->{components}->{psu}->{total}++;

View File

@ -20,12 +20,19 @@
package network::dlink::dgs3100::snmp::mode::hardware; package network::dlink::dgs3100::snmp::mode::hardware;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::hardware);
use strict; use strict;
use warnings; use warnings;
my $thresholds = { sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(fan|psu)$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
psu => [ psu => [
['shutdown', 'WARNING'], ['shutdown', 'WARNING'],
['warning', 'WARNING'], ['warning', 'WARNING'],
@ -42,167 +49,32 @@ my $thresholds = {
['notPresent', 'OK'], ['notPresent', 'OK'],
['normal', 'OK'], ['normal', 'OK'],
], ],
}; };
$self->{components_path} = 'network::dlink::dgs3100::snmp::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 { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $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' },
}); });
$self->{components} = {};
$self->{no_components} = undef;
return $self; 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 treshold-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 treshold-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) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
my $snmp_request = [];
my @components = ('fan', 'psu');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "network::dlink::dgs3100::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 = "network::dlink::dgs3100::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 {
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; 1;
__END__ __END__
@ -218,10 +90,10 @@ Check hardware (Fans, Power Supplies).
Which component to check (Default: '.*'). Which component to check (Default: '.*').
Can be: 'psu', 'fan'. Can be: 'psu', 'fan'.
=item B<--exclude> =item B<--filter>
Exclude some parts (comma seperated list) (Example: --exclude=psu) Exclude some parts (comma seperated list) (Example: --filter=psu)
Can also exclude specific instance: --exclude='fan#fan1_unit2#' Can also exclude specific instance: --filter=fan,fan1_unit2
=item B<--absent-problem> =item B<--absent-problem>
@ -235,7 +107,7 @@ If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload> =item B<--threshold-overload>
Set to overload default threshold values (syntax: section,status,regexp) Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays). It used before default thresholds (order stays).
Example: --threshold-overload='psu,CRITICAL,^(?!(normal)$)' Example: --threshold-overload='psu,CRITICAL,^(?!(normal)$)'

View File

@ -41,9 +41,9 @@ my $mapping = {
my $oid_swFanEntry = '.1.3.6.1.4.1.171.12.11.1.7.1'; my $oid_swFanEntry = '.1.3.6.1.4.1.171.12.11.1.7.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_swFanEntry }; push @{$self->{request}}, { oid => $oid_swFanEntry };
} }
sub check { sub check {
@ -51,14 +51,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking fans"); $self->{output}->output_add(long_msg => "Checking fans");
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
return if ($self->check_exclude(section => 'fan')); return if ($self->check_filter(section => 'fan'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_swFanEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_swFanEntry}})) {
next if ($oid !~ /^$mapping->{swFanStatus}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{swFanStatus}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_swFanEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_swFanEntry}, instance => $instance);
next if ($self->check_exclude(section => 'fan', instance => $instance)); next if ($self->check_filter(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++; $self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("fan '%s' status is %s [speed = %s].", $self->{output}->output_add(long_msg => sprintf("fan '%s' status is %s [speed = %s].",

View File

@ -40,9 +40,9 @@ my $mapping = {
my $oid_swPowerEntry = '.1.3.6.1.4.1.171.12.11.1.6.1'; my $oid_swPowerEntry = '.1.3.6.1.4.1.171.12.11.1.6.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_swPowerEntry }; push @{$self->{request}}, { oid => $oid_swPowerEntry };
} }
sub check { sub check {
@ -50,14 +50,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking power supplies"); $self->{output}->output_add(long_msg => "Checking power supplies");
$self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0};
return if ($self->check_exclude(section => 'psu')); return if ($self->check_filter(section => 'psu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_swPowerEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_swPowerEntry}})) {
next if ($oid !~ /^$mapping->{swPowerStatus}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{swPowerStatus}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_swPowerEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_swPowerEntry}, instance => $instance);
next if ($self->check_exclude(section => 'psu', instance => $instance)); next if ($self->check_filter(section => 'psu', instance => $instance));
$self->{components}->{psu}->{total}++; $self->{components}->{psu}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is %s.", $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is %s.",

View File

@ -30,9 +30,9 @@ my $mapping = {
my $oid_swTemperatureEntry = '.1.3.6.1.4.1.171.12.11.1.8.1'; my $oid_swTemperatureEntry = '.1.3.6.1.4.1.171.12.11.1.8.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_swTemperatureEntry }; push @{$self->{request}}, { oid => $oid_swTemperatureEntry };
} }
sub check { sub check {
@ -40,14 +40,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking temperatures"); $self->{output}->output_add(long_msg => "Checking temperatures");
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; $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_swTemperatureEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_swTemperatureEntry}})) {
next if ($oid !~ /^$mapping->{swTemperatureCurrent}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{swTemperatureCurrent}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_swTemperatureEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_swTemperatureEntry}, instance => $instance);
next if ($self->check_exclude(section => 'temperature', instance => $instance)); next if ($self->check_filter(section => 'temperature', instance => $instance));
$self->{components}->{temperature}->{total}++; $self->{components}->{temperature}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Temperature '%s' is %dC.", $self->{output}->output_add(long_msg => sprintf("Temperature '%s' is %dC.",

View File

@ -20,12 +20,20 @@
package network::dlink::standard::snmp::mode::hardware; package network::dlink::standard::snmp::mode::hardware;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::hardware);
use strict; use strict;
use warnings; use warnings;
my $thresholds = { sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(fan|psu)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(fan|temperature)$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
psu => [ psu => [
['connect', 'OK'], ['connect', 'OK'],
['working', 'OK'], ['working', 'OK'],
@ -44,198 +52,32 @@ my $thresholds = {
['speed-middle', 'OK'], ['speed-middle', 'OK'],
['speed-high', 'WARNING'], ['speed-high', 'WARNING'],
], ],
}; };
$self->{components_path} = 'network::dlink::standard::snmp::mode::components';
$self->{components_module} = ['fan', 'psu', 'temperature'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"exclude:s" => { name => 'exclude' },
"component:s" => { name => 'component', default => '.*' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
"warning:s@" => { name => 'warning' },
"critical:s@" => { name => 'critical' },
}); });
$self->{components} = {};
$self->{no_components} = undef;
return $self; 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 treshold-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 treshold-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 !~ /(fan|temperature)/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: temperature or fan).");
$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) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
my $snmp_request = [];
my @components = ('fan', 'psu', 'temperature');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "network::dlink::standard::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 = "network::dlink::standard::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 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 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);
}
1; 1;
__END__ __END__
@ -251,10 +93,10 @@ Check hardware (Fans, Power Supplies, Temperatures).
Which component to check (Default: '.*'). Which component to check (Default: '.*').
Can be: 'psu', 'fan', 'temperature'. Can be: 'psu', 'fan', 'temperature'.
=item B<--exclude> =item B<--filter>
Exclude some parts (comma seperated list) (Example: --exclude=psu) Exclude some parts (comma seperated list) (Example: --filter=psu)
Can also exclude specific instance: --exclude='fan#1.1#' Can also exclude specific instance: --filter=fan,1.1
=item B<--no-component> =item B<--no-component>
@ -269,12 +111,12 @@ Example: --threshold-overload='fan,CRITICAL,^(?!(working)$)'
=item B<--warning> =item B<--warning>
Set warning threshold for temperatures (syntax: type,regexp,threshold) Set warning threshold for temperatures (syntax: section,[instance,]status,regexp)
Example: --warning='temperature,.*,30' --warning='fan,.*,1000' Example: --warning='temperature,.*,30' --warning='fan,.*,1000'
=item B<--critical> =item B<--critical>
Set critical threshold for temperatures (syntax: type,regexp,threshold) Set critical threshold for temperatures (syntax: section,[instance,]status,regexp)
Example: --critical='temperature,.*,40' Example: --critical='temperature,.*,40'
=back =back

View File

@ -33,7 +33,6 @@ sub set_system {
$self->{cb_hook2} = 'snmp_execute'; $self->{cb_hook2} = 'snmp_execute';
#Example for threshold:
$self->{thresholds} = { $self->{thresholds} = {
psu => [ psu => [
['notPresent', 'OK'], ['notPresent', 'OK'],

View File

@ -33,7 +33,6 @@ sub set_system {
$self->{cb_hook2} = 'snmp_execute'; $self->{cb_hook2} = 'snmp_execute';
#Example for threshold:
$self->{thresholds} = { $self->{thresholds} = {
fan => [ fan => [
['bad', 'CRITICAL'], ['bad', 'CRITICAL'],

View File

@ -34,9 +34,9 @@ my $mapping = {
}; };
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $mapping->{hmFanState}->{oid} }; push @{$self->{request}}, { oid => $mapping->{hmFanState}->{oid} };
} }
sub check { sub check {
@ -44,14 +44,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking fans"); $self->{output}->output_add(long_msg => "Checking fans");
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
return if ($self->check_exclude(section => 'fan')); return if ($self->check_filter(section => 'fan'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{hmFanState}->{oid}}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{hmFanState}->{oid}}})) {
next if ($oid !~ /^$mapping->{hmFanState}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{hmFanState}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{hmFanState}->{oid}}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{hmFanState}->{oid}}, instance => $instance);
next if ($self->check_exclude(section => 'fan', instance => $instance)); next if ($self->check_filter(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++; $self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("fan '%s' status is %s [instance: %s].", $self->{output}->output_add(long_msg => sprintf("fan '%s' status is %s [instance: %s].",

View File

@ -34,9 +34,9 @@ my %map_led_status = (
my $oid_hmLEDGroup = '.1.3.6.1.4.1.248.14.1.1.35'; my $oid_hmLEDGroup = '.1.3.6.1.4.1.248.14.1.1.35';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_hmLEDGroup }; push @{$self->{request}}, { oid => $oid_hmLEDGroup };
} }
sub check_led { sub check_led {
@ -49,7 +49,7 @@ sub check_led {
$options{mapping}->{$name}->{oid} =~ /\.(\d+)$/; $options{mapping}->{$name}->{oid} =~ /\.(\d+)$/;
my $instance = $1; my $instance = $1;
next if ($self->check_exclude(section => 'led', instance => $instance)); next if ($self->check_filter(section => 'led', instance => $instance));
$self->{components}->{led}->{total}++; $self->{components}->{led}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Led '%s' status is %s [instance: %s].", $self->{output}->output_add(long_msg => sprintf("Led '%s' status is %s [instance: %s].",
@ -70,7 +70,7 @@ sub check {
$self->{output}->output_add(long_msg => "Checking leds"); $self->{output}->output_add(long_msg => "Checking leds");
$self->{components}->{led} = {name => 'leds', total => 0, skip => 0}; $self->{components}->{led} = {name => 'leds', total => 0, skip => 0};
return if ($self->check_exclude(section => 'led')); return if ($self->check_filter(section => 'led'));
my $mapping; my $mapping;
if (defined($self->{results}->{$oid_hmLEDGroup}->{$oid_hmLEDGroup . '.1.1.0'})) { if (defined($self->{results}->{$oid_hmLEDGroup}->{$oid_hmLEDGroup . '.1.1.0'})) {

View File

@ -36,9 +36,9 @@ my $mapping = {
}; };
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $mapping->{hmPSState}->{oid} }; push @{$self->{request}}, { oid => $mapping->{hmPSState}->{oid} };
} }
sub check { sub check {
@ -46,14 +46,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking power supplies"); $self->{output}->output_add(long_msg => "Checking power supplies");
$self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0};
return if ($self->check_exclude(section => 'psu')); return if ($self->check_filter(section => 'psu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{hmPSState}->{oid}}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{hmPSState}->{oid}}})) {
next if ($oid !~ /^$mapping->{hmPSState}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{hmPSState}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{hmPSState}->{oid}}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{hmPSState}->{oid}}, instance => $instance);
next if ($self->check_exclude(section => 'psu', instance => $instance)); next if ($self->check_filter(section => 'psu', instance => $instance));
next if ($result->{hmPSState} =~ /notInstalled/i && next if ($result->{hmPSState} =~ /notInstalled/i &&
$self->absent_problem(section => 'psu', instance => $instance)); $self->absent_problem(section => 'psu', instance => $instance));
$self->{components}->{psu}->{total}++; $self->{components}->{psu}->{total}++;

View File

@ -32,9 +32,9 @@ my $mapping = {
my $oid_hmTempTable = '.1.3.6.1.4.1.248.14.2.5'; my $oid_hmTempTable = '.1.3.6.1.4.1.248.14.2.5';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_hmTempTable }; push @{$self->{request}}, { oid => $oid_hmTempTable };
} }
sub check { sub check {
@ -42,13 +42,13 @@ sub check {
$self->{output}->output_add(long_msg => "Checking temperatures"); $self->{output}->output_add(long_msg => "Checking temperatures");
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
return if ($self->check_exclude(section => 'temperature')); return if ($self->check_filter(section => 'temperature'));
return if (!defined($self->{results}->{$oid_hmTempTable}->{$mapping->{hmTemperature}->{oid} . '.0'})); return if (!defined($self->{results}->{$oid_hmTempTable}->{$mapping->{hmTemperature}->{oid} . '.0'}));
my $instance = 0; my $instance = 0;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hmTempTable}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hmTempTable}, instance => $instance);
next if ($self->check_exclude(section => 'temperature', instance => $instance)); next if ($self->check_filter(section => 'temperature', instance => $instance));
$self->{components}->{temperature}->{total}++; $self->{components}->{temperature}->{total}++;
$self->{output}->output_add(long_msg => sprintf("temperature is %dC [instance: %s].", $self->{output}->output_add(long_msg => sprintf("temperature is %dC [instance: %s].",

View File

@ -20,12 +20,20 @@
package network::hirschmann::standard::snmp::mode::hardware; package network::hirschmann::standard::snmp::mode::hardware;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::hardware);
use strict; use strict;
use warnings; use warnings;
my $thresholds = { sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(fan|psu|led)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(temperature)$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
fan => [ fan => [
['ok', 'OK'], ['ok', 'OK'],
['failed', 'CRITICAL'], ['failed', 'CRITICAL'],
@ -42,7 +50,18 @@ my $thresholds = {
['yellow', 'WARNING'], ['yellow', 'WARNING'],
['red', 'CRITICAL'], ['red', 'CRITICAL'],
], ],
}; };
$self->{components_path} = 'network::hirschmann::standard::snmp::mode::components';
$self->{components_module} = ['fan', 'psu', 'temperature', 'led'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
@ -52,207 +71,11 @@ sub new {
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"exclude:s" => { name => 'exclude' },
"absent-problem:s" => { name => 'absent' },
"component:s" => { name => 'component', default => '.*' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
"warning:s@" => { name => 'warning' },
"critical:s@" => { name => 'critical' },
}); });
$self->{components} = {};
$self->{no_components} = undef;
return $self; 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 !~ /(temperature)/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: 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) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
my $snmp_request = [];
my @components = ('fan', 'psu', 'temperature', 'led');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "network::hirschmann::standard::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 = "network::hirschmann::standard::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; 1;
__END__ __END__
@ -268,15 +91,15 @@ Check Hardware (Power Supplies, Fans, Temperatures, LEDs).
Which component to check (Default: '.*'). Which component to check (Default: '.*').
Can be: 'fan', 'psu', 'temperature', 'led'. Can be: 'fan', 'psu', 'temperature', 'led'.
=item B<--exclude> =item B<--filter>
Exclude some parts (comma seperated list) (Example: --exclude=fan) Exclude some parts (comma seperated list) (Example: --filter=fan)
Can also exclude specific instance: --exclude=fan#1.1#,psu#3.2# Can also exclude specific instance: --filter=fan,1.1
=item B<--absent-problem> =item B<--absent-problem>
Return an error if an entity is not 'present' (default is skipping) (comma seperated list) Return an error if an entity is not 'present' (default is skipping) (comma seperated list)
Can be specific or global: --absent-problem=psu#1.1# Can be specific or global: --absent-problem=psu,1.1
=item B<--no-component> =item B<--no-component>
@ -285,7 +108,7 @@ If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload> =item B<--threshold-overload>
Set to overload default threshold values (syntax: section,status,regexp) Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays). It used before default thresholds (order stays).
Example: --threshold-overload='psu,CRITICAL,^(?!(ok)$)' Example: --threshold-overload='psu,CRITICAL,^(?!(ok)$)'

View File

@ -45,9 +45,9 @@ my $mapping = {
my $oid_hpicfSensorEntry = '.1.3.6.1.4.1.11.2.14.11.1.2.6.1'; my $oid_hpicfSensorEntry = '.1.3.6.1.4.1.11.2.14.11.1.2.6.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_hpicfSensorEntry }; push @{$self->{request}}, { oid => $oid_hpicfSensorEntry };
} }
sub check { sub check {
@ -56,7 +56,7 @@ sub check {
$self->{output}->output_add(long_msg => "Checking sensors"); $self->{output}->output_add(long_msg => "Checking sensors");
$self->{components}->{sensor} = {name => 'sensors', total => 0, skip => 0}; $self->{components}->{sensor} = {name => 'sensors', total => 0, skip => 0};
return if ($self->check_exclude(section => 'sensor')); return if ($self->check_filter(section => 'sensor'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_hpicfSensorEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_hpicfSensorEntry}})) {
next if ($oid !~ /^$mapping->{hpicfSensorStatus}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{hpicfSensorStatus}->{oid}\.(.*)$/);
@ -64,7 +64,7 @@ sub check {
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hpicfSensorEntry}, instance => $instance_mapping); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hpicfSensorEntry}, instance => $instance_mapping);
my $instance = $result->{hpicfSensorObjectId} . '.' . $instance_mapping; my $instance = $result->{hpicfSensorObjectId} . '.' . $instance_mapping;
next if ($self->check_exclude(section => 'sensor', instance => $instance)); next if ($self->check_filter(section => 'sensor', instance => $instance));
next if ($result->{hpicfSensorStatus} =~ /not present/i && next if ($result->{hpicfSensorStatus} =~ /not present/i &&
$self->absent_problem(section => 'sensor', instance => $instance)); $self->absent_problem(section => 'sensor', instance => $instance));
$self->{components}->{sensor}->{total}++; $self->{components}->{sensor}->{total}++;

View File

@ -20,13 +20,19 @@
package network::hp::procurve::mode::environment; package network::hp::procurve::mode::environment;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::hardware);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc;
my $thresholds = { sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(sensor)$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
sensor => [ sensor => [
['unknown', 'UNKNOWN'], ['unknown', 'UNKNOWN'],
['bad', 'CRITICAL'], ['bad', 'CRITICAL'],
@ -34,165 +40,32 @@ my $thresholds = {
['good', 'OK'], ['good', 'OK'],
['not present', 'WARNING'], ['not present', 'WARNING'],
], ],
}; };
$self->{components_path} = 'network::hp::procurve::mode::components';
$self->{components_module} = ['sensor'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
sub new { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"exclude:s" => { name => 'exclude' },
"absent-problem:s" => { name => 'absent' },
"component:s" => { name => 'component', default => '.*' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
}); });
return $self; 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) = ('sensor', $1, $2);
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 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 run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
my $snmp_request = [];
my @components = ('sensor');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "network::hp::procurve::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 = "network::hp::procurve::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();
}
1; 1;
__END__ __END__
@ -208,15 +81,15 @@ Check sensors (hpicfChassis.mib).
Which component to check (Default: '.*'). Which component to check (Default: '.*').
Can be: 'sensor'. Can be: 'sensor'.
=item B<--exclude> =item B<--filter>
Exclude some parts (comma seperated list) Exclude some parts (comma seperated list) (Example: --filter=sensor)
Can also exclude specific instance: --exclude=sensor#fan.1# Can also exclude specific instance: --filter=sensor,fan.1
=item B<--absent-problem> =item B<--absent-problem>
Return an error if an entity is not 'present' (default is skipping) (comma seperated list) Return an error if an entity is not 'present' (default is skipping) (comma seperated list)
Can be specific or global: --absent-problem=sensor#temperature.2# Can be specific or global: --absent-problem=sensor,temperature.2
=item B<--no-component> =item B<--no-component>
@ -225,9 +98,9 @@ If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload> =item B<--threshold-overload>
Set to overload default threshold values (syntax: section,status,regexp) Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays). It used before default thresholds (order stays).
Example: --threshold-overload='CRITICAL,^(?!(good)$)' Example: --threshold-overload='sensor,CRITICAL,^(?!(good)$)'
=back =back

View File

@ -76,9 +76,9 @@ my $mapping = {
my $oid_jnxFruEntry = '.1.3.6.1.4.1.2636.3.1.15.1'; my $oid_jnxFruEntry = '.1.3.6.1.4.1.2636.3.1.15.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_jnxFruEntry, start => $mapping->{jnxFruName}->{oid}, end => $mapping->{jnxFruOfflineReason}->{oid} }; push @{$self->{request}}, { oid => $oid_jnxFruEntry, start => $mapping->{jnxFruName}->{oid}, end => $mapping->{jnxFruOfflineReason}->{oid} };
} }
sub check { sub check {
@ -86,14 +86,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking frus"); $self->{output}->output_add(long_msg => "Checking frus");
$self->{components}->{fru} = {name => 'frus', total => 0, skip => 0}; $self->{components}->{fru} = {name => 'frus', total => 0, skip => 0};
return if ($self->check_exclude(section => 'fru')); return if ($self->check_filter(section => 'fru'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_jnxFruEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_jnxFruEntry}})) {
next if ($oid !~ /^$mapping->{jnxFruName}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{jnxFruName}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_jnxFruEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_jnxFruEntry}, instance => $instance);
next if ($self->check_exclude(section => 'fru', instance => $instance)); next if ($self->check_filter(section => 'fru', instance => $instance));
next if ($result->{jnxFruState} =~ /empty/i && next if ($result->{jnxFruState} =~ /empty/i &&
$self->absent_problem(section => 'fru', instance => $instance)); $self->absent_problem(section => 'fru', instance => $instance));
$self->{components}->{fru}->{total}++; $self->{components}->{fru}->{total}++;

View File

@ -41,9 +41,9 @@ my $mapping = {
my $oid_jnxOperatingEntry = '.1.3.6.1.4.1.2636.3.1.13.1'; my $oid_jnxOperatingEntry = '.1.3.6.1.4.1.2636.3.1.13.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_jnxOperatingEntry, start => $mapping->{jnxOperatingDescr}->{oid}, end => $mapping->{jnxOperatingState}->{oid} }; push @{$self->{request}}, { oid => $oid_jnxOperatingEntry, start => $mapping->{jnxOperatingDescr}->{oid}, end => $mapping->{jnxOperatingState}->{oid} };
} }
sub check { sub check {
@ -51,14 +51,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking operatings"); $self->{output}->output_add(long_msg => "Checking operatings");
$self->{components}->{operating} = {name => 'operatings', total => 0, skip => 0}; $self->{components}->{operating} = {name => 'operatings', total => 0, skip => 0};
return if ($self->check_exclude(section => 'operating')); return if ($self->check_filter(section => 'operating'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_jnxOperatingEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_jnxOperatingEntry}})) {
next if ($oid !~ /^$mapping->{jnxOperatingDescr}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{jnxOperatingDescr}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_jnxOperatingEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_jnxOperatingEntry}, instance => $instance);
next if ($self->check_exclude(section => 'operating', instance => $instance)); next if ($self->check_filter(section => 'operating', instance => $instance));
$self->{components}->{operating}->{total}++; $self->{components}->{operating}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Operating '%s' state is %s [instance: %s]", $self->{output}->output_add(long_msg => sprintf("Operating '%s' state is %s [instance: %s]",

View File

@ -20,12 +20,21 @@
package network::juniper::common::junos::mode::hardware; package network::juniper::common::junos::mode::hardware;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::hardware);
use strict; use strict;
use warnings; use warnings;
my $thresholds = { sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(fru|operating)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(fru-temperature)$';
$self->{cb_hook1} = 'get_type';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
fru => [ fru => [
['unknown', 'UNKNOWN'], ['unknown', 'UNKNOWN'],
['present', 'OK'], ['present', 'OK'],
@ -47,7 +56,18 @@ my $thresholds = {
['down', 'CRITICAL'], ['down', 'CRITICAL'],
['standby', 'OK'], ['standby', 'OK'],
], ],
}; };
$self->{components_path} = 'network::juniper::common::junos::mode::components';
$self->{components_module} = ['fru', 'operating'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
@ -57,219 +77,22 @@ sub new {
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"exclude:s" => { name => 'exclude' },
"absent-problem:s" => { name => 'absent' },
"component:s" => { name => 'component', default => '.*' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
"warning:s@" => { name => 'warning' },
"critical:s@" => { name => 'critical' },
}); });
$self->{components} = {};
$self->{no_components} = undef;
return $self; 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 !~ /(fru-temperature)/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: fru-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) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
$self->get_type();
my $snmp_request = [];
my @components = ('fru', 'operating');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "network::juniper::common::junos::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 = "network::juniper::common::junos::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 get_type { sub get_type {
my ($self) = @_; my ($self, %options) = @_;
my $oid_jnxBoxDescr = ".1.3.6.1.4.1.2636.3.1.2.0"; my $oid_jnxBoxDescr = ".1.3.6.1.4.1.2636.3.1.2.0";
my $result = $self->{snmp}->get_leef(oids => [$oid_jnxBoxDescr]); my $result = $options{snmp}->get_leef(oids => [$oid_jnxBoxDescr]);
$self->{env_type} = defined($result->{$oid_jnxBoxDescr}) ? $result->{$oid_jnxBoxDescr} : 'unknown'; $self->{env_type} = defined($result->{$oid_jnxBoxDescr}) ? $result->{$oid_jnxBoxDescr} : 'unknown';
$self->{output}->output_add(long_msg => sprintf("Environment type: %s", $self->{env_type})); $self->{output}->output_add(long_msg => sprintf("Environment type: %s", $self->{env_type}));
} }
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; 1;
__END__ __END__
@ -285,15 +108,15 @@ Check Hardware (mib-jnx-chassis) (frus, operating).
Which component to check (Default: '.*'). Which component to check (Default: '.*').
Can be: 'fru', 'operating'. Can be: 'fru', 'operating'.
=item B<--exclude> =item B<--filter>
Exclude some parts (comma seperated list) (Example: --exclude=fru) Exclude some parts (comma seperated list) (Example: --filter=fru)
Can also exclude specific instance: --exclude=fru#7.3.0.0# Can also exclude specific instance: --filter=fru,7.3.0.0
=item B<--absent-problem> =item B<--absent-problem>
Return an error if an entity is not 'present' (default is skipping) (comma seperated list) Return an error if an entity is not 'present' (default is skipping) (comma seperated list)
Can be specific or global: --absent-problem=fru#7.1.0.0# Can be specific or global: --absent-problem=fru,7.1.0.0
=item B<--no-component> =item B<--no-component>
@ -302,18 +125,18 @@ If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload> =item B<--threshold-overload>
Set to overload default threshold values (syntax: section,status,regexp) Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays). It used before default thresholds (order stays).
Example: --threshold-overload='operating,CRITICAL,^(?!(running)$)' Example: --threshold-overload='operating,CRITICAL,^(?!(running)$)'
=item B<--warning> =item B<--warning>
Set warning threshold for fru temperatures (syntax: type,regexp,treshold) Set warning threshold for fru temperatures (syntax: type,regexp,threshold)
Example: --warning='fru-temperature,.*,30' Example: --warning='fru-temperature,.*,30'
=item B<--critical> =item B<--critical>
Set critical threshold for fru temperatures (syntax: type,regexp,treshold) Set critical threshold for fru temperatures (syntax: type,regexp,threshold)
Example: --critical='fru-temperature,.*,40' Example: --critical='fru-temperature,.*,40'
=back =back

View File

@ -34,9 +34,9 @@ my $mapping = {
my $oid_nsFanEntry = '.1.3.6.1.4.1.3224.21.2.1'; my $oid_nsFanEntry = '.1.3.6.1.4.1.3224.21.2.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_nsFanEntry }; push @{$self->{request}}, { oid => $oid_nsFanEntry };
} }
sub check { sub check {

View File

@ -35,9 +35,9 @@ my $mapping = {
my $oid_nsSlotEntry = '.1.3.6.1.4.1.3224.21.5.1'; my $oid_nsSlotEntry = '.1.3.6.1.4.1.3224.21.5.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_nsSlotEntry }; push @{$self->{request}}, { oid => $oid_nsSlotEntry };
} }
sub check { sub check {

View File

@ -34,9 +34,9 @@ my $mapping = {
my $oid_nsPowerEntry = '.1.3.6.1.4.1.3224.21.1.1'; my $oid_nsPowerEntry = '.1.3.6.1.4.1.3224.21.1.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_nsPowerEntry }; push @{$self->{request}}, { oid => $oid_nsPowerEntry };
} }
sub check { sub check {

View File

@ -30,9 +30,9 @@ my $mapping = {
my $oid_nsTemperatureEntry = '.1.3.6.1.4.1.3224.21.4.1'; my $oid_nsTemperatureEntry = '.1.3.6.1.4.1.3224.21.4.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_nsTemperatureEntry }; push @{$self->{request}}, { oid => $oid_nsTemperatureEntry };
} }
sub check { sub check {

View File

@ -20,12 +20,20 @@
package network::juniper::common::screenos::mode::hardware; package network::juniper::common::screenos::mode::hardware;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::hardware);
use strict; use strict;
use warnings; use warnings;
my $thresholds = { sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(psu|module|fan)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(temperature)$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
fan => [ fan => [
['active', 'OK'], ['active', 'OK'],
['.*', 'CRITICAL'], ['.*', 'CRITICAL'],
@ -38,222 +46,32 @@ my $thresholds = {
['active', 'OK'], ['active', 'OK'],
['.*', 'CRITICAL'], ['.*', 'CRITICAL'],
], ],
}; };
$self->{components_path} = 'network::juniper::common::screenos::mode::components';
$self->{components_module} = ['psu', 'fan', 'temperature', 'module'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"filter:s@" => { name => 'filter' },
"component:s" => { name => 'component', default => '.*' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
"warning:s@" => { name => 'warning' },
"critical:s@" => { name => 'critical' },
}); });
$self->{components} = {};
$self->{no_components} = undef;
return $self; 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->{filter} = [];
foreach my $val (@{$self->{option_results}->{filter}}) {
next if (!defined($val) || $val eq '');
my @values = split (/,/, $val);
push @{$self->{filter}}, { filter => $values[0], instance => $values[1] };
}
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
next if (!defined($val) || $val eq '');
my @values = split (/,/, $val);
if (scalar(@values) < 3) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $instance, $status, $filter);
if (scalar(@values) == 3) {
($section, $status, $filter) = @values;
$instance = '.*';
} else {
($section, $instance, $status, $filter) = @values;
}
if ($section !~ /^temperature|psu|module|fan$/) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload section '" . $val . "'.");
$self->{output}->option_exit();
}
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, instance => $instance };
}
$self->{numeric_threshold} = {};
foreach my $option (('warning', 'critical')) {
foreach my $val (@{$self->{option_results}->{$option}}) {
next if (!defined($val) || $val eq '');
if ($val !~ /^(.*?),(.*?),(.*)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $instance, $value) = ($1, $2, $3);
if ($section !~ /^sensor$/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'.");
$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, instance => $instance };
}
}
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
my $snmp_request = [];
my @components = ('psu', 'fan', 'temperature', 'module');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "network::juniper::common::screenos::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 = "network::juniper::common::screenos::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_filter {
my ($self, %options) = @_;
foreach (@{$self->{filter}}) {
if ($options{section} =~ /$_->{filter}/) {
if (!defined($options{instance}) && !defined($_->{instance})) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
return 1;
} elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
return 1;
}
}
}
return 0;
}
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} =~ /$_->{instance}/) {
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 &&
(!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) {
$status = $_->{status};
return $status;
}
}
}
my $label = defined($options{label}) ? $options{label} : $options{section};
foreach (@{$thresholds->{$label}}) {
if ($options{value} =~ /$$_[0]/i) {
$status = $$_[1];
return $status;
}
}
return $status;
}
1; 1;
__END__ __END__

View File

@ -37,9 +37,9 @@ my $mapping = {
my $oid_rbnSRStorageEntry = '.1.3.6.1.4.1.2352.2.24.1.2.1.1'; my $oid_rbnSRStorageEntry = '.1.3.6.1.4.1.2352.2.24.1.2.1.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_rbnSRStorageEntry }; push @{$self->{request}}, { oid => $oid_rbnSRStorageEntry };
} }
sub check { sub check {
@ -47,14 +47,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking disks"); $self->{output}->output_add(long_msg => "Checking disks");
$self->{components}->{disk} = {name => 'disks', total => 0, skip => 0}; $self->{components}->{disk} = {name => 'disks', total => 0, skip => 0};
return if ($self->check_exclude(section => 'disk')); return if ($self->check_filter(section => 'disk'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rbnSRStorageEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rbnSRStorageEntry}})) {
next if ($oid !~ /^$mapping->{rbnSRStorageStatus}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{rbnSRStorageStatus}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rbnSRStorageEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rbnSRStorageEntry}, instance => $instance);
next if ($self->check_exclude(section => 'disk', instance => $instance)); next if ($self->check_filter(section => 'disk', instance => $instance));
$self->{components}->{disk}->{total}++; $self->{components}->{disk}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Disk '%s' status is %s [instance: %s].", $self->{output}->output_add(long_msg => sprintf("Disk '%s' status is %s [instance: %s].",

View File

@ -38,9 +38,9 @@ my $mapping = {
my $oid_rbnFanStatusEntry = '.1.3.6.1.4.1.2352.2.4.1.1.1'; my $oid_rbnFanStatusEntry = '.1.3.6.1.4.1.2352.2.4.1.1.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_rbnFanStatusEntry }; push @{$self->{request}}, { oid => $oid_rbnFanStatusEntry };
} }
sub check { sub check {
@ -48,14 +48,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking fans"); $self->{output}->output_add(long_msg => "Checking fans");
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
return if ($self->check_exclude(section => 'fan')); return if ($self->check_filter(section => 'fan'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rbnFanStatusEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rbnFanStatusEntry}})) {
next if ($oid !~ /^$mapping->{rbnFanStatus}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{rbnFanStatus}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rbnFanStatusEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rbnFanStatusEntry}, instance => $instance);
next if ($self->check_exclude(section => 'fan', instance => $instance)); next if ($self->check_filter(section => 'fan', instance => $instance));
next if ($result->{rbnFanStatus} =~ /absent/i && next if ($result->{rbnFanStatus} =~ /absent/i &&
$self->absent_problem(section => 'fan', instance => $instance)); $self->absent_problem(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++; $self->{components}->{fan}->{total}++;

View File

@ -38,9 +38,9 @@ my $mapping = {
my $oid_rbnPowerStatusEntry = '.1.3.6.1.4.1.2352.2.4.1.2.1'; my $oid_rbnPowerStatusEntry = '.1.3.6.1.4.1.2352.2.4.1.2.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_rbnPowerStatusEntry }; push @{$self->{request}}, { oid => $oid_rbnPowerStatusEntry };
} }
sub check { sub check {
@ -48,14 +48,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking power supplies"); $self->{output}->output_add(long_msg => "Checking power supplies");
$self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0};
return if ($self->check_exclude(section => 'psu')); return if ($self->check_filter(section => 'psu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rbnPowerStatusEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rbnPowerStatusEntry}})) {
next if ($oid !~ /^$mapping->{rbnPowerStatus}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{rbnPowerStatus}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rbnPowerStatusEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rbnPowerStatusEntry}, instance => $instance);
next if ($self->check_exclude(section => 'psu', instance => $instance)); next if ($self->check_filter(section => 'psu', instance => $instance));
next if ($result->{rbnPowerStatus} =~ /absent/i && next if ($result->{rbnPowerStatus} =~ /absent/i &&
$self->absent_problem(section => 'psu', instance => $instance)); $self->absent_problem(section => 'psu', instance => $instance));
$self->{components}->{psu}->{total}++; $self->{components}->{psu}->{total}++;

View File

@ -31,9 +31,9 @@ my $mapping = {
my $oid_rbnEntityTempSensorEntry = '.1.3.6.1.4.1.2352.2.4.1.6.1'; my $oid_rbnEntityTempSensorEntry = '.1.3.6.1.4.1.2352.2.4.1.6.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_rbnEntityTempSensorEntry }; push @{$self->{request}}, { oid => $oid_rbnEntityTempSensorEntry };
} }
sub check { sub check {
@ -41,14 +41,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking temperatures"); $self->{output}->output_add(long_msg => "Checking temperatures");
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; $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_rbnEntityTempSensorEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rbnEntityTempSensorEntry}})) {
next if ($oid !~ /^$mapping->{rbnEntityTempCurrent}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{rbnEntityTempCurrent}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rbnEntityTempSensorEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rbnEntityTempSensorEntry}, instance => $instance);
next if ($self->check_exclude(section => 'temperature', instance => $instance)); next if ($self->check_filter(section => 'temperature', instance => $instance));
$self->{components}->{temperature}->{total}++; $self->{components}->{temperature}->{total}++;
$self->{output}->output_add(long_msg => sprintf("'%s' temperature is %dC [instance: %s].", $self->{output}->output_add(long_msg => sprintf("'%s' temperature is %dC [instance: %s].",

View File

@ -31,9 +31,9 @@ my $mapping = {
my $oid_rbnVoltageSensorEntry = '.1.3.6.1.4.1.2352.2.4.1.3.1'; my $oid_rbnVoltageSensorEntry = '.1.3.6.1.4.1.2352.2.4.1.3.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_rbnVoltageSensorEntry }; push @{$self->{request}}, { oid => $oid_rbnVoltageSensorEntry };
} }
sub check { sub check {
@ -41,14 +41,14 @@ sub check {
$self->{output}->output_add(long_msg => "Checking voltages"); $self->{output}->output_add(long_msg => "Checking voltages");
$self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0}; $self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0};
return if ($self->check_exclude(section => 'voltage')); return if ($self->check_filter(section => 'voltage'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rbnVoltageSensorEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rbnVoltageSensorEntry}})) {
next if ($oid !~ /^$mapping->{rbnVoltageCurrent}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{rbnVoltageCurrent}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rbnVoltageSensorEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rbnVoltageSensorEntry}, instance => $instance);
next if ($self->check_exclude(section => 'voltage', instance => $instance)); next if ($self->check_filter(section => 'voltage', instance => $instance));
$self->{components}->{voltage}->{total}++; $self->{components}->{voltage}->{total}++;
$self->{output}->output_add(long_msg => sprintf("'%s' voltage is %d mV [instance: %s].", $self->{output}->output_add(long_msg => sprintf("'%s' voltage is %d mV [instance: %s].",

View File

@ -20,12 +20,20 @@
package network::redback::snmp::mode::hardware; package network::redback::snmp::mode::hardware;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::hardware);
use strict; use strict;
use warnings; use warnings;
my $thresholds = { sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(fan|psu|disk)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(temperature|voltage)$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
fan => [ fan => [
['unknown', 'UNKNOWN'], ['unknown', 'UNKNOWN'],
['normal', 'OK'], ['normal', 'OK'],
@ -43,7 +51,18 @@ my $thresholds = {
['failed', 'CRITICAL'], ['failed', 'CRITICAL'],
['degrading', 'WARNING'], ['degrading', 'WARNING'],
], ],
}; };
$self->{components_path} = 'network::redback::snmp::mode::components';
$self->{components_module} = ['fan', 'psu', 'temperature', 'voltage', 'disk'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
@ -53,207 +72,11 @@ sub new {
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"exclude:s" => { name => 'exclude' },
"absent-problem:s" => { name => 'absent' },
"component:s" => { name => 'component', default => '.*' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
"warning:s@" => { name => 'warning' },
"critical:s@" => { name => 'critical' },
}); });
$self->{components} = {};
$self->{no_components} = undef;
return $self; 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 !~ /(temperature|voltage)/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: temperature or voltage).");
$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) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
my $snmp_request = [];
my @components = ('fan', 'psu', 'temperature', 'voltage', 'disk');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "network::redback::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 = "network::redback::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; 1;
__END__ __END__
@ -269,15 +92,15 @@ Check Hardware (Power Supplies, Fans, Temperatures, Voltages, Disks).
Which component to check (Default: '.*'). Which component to check (Default: '.*').
Can be: 'fan', 'psu', 'temperature', 'voltage', 'disk'. Can be: 'fan', 'psu', 'temperature', 'voltage', 'disk'.
=item B<--exclude> =item B<--filter>
Exclude some parts (comma seperated list) (Example: --exclude=fan) Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu)
Can also exclude specific instance: --exclude=fan#1#,psu#3# Can also exclude specific instance: --filter=fan,1
=item B<--absent-problem> =item B<--absent-problem>
Return an error if an entity is not 'present' (default is skipping) (comma seperated list) Return an error if an entity is not 'present' (default is skipping) (comma seperated list)
Can be specific or global: --absent-problem=fan#1# Can be specific or global: --absent-problem=fan,1
=item B<--no-component> =item B<--no-component>
@ -286,7 +109,7 @@ If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload> =item B<--threshold-overload>
Set to overload default threshold values (syntax: section,status,regexp) Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays). It used before default thresholds (order stays).
Example: --threshold-overload='fan,CRITICAL,^(?!(normal)$)' Example: --threshold-overload='fan,CRITICAL,^(?!(normal)$)'