Debian Codegraph @

src/storage/wd/nas/snmp/mode/hardware.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::wd::nas::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
29 sub prefix_fan_output {
30 my ($self, %options) = @_;
31
32 return "fan '" . $options{instance} . "' ";
33 }
34
35 sub prefix_drive_output {
36 my ($self, %options) = @_;
37
38 return "drive '" . $options{instance} . "' ";
39 }
40
41 sub set_counters {
42 my ($self, %options) = @_;
43
44 $self->{maps_counters_type} = [
45 { name => 'global', type => 0 },
46 { name => 'fans', type => 1, cb_prefix_output => 'prefix_fan_output', skipped_code => { -10 => 1 } },
47 { name => 'drives', type => 1, cb_prefix_output => 'prefix_drive_output', skipped_code => { -10 => 1 } }
48 ];
49
50 $self->{maps_counters}->{global} = [
51 { label => 'system-temperature', nlabel => 'hardware.temperature.celsius', set => {
52 key_values => [ { name => 'temperature' } ],
53 output_template => 'system temperature: %s C',
54 closure_custom_perfdata => sub {
55 my ($self, %options) = @_;
56
57 $self->{output}->perfdata_add(
58 nlabel => $self->{nlabel},
59 unit => 'C',
60 instances => 'system',
61 value => $self->{result_values}->{temperature},
62 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
63 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel})
64 );
65 }
66 }
67 }
68 ];
69
70 $self->{maps_counters}->{fans} = [
71 { label => 'fan-status', type => 2, critical_default => '%{status} ne "running"', set => {
72 key_values => [ { name => 'status' } ],
73 output_template => 'status: %s',
74 closure_custom_perfdata => sub { return 0; },
75 closure_custom_threshold_check => \&catalog_status_threshold_ng
76 }
77 }
78 ];
79
80 $self->{maps_counters}->{drives} = [
81 { label => 'drive-temperature', nlabel => 'hardware.temperature.celsius', set => {
82 key_values => [ { name => 'temperature' }, { name => 'serial' } ],
83 output_template => 'temperature: %s C',
84 closure_custom_perfdata => sub {
85 my ($self, %options) = @_;
86
87 $self->{output}->perfdata_add(
88 nlabel => $self->{nlabel},
89 unit => 'C',
90 instances => 'drive:' . $self->{result_values}->{serial},
91 value => $self->{result_values}->{temperature},
92 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
93 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel})
94 );
95 }
96 }
97 }
98 ];
99 }
100
101 sub new {
102 my ($class, %options) = @_;
103 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
104 bless $self, $class;
105
106 $options{options}->add_options(arguments => {});
107
108 return $self;
109 }
110
111 sub manage_selection {
112 my ($self, %options) = @_;
113
114 my $nas = {
115 ex2 => {
116 system => {
117 temperature => { oid => '.1.3.6.1.4.1.5127.1.1.1.2.1.7' },
118 fanStatus => { oid => '.1.3.6.1.4.1.5127.1.1.1.2.1.8' }
119 },
120 drive => {
121 serial => { oid => '.1.3.6.1.4.1.5127.1.1.1.2.1.10.1.4' },
122 temperature => { oid => '.1.3.6.1.4.1.5127.1.1.1.2.1.10.1.5' }
123 },
124 driveTable => '.1.3.6.1.4.1.5127.1.1.1.2.1.10.1'
125 },
126 ex2ultra => {
127 system => {
128 temperature => { oid => '.1.3.6.1.4.1.5127.1.1.1.8.1.7' },
129 fanStatus => { oid => '.1.3.6.1.4.1.5127.1.1.1.8.1.8' }
130 },
131 drive => {
132 serial => { oid => '.1.3.6.1.4.1.5127.1.1.1.8.1.10.1.4' },
133 temperature => { oid => '.1.3.6.1.4.1.5127.1.1.1.8.1.10.1.5' }
134 },
135 driveTable => '.1.3.6.1.4.1.5127.1.1.1.8.1.10.1'
136 },
137 ex4100 => {
138 system => {
139 temperature => { oid => '.1.3.6.1.4.1.5127.1.1.1.6.1.7' },
140 fanStatus => { oid => '.1.3.6.1.4.1.5127.1.1.1.6.1.8' }
141 },
142 drive => {
143 serial => { oid => '.1.3.6.1.4.1.5127.1.1.1.6.1.10.1.4' },
144 temperature => { oid => '.1.3.6.1.4.1.5127.1.1.1.6.1.10.1.5' }
145 },
146 driveTable => '.1.3.6.1.4.1.5127.1.1.1.6.1.10.1'
147 },
148 pr2100 => {
149 system => {
150 temperature => { oid => '.1.3.6.1.4.1.5127.1.1.1.9.1.7' },
151 fanStatus => { oid => '.1.3.6.1.4.1.5127.1.1.1.9.1.8' }
152 },
153 drive => {
154 serial => { oid => '.1.3.6.1.4.1.5127.1.1.1.9.1.10.1.4' },
155 temperature => { oid => '.1.3.6.1.4.1.5127.1.1.1.9.1.10.1.5' }
156 },
157 driveTable => '.1.3.6.1.4.1.5127.1.1.1.9.1.10.1'
158 },
159 pr4100 => {
160 system => {
161 temperature => { oid => '.1.3.6.1.4.1.5127.1.1.1.10.1.7' },
162 fanStatus => { oid => '.1.3.6.1.4.1.5127.1.1.1.10.1.8' }
163 },
164 drive => {
165 serial => { oid => '.1.3.6.1.4.1.5127.1.1.1.10.1.10.1.4' },
166 temperature => { oid => '.1.3.6.1.4.1.5127.1.1.1.10.1.10.1.5' }
167 },
168 driveTable => '.1.3.6.1.4.1.5127.1.1.1.10.1.10.1'
169 }
170 };
171
172 my $snmp_result = $options{snmp}->get_leef(
173 oids => [ map({ $nas->{$_}->{system}->{temperature}->{oid} . '.0', $nas->{$_}->{system}->{fanStatus}->{oid} . '.0' } keys(%$nas)) ],
174 nothing_quit => 1
175 );
176
177 $self->{global} = {};
178 $self->{fans} = {};
179 $self->{drives} = {};
180 foreach my $type (keys %$nas) {
181 next if (!defined($snmp_result->{ $nas->{$type}->{system}->{temperature}->{oid} . '.0' }));
182
183 my $result = $options{snmp}->map_instance(mapping => $nas->{$type}->{system}, results => $snmp_result, instance => 0);
184
185 $self->{global}->{temperature} = $1 if ($result->{temperature} =~ /Centigrade:(\d+)/i);
186 while ($result->{fanStatus} =~ /fan(\d+):\s*(\S+)/g) {
187 $self->{fans}->{$1} = { status => $2 };
188 }
189
190 $snmp_result = $options{snmp}->get_table(
191 oid => $nas->{$type}->{driveTable},
192 start => $nas->{$type}->{drive}->{serial}->{oid},
193 end => $nas->{$type}->{drive}->{temperature}->{oid}
194 );
195
196 foreach (keys %$snmp_result) {
197 next if (! /^$nas->{$type}->{drive}->{serial}->{oid}\.(\d+)$/);
198 $result = $options{snmp}->map_instance(mapping => $nas->{$type}->{drive}, results => $snmp_result, instance => $1);
199 $self->{drives}->{ $result->{serial} } = { serial => $result->{serial} };
200 $self->{drives}->{ $result->{serial} }->{temperature} = $1 if ($result->{temperature} =~ /Centigrade:(\d+)/i);
201 }
202 }
203 }
204
205 1;
206
207 __END__
208
209 =head1 MODE
210
211 Check hardware.
212
213 =over 8
214
215 =item B<--warning-fan-status>
216
217 Define the conditions to match for the status to be WARNING (default : '%{status} ne "running"').
218 You can use the following variables: %{status}
219
220 =item B<--critical-fan-status>
221
222 Define the conditions to match for the status to be CRITICAL.
223 You can use the following variables: %{status}
224
225 =item B<--warning-*> B<--critical-*>
226
227 Thresholds. Can be:
228 'system-temperature', 'drive-temperature'.
229
230 =back
231
232 =cut