Debian Codegraph @

src/storage/hp/storeonce/4/restapi/mode/hardwarestorage.pm

raw
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::hp::storeonce::4::restapi::mode::hardwarestorage;
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} = '^(?:fan\.speed|temperature)$';
32
33 $self->{cb_hook2} = 'snmp_execute';
34
35 $self->{thresholds} = {
36 default => [
37 ['ok', 'OK'],
38 ['missing', 'OK'],
39 ['degraded', 'OK'],
40 ['critical', 'CRITICAL'],
41 ['failed', 'CRITICAL']
42 ]
43 };
44
45 $self->{components_path} = 'storage::hp::storeonce::4::restapi::mode::components';
46 $self->{components_module} = ['drive', 'driveencl', 'fan', 'iomodule', 'pool', 'psu', 'temperature'];
47 }
48
49 sub browse_components {
50 my ($self, %options) = @_;
51
52 foreach my $comp (@{${$options{components}}}) {
53 if ($comp->{name} =~ /tempSensor|pool|driveEnclosure|powerSupply|IOmodule|fan|drive/) {
54 my $entry = {
55 name => join(':', @{$options{path}}, (defined($comp->{value}->{location}) ? $comp->{value}->{location} : $comp->{value}->{name})),
56 status => $comp->{value}->{status}
57 };
58 if ($comp->{name} eq 'tempSensor') {
59 $entry->{temperature} = defined($comp->{value}->{temperature}) && $comp->{value}->{temperature} =~ /^\s*(\d+)\s*C/ ? $1 : undef;
60 $entry->{upperNonCriticalThreshold} = defined($comp->{value}->{upperNonCriticalThreshold}) && $comp->{value}->{upperNonCriticalThreshold} =~ /^\s*(\d+)\s*C/ ? $1 : undef;
61 $entry->{upperCriticalThreshold} = defined($comp->{value}->{upperCriticalThreshold}) && $comp->{value}->{upperCriticalThreshold} =~ /^\s*(\d+)\s*C/ ? $1 : undef;
62 } elsif ($comp->{name} eq 'fan') {
63 $entry->{speed} = defined($comp->{value}->{speed}) && $comp->{value}->{speed} =~ /^\s*(\d+)\s*RPM/i ? $1 : undef;
64 }
65 push @{$self->{subsystems}->{ $comp->{name} }}, $entry;
66 }
67
68 $self->browse_components(
69 components => \$comp->{value}->{component},
70 path => [@{$options{path}}, (defined($comp->{value}->{location}) ? $comp->{value}->{location} : $comp->{value}->{name})]
71 );
72 }
73 }
74
75 sub snmp_execute {
76 my ($self, %options) = @_;
77
78 $self->{subsystems} = {
79 tempSensor => [],
80 pool => [],
81 driveEnclosure => [],
82 powerSupply => [],
83 IOmodule => [],
84 fan => [],
85 drive => []
86 };
87 my $storages = $options{custom}->request_api(endpoint => '/hwmonitor/storage');
88 foreach my $storage (@{$storages->{storageCluster}}) {
89 my $sc_infos = $options{custom}->request_api(endpoint => '/hwmonitor/storage/' . $storage->{name});
90 $self->browse_components(
91 components => \$sc_infos->{hardwareReportResponse}->{hardwareReport}->{component}->[0]->{value}->{component},
92 path => [$storage->{name}]
93 );
94 }
95 }
96
97 sub new {
98 my ($class, %options) = @_;
99 my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1);
100 bless $self, $class;
101
102 $options{options}->add_options(arguments => {});
103
104 return $self;
105 }
106
107 1;
108
109 __END__
110
111 =head1 MODE
112
113 Check hardware.
114
115 =over 8
116
117 =item B<--component>
118
119 Which component to check.
120 Can be: 'drive', 'driveencl', 'fan', 'iomodule', 'pool', 'psu', 'temperature'.
121
122 =item B<--filter>
123
124 Exclude the items given as a comma-separated list (example: --filter=psu).
125 You can also exclude items from specific instances: --filter=fan,fan slot 1
126
127 =item B<--no-component>
128
129 Define the expected status if no components are found (default: critical).
130
131 =item B<--threshold-overload>
132
133 Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,status,regexp).
134 Example: --threshold-overload='fan,WARNING,missing'
135
136 =item B<--warning>
137
138 Set warning threshold for 'fan.speed' (syntax: section,[instance,]status,regexp)
139 Example: --warning='fan.speed,.*,10000'
140
141 =item B<--critical>
142
143 Set critical threshold for 'fan.speed' (syntax: section,[instance,]status,regexp)
144 Example: --critical='fan.speed,.*,11000'
145
146 =back
147
148 =cut