enh(stormshield/snmp): add mode hardware (#3096)

This commit is contained in:
qgarnier 2021-09-10 11:50:56 +02:00 committed by GitHub
parent e44aadcf00
commit b0092b6046
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 452 additions and 0 deletions

View File

@ -0,0 +1,86 @@
#
# Copyright 2021 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 network::stormshield::snmp::mode::components::disk;
use strict;
use warnings;
my $mapping = {
name => { oid => '.1.3.6.1.4.1.11256.1.10.5.1.2' }, # snsDiskEntryDiskName
isRaid => { oid => '.1.3.6.1.4.1.11256.1.10.5.1.4' }, # snsDiskEntryIsRaid
raidStatus => { oid => '.1.3.6.1.4.1.11256.1.10.5.1.5' } # snsDiskEntryRaidStatus
};
my $oid_diskEntry = '.1.3.6.1.4.1.11256.1.10.5.1'; # snsDiskEntry
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_diskEntry, end => $mapping->{raidStatus}->{oid} };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking disks');
$self->{components}->{disk} = { name => 'disks', total => 0, skip => 0 };
return if ($self->check_filter(section => 'disk'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $oid_diskEntry }})) {
next if ($oid !~ /^$mapping->{name}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $oid_diskEntry }, instance => $instance);
next if ($self->check_filter(section => 'disk', instance => $instance));
$self->{components}->{disk}->{total}++;
if ($result->{isRaid} == 0) {
$self->{output}->output_add(
long_msg => sprintf(
"disk '%s' is not member of a raid [instance: %s]",
$result->{name},
$instance
)
);
next;
}
$self->{output}->output_add(
long_msg => sprintf(
"disk '%s' raid status is '%s' [instance: %s]",
$result->{name},
$result->{raidStatus},
$instance
)
);
my $exit = $self->get_severity(section => 'raid', value => $result->{raidStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Disk '%s' raid status is '%s'", $result->{name}, $result->{raidStatus}
)
);
}
}
}
1;

View File

@ -0,0 +1,96 @@
#
# Copyright 2021 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 network::stormshield::snmp::mode::components::fan;
use strict;
use warnings;
my $mapping = {
name => { oid => '.1.3.6.1.4.1.11256.1.10.9.1.2' }, # snsFanName
status => { oid => '.1.3.6.1.4.1.11256.1.10.9.1.3' }, # snsFanStatus
rpm => { oid => '.1.3.6.1.4.1.11256.1.10.9.1.4' } # snsFanRpm
};
my $oid_fanEntry = '.1.3.6.1.4.1.11256.1.10.9.1'; # snsFanEntry
sub load {
my ($self) = @_;
push @{$self->{request}}, {
oid => $oid_fanEntry,
start => $mapping->{name}->{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'));
my ($exit, $warn, $crit, $checked);
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $oid_fanEntry }})) {
next if ($oid !~ /^$mapping->{name}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $oid_fanEntry }, instance => $instance);
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, rpm: %s]",
$result->{name}, $result->{status}, $instance, $result->{rpm}
)
);
$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'", $result->{name}, $result->{status}
)
);
}
($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{rpm});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"fan '%s' speed is '%s' rpm", $result->{name}, $result->{rpm}
)
);
}
$self->{output}->perfdata_add(
nlabel => 'hardware.fan.speed.rpm',
unit => 'rpm',
instances => $result->{fanName},
value => $result->{fanValue},
warning => $warn,
critical => $crit, min => 0
);
}
}
1;

View File

@ -0,0 +1,74 @@
#
# Copyright 2021 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 network::stormshield::snmp::mode::components::psu;
use strict;
use warnings;
my $mapping = {
powered => { oid => '.1.3.6.1.4.1.11256.1.10.6.1.2' }, # snsPowerSupplyPowered
status => { oid => '.1.3.6.1.4.1.11256.1.10.6.1.3' } # snsPowerSupplyStatus
};
my $oid_psuEntry = '.1.3.6.1.4.1.11256.1.10.6.1'; # snsPowerSupplyEntry
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_psuEntry };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking power supplies');
$self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 };
return if ($self->check_filter(section => 'disk'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $oid_psuEntry }})) {
next if ($oid !~ /^$mapping->{status}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $oid_psuEntry }, 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: %s]",
$instance,
$result->{status},
$instance
)
);
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'", $instance, $result->{status}
)
);
}
}
}
1;

View File

@ -0,0 +1,81 @@
#
# Copyright 2021 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 network::stormshield::snmp::mode::components::temperature;
use strict;
use warnings;
my $mapping = {
cpuTemp => { oid => '.1.3.6.1.4.1.11256.1.10.7.1.2' } # snsCpuTemp
};
sub load {
my ($self) = @_;
push @{$self->{request}}, {
oid => $mapping->{cpuTemp}->{oid}
};
}
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'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping->{cpuTemp}->{oid} }})) {
next if ($oid !~ /^$mapping->{cpuTemp}->{oid}\.(.*)$/);
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{cpuTemp}->{oid} }, instance => $1);
my $instance = 'cpu' . $1;
next if ($self->check_filter(section => 'temperature', instance => $instance));
$self->{components}->{temperature}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"temperature '%s' is %s celsius [instance: %s]",
$instance, $result->{cpuTemp}, $instance
)
);
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{tempValue});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"temperature '%s' is %s celsius", $instance, $result->{cpuTemp}
)
);
}
$self->{output}->perfdata_add(
nlabel => 'hardware.temperature.celsius',
unit => 'C',
instances => $instance,
value => $result->{cpuTemp},
warning => $warn,
critical => $crit, min => 0
);
}
}
1;

View File

@ -0,0 +1,114 @@
#
# Copyright 2021 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 network::stormshield::snmp::mode::hardware;
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_numeric_check_section_option} = '^(?:fan|temperature)$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
fan => [
['running', 'OK'],
['.*', 'CRITICAL']
],
psu => [
['OK', 'OK'],
['.*', 'CRITICAL']
],
raid => [
['optimal', 'OK'],
['.*', 'CRITICAL']
]
};
$self->{components_path} = 'network::stormshield::snmp::mode::components';
$self->{components_module} = ['disk', 'fan', 'psu', 'temperature'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {});
return $self;
}
1;
__END__
=head1 MODE
Check hardware.
=over 8
=item B<--component>
Which component to check (Default: '.*').
Can be: 'disk', 'fan', 'psu', 'temperature'.
=item B<--filter>
Exclude some parts (comma seperated list) (Example: --filter=fan)
Can also exclude specific instance: --filter=fan,1
=item B<--no-component>
Return an error if no compenents are checked.
If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='disk,WARNING,missing'
=item B<--warning>
Set warning threshold for 'temperature', 'fan' (syntax: type,regexp,threshold)
Example: --warning='temperature,.*,40'
=item B<--critical>
Set critical threshold for 'temperature', 'fan' (syntax: type,regexp,threshold)
Example: --critical='temperature,.*,50'
=back
=cut

View File

@ -38,6 +38,7 @@ sub new {
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'load' => 'snmp_standard::mode::loadaverage',
'ha-nodes' => 'network::stormshield::snmp::mode::hanodes',
'hardware' => 'network::stormshield::snmp::mode::hardware',
'health' => 'network::stormshield::snmp::mode::health',
'memory' => 'os::freebsd::snmp::mode::memory',
'memory-detailed' => 'network::stormshield::snmp::mode::memorydetailed',