Debian Codegraph @

src/storage/netapp/ontap/snmp/mode/volumeoptions.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::volumeoptions;
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 custom_options_threshold {
30 my ($self, %options) = @_;
31
32 my $status = catalog_status_threshold_ng($self, %options);
33 if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) {
34 $self->{instance_mode}->{global}->{failed}++;
35 }
36 return $status;
37 }
38
39 sub prefix_volume_output {
40 my ($self, %options) = @_;
41
42 return "Volume '" . $options{instance_value}->{display} . "' ";
43 }
44
45 sub set_counters {
46 my ($self, %options) = @_;
47
48 $self->{maps_counters_type} = [
49 { name => 'volumes', type => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'All volumes are ok', skipped_code => { -10 => 1 } },
50 { name => 'global', type => 0 } # need to be after for counting failed
51 ];
52
53 $self->{maps_counters}->{volumes} = [
54 { label => 'status', type => 2, set => {
55 key_values => [ { name => 'status' }, { name => 'display' } ],
56 output_template => "status is '%s'",
57 closure_custom_perfdata => sub { return 0; },
58 closure_custom_threshold_check => \&catalog_status_threshold_ng
59 }
60 },
61 { label => 'options', type => 2, set => {
62 key_values => [ { name => 'options' }, { name => 'display' } ],
63 output_template => "options: '%s'",
64 closure_custom_perfdata => sub { return 0; },
65 closure_custom_threshold_check => $self->can('custom_options_threshold')
66 }
67 }
68 ];
69
70 $self->{maps_counters}->{global} = [
71 { label => 'failed', display_ok => 0, set => {
72 key_values => [ { name => 'failed' } ],
73 output_template => 'Failed: %s',
74 perfdatas => [
75 { label => 'failed', template => '%s', min => 0 }
76 ]
77 }
78 }
79 ];
80 }
81
82 sub new {
83 my ($class, %options) = @_;
84 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
85 bless $self, $class;
86
87 $options{options}->add_options(arguments => {
88 'filter-name:s' => { name => 'filter_name' },
89 'filter-vserver:s' => { name => 'filter_vserver' },
90 'filter-status:s' => { name => 'filter_status' }
91 });
92
93 return $self;
94 }
95
96 sub check_options {
97 my ($self, %options) = @_;
98 $self->SUPER::check_options(%options);
99
100 $self->{test_option} = 0;
101 foreach ('warning', 'unknown', 'critical') {
102 $self->{test_option} = 1 if (defined($self->{option_results}->{$_ . '-options'}) && $self->{option_results}->{$_ . '-options'} ne '');
103 }
104 }
105
106 my $mapping = {
107 name => { oid => '.1.3.6.1.4.1.789.1.5.8.1.2' }, # volName
108 vserver => { oid => '.1.3.6.1.4.1.789.1.5.8.1.14' } # volVserver
109 };
110 my $mapping2 = {
111 status => { oid => '.1.3.6.1.4.1.789.1.5.8.1.5' }, # volState
112 options => { oid => '.1.3.6.1.4.1.789.1.5.8.1.7' } # volOptions
113 };
114
115 sub manage_selection {
116 my ($self, %options) = @_;
117
118 my $snmp_result = $options{snmp}->get_multiple_table(
119 oids => [
120 { oid => $mapping->{name}->{oid} },
121 { oid => $mapping->{vserver}->{oid} }
122 ],
123 return_type => 1,
124 nothing_quit => 1
125 );
126
127 $self->{volumes} = {};
128 foreach my $oid (keys %$snmp_result) {
129 next if ($oid !~ /\.([0-9]+)$/);
130 my $instance = $1;
131
132 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
133 my $name = defined($result->{vserver}) && $result->{vserver} ne '' ?
134 $result->{vserver} . ':' . $result->{name} :
135 $result->{name};
136 if (defined($self->{option_results}->{filter_vserver}) && $self->{option_results}->{filter_vserver} ne '' &&
137 $result->{vserver} !~ /$self->{option_results}->{filter_vserver}/) {
138 $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
139 next;
140 }
141 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
142 $result->{name} !~ /$self->{option_results}->{filter_name}/) {
143 $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
144 next;
145 }
146
147 $self->{volumes}->{$instance} = {
148 display => $name
149 };
150 }
151
152 if (scalar(keys %{$self->{volumes}}) <= 0) {
153 $self->{output}->add_option_msg(short_msg => "No volume found.");
154 $self->{output}->option_exit();
155 }
156
157 my $load_oids = [$mapping2->{status}->{oid}];
158 push @$load_oids, $mapping2->{options}->{oid} if ($self->{test_option} == 1);
159 $options{snmp}->load(oids => $load_oids, instances => [keys %{$self->{volumes}}]);
160 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
161
162 $self->{global} = { failed => 0 };
163 foreach (keys %{$self->{volumes}}) {
164 my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $_);
165 if (defined($self->{option_results}->{filter_status}) && $self->{option_results}->{filter_status} ne '' &&
166 $result->{status} !~ /$self->{option_results}->{filter_status}/) {
167 $self->{output}->output_add(long_msg => "skipping '" . $self->{volumes}->{$_}->{display} . "': no matching filter.", debug => 1);
168 next;
169 }
170
171 $self->{volumes}->{$_}->{status} = $result->{status};
172 $self->{volumes}->{$_}->{options} = $result->{options};
173 }
174 }
175
176 1;
177
178 __END__
179
180 =head1 MODE
181
182 Check options from volumes.
183
184 =over 8
185
186 =item B<--filter-vserver>
187
188 Filter volumes by vserver name (can be a regexp).
189
190 =item B<--filter-name>
191
192 Filter on volume name (can be a regexp).
193
194 =item B<--filter-status>
195
196 Filter on volume status (can be a regexp).
197
198 =item B<--unknown-status>
199
200 Define the conditions to match for the status to be UNKNOWN (default: '').
201 You can use the following variables: %{status}, %{display}
202
203 =item B<--warning-status>
204
205 Define the conditions to match for the status to be WARNING (default: '').
206 You can use the following variables: %{status}, %{display}
207
208 =item B<--critical-status>
209
210 Define the conditions to match for the status to be CRITICAL (default: '').
211 You can use the following variables: %{status}, %{display}
212
213 =item B<--unknown-options>
214
215 Define the conditions to match for the status to be WARNING (default: '').
216 You can use the following variables: %{options}, %{display}
217
218 =item B<--warning-options>
219
220 Define the conditions to match for the status to be WARNING (default: '').
221 You can use the following variables: %{options}, %{display}
222
223 =item B<--critical-options>
224
225 Define the conditions to match for the status to be CRITICAL (default: '').
226 You can use the following variables: %{options}, %{display}
227
228 =back
229
230 =cut
231