+ factorize code
This commit is contained in:
parent
b81605e7b1
commit
2338d9a46b
|
@ -43,10 +43,9 @@ my $oid_cefcFanTrayOperStatus = '.1.3.6.1.4.1.9.9.117.1.4.1.1.1'; # CISCO-ENTITY
|
||||||
my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2';
|
my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2';
|
||||||
|
|
||||||
sub load {
|
sub load {
|
||||||
my (%options) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
push @{$options{request}}, { oid => $oid_ciscoEnvMonFanStatusEntry };
|
push @{$self->{request}}, { oid => $oid_ciscoEnvMonFanStatusEntry }, { oid => $oid_cefcFanTrayOperStatus };
|
||||||
push @{$options{request}}, { oid => $oid_cefcFanTrayOperStatus };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_fan_envmon {
|
sub check_fan_envmon {
|
||||||
|
@ -64,7 +63,7 @@ sub check_fan_envmon {
|
||||||
|
|
||||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonFanStatusEntry}, instance => $instance);
|
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonFanStatusEntry}, instance => $instance);
|
||||||
|
|
||||||
next if ($self->check_exclude(section => 'fan', instance => $instance));
|
next if ($self->check_filter(section => 'fan', instance => $instance));
|
||||||
next if ($result->{ciscoEnvMonFanState} =~ /not present/i &&
|
next if ($result->{ciscoEnvMonFanState} =~ /not present/i &&
|
||||||
$self->absent_problem(section => 'fan', instance => $instance));
|
$self->absent_problem(section => 'fan', instance => $instance));
|
||||||
$self->{components}->{fan}->{total}++;
|
$self->{components}->{fan}->{total}++;
|
||||||
|
@ -95,7 +94,7 @@ sub check_fan_entity {
|
||||||
my $fan_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance};
|
my $fan_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance};
|
||||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcFanTrayOperStatus}, instance => $instance);
|
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcFanTrayOperStatus}, 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]",
|
||||||
|
@ -113,7 +112,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'));
|
||||||
|
|
||||||
check_fan_envmon($self);
|
check_fan_envmon($self);
|
||||||
check_fan_entity($self);
|
check_fan_entity($self);
|
||||||
|
|
|
@ -61,9 +61,9 @@ my $oid_cefcModuleOperStatus = '.1.3.6.1.4.1.9.9.117.1.2.1.1.2';
|
||||||
my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2';
|
my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2';
|
||||||
|
|
||||||
sub load {
|
sub load {
|
||||||
my (%options) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
push @{$options{request}}, { oid => $oid_cefcModuleOperStatus };
|
push @{$self->{request}}, { oid => $oid_cefcModuleOperStatus };
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check {
|
sub check {
|
||||||
|
@ -71,7 +71,7 @@ sub check {
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => "Checking modules");
|
$self->{output}->output_add(long_msg => "Checking modules");
|
||||||
$self->{components}->{module} = {name => 'modules', total => 0, skip => 0};
|
$self->{components}->{module} = {name => 'modules', total => 0, skip => 0};
|
||||||
return if ($self->check_exclude(section => 'module'));
|
return if ($self->check_filter(section => 'module'));
|
||||||
|
|
||||||
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cefcModuleOperStatus}})) {
|
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cefcModuleOperStatus}})) {
|
||||||
$oid =~ /\.([0-9]+)$/;
|
$oid =~ /\.([0-9]+)$/;
|
||||||
|
@ -79,7 +79,7 @@ sub check {
|
||||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcModuleOperStatus}, instance => $instance);
|
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcModuleOperStatus}, instance => $instance);
|
||||||
my $module_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance};
|
my $module_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance};
|
||||||
|
|
||||||
next if ($self->check_exclude(section => 'module', instance => $instance));
|
next if ($self->check_filter(section => 'module', instance => $instance));
|
||||||
|
|
||||||
$self->{components}->{module}->{total}++;
|
$self->{components}->{module}->{total}++;
|
||||||
$self->{output}->output_add(long_msg => sprintf("Module '%s' status is %s [instance: %s]",
|
$self->{output}->output_add(long_msg => sprintf("Module '%s' status is %s [instance: %s]",
|
||||||
|
|
|
@ -38,9 +38,9 @@ my $oid_cefcPhysicalStatus = '.1.3.6.1.4.1.9.9.117.1.5.1.1.1';
|
||||||
my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2';
|
my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2';
|
||||||
|
|
||||||
sub load {
|
sub load {
|
||||||
my (%options) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
push @{$options{request}}, { oid => $oid_cefcPhysicalStatus };
|
push @{$self->{request}}, { oid => $oid_cefcPhysicalStatus };
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check {
|
sub check {
|
||||||
|
@ -48,7 +48,7 @@ sub check {
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => "Checking physicals");
|
$self->{output}->output_add(long_msg => "Checking physicals");
|
||||||
$self->{components}->{physical} = {name => 'physical', total => 0, skip => 0};
|
$self->{components}->{physical} = {name => 'physical', total => 0, skip => 0};
|
||||||
return if ($self->check_exclude(section => 'physical'));
|
return if ($self->check_filter(section => 'physical'));
|
||||||
|
|
||||||
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cefcPhysicalStatus}})) {
|
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cefcPhysicalStatus}})) {
|
||||||
$oid =~ /\.([0-9]+)$/;
|
$oid =~ /\.([0-9]+)$/;
|
||||||
|
@ -61,7 +61,7 @@ sub check {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
next if ($self->check_exclude(section => 'physical', instance => $instance));
|
next if ($self->check_filter(section => 'physical', instance => $instance));
|
||||||
|
|
||||||
$self->{components}->{physical}->{total}++;
|
$self->{components}->{physical}->{total}++;
|
||||||
$self->{output}->output_add(long_msg => sprintf("Physical '%s' status is %s [instance: %s]",
|
$self->{output}->output_add(long_msg => sprintf("Physical '%s' status is %s [instance: %s]",
|
||||||
|
|
|
@ -58,10 +58,9 @@ my $oid_cefcFRUPowerOperStatus = '.1.3.6.1.4.1.9.9.117.1.1.2.1.2'; # CISCO-ENTIT
|
||||||
my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2';
|
my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2';
|
||||||
|
|
||||||
sub load {
|
sub load {
|
||||||
my (%options) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
push @{$options{request}}, { oid => $oid_ciscoEnvMonSupplyStatusEntry };
|
push @{$self->{request}}, { oid => $oid_ciscoEnvMonSupplyStatusEntry }, { oid => $oid_cefcFRUPowerOperStatus };
|
||||||
push @{$options{request}}, { oid => $oid_cefcFRUPowerOperStatus };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_psu_envmon {
|
sub check_psu_envmon {
|
||||||
|
@ -80,7 +79,7 @@ sub check_psu_envmon {
|
||||||
|
|
||||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonSupplyStatusEntry}, instance => $instance);
|
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonSupplyStatusEntry}, instance => $instance);
|
||||||
|
|
||||||
next if ($self->check_exclude(section => 'psu', instance => $instance));
|
next if ($self->check_filter(section => 'psu', instance => $instance));
|
||||||
next if ($result->{ciscoEnvMonSupplyState} =~ /not present/i &&
|
next if ($result->{ciscoEnvMonSupplyState} =~ /not present/i &&
|
||||||
$self->absent_problem(section => 'psu', instance => $instance));
|
$self->absent_problem(section => 'psu', instance => $instance));
|
||||||
$self->{components}->{psu}->{total}++;
|
$self->{components}->{psu}->{total}++;
|
||||||
|
@ -111,7 +110,7 @@ sub check_psu_entity {
|
||||||
my $psu_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance};
|
my $psu_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance};
|
||||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcFRUPowerOperStatus}, instance => $instance);
|
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcFRUPowerOperStatus}, 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 [instance: %s]",
|
$self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is %s [instance: %s]",
|
||||||
|
@ -129,7 +128,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'));
|
||||||
|
|
||||||
check_psu_envmon($self);
|
check_psu_envmon($self);
|
||||||
check_psu_entity($self);
|
check_psu_entity($self);
|
||||||
|
|
|
@ -112,9 +112,9 @@ my $oid_entSensorThresholdEntry = '.1.3.6.1.4.1.9.9.91.1.2.1.1';
|
||||||
my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2';
|
my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2';
|
||||||
|
|
||||||
sub load {
|
sub load {
|
||||||
my (%options) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
push @{$options{request}}, { oid => $oid_entSensorValueEntry }, { oid => $oid_entSensorThresholdEntry };
|
push @{$self->{request}}, { oid => $oid_entSensorValueEntry }, { oid => $oid_entSensorThresholdEntry };
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_default_warning_threshold {
|
sub get_default_warning_threshold {
|
||||||
|
@ -178,7 +178,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_entSensorValueEntry}})) {
|
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_entSensorValueEntry}})) {
|
||||||
next if ($oid !~ /^$mapping->{entSensorStatus}->{oid}\.(.*)$/);
|
next if ($oid !~ /^$mapping->{entSensorStatus}->{oid}\.(.*)$/);
|
||||||
|
@ -188,7 +188,7 @@ sub check {
|
||||||
next if (!defined($self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance}));
|
next if (!defined($self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance}));
|
||||||
my $sensor_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance};
|
my $sensor_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance};
|
||||||
|
|
||||||
next if ($self->check_exclude(section => 'sensor', instance => $instance));
|
next if ($self->check_filter(section => 'sensor', instance => $instance));
|
||||||
$self->{components}->{sensor}->{total}++;
|
$self->{components}->{sensor}->{total}++;
|
||||||
|
|
||||||
$result->{entSensorValue} = defined($result->{entSensorValue}) ?
|
$result->{entSensorValue} = defined($result->{entSensorValue}) ?
|
||||||
|
|
|
@ -42,9 +42,9 @@ my $mapping = {
|
||||||
my $oid_ciscoEnvMonTemperatureStatusEntry = '.1.3.6.1.4.1.9.9.13.1.3.1';
|
my $oid_ciscoEnvMonTemperatureStatusEntry = '.1.3.6.1.4.1.9.9.13.1.3.1';
|
||||||
|
|
||||||
sub load {
|
sub load {
|
||||||
my (%options) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
push @{$options{request}}, { oid => $oid_ciscoEnvMonTemperatureStatusEntry };
|
push @{$self->{request}}, { oid => $oid_ciscoEnvMonTemperatureStatusEntry };
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check {
|
sub check {
|
||||||
|
@ -52,14 +52,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_ciscoEnvMonTemperatureStatusEntry}})) {
|
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_ciscoEnvMonTemperatureStatusEntry}})) {
|
||||||
next if ($oid !~ /^$mapping->{ciscoEnvMonTemperatureState}->{oid}\.(.*)$/);
|
next if ($oid !~ /^$mapping->{ciscoEnvMonTemperatureState}->{oid}\.(.*)$/);
|
||||||
my $instance = $1;
|
my $instance = $1;
|
||||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonTemperatureStatusEntry}, instance => $instance);
|
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonTemperatureStatusEntry}, 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' status is %s [instance: %s] [value: %s C]",
|
$self->{output}->output_add(long_msg => sprintf("Temperature '%s' status is %s [instance: %s] [value: %s C]",
|
||||||
|
|
|
@ -43,9 +43,9 @@ my $mapping = {
|
||||||
my $oid_ciscoEnvMonVoltageStatusEntry = '.1.3.6.1.4.1.9.9.13.1.2.1';
|
my $oid_ciscoEnvMonVoltageStatusEntry = '.1.3.6.1.4.1.9.9.13.1.2.1';
|
||||||
|
|
||||||
sub load {
|
sub load {
|
||||||
my (%options) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
push @{$options{request}}, { oid => $oid_ciscoEnvMonVoltageStatusEntry };
|
push @{$self->{request}}, { oid => $oid_ciscoEnvMonVoltageStatusEntry };
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check {
|
sub check {
|
||||||
|
@ -53,14 +53,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_ciscoEnvMonVoltageStatusEntry}})) {
|
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_ciscoEnvMonVoltageStatusEntry}})) {
|
||||||
next if ($oid !~ /^$mapping->{ciscoEnvMonVoltageState}->{oid}\.(.*)$/);
|
next if ($oid !~ /^$mapping->{ciscoEnvMonVoltageState}->{oid}\.(.*)$/);
|
||||||
my $instance = $1;
|
my $instance = $1;
|
||||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonVoltageStatusEntry}, instance => $instance);
|
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonVoltageStatusEntry}, 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("Voltage '%s' status is %s [instance: %s] [value: %s C]",
|
$self->{output}->output_add(long_msg => sprintf("Voltage '%s' status is %s [instance: %s] [value: %s C]",
|
||||||
|
|
|
@ -20,11 +20,86 @@
|
||||||
|
|
||||||
package centreon::common::cisco::standard::snmp::mode::environment;
|
package centreon::common::cisco::standard::snmp::mode::environment;
|
||||||
|
|
||||||
use base qw(centreon::plugins::mode);
|
use base qw(centreon::plugins::templates::hardware);
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
|
sub set_system {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->{regexp_threshold_overload_check_section_option} = '^(fan|psu|temperature|voltage|module|physical|sensor)$';
|
||||||
|
$self->{regexp_threshold_numeric_check_section_option} = '^(temperature|voltage|sensor)$';
|
||||||
|
|
||||||
|
$self->{cb_hook2} = 'snmp_execute';
|
||||||
|
|
||||||
|
$self->{thresholds} = {
|
||||||
|
fan => [
|
||||||
|
['unknown', 'UNKNOWN'],
|
||||||
|
['down', 'CRITICAL'],
|
||||||
|
['up', 'OK'],
|
||||||
|
|
||||||
|
['normal', 'OK'],
|
||||||
|
['warning', 'WARNING'],
|
||||||
|
['critical', 'CRITICAL'],
|
||||||
|
['shutdown', 'CRITICAL'],
|
||||||
|
['not present', 'OK'],
|
||||||
|
['not functioning', 'WARNING'],
|
||||||
|
],
|
||||||
|
psu => [
|
||||||
|
['^off*', 'WARNING'],
|
||||||
|
['failed', 'CRITICAL'],
|
||||||
|
['onButFanFail|onButInlinePowerFail', 'WARNING'],
|
||||||
|
['on', 'OK'],
|
||||||
|
|
||||||
|
['normal', 'OK'],
|
||||||
|
['warning', 'WARNING'],
|
||||||
|
['critical', 'CRITICAL'],
|
||||||
|
['shutdown', 'CRITICAL'],
|
||||||
|
['not present', 'OK'],
|
||||||
|
['not functioning', 'WARNING'],
|
||||||
|
],
|
||||||
|
temperature => [
|
||||||
|
['normal', 'OK'],
|
||||||
|
['warning', 'WARNING'],
|
||||||
|
['critical', 'CRITICAL'],
|
||||||
|
['shutdown', 'CRITICAL'],
|
||||||
|
['not present', 'OK'],
|
||||||
|
['not functioning', 'WARNING'],
|
||||||
|
],
|
||||||
|
voltage => [
|
||||||
|
['normal', 'OK'],
|
||||||
|
['warning', 'WARNING'],
|
||||||
|
['critical', 'CRITICAL'],
|
||||||
|
['shutdown', 'CRITICAL'],
|
||||||
|
['not present', 'OK'],
|
||||||
|
['not functioning', 'WARNING'],
|
||||||
|
],
|
||||||
|
module => [
|
||||||
|
['unknown|mdr', 'UNKNOWN'],
|
||||||
|
['disabled|okButDiagFailed|missing|mismatchWithParent|mismatchConfig|dormant|outOfServiceAdmin|outOfServiceEnvTemp|powerCycled|okButPowerOverWarning|okButAuthFailed|fwMismatchFound|fwDownloadFailure', 'WARNING'],
|
||||||
|
['failed|diagFailed|poweredDown|powerDenied|okButPowerOverCritical', 'CRITICAL'],
|
||||||
|
['boot|selfTest|poweredUp|syncInProgress|upgrading|fwDownloadSuccess|ok', 'OK'],
|
||||||
|
],
|
||||||
|
physical => [
|
||||||
|
['other', 'UNKNOWN'],
|
||||||
|
['incompatible|unsupported', 'CRITICAL'],
|
||||||
|
['supported', 'OK'],
|
||||||
|
],
|
||||||
|
sensor => [
|
||||||
|
['ok', 'OK'],
|
||||||
|
['unavailable', 'OK'],
|
||||||
|
['nonoperational', 'CRITICAL'],
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
$self->{components_path} = 'centreon::common::cisco::standard::snmp::mode::components';
|
||||||
|
$self->{components_module} = ['fan', 'psu', 'temperature', 'voltage', 'module', 'physical', 'sensor'];
|
||||||
|
}
|
||||||
|
|
||||||
|
my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2';
|
||||||
|
my $oid_ciscoEnvMonPresent = ".1.3.6.1.4.1.9.9.13.1.1";
|
||||||
|
|
||||||
my %map_type_mon = (
|
my %map_type_mon = (
|
||||||
1 => 'oldAgs',
|
1 => 'oldAgs',
|
||||||
2 => 'ags',
|
2 => 'ags',
|
||||||
|
@ -41,65 +116,17 @@ my %map_type_mon = (
|
||||||
14 => 'other'
|
14 => 'other'
|
||||||
);
|
);
|
||||||
|
|
||||||
my $thresholds = {
|
sub snmp_execute {
|
||||||
fan => [
|
my ($self, %options) = @_;
|
||||||
['unknown', 'UNKNOWN'],
|
|
||||||
['down', 'CRITICAL'],
|
$self->{snmp} = $options{snmp};
|
||||||
['up', 'OK'],
|
|
||||||
|
push @{$self->{request}}, { oid => $oid_entPhysicalDescr }, { oid => $oid_ciscoEnvMonPresent };
|
||||||
['normal', 'OK'],
|
$self->{results} = $self->{snmp}->get_multiple_table(oids => );
|
||||||
['warning', 'WARNING'],
|
$self->{output}->output_add(long_msg => sprintf("Environment type: %s",
|
||||||
['critical', 'CRITICAL'],
|
defined($self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}) && defined($map_type_mon{$self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}} ) ?
|
||||||
['shutdown', 'CRITICAL'],
|
$map_type_mon{$self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}} : 'unknown'));
|
||||||
['not present', 'OK'],
|
}
|
||||||
['not functioning', 'WARNING'],
|
|
||||||
],
|
|
||||||
psu => [
|
|
||||||
['^off*', 'WARNING'],
|
|
||||||
['failed', 'CRITICAL'],
|
|
||||||
['onButFanFail|onButInlinePowerFail', 'WARNING'],
|
|
||||||
['on', 'OK'],
|
|
||||||
|
|
||||||
['normal', 'OK'],
|
|
||||||
['warning', 'WARNING'],
|
|
||||||
['critical', 'CRITICAL'],
|
|
||||||
['shutdown', 'CRITICAL'],
|
|
||||||
['not present', 'OK'],
|
|
||||||
['not functioning', 'WARNING'],
|
|
||||||
],
|
|
||||||
temperature => [
|
|
||||||
['normal', 'OK'],
|
|
||||||
['warning', 'WARNING'],
|
|
||||||
['critical', 'CRITICAL'],
|
|
||||||
['shutdown', 'CRITICAL'],
|
|
||||||
['not present', 'OK'],
|
|
||||||
['not functioning', 'WARNING'],
|
|
||||||
],
|
|
||||||
voltage => [
|
|
||||||
['normal', 'OK'],
|
|
||||||
['warning', 'WARNING'],
|
|
||||||
['critical', 'CRITICAL'],
|
|
||||||
['shutdown', 'CRITICAL'],
|
|
||||||
['not present', 'OK'],
|
|
||||||
['not functioning', 'WARNING'],
|
|
||||||
],
|
|
||||||
module => [
|
|
||||||
['unknown|mdr', 'UNKNOWN'],
|
|
||||||
['disabled|okButDiagFailed|missing|mismatchWithParent|mismatchConfig|dormant|outOfServiceAdmin|outOfServiceEnvTemp|powerCycled|okButPowerOverWarning|okButAuthFailed|fwMismatchFound|fwDownloadFailure', 'WARNING'],
|
|
||||||
['failed|diagFailed|poweredDown|powerDenied|okButPowerOverCritical', 'CRITICAL'],
|
|
||||||
['boot|selfTest|poweredUp|syncInProgress|upgrading|fwDownloadSuccess|ok', 'OK'],
|
|
||||||
],
|
|
||||||
physical => [
|
|
||||||
['other', 'UNKNOWN'],
|
|
||||||
['incompatible|unsupported', 'CRITICAL'],
|
|
||||||
['supported', 'OK'],
|
|
||||||
],
|
|
||||||
sensor => [
|
|
||||||
['ok', 'OK'],
|
|
||||||
['unavailable', 'OK'],
|
|
||||||
['nonoperational', 'CRITICAL'],
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
|
@ -109,227 +136,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}}) {
|
|
||||||
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|fan|psu)$/) {
|
|
||||||
$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}}) {
|
|
||||||
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|sensor)/i) {
|
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: temperature, voltage or sensor).");
|
|
||||||
$self->{output}->option_exit();
|
|
||||||
}
|
|
||||||
my $position = 0;
|
|
||||||
if (defined($self->{numeric_threshold}->{$section})) {
|
|
||||||
$position = scalar(@{$self->{numeric_threshold}->{$section}});
|
|
||||||
}
|
|
||||||
if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) {
|
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'.");
|
|
||||||
$self->{output}->option_exit();
|
|
||||||
}
|
|
||||||
$self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section}));
|
|
||||||
push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, regexp => $regexp };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub run {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
$self->{snmp} = $options{snmp};
|
|
||||||
|
|
||||||
my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2';
|
|
||||||
my $oid_ciscoEnvMonPresent = ".1.3.6.1.4.1.9.9.13.1.1";
|
|
||||||
my $snmp_request = [ { oid => $oid_entPhysicalDescr }, { oid => $oid_ciscoEnvMonPresent } ];
|
|
||||||
|
|
||||||
my @components = ('fan', 'psu', 'temperature', 'voltage', 'module', 'physical', 'sensor');
|
|
||||||
foreach (@components) {
|
|
||||||
if (/$self->{option_results}->{component}/) {
|
|
||||||
my $mod_name = "centreon::common::cisco::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}) == 2) {
|
|
||||||
$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);
|
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => sprintf("Environment type: %s",
|
|
||||||
defined($self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}) && defined($map_type_mon{$self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}} ) ?
|
|
||||||
$map_type_mon{$self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}} : 'unknown'));
|
|
||||||
|
|
||||||
foreach (@components) {
|
|
||||||
if (/$self->{option_results}->{component}/) {
|
|
||||||
my $mod_name = "centreon::common::cisco::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}/i) {
|
|
||||||
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__
|
||||||
|
@ -345,15 +156,15 @@ Check environment (Power Supplies, Fans, Temperatures, Voltages, Modules, Physic
|
||||||
Which component to check (Default: '.*').
|
Which component to check (Default: '.*').
|
||||||
Can be: 'fan', 'psu', 'temperature', 'voltage', 'module', 'physical', 'sensor'.
|
Can be: 'fan', 'psu', 'temperature', 'voltage', 'module', 'physical', 'sensor'.
|
||||||
|
|
||||||
=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>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue