-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enh(lenovo-snmp): added system-health, memory and cpu components to h…
…ardware mode (#5359) 🤘🏻😈🤘🏻 Refs: CTOR-666
- Loading branch information
Showing
11 changed files
with
1,636 additions
and
6 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/hardware/server/lenovo/xcc/snmp/mode/components/cpu.pm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
68
src/hardware/server/lenovo/xcc/snmp/mode/components/health.pm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
src/hardware/server/lenovo/xcc/snmp/mode/components/memory.pm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.