enhance cisco sensor check
This commit is contained in:
parent
50a1a13f7f
commit
42d7666f59
|
@ -97,20 +97,21 @@ 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) = @_;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -181,6 +183,7 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -192,6 +195,7 @@ sub check {
|
||||||
$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;
|
||||||
|
@ -206,16 +210,24 @@ sub check {
|
||||||
$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]/);
|
||||||
|
@ -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;
|
||||||
|
|
|
@ -127,9 +127,13 @@ sub snmp_execute {
|
||||||
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 {
|
||||||
|
@ -137,9 +141,8 @@ sub new {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue