+ Enhance cisco standard plugin environment mode (WIP)
This commit is contained in:
parent
cca5fe66de
commit
d355a224eb
|
@ -53,7 +53,7 @@ my %map_module_state = (
|
|||
27 => 'fwDownloadFailure',
|
||||
);
|
||||
|
||||
# In MIB 'CISCO-ENTITY-SENSOR-MIB'
|
||||
# In MIB 'CISCO-ENTITY-FRU-CONTROL-MIB'
|
||||
my $mapping = {
|
||||
cefcModuleOperStatus => { oid => '.1.3.6.1.4.1.9.9.117.1.2.1.1.2', map => \%map_module_state },
|
||||
};
|
||||
|
|
|
@ -0,0 +1,152 @@
|
|||
#
|
||||
# Copyright 2015 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package centreon::common::cisco::standard::snmp::mode::components::sensor;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my %map_sensor_status = (
|
||||
1 => 'ok',
|
||||
2 => 'unavailable',
|
||||
3 => 'nonoperational',
|
||||
);
|
||||
my %map_sensor_type = (
|
||||
1 => 'other',
|
||||
2 => 'unknown',
|
||||
3 => 'voltsAC',
|
||||
4 => 'voltsDC',
|
||||
5 => 'amperes',
|
||||
6 => 'watts',
|
||||
7 => 'hertz',
|
||||
8 => 'celsius',
|
||||
9 => 'percentRH',
|
||||
10 => 'rpm',
|
||||
11 => 'cmm',
|
||||
12 => 'truthvalue',
|
||||
13 => 'specialEnum',
|
||||
14 => 'dBm',
|
||||
);
|
||||
my %map_severity = (
|
||||
1 => 'other',
|
||||
10 => 'minor',
|
||||
20 => 'major',
|
||||
30 => 'critical',
|
||||
);
|
||||
my %map_relation = (
|
||||
1 => 'lessThan',
|
||||
2 => 'lessOrEqual',
|
||||
3 => 'greaterThan',
|
||||
4 => 'greaterOrEqual',
|
||||
5 => 'equalTo',
|
||||
6 => 'notEqualTo',
|
||||
);
|
||||
|
||||
# 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 },
|
||||
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 },
|
||||
};
|
||||
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' },
|
||||
};
|
||||
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';
|
||||
|
||||
sub load {
|
||||
my (%options) = @_;
|
||||
|
||||
push @{$options{request}}, { oid => $oid_entSensorValueEntry }, { oid => $oid_entSensorThresholdEntry };
|
||||
}
|
||||
|
||||
sub get_default_warning_threshold {
|
||||
my ($self, %options) = @_;
|
||||
my $th = '';
|
||||
|
||||
return $th;
|
||||
}
|
||||
|
||||
sub get_default_critical_threshold {
|
||||
my ($self, %options) = @_;
|
||||
my $th = '';
|
||||
|
||||
return $th;
|
||||
}
|
||||
|
||||
|
||||
sub check {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->{output}->output_add(long_msg => "Checking sensors");
|
||||
$self->{components}->{sensor} = {name => 'sensors', total => 0, skip => 0};
|
||||
return if ($self->check_exclude(section => 'sensor'));
|
||||
|
||||
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_entSensorValueEntry}})) {
|
||||
next if ($oid !~ /^$mapping->{entSensorStatus}->{oid}\.(.*)$/);
|
||||
my $instance = $1;
|
||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_entSensorValueEntry}, instance => $instance);
|
||||
my $sensor_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance};
|
||||
|
||||
next if ($self->check_exclude(section => 'sensor', instance => $instance));
|
||||
$self->{components}->{sensor}->{total}++;
|
||||
|
||||
$result->{entSensorValue} = defined($result->{entSensorValue}) ?
|
||||
$result->{entSensorValue} * 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});
|
||||
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' status is '%s'",
|
||||
$sensor_descr, $result->{entSensorStatus}));
|
||||
}
|
||||
|
||||
next if (!defined($result->{entSensorValue}) || $result->{entSensorValue} !~ /[0-9]/);
|
||||
|
||||
my $component = 'sensor.' . $result->{entSensorType};
|
||||
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => $component, instance => $instance, value => $result->{entSensorValue});
|
||||
if ($checked == 0) {
|
||||
my $warn_th = get_default_warning_threshold($self);
|
||||
my $crit_th = get_default_critical_threshold($self);
|
||||
$self->{perfdata}->threshold_validate(label => 'warning-' . $component . '-instance-' . $instance, value => $warn_th);
|
||||
$self->{perfdata}->threshold_validate(label => 'critical-' . $component . '-instance-' . $instance, value => $crit_th);
|
||||
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $component . '-instance-' . $instance);
|
||||
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $component . '-instance-' . $instance);
|
||||
}
|
||||
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit2,
|
||||
short_msg => sprintf("Sensor '%s' is %s %s", $sensor_descr, $result->{entSensorStatus}, $result->{entSensorType}));
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $component . '_' . $sensor_descr,
|
||||
value => $result->{entSensorValue},
|
||||
warning => $warn,
|
||||
critical => $crit);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
|
@ -94,6 +94,11 @@ my $thresholds = {
|
|||
['incompatible|unsupported', 'CRITICAL'],
|
||||
['supported', 'OK'],
|
||||
],
|
||||
sensor => [
|
||||
['ok', 'OK'],
|
||||
['unavailable', 'OK'],
|
||||
['nonoperational', 'CRITICAL'],
|
||||
],
|
||||
};
|
||||
|
||||
sub new {
|
||||
|
@ -133,17 +138,29 @@ sub check_options {
|
|||
|
||||
$self->{overload_th} = {};
|
||||
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
|
||||
if ($val !~ /^(.*?),(.*?),(.*)$/) {
|
||||
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, $status, $filter) = ($1, $2, $3);
|
||||
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};
|
||||
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance };
|
||||
}
|
||||
|
||||
$self->{numeric_threshold} = {};
|
||||
|
@ -154,8 +171,8 @@ sub check_options {
|
|||
$self->{output}->option_exit();
|
||||
}
|
||||
my ($section, $regexp, $value) = ($1, $2, $3);
|
||||
if ($section !~ /(temperature|voltage)/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: temperature or voltage).");
|
||||
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;
|
||||
|
@ -181,7 +198,7 @@ sub run {
|
|||
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');
|
||||
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::$_";
|
||||
|
@ -278,7 +295,7 @@ sub get_severity_numeric {
|
|||
if (defined($self->{numeric_threshold}->{$options{section}})) {
|
||||
my $exits = [];
|
||||
foreach (@{$self->{numeric_threshold}->{$options{section}}}) {
|
||||
if ($options{instance} =~ /$_->{regexp}/) {
|
||||
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;
|
||||
|
@ -296,13 +313,15 @@ sub get_severity {
|
|||
|
||||
if (defined($self->{overload_th}->{$options{section}})) {
|
||||
foreach (@{$self->{overload_th}->{$options{section}}}) {
|
||||
if ($options{value} =~ /$_->{filter}/i) {
|
||||
if ($options{value} =~ /$_->{filter}/i &&
|
||||
(!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) {
|
||||
$status = $_->{status};
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (@{$thresholds->{$options{section}}}) {
|
||||
my $label = defined($options{label}) ? $options{label} : $options{section};
|
||||
foreach (@{$thresholds->{$label}}) {
|
||||
if ($options{value} =~ /$$_[0]/i) {
|
||||
$status = $$_[1];
|
||||
return $status;
|
||||
|
@ -325,7 +344,7 @@ Check environment (Power Supplies, Fans, Temperatures, Voltages, Modules, Physic
|
|||
=item B<--component>
|
||||
|
||||
Which component to check (Default: '.*').
|
||||
Can be: 'fan', 'psu', 'temperature', 'voltage', 'module', 'physical'.
|
||||
Can be: 'fan', 'psu', 'temperature', 'voltage', 'module', 'physical', 'sensor'.
|
||||
|
||||
=item B<--exclude>
|
||||
|
||||
|
@ -350,12 +369,12 @@ Example: --threshold-overload='fan,CRITICAL,^(?!(up|normal)$)'
|
|||
|
||||
=item B<--warning>
|
||||
|
||||
Set warning threshold for temperatures, voltages (syntax: type,regexp,treshold)
|
||||
Set warning threshold for temperatures, voltages, sensors (syntax: type,regexp,treshold)
|
||||
Example: --warning='temperature,.*,30'
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Set critical threshold for temperatures, voltages (syntax: type,regexp,treshold)
|
||||
Set critical threshold for temperatures, voltages, sensors (syntax: type,regexp,treshold)
|
||||
Example: --critical='temperature,.*,40'
|
||||
|
||||
=back
|
||||
|
|
Loading…
Reference in New Issue