enhance cisco sensor check

This commit is contained in:
garnier-quentin 2020-01-10 13:37:03 +01:00
parent 50a1a13f7f
commit 42d7666f59
2 changed files with 106 additions and 46 deletions

View File

@ -97,20 +97,21 @@ my %perfdata_unit = (
# In MIB 'CISCO-ENTITY-SENSOR-MIB'
my $mapping = {
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 },
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' },
entSensorStatus => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.5', map => \%map_sensor_status },
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 },
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' },
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 = {
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 },
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_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 {
my ($self) = @_;
@ -148,6 +149,7 @@ sub get_default_warning_threshold {
my $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 = '~:' . $high_th if (defined($high_th) && !defined($low_th));
return $th;
}
@ -181,6 +183,7 @@ sub get_default_critical_threshold {
my $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 = '~:' . $high_th if (defined($high_th) && !defined($low_th));
return $th;
}
@ -192,6 +195,7 @@ sub check {
$self->{components}->{sensor} = {name => 'sensors', total => 0, skip => 0};
return if ($self->check_filter(section => 'sensor'));
my $verify_th_update = {};
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_entSensorValueEntry}})) {
next if ($oid !~ /^$mapping->{entSensorStatus}->{oid}\.(.*)$/);
my $instance = $1;
@ -206,16 +210,24 @@ sub check {
$result->{entSensorValue} = defined($result->{entSensorValue}) ?
$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]",
$sensor_descr, $result->{entSensorStatus},
$instance,
defined($result->{entSensorValue}) ? $result->{entSensorValue} : '-',
$result->{entSensorType}));
$self->{output}->output_add(
long_msg => sprintf(
"Sensor '%s' status is '%s' [instance: %s] [value: %s %s]",
$sensor_descr, $result->{entSensorStatus},
$instance,
defined($result->{entSensorValue}) ? $result->{entSensorValue} : '-',
$result->{entSensorType}
)
);
my $exit = $self->get_severity(section => $result->{entSensorType}, label => 'sensor', value => $result->{entSensorStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Sensor '%s/%s' status is '%s'",
$sensor_descr, $instance, $result->{entSensorStatus}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Sensor '%s/%s' status is '%s'",
$sensor_descr, $instance, $result->{entSensorStatus}
)
);
}
next if (!defined($result->{entSensorValue}) || $result->{entSensorValue} !~ /[0-9]/);
@ -231,15 +243,28 @@ sub check {
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $component . '-instance-' . $instance);
$exit2 = $self->{perfdata}->threshold_check(
value => $result->{entSensorValue},
threshold => [ { label => 'critical-' . $component . '-instance-' . $instance, exit_litteral => 'critical' },
{ label => 'warning-' . $component . '-instance-' . $instance, exit_litteral => 'warning' }
threshold => [
{ 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)) {
$self->{output}->output_add(severity => $exit2,
short_msg => sprintf("Sensor '%s/%s' is %s %s", $sensor_descr, $instance, $result->{entSensorValue}, $perfdata_unit{$result->{entSensorType}}));
# we verify if it's a entSensorValueUpdateRate is not zero
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(
label => $component, unit => $perfdata_unit{$result->{entSensorType}},
nlabel => 'hardware.' . $component,
@ -249,6 +274,38 @@ sub check {
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;

View File

@ -127,9 +127,13 @@ sub snmp_execute {
while (my ($key, $value) = each %{$self->{results}->{$oid_entPhysicalDescr}}) {
$self->{results}->{$oid_entPhysicalDescr}->{$key} = centreon::plugins::misc::trim($value);
}
$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'));
$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'
)
);
}
sub new {
@ -137,9 +141,8 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
});
$options{options}->add_options(arguments => {
});
return $self;
}