| 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 hardware::server::supermicro::bmc::snmp::mode::hardware; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::hardware); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub set_system { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
$self->{regexp_threshold_numeric_check_section_option} = '^(?:sensor)$'; |
| 32 |
|
| 33 |
$self->{cb_hook2} = 'snmp_execute'; |
| 34 |
|
| 35 |
$self->{thresholds} = {}; |
| 36 |
|
| 37 |
$self->{components_path} = 'hardware::server::supermicro::bmc::snmp::mode::components'; |
| 38 |
$self->{components_module} = ['sensor']; |
| 39 |
} |
| 40 |
|
| 41 |
sub new { |
| 42 |
my ($class, %options) = @_; |
| 43 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1, force_new_perfdata => 1); |
| 44 |
bless $self, $class; |
| 45 |
|
| 46 |
$options{options}->add_options(arguments => { |
| 47 |
}); |
| 48 |
|
| 49 |
return $self; |
| 50 |
} |
| 51 |
|
| 52 |
sub snmp_execute { |
| 53 |
my ($self, %options) = @_; |
| 54 |
|
| 55 |
$self->{option_results}->{add_name_instance} = 1; |
| 56 |
|
| 57 |
$self->{snmp} = $options{snmp}; |
| 58 |
} |
| 59 |
|
| 60 |
1; |
| 61 |
|
| 62 |
=head1 MODE |
| 63 |
|
| 64 |
Check hardware. |
| 65 |
|
| 66 |
=over 8 |
| 67 |
|
| 68 |
=item B<--component> |
| 69 |
|
| 70 |
Which component to check (default: '.*'). |
| 71 |
Can be: 'sensor'. |
| 72 |
|
| 73 |
=item B<--filter> |
| 74 |
|
| 75 |
You can also exclude items from specific instances: --filter=sensor,fan |
| 76 |
|
| 77 |
=item B<--no-component> |
| 78 |
|
| 79 |
Define the expected status if no components are found (default: critical). |
| 80 |
|
| 81 |
=item B<--warning> |
| 82 |
|
| 83 |
Set warning threshold (syntax: type,regexp,threshold) |
| 84 |
Example: --warning='sensor,.*,30' |
| 85 |
|
| 86 |
=item B<--critical> |
| 87 |
|
| 88 |
Set critical threshold (syntax: type,regexp,threshold) |
| 89 |
Example: --critical='sensor,.*,40' |
| 90 |
|
| 91 |
=back |
| 92 |
|
| 93 |
=cut |
| 94 |
|
| 95 |
package hardware::server::supermicro::bmc::snmp::mode::components::sensor; |
| 96 |
|
| 97 |
use strict; |
| 98 |
use warnings; |
| 99 |
use centreon::plugins::misc; |
| 100 |
|
| 101 |
my $mapping = { |
| 102 |
lncThreshold => { oid => '.1.3.6.1.4.1.21317.1.3.1.5' }, |
| 103 |
lcThreshold => { oid => '.1.3.6.1.4.1.21317.1.3.1.6' }, |
| 104 |
uncThreshold => { oid => '.1.3.6.1.4.1.21317.1.3.1.8' }, |
| 105 |
ucThreshold => { oid => '.1.3.6.1.4.1.21317.1.3.1.9' }, |
| 106 |
sensorIDString => { oid => '.1.3.6.1.4.1.21317.1.3.1.13' } |
| 107 |
}; |
| 108 |
|
| 109 |
sub load {} |
| 110 |
|
| 111 |
sub check { |
| 112 |
my ($self) = @_; |
| 113 |
|
| 114 |
$self->{output}->output_add(long_msg => "Checking sensors"); |
| 115 |
$self->{components}->{sensor} = { name => 'sensors', total => 0, skip => 0 }; |
| 116 |
return if ($self->check_filter(section => 'sensor')); |
| 117 |
|
| 118 |
my $sensorReading = '.1.3.6.1.4.1.21317.1.3.1.2'; |
| 119 |
my $snmp_result = $self->{snmp}->get_table(oid => $sensorReading); |
| 120 |
return if (scalar(keys %$snmp_result) <= 0); |
| 121 |
|
| 122 |
my $instances = []; |
| 123 |
foreach (keys %$snmp_result) { |
| 124 |
push @$instances, $1 if (/^$sensorReading\.(.*)$/); |
| 125 |
} |
| 126 |
$self->{snmp}->load( |
| 127 |
oids => [map($_->{oid}, values(%$mapping))], |
| 128 |
instances => $instances |
| 129 |
); |
| 130 |
my $results = $self->{snmp}->get_leef(); |
| 131 |
|
| 132 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) { |
| 133 |
next if ($oid !~ /^$sensorReading\.(.*)$/); |
| 134 |
my $instance = $1; |
| 135 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); |
| 136 |
|
| 137 |
$result->{sensorReading} = $snmp_result->{$oid}; |
| 138 |
$result->{sensorIDString} = centreon::plugins::misc::trim($result->{sensorIDString}); |
| 139 |
next if ($result->{sensorIDString} eq ''); |
| 140 |
next if ($result->{sensorReading} =~ /^0\.0+$/ && $result->{lncThreshold} =~ /^0\.0+$/); |
| 141 |
|
| 142 |
next if ($self->check_filter(section => 'sensor', instance => $instance, name => $result->{sensorIDString})); |
| 143 |
|
| 144 |
foreach (('sensorReading', 'lncThreshold', 'lcThreshold', 'uncThreshold', 'ucThreshold')) { |
| 145 |
$result->{$_} = $1 if ($result->{$_} =~ /^(\d+)\.0+$/); |
| 146 |
} |
| 147 |
|
| 148 |
$self->{components}->{sensor}->{total}++; |
| 149 |
$self->{output}->output_add( |
| 150 |
long_msg => sprintf( |
| 151 |
"sensor '%s' reading is '%s' [instance: %s]", |
| 152 |
$result->{sensorIDString}, |
| 153 |
$result->{sensorReading}, |
| 154 |
$instance . '#' . $result->{sensorIDString} |
| 155 |
) |
| 156 |
); |
| 157 |
|
| 158 |
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric( |
| 159 |
section => 'sensor', |
| 160 |
instance => $instance, |
| 161 |
name => $result->{sensorIDString}, |
| 162 |
value => $result->{sensorReading} |
| 163 |
); |
| 164 |
if ($checked == 0 && $result->{lncThreshold} != 0 && $result->{lcThreshold} != 0 && |
| 165 |
$result->{uncThreshold} != 0 && $result->{ucThreshold} != 0) { |
| 166 |
my $warn_th = $result->{lncThreshold} . ':' . $result->{uncThreshold}; |
| 167 |
my $crit_th = $result->{lcThreshold} . ':' . $result->{ucThreshold}; |
| 168 |
$self->{perfdata}->threshold_validate(label => 'warning-sensor-instance-' . $instance, value => $warn_th); |
| 169 |
$self->{perfdata}->threshold_validate(label => 'critical-sensor-instance-' . $instance, value => $crit_th); |
| 170 |
|
| 171 |
$exit = $self->{perfdata}->threshold_check( |
| 172 |
value => $result->{sensorReading}, |
| 173 |
threshold => [ |
| 174 |
{ label => 'critical-sensor-instance-' . $instance, exit_litteral => 'critical' }, |
| 175 |
{ label => 'warning-sensor-instance-' . $instance, exit_litteral => 'warning' } |
| 176 |
] |
| 177 |
); |
| 178 |
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-sensor-instance-' . $instance); |
| 179 |
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-sensor-instance-' . $instance); |
| 180 |
} |
| 181 |
|
| 182 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 183 |
$self->{output}->output_add( |
| 184 |
severity => $exit, |
| 185 |
short_msg => sprintf( |
| 186 |
"Sensor '%s' reading is %s", |
| 187 |
$result->{sensorIDString}, |
| 188 |
$result->{sensorReading} |
| 189 |
) |
| 190 |
); |
| 191 |
} |
| 192 |
|
| 193 |
$self->{output}->perfdata_add( |
| 194 |
nlabel => 'hardware.sensor.reading.count', |
| 195 |
instances => $result->{sensorIDString}, |
| 196 |
value => $result->{sensorReading}, |
| 197 |
warning => $warn, |
| 198 |
critical => $crit |
| 199 |
); |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
1; |