From c88381bb1e0bef254ec91e6f49d060815a1902dc Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Wed, 30 Dec 2020 14:15:41 +0100 Subject: [PATCH] enh(imm) Add some modes (#2465) --- .../imm/snmp/mode/components/cpu.pm | 64 +++++++++++++++++++ .../imm/snmp/mode/components/disk.pm | 64 +++++++++++++++++++ .../imm/snmp/mode/components/fan.pm | 25 ++++---- .../imm/snmp/mode/components/memory.pm | 64 +++++++++++++++++++ .../imm/snmp/mode/components/power.pm | 64 +++++++++++++++++++ .../mgmt_cards/imm/snmp/mode/environment.pm | 13 ++-- 6 files changed, 275 insertions(+), 19 deletions(-) create mode 100644 hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/cpu.pm create mode 100644 hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/disk.pm create mode 100644 hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/memory.pm create mode 100644 hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/power.pm diff --git a/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/cpu.pm b/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/cpu.pm new file mode 100644 index 000000000..be6966a66 --- /dev/null +++ b/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/cpu.pm @@ -0,0 +1,64 @@ +# +# Copyright 2020 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::ibm::mgmt_cards::imm::snmp::mode::components::cpu; + +use strict; +use warnings; +use centreon::plugins::misc; + +my $mapping = { + cpuDescr => { oid => '.1.3.6.1.4.1.2.3.51.3.1.5.20.1.2' }, + cpuHealthStatus => { oid => '.1.3.6.1.4.1.2.3.51.3.1.5.20.1.11' } +}; +my $oid_cpuEntry = '.1.3.6.1.4.1.2.3.51.3.1.5.20.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_cpuEntry, start => $mapping->{cpuDescr}->{oid}, end => $mapping->{cpuHealthStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking cpus"); + $self->{components}->{cpu} = {name => 'cpus', 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->{cpuDescr}->{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)); + + $self->{components}->{cpu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("CPU '%s' is '%s' [instance = %s]", + $result->{cpuDescr}, $result->{cpuHealthStatus}, $instance)); + my $exit = $self->get_severity(section => 'health', value => $result->{cpuHealthStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("CPU '%s' is '%s'", $result->{cpuDescr}, $result->{cpuHealthStatus})); + } + } +} + +1; diff --git a/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/disk.pm b/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/disk.pm new file mode 100644 index 000000000..2b908d9d0 --- /dev/null +++ b/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/disk.pm @@ -0,0 +1,64 @@ +# +# Copyright 2020 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::ibm::mgmt_cards::imm::snmp::mode::components::disk; + +use strict; +use warnings; +use centreon::plugins::misc; + +my $mapping = { + diskDescr => { oid => '.1.3.6.1.4.1.2.3.51.3.1.12.2.1.2' }, + diskHealthStatus => { oid => '.1.3.6.1.4.1.2.3.51.3.1.12.2.1.3' } +}; +my $oid_diskEntry = '.1.3.6.1.4.1.2.3.51.3.1.12.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_diskEntry, start => $mapping->{diskDescr}->{oid}, end => $mapping->{diskHealthStatus}->{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->{diskDescr}->{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}++; + $self->{output}->output_add(long_msg => sprintf("Disk '%s' is '%s' [instance = %s]", + $result->{diskDescr}, $result->{diskHealthStatus}, $instance)); + my $exit = $self->get_severity(section => 'health', value => $result->{diskHealthStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Disk '%s' is '%s'", $result->{diskDescr}, $result->{diskHealthStatus})); + } + } +} + +1; diff --git a/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/fan.pm b/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/fan.pm index 0b71984ef..9c0f257c6 100644 --- a/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/fan.pm +++ b/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/fan.pm @@ -25,15 +25,16 @@ use warnings; use centreon::plugins::misc; my $mapping = { - fanDescr => { oid => '.1.3.6.1.4.1.2.3.51.3.1.3.2.1.2' }, - fanSpeed => { oid => '.1.3.6.1.4.1.2.3.51.3.1.3.2.1.3' }, + fanDescr => { oid => '.1.3.6.1.4.1.2.3.51.3.1.3.2.1.2' }, + fanSpeed => { oid => '.1.3.6.1.4.1.2.3.51.3.1.3.2.1.3' }, + fanHealthStatus => { oid => '.1.3.6.1.4.1.2.3.51.3.1.3.2.1.10' } }; my $oid_fanEntry = '.1.3.6.1.4.1.2.3.51.3.1.3.2.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_fanEntry, start => $mapping->{fanDescr}->{oid}, end => $mapping->{fanSpeed}->{oid} }; + push @{$self->{request}}, { oid => $oid_fanEntry, start => $mapping->{fanDescr}->{oid}, end => $mapping->{fanHealthStatus}->{oid} }; } sub check { @@ -44,7 +45,7 @@ sub check { return if ($self->check_filter(section => 'fan')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fanEntry}})) { - next if ($oid !~ /^$mapping->{fanSpeed}->{oid}\.(.*)$/); + next if ($oid !~ /^$mapping->{fanDescr}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fanEntry}, instance => $instance); $result->{fanDescr} = centreon::plugins::misc::trim($result->{fanDescr}); @@ -55,20 +56,18 @@ sub check { $self->{components}->{fan}->{total}++; $self->{output}->output_add(long_msg => sprintf("Fan '%s' speed is '%s' [instance = %s]", $result->{fanDescr}, $result->{fanSpeed}, $instance)); - if ($result->{fanSpeed} =~ /offline/i) { - my $exit = $self->get_severity(section => 'fan', value => $result->{fanSpeed}); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Fan '%s' is offline", $result->{fanDescr})); - } + my $exit = $self->get_severity(section => 'health', value => $result->{fanHealthStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan '%s' is '%s'", $result->{fanDescr}, $result->{fanHealthStatus})); } next if ($result->{fanSpeed} !~ /(\d+)/); my $fan_speed = $1; - my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $fan_speed); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $fan_speed); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, short_msg => sprintf("Fan '%s' is '%s' %%", $result->{fanDescr}, $fan_speed)); } $self->{output}->perfdata_add( diff --git a/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/memory.pm b/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/memory.pm new file mode 100644 index 000000000..b5216a572 --- /dev/null +++ b/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/memory.pm @@ -0,0 +1,64 @@ +# +# Copyright 2020 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::ibm::mgmt_cards::imm::snmp::mode::components::memory; + +use strict; +use warnings; +use centreon::plugins::misc; + +my $mapping = { + memoryDescr => { oid => '.1.3.6.1.4.1.2.3.51.3.1.5.21.1.2' }, + memoryHealthStatus => { oid => '.1.3.6.1.4.1.2.3.51.3.1.5.21.1.8' } +}; +my $oid_memoryEntry = '.1.3.6.1.4.1.2.3.51.3.1.5.21.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_memoryEntry, start => $mapping->{memoryDescr}->{oid}, end => $mapping->{memoryHealthStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking memorys"); + $self->{components}->{memory} = {name => 'memorys', 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->{memoryDescr}->{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)); + + $self->{components}->{memory}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Memory '%s' is '%s' [instance = %s]", + $result->{memoryDescr}, $result->{memoryHealthStatus}, $instance)); + my $exit = $self->get_severity(section => 'health', value => $result->{memoryHealthStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Memory '%s' is '%s'", $result->{memoryDescr}, $result->{memoryHealthStatus})); + } + } +} + +1; diff --git a/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/power.pm b/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/power.pm new file mode 100644 index 000000000..d4e54807c --- /dev/null +++ b/hardware/server/ibm/mgmt_cards/imm/snmp/mode/components/power.pm @@ -0,0 +1,64 @@ +# +# Copyright 2020 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::ibm::mgmt_cards::imm::snmp::mode::components::power; + +use strict; +use warnings; +use centreon::plugins::misc; + +my $mapping = { + powerDescr => { oid => '.1.3.6.1.4.1.2.3.51.3.1.11.2.1.2' }, + powerHealthStatus => { oid => '.1.3.6.1.4.1.2.3.51.3.1.11.2.1.6' } +}; +my $oid_powerEntry = '.1.3.6.1.4.1.2.3.51.3.1.11.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_powerEntry, start => $mapping->{powerDescr}->{oid}, end => $mapping->{powerHealthStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking powers"); + $self->{components}->{power} = {name => 'powers', total => 0, skip => 0}; + return if ($self->check_filter(section => 'power')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_powerEntry}})) { + next if ($oid !~ /^$mapping->{powerDescr}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_powerEntry}, instance => $instance); + + next if ($self->check_filter(section => 'power', instance => $instance)); + + $self->{components}->{power}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Power '%s' is '%s' [instance = %s]", + $result->{powerDescr}, $result->{powerHealthStatus}, $instance)); + my $exit = $self->get_severity(section => 'health', value => $result->{powerHealthStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power '%s' is '%s'", $result->{powerDescr}, $result->{powerHealthStatus})); + } + } +} + +1; diff --git a/hardware/server/ibm/mgmt_cards/imm/snmp/mode/environment.pm b/hardware/server/ibm/mgmt_cards/imm/snmp/mode/environment.pm index cef6b8e66..8ea06543f 100644 --- a/hardware/server/ibm/mgmt_cards/imm/snmp/mode/environment.pm +++ b/hardware/server/ibm/mgmt_cards/imm/snmp/mode/environment.pm @@ -28,7 +28,7 @@ use warnings; sub set_system { my ($self, %options) = @_; - $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|voltage|fan)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(fan|temperature|voltage)$'; $self->{cb_hook2} = 'snmp_execute'; @@ -39,14 +39,15 @@ sub set_system { ['critical', 'CRITICAL'], ['nominal', 'OK'] ], - fan => [ - ['offline', 'WARNING'], - ['.*', 'OK'] + health => [ + ['Normal', 'OK'], + ['Warning', 'WARNING'], + ['.*', 'CRITICAL'] ] }; $self->{components_path} = 'hardware::server::ibm::mgmt_cards::imm::snmp::mode::components'; - $self->{components_module} = ['global', 'temperature', 'voltage', 'fan']; + $self->{components_module} = ['cpu', 'disk', 'fan', 'global', 'memory', 'power', 'temperature', 'voltage']; } sub snmp_execute { @@ -79,7 +80,7 @@ Check sensors (Fans, Temperatures, Voltages). =item B<--component> Which component to check (Default: '.*'). -Can be: 'global', 'fan', 'temperature', 'voltage'. +Can be: 'cpu', 'disk', 'fan', 'global', 'memory', 'power', 'temperature', 'voltage'. =item B<--filter>