Skip to content

Commit

Permalink
feat(lenovo-xcc): add new mode and tests for mem,health and cpu
Browse files Browse the repository at this point in the history
Refs:CTOR-666
  • Loading branch information
Evan-Adam committed Dec 23, 2024
1 parent 66bebf3 commit 293bee3
Show file tree
Hide file tree
Showing 9 changed files with 1,468 additions and 4 deletions.
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;


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
Loading

0 comments on commit 293bee3

Please sign in to comment.