| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package network::lenovo::rackswitch::snmp::mode::hardware; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 28 |
use network::lenovo::rackswitch::snmp::mode::resources; |
| 29 |
|
| 30 |
sub prefix_sensor_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
return "sensor '" . $options{instance} . "' "; |
| 34 |
} |
| 35 |
|
| 36 |
sub prefix_fan_output { |
| 37 |
my ($self, %options) = @_; |
| 38 |
|
| 39 |
return "fan '" . $options{instance} . "' "; |
| 40 |
} |
| 41 |
|
| 42 |
sub set_counters { |
| 43 |
my ($self, %options) = @_; |
| 44 |
|
| 45 |
$self->{maps_counters_type} = [ |
| 46 |
{ name => 'global', type => 0 }, |
| 47 |
{ name => 'sensors', type => 1, cb_prefix_output => 'prefix_sensor_output', message_multiple => 'All sensors are ok', skipped_code => { -10 => 1 } }, |
| 48 |
{ name => 'fans', type => 1, cb_prefix_output => 'prefix_fan_output', message_multiple => 'All fans are ok', skipped_code => { -10 => 1 } } |
| 49 |
]; |
| 50 |
|
| 51 |
$self->{maps_counters}->{global} = [ |
| 52 |
{ |
| 53 |
label => 'status', |
| 54 |
type => 2, |
| 55 |
warning_default => '%{status} eq "noncritical"', |
| 56 |
critical_default => '%{status} eq "critical"', |
| 57 |
set => { |
| 58 |
key_values => [ { name => 'status' } ], |
| 59 |
output_template => 'global health status: %s', |
| 60 |
closure_custom_perfdata => sub { return 0; }, |
| 61 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 62 |
} |
| 63 |
} |
| 64 |
]; |
| 65 |
|
| 66 |
$self->{maps_counters}->{sensors} = [ |
| 67 |
{ label => 'sensor-temperature', nlabel => 'hardware.sensor.temperature.celsius', set => { |
| 68 |
key_values => [ { name => 'temp' } ], |
| 69 |
output_template => 'temperature is %s C', |
| 70 |
perfdatas => [ |
| 71 |
{ template => '%s', unit => 'C', label_extra_instance => 1 } |
| 72 |
] |
| 73 |
} |
| 74 |
} |
| 75 |
]; |
| 76 |
|
| 77 |
$self->{maps_counters}->{fans} = [ |
| 78 |
{ label => 'fan-speed', nlabel => 'hardware.fan.speed.rpm', set => { |
| 79 |
key_values => [ { name => 'speed' } ], |
| 80 |
output_template => 'speed is %s rpm', |
| 81 |
perfdatas => [ |
| 82 |
{ template => '%s', unit => 'rpm', min => 0, label_extra_instance => 1 } |
| 83 |
] |
| 84 |
} |
| 85 |
} |
| 86 |
]; |
| 87 |
} |
| 88 |
|
| 89 |
sub new { |
| 90 |
my ($class, %options) = @_; |
| 91 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 92 |
bless $self, $class; |
| 93 |
|
| 94 |
return $self; |
| 95 |
} |
| 96 |
|
| 97 |
sub manage_selection { |
| 98 |
my ($self, %options) = @_; |
| 99 |
|
| 100 |
my $map_status = { |
| 101 |
1 => 'ok', 2 => 'noncritical', 3 => 'critical' |
| 102 |
}; |
| 103 |
|
| 104 |
my $branch = network::lenovo::rackswitch::snmp::mode::resources::find_rackswitch_branch( |
| 105 |
output => $self->{output}, snmp => $options{snmp} |
| 106 |
); |
| 107 |
my $oid_fan_speed = $branch . '.1.3.1.13.0'; # hwFanSpeed |
| 108 |
my $oid_temp_sensors = $branch . '.1.3.1.14.0'; # hwTempSensors |
| 109 |
my $oid_health_status = $branch . '.1.3.1.15.0'; # hwGlobalHealthStatus |
| 110 |
my $snmp_result = $options{snmp}->get_leef( |
| 111 |
oids => [$oid_fan_speed, $oid_temp_sensors, $oid_health_status], |
| 112 |
nothing_quit => 1 |
| 113 |
); |
| 114 |
|
| 115 |
$self->{global} = { status => $map_status->{ $snmp_result->{$oid_health_status} } }; |
| 116 |
$self->{sensors} = {}; |
| 117 |
while ($snmp_result->{$oid_temp_sensors} =~ /Sensor\s+(\d+):\s*([0-9\.]+)/ig) { |
| 118 |
$self->{sensors}->{$1} = { temp => $2 }; |
| 119 |
} |
| 120 |
|
| 121 |
$self->{fans} = {}; |
| 122 |
while ($snmp_result->{$oid_fan_speed} =~ /Fan\s+(\d+):\s*([0-9\.]+)\s*RPM/ig) { |
| 123 |
$self->{fans}->{$1} = { speed => $2 }; |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
1; |
| 128 |
|
| 129 |
__END__ |
| 130 |
|
| 131 |
=head1 MODE |
| 132 |
|
| 133 |
Check hardware. |
| 134 |
|
| 135 |
=over 8 |
| 136 |
|
| 137 |
=item B<--unknown-status> |
| 138 |
|
| 139 |
Define the conditions to match for the status to be UNKNOWN. |
| 140 |
You can use the following variables: %{status} |
| 141 |
|
| 142 |
=item B<--warning-status> |
| 143 |
|
| 144 |
Define the conditions to match for the status to be WARNING (default: '%{status} eq "noncritical"'). |
| 145 |
You can use the following variables: %{status} |
| 146 |
|
| 147 |
=item B<--critical-status> |
| 148 |
|
| 149 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} eq "critical"'). |
| 150 |
You can use the following variables: %{status} |
| 151 |
|
| 152 |
=item B<--warning-*> B<--critical-*> |
| 153 |
|
| 154 |
Thresholds. |
| 155 |
Can be: 'sensor-temperature', 'fan-speed'. |
| 156 |
|
| 157 |
=back |
| 158 |
|
| 159 |
=cut |