Debian Codegraph @

src/storage/netapp/ontap/snmp/mode/snapmirrorlag.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::snapmirrorlag;
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);
28
29 sub custom_status_calc {
30 my ($self, %options) = @_;
31
32 $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
33 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
34 return 0;
35 }
36
37 sub set_counters {
38 my ($self, %options) = @_;
39
40 $self->{maps_counters_type} = [
41 { name => 'snapmirror', type => 1, cb_prefix_output => 'prefix_snapmirror_output', message_multiple => 'All snapmirrors lags are ok' },
42 ];
43
44 $self->{maps_counters}->{snapmirror} = [
45 { label => 'status', threshold => 0, set => {
46 key_values => [ { name => 'state' }, { name => 'display' } ],
47 output_template => "state is '%s'",
48 output_use => 'state',
49 closure_custom_calc => $self->can('custom_status_calc'),
50 closure_custom_perfdata => sub { return 0; },
51 closure_custom_threshold_check => \&catalog_status_threshold,
52 }
53 },
54 { label => 'lag', set => {
55 key_values => [ { name => 'lag' }, { name => 'display' } ],
56 output_template => 'lag: %s seconds',
57 perfdatas => [
58 { label => 'lag', value => 'lag', template => '%s', min => 0, unit => 's',
59 label_extra_instance => 1, instance_use => 'display' },
60 ],
61 }
62 },
63 ];
64 }
65
66 sub prefix_snapmirror_output {
67 my ($self, %options) = @_;
68
69 return "Snapmirror '" . $options{instance_value}->{display} . "' ";
70 }
71
72 sub new {
73 my ($class, %options) = @_;
74 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
75 bless $self, $class;
76
77 $options{options}->add_options(arguments => {
78 'filter-name:s' => { name => 'filter_name' },
79 'filter-status:s' => { name => 'filter_status' },
80 'unknown-status:s' => { name => 'unknown_status', default => '' },
81 'warning-status:s' => { name => 'warning_status', default => '%{state} =~ /quiesced/i' },
82 'critical-status:s' => { name => 'critical_status', default => '%{state} =~ /unknown|brokenOff|uninitialized/i' },
83 });
84
85 return $self;
86 }
87
88 sub check_options {
89 my ($self, %options) = @_;
90 $self->SUPER::check_options(%options);
91
92 $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
93 }
94
95 sub check_snapmirror {
96 my ($self, %options) = @_;
97
98 my $oid_snapmirrorOn = '.1.3.6.1.4.1.789.1.9.1.0';
99 my $oid_snapmirrorSrc = '.1.3.6.1.4.1.789.1.9.20.1.2';
100
101 my $snmp_result = $options{snmp}->get_leef(oids => [$oid_snapmirrorOn]);
102 return if (!defined($snmp_result->{$oid_snapmirrorOn}));
103
104 if ($snmp_result->{$oid_snapmirrorOn} != 2) {
105 $self->{output}->add_option_msg(short_msg => "snapmirror is not turned on.");
106 $self->{output}->option_exit();
107 }
108
109 my $id_selected = [];
110 my $snmp_result_name = $options{snmp}->get_table(oid => $oid_snapmirrorSrc);
111 foreach my $oid (keys %$snmp_result_name) {
112 next if ($oid !~ /\.([0-9]+)$/);
113 my $instance = $1;
114
115 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
116 $snmp_result_name->{$oid} !~ /$self->{option_results}->{filter_name}/) {
117 $self->{output}->output_add(long_msg => "skipping '" . $snmp_result_name->{$oid} . "': no matching filter.", debug => 1);
118 next;
119 }
120
121 push @$id_selected, $instance;
122 }
123
124 return if (scalar(@$id_selected) <= 0);
125
126 my $map_state = {
127 1 => 'uninitialized', 2 => 'snapmirrored',
128 3 => 'brokenOff', 4 => 'quiesced',
129 5 => 'source', 6 => 'unknown',
130 };
131 my $mapping = {
132 snapmirrorState => { oid => '.1.3.6.1.4.1.789.1.9.20.1.5', map => $map_state },
133 snapmirrorLag => { oid => '.1.3.6.1.4.1.789.1.9.20.1.6' },
134 };
135
136 $options{snmp}->load(oids => [$mapping->{snapmirrorState}->{oid}, $mapping->{snapmirrorLag}->{oid}], instances => $id_selected);
137 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
138
139 $self->{snapmirror} = {};
140 foreach (@$id_selected) {
141 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
142 if (defined($self->{option_results}->{filter_status}) && $self->{option_results}->{filter_status} ne '' &&
143 $result->{snapmirrorState} !~ /$self->{option_results}->{filter_status}/) {
144 $self->{output}->output_add(long_msg => "skipping '" . $snmp_result_name->{$oid_snapmirrorSrc . '.' . $_} . "': no matching filter.", debug => 1);
145 next;
146 }
147
148 $self->{snapmirror}->{$_} = {
149 display => $snmp_result_name->{$oid_snapmirrorSrc . '.' . $_},
150 state => $result->{snapmirrorState},
151 lag => int($result->{snapmirrorLag} / 100),
152 };
153 }
154 }
155
156 sub check_sm {
157 my ($self, %options) = @_;
158
159 return if (scalar(keys %{$self->{snapmirror}}) > 0);
160
161 my $oid_snapmirrorRelSrcPath = '.1.3.6.1.4.1.789.1.29.1.1.2';
162
163 my $id_selected = [];
164 my $snmp_result_name = $options{snmp}->get_table(oid => $oid_snapmirrorRelSrcPath, nothing_quit => 1);
165 foreach my $oid (keys %$snmp_result_name) {
166 next if ($oid !~ /\.([0-9]+)$/);
167 my $instance = $1;
168
169 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
170 $snmp_result_name->{$oid} !~ /$self->{option_results}->{filter_name}/) {
171 $self->{output}->output_add(long_msg => "skipping '" . $snmp_result_name->{$oid} . "': no matching filter.", debug => 1);
172 next;
173 }
174
175 push @$id_selected, $instance;
176 }
177
178 if (scalar(@$id_selected) <= 0) {
179 $self->{output}->add_option_msg(short_msg => "No snapmirrors found for filter '" . $self->{option_results}->{filter_name} . "'.");
180 $self->{output}->option_exit();
181 }
182
183 my $map_state = {
184 0 => 'uninitialized', 1 => 'snapmirrored', 2 => 'brokenOff',
185 };
186 my $mapping = {
187 snapmirrorRelState => { oid => '.1.3.6.1.4.1.789.1.29.1.1.6', map => $map_state },
188 snapmirrorRelLag => { oid => '.1.3.6.1.4.1.789.1.29.1.1.7' },
189 };
190
191 $options{snmp}->load(oids => [$mapping->{snapmirrorRelState}->{oid}, $mapping->{snapmirrorRelLag}->{oid}], instances => $id_selected);
192 my $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
193
194 $self->{snapmirror} = {};
195 foreach (@$id_selected) {
196 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
197 if (defined($self->{option_results}->{filter_status}) && $self->{option_results}->{filter_status} ne '' &&
198 $result->{snapmirrorState} !~ /$self->{option_results}->{filter_status}/) {
199 $self->{output}->output_add(long_msg => "skipping '" . $snmp_result_name->{$oid_snapmirrorRelSrcPath . '.' . $_} . "': no matching filter.", debug => 1);
200 next;
201 }
202
203 $self->{snapmirror}->{$_} = {
204 display => $snmp_result_name->{$oid_snapmirrorRelSrcPath . '.' . $_},
205 state => $result->{snapmirrorRelState},
206 lag => int($result->{snapmirrorRelLag} / 100),
207 };
208 }
209 }
210
211 sub manage_selection {
212 my ($self, %options) = @_;
213
214 $self->check_snapmirror(%options);
215 $self->check_sm(%options);
216
217 if (scalar(keys %{$self->{snapmirror}}) <= 0) {
218 $self->{output}->add_option_msg(short_msg => "No snapmirrors found.");
219 $self->{output}->option_exit();
220 }
221 }
222
223 1;
224
225 __END__
226
227 =head1 MODE
228
229 Check snapmirrors status and lag.
230
231 =over 8
232
233 =item B<--filter-name>
234
235 Filter the snapmirror name (can be a regexp).
236
237 =item B<--filter-status>
238
239 Filter on status (can be a regexp).
240
241 =item B<--filter-counters>
242
243 Only display some counters (regexp can be used).
244 Example: --filter-counters='^status$'
245
246 =item B<--unknown-status>
247
248 Define the conditions to match for the status to be UNKNOWN (default: '').
249 You can use the following variables: %{state}, %{display}
250
251 =item B<--warning-status>
252
253 Define the conditions to match for the status to be WARNING (default: '%{state} =~ /quiesced/i').
254 You can use the following variables: %{state}, %{display}
255
256 =item B<--critical-status>
257
258 Define the conditions to match for the status to be CRITICAL (default: '%{state} =~ /unknown|brokenOff|uninitialized/i').
259 You can use the following variables: %{state}, %{display}
260
261 =item B<--warning-lag>
262
263 Warning threshold.
264
265 =item B<--critical-lag>
266
267 Critical threshold.
268
269 =back
270
271 =cut
272