add dlink hardware

This commit is contained in:
garnier-quentin 2020-10-15 11:40:24 +02:00
parent 046192a8a6
commit e599f32b33
4 changed files with 325 additions and 93 deletions

View File

@ -23,70 +23,147 @@ package network::dlink::standard::snmp::mode::components::fan;
use strict;
use warnings;
my %map_states = (
0 => 'other',
1 => 'working',
2 => 'fail',
3 => 'speed-0',
4 => 'speed-low',
5 => 'speed-middle',
6 => 'speed-high',
);
my $map_status_equipment = {
0 => 'other', 1 => 'working',
2 => 'fail', 3 => 'speed-0',
4 => 'speed-low', 5 => 'speed-middle',
6 => 'speed-high'
};
my $map_status = {
1 => 'ok', 2 => 'fault'
};
# In MIB 'env_mib.mib'
my $mapping = {
swFanStatus => { oid => '.1.3.6.1.4.1.171.12.11.1.7.1.3', map => \%map_states },
swFanSpeed => { oid => '.1.3.6.1.4.1.171.12.11.1.7.1.6' },
my $mapping_equipment = {
swFanStatus => { oid => '.1.3.6.1.4.1.171.12.11.1.7.1.3', map => $map_status_equipment },
swFanSpeed => { oid => '.1.3.6.1.4.1.171.12.11.1.7.1.6' }
};
my $oid_swFanEntry = '.1.3.6.1.4.1.171.12.11.1.7.1';
my $mapping_industrial = {
description => { oid => '.1.3.6.1.4.1.171.14.5.1.1.2.1.3' }, # dEntityExtEnvFanDescr
status => { oid => '.1.3.6.1.4.1.171.14.5.1.1.2.1.4', map => $map_status } # dEntityExtEnvFanStatus
};
my $oid_dEntityExtEnvFanEntry = '.1.3.6.1.4.1.171.14.5.1.1.2.1';
my $mapping_common = {
description => { oid => '.1.3.6.1.4.1.171.17.5.1.1.2.1.3' }, # esEntityExtEnvFanDescr
status => { oid => '.1.3.6.1.4.1.171.17.5.1.1.2.1.4', map => $map_status } # esEntityExtEnvFanStatus
};
my $oid_esEntityExtEnvFanEntry = '.1.3.6.1.4.1.171.17.5.1.1.2.1';
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_swFanEntry };
push @{$self->{request}},
{ oid => $oid_swFanEntry, start => $mapping_equipment->{swFanStatus}->{oid} },
{ oid => $oid_dEntityExtEnvFanEntry, start => $mapping_industrial->{description}->{oid} },
{ oid => $oid_esEntityExtEnvFanEntry, start => $mapping_common->{description}->{oid} }
;
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking fans");
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
return if ($self->check_filter(section => 'fan'));
sub check_fan_equipment {
my ($self, %options) = @_;
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_swFanEntry}})) {
next if ($oid !~ /^$mapping->{swFanStatus}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_swFanEntry}, instance => $instance);
next if ($oid !~ /^$mapping_equipment->{swFanStatus}->{oid}\.(\d+)\.(\d+)$/);
my ($unit_id, $fan_id) = ($1, $2);
my $instance = $1 . '.' . $2;
my $result = $self->{snmp}->map_instance(mapping => $mapping_equipment, results => $self->{results}->{$oid_swFanEntry}, instance => $instance);
my $description = 'unit' . $unit_id . ':fan' . $fan_id;
next if ($self->check_filter(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("fan '%s' status is %s [speed = %s].",
$instance, $result->{swFanStatus}, $result->{swFanSpeed}
));
$self->{output}->output_add(
long_msg => sprintf(
"fan '%s' status is %s [instance: %s, speed: %s]",
$description,
$result->{swFanStatus},
$instance,
$result->{swFanSpeed}
)
);
my $exit = $self->get_severity(section => 'fan', value => $result->{swFanStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("fan '%s' status is %s",
$instance, $result->{swFanStatus}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"fan '%s' status is %s",
$description, $result->{swFanStatus}
)
);
}
if (defined($result->{swFanSpeed})) {
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{swFanSpeed});
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit2,
short_msg => sprintf("fan '%s' speed is %s rpm", $instance, $result->{swFanSpeed}));
$self->{output}->output_add(
severity => $exit2,
short_msg => sprintf(
"fan '%s' speed is %s rpm",
$description,
$result->{swFanSpeed}
)
);
}
$self->{output}->perfdata_add(
label => "fan", unit => 'rpm',
unit => 'rpm',
nlabel => 'hardware.fan.speed.rpm',
instances => $instance,
instances => ['unit' . $unit_id, 'fan' . $fan_id],
value => $result->{swFanSpeed},
warning => $warn,
critical => $crit, min => 0
critical => $crit,
min => 0
);
}
}
}
sub check_fan {
my ($self, %options) = @_;
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $options{entry} }})) {
next if ($oid !~ /^$options{mapping}->{status}->{oid}\.(\d+)\.(\d+)$/);
my ($unit_id, $fan_id) = ($1, $2);
my $instance = $1 . '.' . $2;
my $result = $self->{snmp}->map_instance(mapping => $options{mapping}, results => $self->{results}->{ $options{entry} }, instance => $instance);
my $description = 'unit' . $unit_id . ':fan' . $fan_id;
next if ($self->check_filter(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"fan '%s' status is '%s' [instance: %s, description: %s]",
$description,
$result->{status},
$instance,
$result->{description}
)
);
my $exit = $self->get_severity(section => 'fan', value => $result->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"fan '%s' status is '%s'",
$description, $result->{status}
)
);
}
}
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking fans');
$self->{components}->{fan} = { name => 'fans', total => 0, skip => 0 };
return if ($self->check_filter(section => 'fan'));
check_fan_equipment($self);
check_fan($self, entry => $oid_dEntityExtEnvFanEntry, mapping => $mapping_industrial);
check_fan($self, entry => $oid_esEntityExtEnvFanEntry, mapping => $mapping_common);
}
1;

View File

@ -22,54 +22,87 @@ package network::dlink::standard::snmp::mode::components::psu;
use strict;
use warnings;
use centreon::plugins::misc;
my %map_states = (
0 => 'other',
1 => 'lowVoltage',
2 => 'overCurrent',
3 => 'working',
4 => 'fail',
5 => 'connect',
6 => 'disconnect',
);
# In MIB 'equipment.mib'
my $mapping = {
swPowerStatus => { oid => '.1.3.6.1.4.1.171.12.11.1.6.1.3', map => \%map_states },
my $map_status_equipment = {
0 => 'other', 1 => 'lowVoltage', 2 => 'overCurrent',
3 => 'working', 4 => 'fail', 5 => 'connect',
6 => 'disconnect'
};
my $oid_swPowerEntry = '.1.3.6.1.4.1.171.12.11.1.6.1';
my $map_status = {
1 => 'inOperation', 2 => 'failed', 3 => 'empty'
};
my $mapping_equipment = {
status => { oid => '.1.3.6.1.4.1.171.12.11.1.6.1.3', map => $map_status_equipment } # swPowerStatus
};
my $mapping_industrial = {
description => { oid => '.1.3.6.1.4.1.171.14.5.1.1.3.1.3' }, # dEntityExtEnvPowerDescr
status => { oid => '.1.3.6.1.4.1.171.14.5.1.1.3.1.6', map => $map_status } # dEntityExtEnvPowerStatus
};
my $oid_dEntityExtEnvPowerEntry = '.1.3.6.1.4.1.171.14.5.1.1.3.1';
my $mapping_common = {
description => { oid => '.1.3.6.1.4.1.171.17.5.1.1.3.1.3' }, # esEntityExtEnvPowerDescr
status => { oid => '.1.3.6.1.4.1.171.17.5.1.1.3.1.6', map => $map_status } # esEntityExtEnvPowerStatus
};
my $oid_esEntityExtEnvPowerEntry = '.1.3.6.1.4.1.171.17.5.1.1.3.1';
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_swPowerEntry };
push @{$self->{request}},
{ oid => $mapping_equipment->{status}->{oid} },
{ oid => $oid_dEntityExtEnvPowerEntry, start => $mapping_industrial->{description}->{oid} },
{ oid => $oid_esEntityExtEnvPowerEntry, start => $mapping_common->{description}->{oid} }
;
}
sub check_psu {
my ($self, %options) = @_;
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $options{entry} }})) {
next if ($oid !~ /^$options{mapping}->{status}->{oid}\.(\d+)\.(\d+)$/);
my ($unit_id, $psu_id) = ($1, $2);
my $instance = $1 . '.' . $2;
my $result = $self->{snmp}->map_instance(mapping => $options{mapping}, results => $self->{results}->{ $options{entry} }, instance => $instance);
my $description = 'unit' . $unit_id . ':psu' . $psu_id;
next if ($self->check_filter(section => 'psu', instance => $instance));
$self->{components}->{psu}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"power supply '%s' status is '%s' [instance: %s, description: %s]",
$description,
$result->{status},
$instance,
defined($result->{description}) ? centreon::plugins::misc::trim($result->{description}) : '-'
)
);
my $exit = $self->get_severity(section => 'psu', value => $result->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Power supply '%s' status is '%s'",
$description, $result->{status}
)
);
}
}
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking power supplies");
$self->{components}->{psu} = {name => 'psus', total => 0, skip => 0};
$self->{output}->output_add(long_msg => 'checking power supplies');
$self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 };
return if ($self->check_filter(section => 'psu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_swPowerEntry}})) {
next if ($oid !~ /^$mapping->{swPowerStatus}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_swPowerEntry}, instance => $instance);
next if ($self->check_filter(section => 'psu', instance => $instance));
$self->{components}->{psu}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is %s.",
$instance, $result->{swPowerStatus}
));
my $exit = $self->get_severity(section => 'psu', value => $result->{swPowerStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Power supply '%s' status is %s",
$instance, $result->{swPowerStatus}));
}
}
check_psu($self, entry => $mapping_equipment->{status}->{oid}, mapping => $mapping_equipment);
check_psu($self, entry => $oid_dEntityExtEnvPowerEntry, mapping => $mapping_industrial);
check_psu($self, entry => $oid_esEntityExtEnvPowerEntry, mapping => $mapping_common);
}
1;

