Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTOR-666-plugin-hardware-server-lenovo-xcc-snmp-mode-hardware-system-health-memory-and-cpu-table-not-checked #5359

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/centreon/plugins/templates/hardware.pm
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ sub get_severity_numeric {

sub get_severity {
my ($self, %options) = @_;
use Data::Dumper;


Evan-Adam marked this conversation as resolved.
Show resolved Hide resolved
my $status = 'UNKNOWN'; # default

$options{instance} .= '#' . $options{name} if (defined($self->{option_results}->{add_name_instance}) && defined($options{name}));
Expand Down
48 changes: 48 additions & 0 deletions src/hardware/server/lenovo/xcc/snmp/mode/components/cpu.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package hardware::server::lenovo::xcc::snmp::mode::components::cpu;
use strict;
use warnings FATAL => 'all';

use strict;
use warnings;
use centreon::plugins::misc;

my $mapping = {
cpuStatus => { oid => '.1.3.6.1.4.1.19046.11.1.1.5.20.1.11' },
cpuString => { oid => '.1.3.6.1.4.1.19046.11.1.1.5.20.1.2' },
};

my $oid_cpuEntry = '.1.3.6.1.4.1.19046.11.1.1.5.20.1';

sub load {
my ($self) = @_;

push @{$self->{request}}, { oid => $oid_cpuEntry };
}
sub check {
my ($self) = @_;

$self->{output}->output_add(long_msg => "Checking cpu");
$self->{components}->{cpu} = { name => 'cpu', total => 0, skip => 0 };
return if ($self->check_filter(section => 'cpu'));

foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cpuEntry}})) {

next if ($oid !~ /^$mapping->{cpuString}->{oid}\.(.*)$/);

my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cpuEntry}, instance => $instance);
next if ($self->check_filter(section => 'cpu', instance => $instance));
$result->{cpuStatus} = centreon::plugins::misc::trim($result->{cpuStatus});
$self->{components}->{cpu}->{total}++;

$self->{output}->output_add(long_msg => sprintf("'%s' status is %s [instance: %s].",
$result->{cpuStatus}, $result->{cpuString}, $instance));

my $exit = $self->get_severity(label => 'default', section => 'default', value => $result->{cpuStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("'%s' cpu status for '%s'", $result->{cpuStatus}, $result->{cpuString}));
}
}
}
1;
68 changes: 68 additions & 0 deletions src/hardware/server/lenovo/xcc/snmp/mode/components/health.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#
# Copyright 2024 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 hardware::server::lenovo::xcc::snmp::mode::components::health;
use Data::Dumper;

use strict;
use warnings;
use centreon::plugins::misc;

my $mapping = {
healthStatus => { oid => '.1.3.6.1.4.1.19046.11.1.1.4.2.1.2' },
healthString => { oid => '.1.3.6.1.4.1.19046.11.1.1.4.2.1.3' },
};

my $oid_healthEntry = '.1.3.6.1.4.1.19046.11.1.1.4.2.1';

sub load {
my ($self) = @_;

push @{$self->{request}}, { oid => $oid_healthEntry };
}
sub check {
my ($self) = @_;

$self->{output}->output_add(long_msg => "Checking health");
$self->{components}->{health} = { name => 'health', total => 0, skip => 0 };
return if ($self->check_filter(section => 'health'));

foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_healthEntry}})) {

next if ($oid !~ /^$mapping->{healthString}->{oid}\.(.*)$/);

my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_healthEntry}, instance => $instance);
next if ($self->check_filter(section => 'health', instance => $instance));
$result->{healthStatus} = centreon::plugins::misc::trim($result->{healthStatus});
$self->{components}->{health}->{total}++;

$self->{output}->output_add(long_msg => sprintf("health '%s' status is %s [instance: %s].",
$result->{healthStatus}, $result->{healthString}, $instance));

my $exit = $self->get_severity(label => 'default', section => 'default', value => $result->{healthStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("'%s' health status for '%s'", $result->{healthStatus}, $result->{healthString}));
}
}
}

1;
48 changes: 48 additions & 0 deletions src/hardware/server/lenovo/xcc/snmp/mode/components/memory.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package hardware::server::lenovo::xcc::snmp::mode::components::memory;
use strict;
use warnings;

use strict;
use warnings;
use centreon::plugins::misc;

my $mapping = {
memoryStatus => { oid => '.1.3.6.1.4.1.19046.11.1.1.5.21.1.8' },
memoryString => { oid => '.1.3.6.1.4.1.19046.11.1.1.5.21.1.2' },
};

my $oid_memoryEntry = '.1.3.6.1.4.1.19046.11.1.1.5.21.1';

sub load {
my ($self) = @_;

push @{$self->{request}}, { oid => $oid_memoryEntry };
}
sub check {
my ($self) = @_;

$self->{output}->output_add(long_msg => "Checking memory");
$self->{components}->{memory} = { name => 'memory', total => 0, skip => 0 };
return if ($self->check_filter(section => 'memory'));

foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_memoryEntry}})) {

next if ($oid !~ /^$mapping->{memoryString}->{oid}\.(.*)$/);

my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_memoryEntry}, instance => $instance);
next if ($self->check_filter(section => 'memory', instance => $instance));
$result->{memoryStatus} = centreon::plugins::misc::trim($result->{memoryStatus});
$self->{components}->{memory}->{total}++;

$self->{output}->output_add(long_msg => sprintf("'%s' status is %s [instance: %s].",
$result->{memoryStatus}, $result->{memoryString}, $instance));

my $exit = $self->get_severity(label => 'default', section => 'default', value => $result->{memoryStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("'%s' memory status for '%s'", $result->{memoryStatus}, $result->{memoryString}));
}
}
}
1;
9 changes: 5 additions & 4 deletions src/hardware/server/lenovo/xcc/snmp/mode/hardware.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ sub set_system {
$self->{cb_hook2} = 'snmp_execute';

$self->{thresholds} = {
default => [
default => [
['Normal', 'OK'],
['.*', 'CRITICAL']
],
raidvolume => [
['Optimal', 'OK'],
['.*', 'CRITICAL']
]
],

};

$self->{components_path} = 'hardware::server::lenovo::xcc::snmp::mode::components';
$self->{components_module} = ['temperature', 'voltage', 'fan', 'psu', 'disk', 'raidvolume'];
$self->{components_module} = ['temperature', 'voltage', 'fan', 'psu', 'disk', 'raidvolume', 'health', 'cpu', 'memory'];
}

sub snmp_execute {
Expand Down Expand Up @@ -77,7 +78,7 @@ Check hardware.
=item B<--component>

Which component to check (default: '.*').
Can be: 'temperature', 'voltage', 'fan', 'psu', 'disk', 'raidvolume'.
Can be: 'temperature', 'voltage', 'fan', 'psu', 'disk', 'raidvolume', 'health', 'cpu', 'memory'.

=item B<--filter>

Expand Down
67 changes: 67 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# centreon-plugins Automated tests

## Robot tests

In this project robot is used to order the integration tests.

### install snmpsim

See docker image in ./github/docker/testing/ to find the right package to install and the method to install it.
Once snmpsim is installed, you need to create the snmp user :

````bash
useradd snmp
mkdir -p /var/lib/snmp/cert_indexes/
chown snmp:snmp -R /var/lib/snmp/cert_indexes/
````

to launch snmpsim use this from the root of the project (one level above this file) :
```bash
sudo snmpsim-command-responder --logging-method=null --agent-udpv4-endpoint=127.0.0.1:2024 --process-user=snmp --process-group=snmp --data-dir='./tests' &
# to test it : snmpwalk -v2c -c hardware/server/lenovo/xcc/snmp/system-health-ok 127.0.0.1:2024
```

test should be run with the "robot" binary, indicating the path to the test file to run.
robot consider every file with .robot extension and try to execute every test case in it.

```bash
robot tests/
```

you can filter the tests run by specifying -e to exclude and -i to include a specific tag before the file path.


## Anonymize tests

As most snmpwalk are provided by users, a script allow to anonymize the data and remove oid not used.
the option `--no-anonymization` allow to not anonymize the data and only remove oid not used.

```bash
perl ./tests/scripts/slim_walk.pl --snmpwalk-path=tests/hardware/client.snmpwalk > smaller-file.snmpwalk
```


## unit tests

In this project perl test::v0 is used to run unit tests.

## test coverage
To check your test coverage you can use Deve::Cover
when launching any type of test, prepend this to your command :

```bash
PERL5OPT=-MDevel::Cover
```

for exemple for robot :

```bash
PERL5OPT=-MDevel::Cover robot tests/
```

It will create a cover_db/ folder to store all data, you can use the `cover` to generate a html report.
```bash
cover
```

Then open the coverage.html file in the cover_db/ folder to navigate your code with coverage.
Loading