+ update: refactoring with hardware template class

This commit is contained in:
garnier-quentin 2016-01-08 16:05:55 +01:00
parent 27d9d58848
commit 8ea10bda11
18 changed files with 441 additions and 1160 deletions

View File

@ -198,7 +198,7 @@ sub check_options {
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->call_object_callback(method_name => $self->{cb_threshold_numeric_check_section_option}, $self->call_object_callback(method_name => $self->{cb_threshold_numeric_check_section_option},
section => $section, option_value => $val); section => $section, option_name => $option, option_value => $val);
my $position = 0; my $position = 0;
if (defined($self->{numeric_threshold}->{$section})) { if (defined($self->{numeric_threshold}->{$section})) {
@ -215,12 +215,9 @@ sub check_options {
} }
} }
sub run { sub load_components {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{loaded} = 0;
$self->call_object_callback(method_name => $self->{cb_hook1},
%options);
foreach (@{$self->{components_module}}) { foreach (@{$self->{components_module}}) {
if (/$self->{option_results}->{component}/) { if (/$self->{option_results}->{component}/) {
my $mod_name = $self->{components_path} . "::$_"; my $mod_name = $self->{components_path} . "::$_";
@ -233,15 +230,10 @@ sub run {
} }
} }
} }
}
if ($self->{loaded} == 0) { sub exec_components {
$self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); my ($self, %options) = @_;
$self->{output}->option_exit();
}
$self->call_object_callback(method_name => $self->{cb_hook2},
%options);
foreach (@{$self->{components_module}}) { foreach (@{$self->{components_module}}) {
if (/$self->{option_results}->{component}/) { if (/$self->{option_results}->{component}/) {
@ -250,9 +242,23 @@ sub run {
$func->($self); $func->($self);
} }
} }
}
$self->call_object_callback(method_name => $self->{cb_hook3}, sub run {
%options); my ($self, %options) = @_;
$self->{loaded} = 0;
$self->call_object_callback(method_name => $self->{cb_hook1}, %options);
$self->load_components(%options);
if ($self->{loaded} == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'.");
$self->{output}->option_exit();
}
$self->call_object_callback(method_name => $self->{cb_hook2}, %options);
$self->exec_components(%options);
$self->call_object_callback(method_name => $self->{cb_hook3}, %options);
my $total_components = 0; my $total_components = 0;
my $display_by_component = ''; my $display_by_component = '';

View File

@ -25,9 +25,9 @@ use warnings;
use hardware::pdu::raritan::snmp::mode::components::resources qw($mapping %raritan_type %map_type); use hardware::pdu::raritan::snmp::mode::components::resources qw($mapping %raritan_type %map_type);
sub load { sub load {
my (%options) = @_; my ($self, %options) = @_;
push @{$options{request}}, { oid => $mapping->{$options{type} . '_label'}->{Label}->{oid} }, push @{$self->{request}}, { oid => $mapping->{$options{type} . '_label'}->{Label}->{oid} },
{ oid => $mapping->{$options{type}}->{Unit}->{oid} }, { oid => $mapping->{$options{type}}->{Unit}->{oid} },
{ oid => $mapping->{$options{type}}->{Decimal}->{oid} }, { oid => $mapping->{$options{type}}->{Decimal}->{oid} },
{ oid => $mapping->{$options{type}}->{EnabledThresholds}->{oid} }, { oid => $mapping->{$options{type}}->{EnabledThresholds}->{oid} },

View File

@ -20,210 +20,73 @@
package hardware::pdu::raritan::snmp::mode::inletsensors; package hardware::pdu::raritan::snmp::mode::inletsensors;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::hardware);
use strict; use strict;
use warnings; use warnings;
use hardware::pdu::raritan::snmp::mode::components::resources qw($thresholds %raritan_type); use hardware::pdu::raritan::snmp::mode::components::resources qw($thresholds %raritan_type);
sub set_system {
my ($self, %options) = @_;
$self->{cb_threshold_numeric_check_section_option} = 'check_numeric_section_option';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = $thresholds;
$self->{components_path} = 'hardware::pdu::raritan::snmp::mode::components';
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}, return_type => 1);
}
sub check_numeric_section_option {
my ($self, %options) = @_;
if (!defined($raritan_type{$options{section}})) {
$self->{output}->add_option_msg(short_msg => "Wrong $options{option_name} option '" . $options{option_value} . "'.");
$self->{output}->option_exit();
}
}
sub load_components {
my ($self, %options) = @_;
my $mod_name = $self->{components_path} . "::sensor";
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->($self, type => 'inlet');
$self->{loaded} = 1;
}
sub exec_components {
my ($self, %options) = @_;
my $mod_name = $self->{components_path} . "::sensor";
my $func = $mod_name->can('check');
$func->($self, component => $self->{option_results}->{component}, type => 'inlet');
}
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 ($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 (!defined($raritan_type{$section})) {
$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 $mod_name = "hardware::pdu::raritan::snmp::mode::components::sensor";
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->(type => 'inlet', request => $snmp_request);
$self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request, return_type => 1);
$func = $mod_name->can('check');
$func->($self, component => $self->{option_results}->{component}, type => 'inlet');
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 sensors 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 sensors 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

@ -20,210 +20,73 @@
package hardware::pdu::raritan::snmp::mode::ocprotsensors; package hardware::pdu::raritan::snmp::mode::ocprotsensors;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::hardware);
use strict; use strict;
use warnings; use warnings;
use hardware::pdu::raritan::snmp::mode::components::resources qw($thresholds %raritan_type); use hardware::pdu::raritan::snmp::mode::components::resources qw($thresholds %raritan_type);
sub set_system {
my ($self, %options) = @_;
$self->{cb_threshold_numeric_check_section_option} = 'check_numeric_section_option';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = $thresholds;
$self->{components_path} = 'hardware::pdu::raritan::snmp::mode::components';
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}, return_type => 1);
}
sub check_numeric_section_option {
my ($self, %options) = @_;
if (!defined($raritan_type{$options{section}})) {
$self->{output}->add_option_msg(short_msg => "Wrong $options{option_name} option '" . $options{option_value} . "'.");
$self->{output}->option_exit();
}
}
sub load_components {
my ($self, %options) = @_;
my $mod_name = $self->{components_path} . "::sensor";
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->($self, type => 'ocprot');
$self->{loaded} = 1;
}
sub exec_components {
my ($self, %options) = @_;
my $mod_name = $self->{components_path} . "::sensor";
my $func = $mod_name->can('check');
$func->($self, component => $self->{option_results}->{component}, type => 'ocprot');
}
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 ($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 (!defined($raritan_type{$section})) {
$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 $mod_name = "hardware::pdu::raritan::snmp::mode::components::sensor";
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->(type => 'ocprot', request => $snmp_request);
$self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request, return_type => 1);
$func = $mod_name->can('check');
$func->($self, component => $self->{option_results}->{component}, type => 'ocprot');
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 sensors 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 sensors 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

@ -20,12 +20,60 @@
package hardware::pdu::raritan::snmp::mode::outletsensors; package hardware::pdu::raritan::snmp::mode::outletsensors;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::hardware);
use strict; use strict;
use warnings; use warnings;
use hardware::pdu::raritan::snmp::mode::components::resources qw($thresholds %raritan_type); use hardware::pdu::raritan::snmp::mode::components::resources qw($thresholds %raritan_type);
sub set_system {
my ($self, %options) = @_;
$self->{cb_threshold_numeric_check_section_option} = 'check_numeric_section_option';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = $thresholds;
$self->{components_path} = 'hardware::pdu::raritan::snmp::mode::components';
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}, return_type => 1);
}
sub check_numeric_section_option {
my ($self, %options) = @_;
if (!defined($raritan_type{$options{section}})) {
$self->{output}->add_option_msg(short_msg => "Wrong $options{option_name} option '" . $options{option_value} . "'.");
$self->{output}->option_exit();
}
}
sub load_components {
my ($self, %options) = @_;
my $mod_name = $self->{components_path} . "::sensor";
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->($self, type => 'outlet');
$self->{loaded} = 1;
}
sub exec_components {
my ($self, %options) = @_;
my $mod_name = $self->{components_path} . "::sensor";
my $func = $mod_name->can('check');
$func->($self, component => $self->{option_results}->{component}, type => 'outlet');
}
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);
@ -34,196 +82,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' },
"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 ($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 (!defined($raritan_type{$section})) {
$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 $mod_name = "hardware::pdu::raritan::snmp::mode::components::sensor";
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->(type => 'outlet', request => $snmp_request);
$self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request, return_type => 1);
$func = $mod_name->can('check');
$func->($self, component => $self->{option_results}->{component}, type => 'outlet');
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 sensors 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 sensors 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

@ -48,7 +48,7 @@ sub check {
$self->{output}->output_add(long_msg => "Checking " . $options{component}); $self->{output}->output_add(long_msg => "Checking " . $options{component});
$self->{components}->{$options{component}} = {name => $options{component}, total => 0, skip => 0}; $self->{components}->{$options{component}} = {name => $options{component}, total => 0, skip => 0};
return if ($self->check_exclude(section => $options{component})); return if ($self->check_filter(section => $options{component}));
my $mapping = { my $mapping = {
EntityExtErrorStatus => { oid => $self->{branch} . '.19', map => \%map_default_status }, EntityExtErrorStatus => { oid => $self->{branch} . '.19', map => \%map_default_status },
@ -58,7 +58,7 @@ sub check {
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$self->{branch} . '.19'}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$self->{branch} . '.19'}, instance => $instance);
next if (!defined($result->{EntityExtErrorStatus})); next if (!defined($result->{EntityExtErrorStatus}));
next if ($self->check_exclude(section => $options{component}, instance => $instance)); next if ($self->check_filter(section => $options{component}, instance => $instance));
if ($result->{EntityExtErrorStatus} =~ /entityAbsent/i) { if ($result->{EntityExtErrorStatus} =~ /entityAbsent/i) {
$self->absent_problem(section => $options{component}, instance => $instance); $self->absent_problem(section => $options{component}, instance => $instance);
next; next;

View File

@ -36,7 +36,7 @@ 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'));
my $mapping = { my $mapping = {
EntityExtErrorStatus => { oid => $self->{branch} . '.19', map => \%map_fan_status }, EntityExtErrorStatus => { oid => $self->{branch} . '.19', map => \%map_fan_status },
@ -46,7 +46,7 @@ sub check {
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$self->{branch} . '.19'}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$self->{branch} . '.19'}, instance => $instance);
next if (!defined($result->{EntityExtErrorStatus})); next if (!defined($result->{EntityExtErrorStatus}));
next if ($self->check_exclude(section => 'fan', instance => $instance)); next if ($self->check_filter(section => 'fan', instance => $instance));
if ($result->{EntityExtErrorStatus} =~ /entityAbsent/i) { if ($result->{EntityExtErrorStatus} =~ /entityAbsent/i) {
$self->absent_problem(section => 'fan', instance => $instance); $self->absent_problem(section => 'fan', instance => $instance);
next; next;

View File

@ -36,7 +36,7 @@ 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'));
my $mapping = { my $mapping = {
EntityExtErrorStatus => { oid => $self->{branch} . '.19', map => \%map_psu_status }, EntityExtErrorStatus => { oid => $self->{branch} . '.19', map => \%map_psu_status },
@ -46,7 +46,7 @@ sub check {
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$self->{branch} . '.19'}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$self->{branch} . '.19'}, instance => $instance);
next if (!defined($result->{EntityExtErrorStatus})); next if (!defined($result->{EntityExtErrorStatus}));
next if ($self->check_exclude(section => 'psu', instance => $instance)); next if ($self->check_filter(section => 'psu', instance => $instance));
if ($result->{EntityExtErrorStatus} =~ /entityAbsent/i) { if ($result->{EntityExtErrorStatus} =~ /entityAbsent/i) {
$self->absent_problem(section => 'psu', instance => $instance); $self->absent_problem(section => 'psu', instance => $instance);
next; next;

View File

@ -36,7 +36,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'));
my $mapping = { my $mapping = {
EntityExtErrorStatus => { oid => $self->{branch} . '.19', map => \%map_sensor_status }, EntityExtErrorStatus => { oid => $self->{branch} . '.19', map => \%map_sensor_status },
@ -59,7 +59,7 @@ sub check {
my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $results, instance => $instance); my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $results, instance => $instance);
next if (!defined($result->{EntityExtErrorStatus})); next if (!defined($result->{EntityExtErrorStatus}));
next if ($self->check_exclude(section => 'sensor', instance => $instance)); next if ($self->check_filter(section => 'sensor', instance => $instance));
if ($result->{EntityExtErrorStatus} =~ /entityAbsent/i) { if ($result->{EntityExtErrorStatus} =~ /entityAbsent/i) {
$self->absent_problem(section => 'sensor', instance => $instance); $self->absent_problem(section => 'sensor', instance => $instance);
next; next;

View File

@ -20,13 +20,21 @@
package network::h3c::snmp::mode::hardware; package network::h3c::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::statefile; use centreon::plugins::statefile;
my $thresholds = { sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_numeric_check_section_option} = '^(temperature)$';
$self->{cb_hook1} = 'init_cache';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
psu => [ psu => [
['notSupported', 'WARNING'], ['notSupported', 'WARNING'],
['normal', 'OK'], ['normal', 'OK'],
@ -102,7 +110,48 @@ my $thresholds = {
['entityAbsent', 'OK'], ['entityAbsent', 'OK'],
['hardwareFaulty', 'CRITICAL'], ['hardwareFaulty', 'CRITICAL'],
], ],
}; };
$self->{components_path} = 'network::h3c::snmp::mode::components';
$self->{components_module} = ['fan', 'psu', 'slot', 'temperature'];
$self->{mapping_name} = {
1 => 'other', 2 => 'unknown', 3 => 'chassis', 4 => 'backplane', 5 => 'container', 6 => 'psu',
7 => 'fan', 8 => 'sensor', 9 => 'module', 10 => 'port', 11 => 'stack', 12 => 'cpu'
};
$self->{mapping_component} = {
1 => 'default', 2 => 'default', 3 => 'default', 4 => 'default', 5 => 'default', 6 => 'psu',
7 => 'fan', 8 => 'sensor', 9 => 'default', 10 => 'default', 11 => 'default', 12 => 'default'
};
}
my $oid_hh3cEntityExtStateEntry = '.1.3.6.1.4.1.25506.2.6.1.1.1.1';
my $oid_h3cEntityExtStateEntry = '.1.3.6.1.4.1.2011.10.2.6.1.1.1.1';
my $oid_h3cEntityExtErrorStatus = '.1.3.6.1.4.1.2011.10.2.6.1.1.1.1.19';
my $oid_hh3cEntityExtErrorStatus = '.1.3.6.1.4.1.25506.2.6.1.1.1.1.19';
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
$self->write_cache();
$self->{branch} = $oid_hh3cEntityExtStateEntry;
if (defined($self->{results}->{$oid_h3cEntityExtErrorStatus}) && scalar(keys %{$self->{results}->{$oid_h3cEntityExtErrorStatus}}) > 0) {
$self->{branch} = $oid_h3cEntityExtStateEntry;
}
}
sub init_cache {
my ($self, %options) = @_;
$self->{request} = [
{ oid => $oid_h3cEntityExtErrorStatus },
{ oid => $oid_hh3cEntityExtErrorStatus },
];
$self->check_cache(%options);
}
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
@ -112,20 +161,10 @@ 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' },
"reload-cache-time:s" => { name => 'reload_cache_time', default => 180 }, "reload-cache-time:s" => { name => 'reload_cache_time', default => 180 },
}); });
$self->{components} = {};
$self->{no_components} = undef;
$self->{statefile_cache} = centreon::plugins::statefile->new(%options); $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self; return $self;
} }
@ -133,54 +172,6 @@ sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::init(%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 };
}
}
$self->{statefile_cache}->check_options(%options); $self->{statefile_cache}->check_options(%options);
} }
@ -193,8 +184,8 @@ my $oid_entPhysicalName = '.1.3.6.1.2.1.47.1.1.1.1.7';
sub check_cache { sub check_cache {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{hostname} = $self->{snmp}->get_hostname(); $self->{hostname} = $options{snmp}->get_hostname();
$self->{snmp_port} = $self->{snmp}->get_port(); $self->{snmp_port} = $options{snmp}->get_port();
# init cache file # init cache file
$self->{write_cache} = 0; $self->{write_cache} = 0;
@ -202,7 +193,7 @@ sub check_cache {
my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp'); my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
if ($has_cache_file == 0 || if ($has_cache_file == 0 ||
!defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) { !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
push @{$self->{snmp_request}}, { oid => $oid_entPhysicalEntry, start => $oid_entPhysicalDescr, end => $oid_entPhysicalName }; push @{$self->{request}}, { oid => $oid_entPhysicalEntry, start => $oid_entPhysicalDescr, end => $oid_entPhysicalName };
$self->{write_cache} = 1; $self->{write_cache} = 1;
} }
} }
@ -250,159 +241,29 @@ sub get_instance_class {
return @instances; return @instances;
} }
sub run { sub load_components {
my ($self, %options) = @_; my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
my $oid_hh3cEntityExtStateEntry = '.1.3.6.1.4.1.25506.2.6.1.1.1.1'; foreach (keys %{$self->{mapping_name}}) {
my $oid_h3cEntityExtStateEntry = '.1.3.6.1.4.1.2011.10.2.6.1.1.1.1'; if ($self->{mapping_name}->{$_} =~ /$self->{option_results}->{component}/) {
my $oid_h3cEntityExtErrorStatus = '.1.3.6.1.4.1.2011.10.2.6.1.1.1.1.19'; my $mod_name = $self->{components_path} . "::" . $self->{mapping_component}->{$_};
my $oid_hh3cEntityExtErrorStatus = '.1.3.6.1.4.1.25506.2.6.1.1.1.1.19';
$self->{snmp_request} = [
{ oid => $oid_h3cEntityExtErrorStatus },
{ oid => $oid_hh3cEntityExtErrorStatus },
];
$self->check_cache();
my %mapping_name = (
1 => 'other', 2 => 'unknown', 3 => 'chassis', 4 => 'backplane', 5 => 'container', 6 => 'psu',
7 => 'fan', 8 => 'sensor', 9 => 'module', 10 => 'port', 11 => 'stack', 12 => 'cpu'
);
my %mapping_component = (
1 => 'default', 2 => 'default', 3 => 'default', 4 => 'default', 5 => 'default', 6 => 'psu',
7 => 'fan', 8 => 'sensor', 9 => 'default', 10 => 'default', 11 => 'default', 12 => 'default'
);
my $component = 0;
foreach (keys %mapping_name) {
if ($mapping_name{$_} =~ /$self->{option_results}->{component}/) {
my $mod_name = "network::h3c::snmp::mode::components::" . $mapping_component{$_};
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name,
error_msg => "Cannot load module '$mod_name'."); error_msg => "Cannot load module '$mod_name'.");
$component = 1; $self->{loaded} = 1;
} }
} }
if ($component == 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 => $self->{snmp_request}); sub exec_components {
$self->write_cache(); my ($self, %options) = @_;
$self->{branch} = $oid_hh3cEntityExtStateEntry; foreach (keys %{$self->{mapping_name}}) {
if (defined($self->{results}->{$oid_h3cEntityExtErrorStatus}) && scalar(keys %{$self->{results}->{$oid_h3cEntityExtErrorStatus}}) > 0) { if ($self->{mapping_name}->{$_} =~ /$self->{option_results}->{component}/) {
$self->{branch} = $oid_h3cEntityExtStateEntry; my $mod_name = $self->{components_path} . "::" . $self->{mapping_component}->{$_};
}
foreach (keys %mapping_name) {
if ($mapping_name{$_} =~ /$self->{option_results}->{component}/) {
my $mod_name = "network::h3c::snmp::mode::components::" . $mapping_component{$_};
my $func = $mod_name->can('check'); my $func = $mod_name->can('check');
$func->($self, component => $mapping_name{$_}, component_class => $_); $func->($self, component => $self->{mapping_name}->{$_}, component_class => $_);
} }
} }
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;
@ -421,10 +282,10 @@ Which component to check (Default: '.*').
Can be: 'fan', 'psu', 'other', 'unknown', 'sensor', 'chassis', 'backplane', Can be: 'fan', 'psu', 'other', 'unknown', 'sensor', 'chassis', 'backplane',
'container', 'module', 'port', 'stack', 'cpu'. 'container', 'module', 'port', 'stack', 'cpu'.
=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#101# Can also exclude specific instance: --filter=fan,101
=item B<--absent-problem> =item B<--absent-problem>
@ -438,7 +299,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

@ -37,9 +37,9 @@ my $oid_enclChannelShelfAddr = '.1.3.6.1.4.1.789.1.21.1.2.1.3';
my $oid_enclContactState = '.1.3.6.1.4.1.789.1.21.1.2.1.2'; my $oid_enclContactState = '.1.3.6.1.4.1.789.1.21.1.2.1.2';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_enclContactState }; push @{$self->{request}}, { oid => $oid_enclContactState };
} }
sub check { sub check {
@ -47,13 +47,13 @@ sub check {
$self->{output}->output_add(long_msg => "Checking communications"); $self->{output}->output_add(long_msg => "Checking communications");
$self->{components}->{communication} = {name => 'communications', total => 0, skip => 0}; $self->{components}->{communication} = {name => 'communications', total => 0, skip => 0};
return if ($self->check_exclude(section => 'communication')); return if ($self->check_filter(section => 'communication'));
for (my $i = 1; $i <= $self->{number_shelf}; $i++) { for (my $i = 1; $i <= $self->{number_shelf}; $i++) {
my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i}; my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i};
my $com_state = $map_com_states{$self->{results}->{$oid_enclContactState}->{$oid_enclContactState . '.' . $i}}; my $com_state = $map_com_states{$self->{results}->{$oid_enclContactState}->{$oid_enclContactState . '.' . $i}};
next if ($self->check_exclude(section => 'communication', instance => $shelf_addr)); next if ($self->check_filter(section => 'communication', instance => $shelf_addr));
$self->{components}->{communication}->{total}++; $self->{components}->{communication}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Shelve '%s' communication state is '%s'", $self->{output}->output_add(long_msg => sprintf("Shelve '%s' communication state is '%s'",

View File

@ -30,10 +30,9 @@ my $oid_enclElectronicsPresent = '.1.3.6.1.4.1.789.1.21.1.2.1.31';
my $oid_enclElectronicsFailed = '.1.3.6.1.4.1.789.1.21.1.2.1.33'; my $oid_enclElectronicsFailed = '.1.3.6.1.4.1.789.1.21.1.2.1.33';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_enclElectronicsPresent }; push @{$self->{request}}, { oid => $oid_enclElectronicsPresent }, { oid => $oid_enclElectronicsFailed };
push @{$options{request}}, { oid => $oid_enclElectronicsFailed };
} }
sub check { sub check {
@ -41,7 +40,7 @@ sub check {
$self->{output}->output_add(long_msg => "Checking electronics"); $self->{output}->output_add(long_msg => "Checking electronics");
$self->{components}->{electronics} = {name => 'electronics', total => 0, skip => 0}; $self->{components}->{electronics} = {name => 'electronics', total => 0, skip => 0};
return if ($self->check_exclude(section => 'electronics')); return if ($self->check_filter(section => 'electronics'));
for (my $i = 1; $i <= $self->{number_shelf}; $i++) { for (my $i = 1; $i <= $self->{number_shelf}; $i++) {
my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i}; my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i};
@ -52,7 +51,7 @@ sub check {
$num = centreon::plugins::misc::trim($num); $num = centreon::plugins::misc::trim($num);
next if ($num !~ /[0-9]/); next if ($num !~ /[0-9]/);
next if ($self->check_exclude(section => 'electronics', instance => $shelf_addr . '.' . $num)); next if ($self->check_filter(section => 'electronics', instance => $shelf_addr . '.' . $num));
$self->{components}->{electronics}->{total}++; $self->{components}->{electronics}->{total}++;
my $status = 'ok'; my $status = 'ok';

View File

@ -31,11 +31,10 @@ my $oid_enclFansFailed = '.1.3.6.1.4.1.789.1.21.1.2.1.18';
my $oid_enclFansSpeed = '.1.3.6.1.4.1.789.1.21.1.2.1.62'; my $oid_enclFansSpeed = '.1.3.6.1.4.1.789.1.21.1.2.1.62';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_enclFansPresent }; push @{$self->{request}}, { oid => $oid_enclFansPresent }, { oid => $oid_enclFansFailed },
push @{$options{request}}, { oid => $oid_enclFansFailed }; { oid => $oid_enclFansSpeed };
push @{$options{request}}, { oid => $oid_enclFansSpeed };
} }
sub check { sub check {
@ -43,7 +42,7 @@ 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'));
for (my $i = 1; $i <= $self->{number_shelf}; $i++) { for (my $i = 1; $i <= $self->{number_shelf}; $i++) {
my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i}; my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i};
@ -56,7 +55,7 @@ sub check {
next if ($num !~ /[0-9]/); next if ($num !~ /[0-9]/);
my $current_value = (defined($current_speed[$num - 1]) && $current_speed[$num - 1] =~ /(^|\s)([0-9]+)/) ? $2 : ''; my $current_value = (defined($current_speed[$num - 1]) && $current_speed[$num - 1] =~ /(^|\s)([0-9]+)/) ? $2 : '';
next if ($self->check_exclude(section => 'fan', instance => $shelf_addr . '.' . $num)); next if ($self->check_filter(section => 'fan', instance => $shelf_addr . '.' . $num));
$self->{components}->{fan}->{total}++; $self->{components}->{fan}->{total}++;
my $status = 'ok'; my $status = 'ok';

View File

@ -30,10 +30,9 @@ my $oid_enclPowerSuppliesPresent = '.1.3.6.1.4.1.789.1.21.1.2.1.13';
my $oid_enclPowerSuppliesFailed = '.1.3.6.1.4.1.789.1.21.1.2.1.15'; my $oid_enclPowerSuppliesFailed = '.1.3.6.1.4.1.789.1.21.1.2.1.15';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_enclPowerSuppliesPresent }; push @{$self->{request}}, { oid => $oid_enclPowerSuppliesPresent }, { oid => $oid_enclPowerSuppliesFailed };
push @{$options{request}}, { oid => $oid_enclPowerSuppliesFailed };
} }
sub check { sub check {
@ -41,7 +40,7 @@ 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'));
for (my $i = 1; $i <= $self->{number_shelf}; $i++) { for (my $i = 1; $i <= $self->{number_shelf}; $i++) {
my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i}; my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i};
@ -52,7 +51,7 @@ sub check {
$num = centreon::plugins::misc::trim($num); $num = centreon::plugins::misc::trim($num);
next if ($num !~ /[0-9]/); next if ($num !~ /[0-9]/);
next if ($self->check_exclude(section => 'psu', instance => $shelf_addr . '.' . $num)); next if ($self->check_filter(section => 'psu', instance => $shelf_addr . '.' . $num));
$self->{components}->{psu}->{total}++; $self->{components}->{psu}->{total}++;
my $status = 'ok'; my $status = 'ok';

View File

@ -38,9 +38,9 @@ my %map_raid_states = (
my $oid_raidPStatus = '.1.3.6.1.4.1.789.1.6.10.1.2'; my $oid_raidPStatus = '.1.3.6.1.4.1.789.1.6.10.1.2';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_raidPStatus }; push @{$self->{request}}, { oid => $oid_raidPStatus };
} }
sub check { sub check {
@ -48,14 +48,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_raidPStatus}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_raidPStatus}})) {
$oid =~ /^$oid_raidPStatus\.(.*)$/; $oid =~ /^$oid_raidPStatus\.(.*)$/;
my $instance = $1; my $instance = $1;
my $raid_state = $map_raid_states{$self->{results}->{$oid_raidPStatus}->{$oid}}; my $raid_state = $map_raid_states{$self->{results}->{$oid_raidPStatus}->{$oid}};
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' state is '%s'", $self->{output}->output_add(long_msg => sprintf("Raid '%s' state is '%s'",

View File

@ -53,9 +53,9 @@ my $oid_enclChannelShelfAddr = '.1.3.6.1.4.1.789.1.21.1.2.1.3';
my $oid_enclEntry = '.1.3.6.1.4.1.789.1.21.1.2.1'; my $oid_enclEntry = '.1.3.6.1.4.1.789.1.21.1.2.1';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_enclEntry, begin => $mapping->{enclTempSensorsPresent}->{oid}, end => $mapping->{enclTempSensorsUnderTempWarnThr}->{oid} }; push @{$self->{request}}, { oid => $oid_enclEntry, begin => $mapping->{enclTempSensorsPresent}->{oid}, end => $mapping->{enclTempSensorsUnderTempWarnThr}->{oid} };
} }
sub check { sub check {
@ -63,7 +63,7 @@ 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'));
for (my $i = 1; $i <= $self->{number_shelf}; $i++) { for (my $i = 1; $i <= $self->{number_shelf}; $i++) {
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_enclEntry}, instance => $i); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_enclEntry}, instance => $i);
@ -90,7 +90,7 @@ sub check {
$current_temp[$num - 1] =~ /(-*[0-9]+)C/; $current_temp[$num - 1] =~ /(-*[0-9]+)C/;
my $current_value = $1; my $current_value = $1;
next if ($self->check_exclude(section => 'temperature', instance => $shelf_addr . '.' . $num)); next if ($self->check_filter(section => 'temperature', instance => $shelf_addr . '.' . $num));
$self->{components}->{temperature}->{total}++; $self->{components}->{temperature}->{total}++;
my $status = 'ok'; my $status = 'ok';

View File

@ -53,9 +53,9 @@ my $oid_enclChannelShelfAddr = '.1.3.6.1.4.1.789.1.21.1.2.1.3';
my $oid_enclTable = '.1.3.6.1.4.1.789.1.21.1.2'; my $oid_enclTable = '.1.3.6.1.4.1.789.1.21.1.2';
sub load { sub load {
my (%options) = @_; my ($self) = @_;
push @{$options{request}}, { oid => $oid_enclTable, begin => $mapping->{enclVoltSensorsPresent}->{oid}, end => $mapping->{enclVoltSensorsUnderVoltWarnThr}->{oid} }; push @{$self->{request}}, { oid => $oid_enclTable, begin => $mapping->{enclVoltSensorsPresent}->{oid}, end => $mapping->{enclVoltSensorsUnderVoltWarnThr}->{oid} };
} }
sub check { sub check {
@ -63,7 +63,7 @@ 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'));
for (my $i = 1; $i <= $self->{number_shelf}; $i++) { for (my $i = 1; $i <= $self->{number_shelf}; $i++) {
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_enclTable}, instance => $i); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_enclTable}, instance => $i);
@ -86,7 +86,7 @@ sub check {
my $co_thr = (defined($crit_over_thr[$num - 1]) && $crit_over_thr[$num - 1] =~ /(^|\s)(-*[0-9]+)/) ? $2 : ''; my $co_thr = (defined($crit_over_thr[$num - 1]) && $crit_over_thr[$num - 1] =~ /(^|\s)(-*[0-9]+)/) ? $2 : '';
my $current_value = ($current_volt[$num - 1] =~ /(^|\s)(-*[0-9]+)/) ? $2 : ''; my $current_value = ($current_volt[$num - 1] =~ /(^|\s)(-*[0-9]+)/) ? $2 : '';
next if ($self->check_exclude(section => 'voltage', instance => $shelf_addr . '.' . $num)); next if ($self->check_filter(section => 'voltage', instance => $shelf_addr . '.' . $num));
$self->{components}->{voltage}->{total}++; $self->{components}->{voltage}->{total}++;
my $status = 'ok'; my $status = 'ok';

View File

@ -20,13 +20,20 @@
package storage::netapp::snmp::mode::shelf; package storage::netapp::snmp::mode::shelf;
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_numeric_check_section_option} = '^(voltage|temperature|fan)$';
$self->{cb_hook1} = 'init_shelf';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
communication => [ communication => [
['initializing', 'WARNING'], ['initializing', 'WARNING'],
['transitioning', 'WARNING'], ['transitioning', 'WARNING'],
@ -70,11 +77,24 @@ my $thresholds = {
['over warning threshold', 'WARNING'], ['over warning threshold', 'WARNING'],
['ok', 'OK'], ['ok', 'OK'],
], ],
}; };
$self->{components_path} = 'storage::netapp::snmp::mode::components';
$self->{components_module} = ['communication', 'psu', 'fan', 'temperature', 'voltage', 'electronics', 'raid'];
}
my $oid_enclNumber = '.1.3.6.1.4.1.789.1.21.1.1'; my $oid_enclNumber = '.1.3.6.1.4.1.789.1.21.1.1';
my $oid_enclChannelShelfAddr = '.1.3.6.1.4.1.789.1.21.1.2.1.3'; my $oid_enclChannelShelfAddr = '.1.3.6.1.4.1.789.1.21.1.2.1.3';
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
$self->{number_shelf} = defined($self->{results}->{$oid_enclNumber}->{$oid_enclNumber . '.0'}) ? $self->{results}->{$oid_enclNumber}->{$oid_enclNumber . '.0'} : -1;
$self->{shelf_addr} = $self->{results}->{$oid_enclChannelShelfAddr};
}
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);
@ -83,207 +103,15 @@ sub new {
$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' },
"warning:s@" => { name => 'warning' },
"critical:s@" => { name => 'critical' },
}); });
$self->{components} = {};
$self->{no_components} = undef;
return $self; return $self;
} }
sub check_options { sub init_shelf {
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 !~ /(voltage|temperature|fan)/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: fan, voltage or temperature).");
$self->{output}->option_exit();
}
my $position = 0;
if (defined($self->{numeric_threshold}->{$section})) {
$position = scalar(@{$self->{numeric_threshold}->{$section}});
}
if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'.");
$self->{output}->option_exit();
}
$self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section}));
push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, regexp => $regexp };
}
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
my $snmp_request = [];
my @components = ('communication', 'psu', 'fan', 'temperature', 'voltage', 'electronics', 'raid');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "storage::netapp::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();
}
push @{$snmp_request}, ({ oid => $oid_enclNumber }, { oid => $oid_enclChannelShelfAddr });
$self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request);
$self->{number_shelf} = defined($self->{results}->{$oid_enclNumber}->{$oid_enclNumber . '.0'}) ? $self->{results}->{$oid_enclNumber}->{$oid_enclNumber . '.0'} : -1;
$self->{shelf_addr} = $self->{results}->{$oid_enclChannelShelfAddr};
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "storage::netapp::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) = @_; my ($self, %options) = @_;
if (defined($options{instance})) { push @{$self->{request}}, ({ oid => $oid_enclNumber }, { oid => $oid_enclChannelShelfAddr });
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;
@ -301,15 +129,15 @@ Check Shelves hardware (temperatures, voltages, electronics, fan, power supplies
Which component to check (Default: '.*'). Which component to check (Default: '.*').
Can be: 'psu', 'fan', 'communication', 'voltage', 'temperature', 'electronics', 'raid'. Can be: 'psu', 'fan', 'communication', 'voltage', 'temperature', 'electronics', 'raid'.
=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#41239F00647-A#' Can also exclude specific instance: --filter=psu,41239F00647-A
=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#41239F00647-fan02# Can be specific or global: --absent-problem=fan,41239F00647-fan02
=item B<--no-component> =item B<--no-component>
@ -318,19 +146,19 @@ 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='gfc,CRITICAL,^(?!(Online)$)' Example: --threshold-overload='gfc,CRITICAL,^(?!(Online)$)'
=item B<--warning> =item B<--warning>
Set warning threshold for temperatures (syntax: regexp,treshold) Set warning threshold for temperature, fan, voltage (syntax: type,regexp,threshold)
Example: --warning='41239F00647-vimm46,20' --warning='41239F00647-vimm5.*,30' Example: --warning='41239F00647-vimm46,20' --warning='41239F00647-vimm5.*,30'
=item B<--critical> =item B<--critical>
Set critical threshold for temperatures (syntax: regexp,treshold) Set critical threshold for temperature, fan, voltage (syntax: type,regexp,threshold)
Example: --critical='41239F00647-vimm46,25' --warning='41239F00647-vimm5.*,35' Example: --critical='temperature,.*,25' --warning='temperature,.*,35'
=back =back