View File

@ -23,43 +23,73 @@ package network::dlink::standard::snmp::mode::components::temperature;
use strict;
use warnings;
# In MIB 'env_mib.mib'
my $mapping = {
swTemperatureCurrent => { oid => '.1.3.6.1.4.1.171.12.11.1.8.1.2' },
my $map_status = {
1 => 'ok', 2 => 'abnormal'
};
my $oid_swTemperatureEntry = '.1.3.6.1.4.1.171.12.11.1.8.1';
my $mapping_equipment = {
swTemperatureCurrent => { oid => '.1.3.6.1.4.1.171.12.11.1.8.1.2' }
};
my $mapping_industrial = {
description => { oid => '.1.3.6.1.4.1.171.14.5.1.1.1.1.3' }, # dEntityExtEnvTempDescr
current => { oid => '.1.3.6.1.4.1.171.14.5.1.1.1.1.4' }, # dEntityExtEnvTempCurrent
threshold_low => { oid => '.1.3.6.1.4.1.171.14.5.1.1.1.1.5' }, # dEntityExtEnvTempThresholdLow
threshold_high => { oid => '.1.3.6.1.4.1.171.14.5.1.1.1.1.6' }, # dEntityExtEnvTempThresholdHigh
status => { oid => '.1.3.6.1.4.1.171.14.5.1.1.1.1.7', map => $map_status } # dEntityExtEnvTempStatus
};
my $oid_dEntityExtEnvTempEntry = '.1.3.6.1.4.1.171.14.5.1.1.1.1';
my $mapping_common = {
description => { oid => '.1.3.6.1.4.1.171.17.5.1.1.1.1.3' }, # esEntityExtEnvTempDescr
current => { oid => '.1.3.6.1.4.1.171.17.5.1.1.1.1.4' }, # esEntityExtEnvTempCurrent
threshold_low => { oid => '.1.3.6.1.4.1.171.17.5.1.1.1.1.5' }, # esEntityExtEnvTempThresholdLow
threshold_high => { oid => '.1.3.6.1.4.1.171.17.5.1.1.1.1.6' }, # esEntityExtEnvTempThresholdHigh
status => { oid => '.1.3.6.1.4.1.171.17.5.1.1.1.1.7', map => $map_status } # esEntityExtEnvTempStatus
};
my $oid_esEntityExtEnvTempEntry = '.1.3.6.1.4.1.171.17.5.1.1.1.1';
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_swTemperatureEntry };
push @{$self->{request}},
{ oid => $mapping_equipment->{swTemperatureCurrent}->{oid} },
{ oid => $oid_dEntityExtEnvTempEntry, start => $mapping_industrial->{description}->{oid} },
{ oid => $oid_esEntityExtEnvTempEntry, start => $mapping_common->{description}->{oid} }
;
}
sub check {
my ($self) = @_;
sub check_temperature_equipment {
my ($self, %options) = @_;
$self->{output}->output_add(long_msg => "Checking temperatures");
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
return if ($self->check_filter(section => 'temperature'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_swTemperatureEntry}})) {
next if ($oid !~ /^$mapping->{swTemperatureCurrent}->{oid}\.(.*)$/);
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping_equipment->{swTemperatureCurrent}->{oid} }})) {
$oid =~ /^$mapping_equipment->{swTemperatureCurrent}->{oid}\.(.*)$/;
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_swTemperatureEntry}, instance => $instance);
my $result = $self->{snmp}->map_instance(mapping => $mapping_equipment, results => $self->{results}->{ $mapping_equipment->{swTemperatureCurrent}->{oid} }, instance => $instance);
next if ($self->check_filter(section => 'temperature', instance => $instance));
$self->{components}->{temperature}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Temperature '%s' is %dC.",
$instance, $result->{swTemperatureCurrent}));
$self->{output}->output_add(long_msg =>
sprintf(
"temperature '%s' is %dC.",
$instance,
$result->{swTemperatureCurrent}
)
);
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{swTemperatureCurrent});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Temperature '%s' is %s degree centigrade", $instance, $result->{swTemperatureCurrent}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Temperature '%s' is %s degree centigrade",
$instance,
$result->{swTemperatureCurrent}
)
);
}
$self->{output}->perfdata_add(
label => "temp", unit => 'C',
unit => 'C',
nlabel => 'hardware.temperature.celsius',
instances => $instance,
value => $result->{swTemperatureCurrent},
@ -69,4 +99,85 @@ sub check {
}
}
sub check_temperature {
my ($self, %options) = @_;
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $options{entry} }})) {
next if ($oid !~ /^$options{mapping}->{status}->{oid}\.(\d+)\.(\d+)$/);
my ($unit_id, $temp_id) = ($1, $2);
my $instance = $1 . '.' . $2;
my $result = $self->{snmp}->map_instance(mapping => $options{mapping}, results => $self->{results}->{ $options{entry} }, instance => $instance);
my $description = 'unit' . $unit_id . ':temp' . $temp_id;
next if ($self->check_filter(section => 'temperature', instance => $instance));
$self->{components}->{temperature}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"temperature '%s' status is '%s' [instance: %s, description: %s, current: %s]",
$description,
$result->{status},
$instance,
$result->{description},
$result->{current}
)
);
my $exit = $self->get_severity(section => 'temperature', value => $result->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"temperature '%s' status is %s",
$description, $result->{status}
)
);
}
next if (!defined($result->{current}));
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{current});
if ($checked == 0) {
my $warn_th = '';
my $crit_th = defined($result->{threshold_high}) && $result->{threshold_high} =~ /\d/ ? $result->{threshold_high} : '';
$crit_th = $result->{threshold_low} . ':' . $crit_th if (defined($result->{threshold_low}) && $result->{threshold_low} =~ /\d/);
$self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
$self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance);
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance)
}
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit2,
short_msg => sprintf(
"temperature '%s' is %s degree centigrate",
$description,
$result->{current}
)
);
}
$self->{output}->perfdata_add(
unit => 'C',
nlabel => 'hardware.temperature.celsius',
instances => ['unit' . $unit_id, 'temp' . $temp_id],
value => $result->{current},
warning => $warn,
critical => $crit
);
}
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking temperatures');
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
return if ($self->check_filter(section => 'temperature'));
check_temperature_equipment($self);
check_temperature($self, entry => $oid_dEntityExtEnvTempEntry, mapping => $mapping_industrial);
check_temperature($self, entry => $oid_esEntityExtEnvTempEntry, mapping => $mapping_common);
}
1;

View File

@ -34,6 +34,10 @@ sub set_system {
$self->{thresholds} = {
psu => [
['inOperation', 'OK'],
['failed', 'CRITICAL'],
['empty', 'OK'],
['connect', 'OK'],
['working', 'OK'],
['other', 'UNKNOWN'],
@ -43,6 +47,9 @@ sub set_system {
['disconnect', 'WARNING']
],
fan => [
['ok', 'OK'],
['fault', 'CRITICAL'],
['working', 'OK'],
['fail', 'CRITICAL'],
['other', 'UNKNOWN'],
@ -50,6 +57,10 @@ sub set_system {
['speed-low', 'WARNING'],
['speed-middle', 'OK'],
['speed-high', 'WARNING']
],
temperature => [
['ok', 'OK'],
['abnormal', 'CRITICAL']
]
};
@ -66,7 +77,7 @@ sub snmp_execute {
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {});