enhance cisco sensor check

This commit is contained in:
garnier-quentin 2020-01-10 13:37:03 +01:00
parent 923cc8e27b
commit ff3b2ae8ed
2 changed files with 106 additions and 46 deletions

View File

@ -97,24 +97,25 @@ my %perfdata_unit = (
# In MIB 'CISCO-ENTITY-SENSOR-MIB' # In MIB 'CISCO-ENTITY-SENSOR-MIB'
my $mapping = { my $mapping = {
entSensorType => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.1', map => \%map_sensor_type }, entSensorType => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.1', map => \%map_sensor_type },
entSensorScale => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.2', map => \%map_scale }, entSensorScale => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.2', map => \%map_scale },
entSensorPrecision => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.3' }, entSensorPrecision => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.3' },
entSensorValue => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.4' }, entSensorValue => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.4' },
entSensorStatus => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.5', map => \%map_sensor_status }, entSensorStatus => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.5', map => \%map_sensor_status },
entSensorValueUpdateRate => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.7' }, # 0 means no threshold check
}; };
my $mapping2 = { my $mapping2 = {
entSensorThresholdSeverity => { oid => '.1.3.6.1.4.1.9.9.91.1.2.1.1.2', map => \%map_severity }, entSensorThresholdSeverity => { oid => '.1.3.6.1.4.1.9.9.91.1.2.1.1.2', map => \%map_severity },
entSensorThresholdRelation => { oid => '.1.3.6.1.4.1.9.9.91.1.2.1.1.3', map => \%map_relation }, entSensorThresholdRelation => { oid => '.1.3.6.1.4.1.9.9.91.1.2.1.1.3', map => \%map_relation },
entSensorThresholdValue => { oid => '.1.3.6.1.4.1.9.9.91.1.2.1.1.4' }, entSensorThresholdValue => { oid => '.1.3.6.1.4.1.9.9.91.1.2.1.1.4' },
}; };
my $oid_entSensorValueEntry = '.1.3.6.1.4.1.9.9.91.1.1.1.1'; my $oid_entSensorValueEntry = '.1.3.6.1.4.1.9.9.91.1.1.1.1';
my $oid_entSensorThresholdEntry = '.1.3.6.1.4.1.9.9.91.1.2.1.1'; 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 ($self) = @_; my ($self) = @_;
push @{$self->{request}}, { oid => $oid_entSensorValueEntry, end => $mapping->{entSensorStatus}->{oid} }, push @{$self->{request}}, { oid => $oid_entSensorValueEntry, end => $mapping->{entSensorStatus}->{oid} },
{ oid => $oid_entSensorThresholdEntry, end => $mapping2->{entSensorThresholdValue}->{oid} }; { oid => $oid_entSensorThresholdEntry, end => $mapping2->{entSensorThresholdValue}->{oid} };
} }
@ -140,7 +141,7 @@ sub get_default_warning_threshold {
$low_th = $value; $low_th = $value;
} }
} }
# when it's the same value. Means no threshold. # when it's the same value. Means no threshold.
if (defined($low_th) && defined($high_th) && $high_th <= $low_th) { if (defined($low_th) && defined($high_th) && $high_th <= $low_th) {
return ''; return '';
@ -148,6 +149,7 @@ sub get_default_warning_threshold {
my $th = ''; my $th = '';
$th = centreon::plugins::misc::expand_exponential(value => $low_th) . ':' if (defined($low_th)); $th = centreon::plugins::misc::expand_exponential(value => $low_th) . ':' if (defined($low_th));
$th .= centreon::plugins::misc::expand_exponential(value => $high_th) if (defined($high_th)); $th .= centreon::plugins::misc::expand_exponential(value => $high_th) if (defined($high_th));
$th = '~:' . $high_th if (defined($high_th) && !defined($low_th));
return $th; return $th;
} }
@ -161,7 +163,7 @@ sub get_default_critical_threshold {
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_entSensorThresholdEntry}, instance => $options{instance} . '.' . $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_entSensorThresholdEntry}, instance => $options{instance} . '.' . $instance);
next if ($result->{entSensorThresholdSeverity} !~ /major|critical/); next if ($result->{entSensorThresholdSeverity} !~ /major|critical/);
my $value = $result->{entSensorThresholdValue} * (10 ** ($options{result}->{entSensorScale}) * (10 ** -($options{result}->{entSensorPrecision}))); my $value = $result->{entSensorThresholdValue} * (10 ** ($options{result}->{entSensorScale}) * (10 ** -($options{result}->{entSensorPrecision})));
if ($result->{entSensorThresholdRelation} eq 'greaterOrEqual') { if ($result->{entSensorThresholdRelation} eq 'greaterOrEqual') {
$high_th = $value - (1 * (10 ** ($options{result}->{entSensorScale}) * (10 ** -($options{result}->{entSensorPrecision})))); $high_th = $value - (1 * (10 ** ($options{result}->{entSensorScale}) * (10 ** -($options{result}->{entSensorPrecision}))));
@ -181,45 +183,55 @@ sub get_default_critical_threshold {
my $th = ''; my $th = '';
$th = centreon::plugins::misc::expand_exponential(value => $low_th) . ':' if (defined($low_th)); $th = centreon::plugins::misc::expand_exponential(value => $low_th) . ':' if (defined($low_th));
$th .= centreon::plugins::misc::expand_exponential(value => $high_th) if (defined($high_th)); $th .= centreon::plugins::misc::expand_exponential(value => $high_th) if (defined($high_th));
$th = '~:' . $high_th if (defined($high_th) && !defined($low_th));
return $th; return $th;
} }
sub check { sub check {
my ($self) = @_; my ($self) = @_;
$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_filter(section => 'sensor')); return if ($self->check_filter(section => 'sensor'));
my $verify_th_update = {};
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}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_entSensorValueEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_entSensorValueEntry}, instance => $instance);
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_filter(section => 'sensor', instance => $result->{entSensorType} . '.' . $instance)); next if ($self->check_filter(section => 'sensor', instance => $result->{entSensorType} . '.' . $instance));
$self->{components}->{sensor}->{total}++; $self->{components}->{sensor}->{total}++;
$result->{entSensorValue} = defined($result->{entSensorValue}) ? $result->{entSensorValue} = defined($result->{entSensorValue}) ?
$result->{entSensorValue} * (10 ** ($result->{entSensorScale}) * (10 ** -($result->{entSensorPrecision}))) : undef; $result->{entSensorValue} * (10 ** ($result->{entSensorScale}) * (10 ** -($result->{entSensorPrecision}))) : undef;
$self->{output}->output_add(long_msg => sprintf("Sensor '%s' status is '%s' [instance: %s] [value: %s %s]", $self->{output}->output_add(
$sensor_descr, $result->{entSensorStatus}, long_msg => sprintf(
$instance, "Sensor '%s' status is '%s' [instance: %s] [value: %s %s]",
defined($result->{entSensorValue}) ? $result->{entSensorValue} : '-', $sensor_descr, $result->{entSensorStatus},
$result->{entSensorType})); $instance,
defined($result->{entSensorValue}) ? $result->{entSensorValue} : '-',
$result->{entSensorType}
)
);
my $exit = $self->get_severity(section => $result->{entSensorType}, label => 'sensor', value => $result->{entSensorStatus}); my $exit = $self->get_severity(section => $result->{entSensorType}, label => 'sensor', value => $result->{entSensorStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(
short_msg => sprintf("Sensor '%s/%s' status is '%s'", severity => $exit,
$sensor_descr, $instance, $result->{entSensorStatus})); short_msg => sprintf(
"Sensor '%s/%s' status is '%s'",
$sensor_descr, $instance, $result->{entSensorStatus}
)
);
} }
next if (!defined($result->{entSensorValue}) || $result->{entSensorValue} !~ /[0-9]/); next if (!defined($result->{entSensorValue}) || $result->{entSensorValue} !~ /[0-9]/);
my $component = 'sensor.' . $result->{entSensorType}; my $component = 'sensor.' . $result->{entSensorType};
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => $component, instance => $instance, value => $result->{entSensorValue}); my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => $component, instance => $instance, value => $result->{entSensorValue});
if ($checked == 0) { if ($checked == 0) {
@ -231,15 +243,28 @@ sub check {
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $component . '-instance-' . $instance); $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $component . '-instance-' . $instance);
$exit2 = $self->{perfdata}->threshold_check( $exit2 = $self->{perfdata}->threshold_check(
value => $result->{entSensorValue}, value => $result->{entSensorValue},
threshold => [ { label => 'critical-' . $component . '-instance-' . $instance, exit_litteral => 'critical' }, threshold => [
{ label => 'warning-' . $component . '-instance-' . $instance, exit_litteral => 'warning' } { label => 'critical-' . $component . '-instance-' . $instance, exit_litteral => 'critical' },
{ label => 'warning-' . $component . '-instance-' . $instance, exit_litteral => 'warning' }
] ]
); );
} }
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit2, # we verify if it's a entSensorValueUpdateRate is not zero
short_msg => sprintf("Sensor '%s/%s' is %s %s", $sensor_descr, $instance, $result->{entSensorValue}, $perfdata_unit{$result->{entSensorType}})); if ($checked == 0) {
$verify_th_update->{$instance} = { result => $result, warn => $warn, crit => $crit, sensor_descr => $sensor_descr, status => $exit2 };
next;
}
$self->{output}->output_add(
severity => $exit2,
short_msg => sprintf(
"Sensor '%s/%s' is %s %s",
$sensor_descr, $instance, $result->{entSensorValue}, $perfdata_unit{$result->{entSensorType}}
)
);
} }
$self->{output}->perfdata_add( $self->{output}->perfdata_add(
label => $component, unit => $perfdata_unit{$result->{entSensorType}}, label => $component, unit => $perfdata_unit{$result->{entSensorType}},
nlabel => 'hardware.' . $component, nlabel => 'hardware.' . $component,
@ -249,6 +274,38 @@ sub check {
critical => $crit critical => $crit
); );
} }
return if (scalar(keys %$verify_th_update) <= 0);
my $snmp_result = $self->{snmp}->get_leef(oids => [map($mapping->{entSensorValueUpdateRate}->{oid} . '.' . $_, keys(%$verify_th_update))]);
foreach (keys %$verify_th_update) {
my ($warn, $crit) = ($verify_th_update->{$_}->{warn}, $verify_th_update->{$_}->{crit});
if (defined($snmp_result->{$mapping->{entSensorValueUpdateRate}->{oid} . '.' . $_}) &&
$snmp_result->{$mapping->{entSensorValueUpdateRate}->{oid} . '.' . $_} == 0) {
($warn, $crit) = ('', '');
}
if (!$self->{output}->is_status(value => $verify_th_update->{$_}->{status}, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $verify_th_update->{$_}->{status},
short_msg => sprintf(
"Sensor '%s/%s' is %s %s",
$verify_th_update->{$_}->{sensor_descr}, $_,
$verify_th_update->{$_}->{result}->{entSensorValue},
$perfdata_unit{ $verify_th_update->{$_}->{result}->{entSensorType} }
)
);
}
$self->{output}->perfdata_add(
label => 'sensor.' . $verify_th_update->{$_}->{result}->{entSensorType},
unit => $perfdata_unit{ $verify_th_update->{$_}->{result}->{entSensorType} },
nlabel => 'hardware.sensor.' . $verify_th_update->{$_}->{result}->{entSensorType},
instances => $verify_th_update->{$_}->{sensor_descr},
value => $verify_th_update->{$_}->{result}->{entSensorValue},
warning => $warn,
critical => $crit
);
}
} }
1; 1;

View File

@ -28,18 +28,18 @@ use centreon::plugins::misc;
sub set_system { sub set_system {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(fan|psu|temperature|voltage|module|physical|sensor)$'; $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->{regexp_threshold_numeric_check_section_option} = '^(temperature|voltage|sensor.*)$';
$self->{cb_hook2} = 'snmp_execute'; $self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = { $self->{thresholds} = {
fan => [ fan => [
['unknown', 'UNKNOWN'], ['unknown', 'UNKNOWN'],
['down', 'CRITICAL'], ['down', 'CRITICAL'],
['up', 'OK'], ['up', 'OK'],
['normal', 'OK'], ['normal', 'OK'],
['warning', 'WARNING'], ['warning', 'WARNING'],
['critical', 'CRITICAL'], ['critical', 'CRITICAL'],
@ -93,7 +93,7 @@ sub set_system {
['nonoperational', 'CRITICAL'], ['nonoperational', 'CRITICAL'],
], ],
}; };
$self->{components_path} = 'centreon::common::cisco::standard::snmp::mode::components'; $self->{components_path} = 'centreon::common::cisco::standard::snmp::mode::components';
$self->{components_module} = ['fan', 'psu', 'temperature', 'voltage', 'module', 'physical', 'sensor']; $self->{components_module} = ['fan', 'psu', 'temperature', 'voltage', 'module', 'physical', 'sensor'];
} }
@ -119,28 +119,31 @@ my %map_type_mon = (
sub snmp_execute { sub snmp_execute {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{snmp} = $options{snmp}; $self->{snmp} = $options{snmp};
push @{$self->{request}}, { oid => $oid_entPhysicalDescr }, { oid => $oid_ciscoEnvMonPresent }; push @{$self->{request}}, { oid => $oid_entPhysicalDescr }, { oid => $oid_ciscoEnvMonPresent };
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
while (my ($key, $value) = each %{$self->{results}->{$oid_entPhysicalDescr}}) { while (my ($key, $value) = each %{$self->{results}->{$oid_entPhysicalDescr}}) {
$self->{results}->{$oid_entPhysicalDescr}->{$key} = centreon::plugins::misc::trim($value); $self->{results}->{$oid_entPhysicalDescr}->{$key} = centreon::plugins::misc::trim($value);
} }
$self->{output}->output_add(long_msg => sprintf("Environment type: %s", $self->{output}->output_add(
defined($self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}) && defined($map_type_mon{$self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}} ) ? long_msg => sprintf(
$map_type_mon{$self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}} : 'unknown')); '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'
)
);
} }
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);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ });
});
return $self; return $self;
} }