Debian Codegraph @

src/storage/netapp/ontap/snmp/mode/filesys.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::netapp::ontap::snmp::mode::filesys;
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 catalog_status_calc);
28
29 sub custom_vs_status_output {
30 my ($self, %options) = @_;
31
32 my $msg = sprintf(
33 "vserver '%s' status : %s",
34 $self->{result_values}->{vserver_name},
35 $self->{result_values}->{vserver_status},
36 );
37 return $msg;
38 }
39
40 sub set_counters {
41 my ($self, %options) = @_;
42
43 $self->{maps_counters_type} = [
44 { name => 'fs', type => 1, cb_prefix_output => 'prefix_fs_output', message_multiple => 'All filesystems are ok', skipped_code => { -10 => 1 } },
45 ];
46
47 $self->{maps_counters}->{fs} = [
48 { label => 'usage', set => {
49 key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' } ],
50 closure_custom_calc => $self->can('custom_usage_calc'),
51 closure_custom_output => $self->can('custom_usage_output'),
52 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
53 closure_custom_threshold_check => $self->can('custom_usage_threshold'),
54 }
55 },
56 { label => 'inodes', set => {
57 key_values => [ { name => 'dfPerCentInodeCapacity' }, { name => 'display' } ],
58 output_template => 'Inodes Used : %s %%', output_error_template => "Inodes : %s",
59 perfdatas => [
60 { label => 'inodes', value => 'dfPerCentInodeCapacity', template => '%d',
61 unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
62 ],
63 }
64 },
65 { label => 'compresssaved', set => {
66 key_values => [ { name => 'dfCompressSavedPercent' }, { name => 'display' } ],
67 output_template => 'Compress Saved : %s %%', output_error_template => "Compress Saved : %s",
68 perfdatas => [
69 { label => 'compresssaved', value => 'dfCompressSavedPercent', template => '%d',
70 unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
71 ],
72 }
73 },
74 { label => 'dedupsaved', set => {
75 key_values => [ { name => 'dfDedupeSavedPercent' }, { name => 'display' } ],
76 output_template => 'Dedupe Saved : %s %%', output_error_template => "Dedupe Saved : %s",
77 perfdatas => [
78 { label => 'dedupsaved', value => 'dfDedupeSavedPercent', template => '%d',
79 unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
80 ],
81 }
82 },
83 { label => 'vserver-status', threshold => 0, set => {
84 key_values => [ { name => 'vserver_status' }, { name => 'vserver_name' } ],
85 closure_custom_calc => \&catalog_status_calc,
86 closure_custom_output => $self->can('custom_vs_status_output'),
87 closure_custom_perfdata => sub { return 0; },
88 closure_custom_threshold_check => \&catalog_status_threshold,
89 }
90 },
91 ];
92 }
93
94 sub custom_usage_perfdata {
95 my ($self, %options) = @_;
96
97 return if ($self->{result_values}->{total} <= 0);
98 my $label = 'used';
99 my $value_perf = $self->{result_values}->{used};
100 if (defined($self->{instance_mode}->{option_results}->{free})) {
101 $label = 'free';
102 $value_perf = $self->{result_values}->{free};
103 }
104
105 my %total_options = ();
106 if ($self->{instance_mode}->{option_results}->{units} eq '%') {
107 $total_options{total} = $self->{result_values}->{total};
108 $total_options{cast_int} = 1;
109 }
110
111 $self->{output}->perfdata_add(
112 label => $label, unit => 'B',
113 instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
114 value => $value_perf,
115 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
116 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
117 min => 0, max => $self->{result_values}->{total}
118 );
119 }
120
121 sub custom_usage_threshold {
122 my ($self, %options) = @_;
123
124 return 'ok' if ($self->{result_values}->{total} <= 0);
125 my ($exit, $threshold_value);
126 $threshold_value = $self->{result_values}->{used};
127 $threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free}));
128 if ($self->{instance_mode}->{option_results}->{units} eq '%') {
129 $threshold_value = $self->{result_values}->{prct_used};
130 $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free}));
131 }
132 $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]);
133 return $exit;
134 }
135
136 sub custom_usage_output {
137 my ($self, %options) = @_;
138
139 my $msg;
140 if ($self->{result_values}->{total} == 0) {
141 $msg = 'skipping: total size is 0';
142 } elsif ($self->{result_values}->{total} < 0) {
143 $msg = 'skipping: negative total value (maybe use snmp v2c)';
144 } else {
145 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
146 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
147 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
148 $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
149 $total_size_value . " " . $total_size_unit,
150 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
151 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
152 }
153 return $msg;
154 }
155
156 sub custom_usage_calc {
157 my ($self, %options) = @_;
158
159 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
160 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
161 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
162
163 return 0 if ($options{new_datas}->{$self->{instance} . '_total'} == 0);
164 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
165
166 $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
167 $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
168 # snapshot can be over 100%
169 if ($self->{result_values}->{free} < 0) {
170 $self->{result_values}->{free} = 0;
171 $self->{result_values}->{prct_free} = 0;
172 }
173
174 return 0;
175 }
176
177 sub prefix_fs_output {
178 my ($self, %options) = @_;
179
180 return "Filesys '" . $options{instance_value}->{display} . "' ";
181 }
182
183 sub new {
184 my ($class, %options) = @_;
185 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
186 bless $self, $class;
187
188 $options{options}->add_options(arguments => {
189 'units:s' => { name => 'units', default => '%' },
190 'free' => { name => 'free' },
191 'filter-name:s' => { name => 'filter_name' },
192 'filter-type:s' => { name => 'filter_type' },
193 'filter-vserver:s' => { name => 'filter_vserver' },
194 'filter-vserver-state:s' => { name => 'filter_vserver_state' },
195 'unknown-vserver-status:s' => { name => 'unknown_vserver_status', default => '' },
196 'warning-vserver-status:s' => { name => 'warning_vserver_status', default => '' },
197 'critical-vserver-status:s' => { name => 'critical_vserver_status', default => '' },
198 });
199
200 return $self;
201 }
202
203 sub check_options {
204 my ($self, %options) = @_;
205 $self->SUPER::check_options(%options);
206
207 $self->change_macros(macros => ['warning_vserver_status', 'critical_vserver_status', 'unknown_vserver_status']);
208 }
209
210 my $map_types = {
211 1 => 'traditionalVolume',
212 2 => 'flexibleVolume',
213 3 => 'aggregate',
214 4 => 'stripedAggregate',
215 5 => 'stripedVolume'
216 };
217 my $map_vserver_state = {
218 0 => 'running', 1 => 'stopped', 2 => 'starting', 3 => 'stopping'
219 };
220 my $mapping = {
221 dfType => { oid => '.1.3.6.1.4.1.789.1.5.4.1.23', map => $map_types },
222 };
223 my $mapping2 = {
224 dfFileSys => { oid => '.1.3.6.1.4.1.789.1.5.4.1.2' },
225 dfKBytesTotal => { oid => '.1.3.6.1.4.1.789.1.5.4.1.3' },
226 dfKBytesUsed => { oid => '.1.3.6.1.4.1.789.1.5.4.1.4' },
227 dfPerCentInodeCapacity => { oid => '.1.3.6.1.4.1.789.1.5.4.1.9' },
228 df64TotalKBytes => { oid => '.1.3.6.1.4.1.789.1.5.4.1.29' },
229 df64UsedKBytes => { oid => '.1.3.6.1.4.1.789.1.5.4.1.30' },
230 dfVserver => { oid => '.1.3.6.1.4.1.789.1.5.4.1.34' },
231 dfCompressSavedPercent => { oid => '.1.3.6.1.4.1.789.1.5.4.1.38' },
232 dfDedupeSavedPercent => { oid => '.1.3.6.1.4.1.789.1.5.4.1.40' },
233 };
234 my $mapping3 = {
235 vserverName => { oid => '.1.3.6.1.4.1.789.1.27.1.1.2' },
236 vserverState => { oid => '.1.3.6.1.4.1.789.1.27.1.1.16', map => $map_vserver_state },
237 };
238
239 sub get_vserver_state {
240 my ($self, %options) = @_;
241
242 return if (
243 (!defined($self->{option_results}->{filter_vserver_state}) || $self->{option_results}->{filter_vserver} eq '') &&
244 (!defined($self->{option_results}->{warning_vserver_status}) || $self->{option_results}->{warning_vserver_status} eq '') &&
245 (!defined($self->{option_results}->{critical_vserver_status}) || $self->{option_results}->{critical_vserver_status} eq '') &&
246 (!defined($self->{option_results}->{unknown_vserver_status}) || $self->{option_results}->{unknown_vserver_status} eq '')
247 );
248
249 my $snmp_result = $options{snmp}->get_multiple_table(
250 oids => [
251 { oid => $mapping3->{vserverName}->{oid} },
252 { oid => $mapping3->{vserverState}->{oid} }
253 ],
254 return_type => 1,
255 );
256
257 $self->{vserver} = {};
258 foreach (keys %$snmp_result) {
259 next if (! /^$mapping3->{vserverName}->{oid}\.(.*)/);
260 my $result = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result, instance => $1);
261 $self->{vserver}->{$result->{vserverName}} = $result->{vserverState};
262 }
263 }
264
265 sub manage_selection {
266 my ($self, %options) = @_;
267
268 my @oids = (
269 $mapping2->{dfKBytesTotal}->{oid},
270 $mapping2->{dfKBytesUsed}->{oid},
271 $mapping2->{dfPerCentInodeCapacity}->{oid},
272 $mapping2->{dfCompressSavedPercent}->{oid},
273 $mapping2->{dfDedupeSavedPercent}->{oid},
274 $mapping2->{dfVserver}->{oid},
275 );
276 if (!$options{snmp}->is_snmpv1()) {
277 push @oids, $mapping2->{df64TotalKBytes}->{oid};
278 push @oids, $mapping2->{df64UsedKBytes}->{oid};
279 }
280
281 $self->get_vserver_state(%options);
282
283 my $results;
284 if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '') {
285 $results = $options{snmp}->get_multiple_table(
286 oids => [
287 { oid => $mapping->{dfType}->{oid} },
288 { oid => $mapping2->{dfFileSys}->{oid} }
289 ],
290 return_type => 1,
291 nothing_quit => 1
292 );
293 } else {
294 $results = $options{snmp}->get_table(oid => $mapping2->{dfFileSys}->{oid}, nothing_quit => 1);
295 }
296 my @fs_selected;
297 foreach my $oid (keys %{$results}) {
298 next if ($oid !~ /^$mapping2->{dfFileSys}->{oid}\.(\d+)/);
299 my $instance = $1;
300 my $name = $results->{$oid};
301 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
302 $name !~ /$self->{option_results}->{filter_name}/) {
303 $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter name.", debug => 1);
304 next;
305 }
306 if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
307 $map_types->{$results->{$mapping->{dfType}->{oid} . '.' . $instance}} !~ /$self->{option_results}->{filter_type}/) {
308 $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter type.", debug => 1);
309 next;
310 }
311 push @fs_selected, $instance;
312 }
313
314 if (scalar(@fs_selected) <= 0) {
315 $self->{output}->add_option_msg(short_msg => "No entry found.");
316 $self->{output}->option_exit();
317 }
318
319 $self->{fs} = {};
320 $options{snmp}->load(oids => \@oids, instances => \@fs_selected);
321 my $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
322 foreach my $instance (sort @fs_selected) {
323 my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $instance);
324
325 if (defined($result2->{dfVserver}) && $result2->{dfVserver} ne '' &&
326 defined($self->{option_results}->{filter_vserver_state}) && $self->{option_results}->{filter_vserver_state} ne '' &&
327 $self->{vserver}->{$result2->{dfVserver}} !~ /$self->{option_results}->{filter_vserver_state}/) {
328 $self->{output}->output_add(long_msg => "skipping '" . $instance . "': no matching filter vserver state.", debug => 1);
329 next;
330 }
331 if (defined($result2->{dfVserver}) && defined($self->{option_results}->{filter_vserver}) && $self->{option_results}->{filter_vserver} ne '' &&
332 $result2->{dfVserver} !~ /$self->{option_results}->{filter_vserver}/) {
333 $self->{output}->output_add(long_msg => "skipping '" . $instance . "': no matching filter vserver.", debug => 1);
334 next;
335 }
336
337 $self->{fs}->{$instance} = {
338 display => defined($result2->{dfVserver}) && $result2->{dfVserver} ne '' ?
339 $result2->{dfVserver} . ':' . $results->{$mapping2->{dfFileSys}->{oid} . '.' . $instance} :
340 $results->{$mapping2->{dfFileSys}->{oid} . '.' . $instance}
341 };
342 $self->{fs}->{$instance}->{total} = $result2->{dfKBytesTotal} * 1024;
343 $self->{fs}->{$instance}->{used} = $result2->{dfKBytesUsed} * 1024;
344 if (defined($result2->{df64TotalKBytes}) && $result2->{df64TotalKBytes} > 0) {
345 $self->{fs}->{$instance}->{total} = $result2->{df64TotalKBytes} * 1024;
346 $self->{fs}->{$instance}->{used} = $result2->{df64UsedKBytes} * 1024;
347 }
348 $self->{fs}->{$instance}->{dfCompressSavedPercent} = $result2->{dfCompressSavedPercent};
349 $self->{fs}->{$instance}->{dfDedupeSavedPercent} = $result2->{dfDedupeSavedPercent};
350 if ($self->{fs}->{$instance}->{total} > 0) {
351 $self->{fs}->{$instance}->{dfPerCentInodeCapacity} = $result2->{dfPerCentInodeCapacity};
352 }
353
354 $self->{fs}->{$instance}->{vserver_name} = $result2->{dfVserver};
355 $self->{fs}->{$instance}->{vserver_status} = defined($result2->{dfVserver}) ? $self->{vserver}->{$result2->{dfVserver}} : undef;
356 }
357 }
358
359 1;
360
361 __END__
362
363 =head1 MODE
364
365 Check filesystem usage (volumes, snapshots and aggregates also).
366
367 =over 8
368
369 =item B<--unknown-vserver-status>
370
371 Define the conditions to match for the status to be UNKNOWN (default: '').
372 You can use the following variables: %{vserver_status}, %{vserver_name}
373
374 =item B<--warning-vserver-status>
375
376 Define the conditions to match for the status to be WARNING (default: '').
377 You can use the following variables: %{vserver_status}, %{vserver_name}
378
379 =item B<--critical-vserver-status>
380
381 Define the conditions to match for the status to be CRITICAL (default: '').
382 You can use the following variables: %{vserver_status}, %{vserver_name}
383
384 =item B<--warning-*>
385
386 Warning threshold.
387 Can be: usage, inodes (%), compresssaved (%), dedupsaved (%).
388
389 =item B<--critical-*>
390
391 Critical threshold.
392 Can be: usage, inodes (%), compresssaved (%), dedupsaved (%).
393
394 =item B<--units>
395
396 Units of thresholds (default: '%') ('%', 'B').
397
398 =item B<--free>
399
400 Thresholds are on free space left.
401
402 =item B<--filter-name>
403
404 Filter by filesystem name (can be a regexp).
405
406 =item B<--filter-vserver>
407
408 Filter by vserver name (can be a regexp).
409
410 =item B<--filter-vserver-state>
411
412 Filter by vserver state (can be a regexp).
413
414 =item B<--filter-type>
415
416 Filter filesystem type (can be a regexp. Example: 'flexibleVolume|aggregate').
417
418 =back
419
420 =cut