| 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 storage::dell::me4::restapi::mode::components::sensor; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
|
| 26 |
sub load { |
| 27 |
my ($self) = @_; |
| 28 |
|
| 29 |
$self->{json_results}->{sensors} = $self->{custom}->request_api(method => 'GET', url_path => '/api/show/sensor-status'); |
| 30 |
} |
| 31 |
|
| 32 |
my %mapping = ( |
| 33 |
'Voltage' => { |
| 34 |
unit => 'V', |
| 35 |
nlabel => 'voltage', |
| 36 |
nunit => 'volt', |
| 37 |
regexp => qr/(\d+)/ |
| 38 |
}, |
| 39 |
'Current' => { |
| 40 |
unit => 'A', |
| 41 |
nlabel => 'current', |
| 42 |
nunit => 'ampere', |
| 43 |
regexp => qr/(\d+)/ |
| 44 |
}, |
| 45 |
'Temperature' => { |
| 46 |
unit => 'C', |
| 47 |
nlabel => 'temperature', |
| 48 |
nunit => 'celsius', |
| 49 |
regexp => qr/(\d+)\sC/ |
| 50 |
}, |
| 51 |
'Charge Capacity' => { |
| 52 |
unit => '%', |
| 53 |
nlabel => 'capacity', |
| 54 |
nunit => 'percentage', |
| 55 |
regexp => qr/(\d+)%/ |
| 56 |
}, |
| 57 |
); |
| 58 |
|
| 59 |
sub check { |
| 60 |
my ($self) = @_; |
| 61 |
|
| 62 |
$self->{output}->output_add(long_msg => "Checking sensors"); |
| 63 |
$self->{components}->{sensor} = {name => 'sensors', total => 0, skip => 0}; |
| 64 |
return if ($self->check_filter(section => 'sensor')); |
| 65 |
return if (!defined($self->{json_results}->{sensors})); |
| 66 |
|
| 67 |
foreach my $result (@{$self->{json_results}->{sensors}->{sensors}}) { |
| 68 |
my $instance = $result->{'durable-id'}; |
| 69 |
|
| 70 |
next if ($self->check_filter(section => 'sensor', instance => $instance)); |
| 71 |
|
| 72 |
$self->{components}->{sensor}->{total}++; |
| 73 |
|
| 74 |
$self->{output}->output_add( |
| 75 |
long_msg => sprintf( |
| 76 |
"sensor '%s' status is '%s' [instance = %s] [value = %s]", |
| 77 |
$result->{'sensor-name'}, $result->{status}, $instance, |
| 78 |
$result->{value} |
| 79 |
) |
| 80 |
); |
| 81 |
|
| 82 |
my $exit1 = $self->get_severity(section => 'sensor', value => $result->{status}); |
| 83 |
if (!$self->{output}->is_status(value => $exit1, compare => 'ok', litteral => 1)) { |
| 84 |
$self->{output}->output_add( |
| 85 |
severity => $exit1, |
| 86 |
short_msg => sprintf("sensor '%s' status is '%s'", $result->{'sensor-name'}, $result->{status}) |
| 87 |
); |
| 88 |
} |
| 89 |
|
| 90 |
next if (!defined($mapping{$result->{'sensor-type'}})); |
| 91 |
next if ($result->{value} !~ $mapping{$result->{'sensor-type'}}->{regexp}); |
| 92 |
my $value = $1; |
| 93 |
my ($exit3, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'sensor', instance => $instance, value => $value); |
| 94 |
if (!$self->{output}->is_status(value => $exit3, compare => 'ok', litteral => 1)) { |
| 95 |
$self->{output}->output_add( |
| 96 |
severity => $exit3, |
| 97 |
short_msg => sprintf("Sensor '%s' value is %s %s", $result->{'sensor-name'}, $value, $mapping{$result->{'sensor-type'}}->{nunit}) |
| 98 |
); |
| 99 |
} |
| 100 |
$self->{output}->perfdata_add( |
| 101 |
nlabel => 'hardware.sensor.' . $mapping{$result->{'sensor-type'}}->{nlabel} . '.' . $mapping{$result->{'sensor-type'}}->{nunit}, |
| 102 |
instances => $instance, |
| 103 |
value => $value, |
| 104 |
warning => $warn, |
| 105 |
critical => $crit, |
| 106 |
min => 0 |
| 107 |
); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
1; |