Debian Codegraph @

src/storage/emc/datadomain/snmp/mode/replications.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::emc::datadomain::snmp::mode::replications;
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 use storage::emc::datadomain::snmp::lib::functions;
29 use centreon::plugins::misc;
30 use POSIX;
31
32 my $unitdiv = { s => 1, w => 604800, d => 86400, h => 3600, m => 60 };
33 my $unitdiv_long = { s => 'seconds', w => 'weeks', d => 'days', h => 'hours', m => 'minutes' };
34
35 sub custom_replication_perfdata {
36 my ($self) = @_;
37
38 my $instances = [];
39 foreach (@{$self->{instance_mode}->{custom_perfdata_instances}}) {
40 push @$instances, $self->{result_values}->{$_};
41 }
42
43 $self->{output}->perfdata_add(
44 nlabel => $self->{nlabel},
45 instances => $instances,
46 value => $self->{result_values}->{ $self->{key_values}->[0]->{name} },
47 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
48 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
49 min => 0
50 );
51 }
52
53 sub custom_sync_perfdata {
54 my ($self, %options) = @_;
55
56 my $instances = [];
57 foreach (@{$self->{instance_mode}->{custom_perfdata_instances}}) {
58 push @$instances, $self->{result_values}->{$_};
59 }
60
61 $self->{output}->perfdata_add(
62 nlabel => 'replication.last.insync.' . $unitdiv_long->{ $self->{instance_mode}->{option_results}->{unit} },
63 unit => $self->{instance_mode}->{option_results}->{unit},
64 instances => $instances,
65 value => floor($self->{result_values}->{offset_seconds} / $unitdiv->{ $self->{instance_mode}->{option_results}->{unit} }),
66 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
67 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
68 min => 0
69 );
70 }
71
72 sub custom_sync_threshold {
73 my ($self, %options) = @_;
74
75 return $self->{perfdata}->threshold_check(
76 value => floor($self->{result_values}->{offset_seconds} / $unitdiv->{ $self->{instance_mode}->{option_results}->{unit} }),
77 threshold => [
78 { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
79 { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' },
80 { label => 'unknown-'. $self->{thlabel}, exit_litteral => 'unknown' }
81 ]
82 );
83 }
84
85 sub custom_repl_output {
86 my ($self, %options) = @_;
87
88 return sprintf(
89 "state: %s, status: %s",
90 $self->{result_values}->{state},
91 $self->{result_values}->{status}
92 );
93 }
94
95 sub repl_long_output {
96 my ($self, %options) = @_;
97
98 return sprintf(
99 "checking replication source '%s' destination '%s' [type: %s]",
100 $options{instance_value}->{source},
101 $options{instance_value}->{destination},
102 $options{instance_value}->{type}
103 );
104 }
105
106 sub prefix_repl_output {
107 my ($self, %options) = @_;
108
109 return sprintf(
110 "replication source '%s' destination '%s' [type: %s] ",
111 $options{instance_value}->{source},
112 $options{instance_value}->{destination},
113 $options{instance_value}->{type}
114 );
115 }
116
117 sub prefix_global_output {
118 my ($self, %options) = @_;
119
120 return 'Number of replications ';
121 }
122
123 sub set_counters {
124 my ($self, %options) = @_;
125
126 $self->{maps_counters_type} = [
127 { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
128 {
129 name => 'repl', type => 3, cb_prefix_output => 'prefix_repl_output', cb_long_output => 'repl_long_output', indent_long_output => ' ', message_multiple => 'All replications are ok',
130 group => [
131 { name => 'status', type => 0, skipped_code => { -10 => 1 } },
132 { name => 'precomp', type => 0, skipped_code => { -10 => 1 } },
133 { name => 'sync', type => 0, skipped_code => { -10 => 1 } }
134 ]
135 }
136 ];
137
138 $self->{maps_counters}->{global} = [
139 { label => 'repl-detected', display_ok => 0, nlabel => 'replications.detected.count', set => {
140 key_values => [ { name => 'detected' } ],
141 output_template => 'detected: %s',
142 perfdatas => [
143 { template => '%s', min => 0 }
144 ]
145 }
146 }
147 ];
148
149 $self->{maps_counters}->{status} = [
150 {
151 label => 'status',
152 type => 2,
153 warning_default => '%{state} =~ /initializing|recovering/i',
154 critical_default => '%{state} =~ /disabledNeedsResync|uninitialized/i',
155 set => {
156 key_values => [ { name => 'state' }, { name => 'status' }, { name => 'source' }, { name => 'destination' }, { name => 'type' } ],
157 closure_custom_output => $self->can('custom_repl_output'),
158 closure_custom_perfdata => sub { return 0; },
159 closure_custom_threshold_check => \&catalog_status_threshold_ng
160 }
161 }
162 ];
163
164 $self->{maps_counters}->{precomp} = [
165 { label => 'precompression-data-remaining', nlabel => 'replication.precompression.data.remaining.bytes', set => {
166 key_values => [ { name => 'remaining' }, { name => 'source' }, { name => 'destination' }, { name => 'type' } ],
167 output_template => 'precompression data remaining: %s %s',
168 output_change_bytes => 1,
169 closure_custom_perfdata => $self->can('custom_replication_perfdata')
170 }
171 }
172 ];
173
174 $self->{maps_counters}->{sync} = [
175 { label => 'last-insync-time', set => {
176 key_values => [ { name => 'offset_seconds' }, { name => 'offset_human' }, { name => 'source' }, { name => 'destination' }, { name => 'type' } ],
177 output_template => 'last in sync time: %s',
178 output_use => 'offset_human',
179 closure_custom_perfdata => $self->can('custom_sync_perfdata'),
180 closure_custom_threshold_check => $self->can('custom_sync_threshold')
181 }
182 }
183 ];
184 }
185
186 sub new {
187 my ($class, %options) = @_;
188 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
189 bless $self, $class;
190
191 $options{options}->add_options(arguments => {
192 'filter-repl-index:s' => { name => 'filter_repl_index' },
193 'filter-repl-source:s' => { name => 'filter_repl_source' },
194 'filter-repl-destination:s' => { name => 'filter_repl_destination' },
195 'custom-perfdata-instances:s' => { name => 'custom_perfdata_instances' },
196 'unit:s' => { name => 'unit', default => 'd' }
197 });
198
199 return $self;
200 }
201
202 sub check_options {
203 my ($self, %options) = @_;
204 $self->SUPER::check_options(%options);
205
206 if ($self->{option_results}->{unit} eq '' || !defined($unitdiv->{$self->{option_results}->{unit}})) {
207 $self->{option_results}->{unit} = 'd';
208 }
209
210 if (!defined($self->{option_results}->{custom_perfdata_instances}) || $self->{option_results}->{custom_perfdata_instances} eq '') {
211 $self->{option_results}->{custom_perfdata_instances} = '%(type) %(source) %(destination)';
212 }
213
214 $self->{custom_perfdata_instances} = $self->custom_perfdata_instances(
215 option_name => '--custom-perfdata-instances',
216 instances => $self->{option_results}->{custom_perfdata_instances},
217 labels => { type => 1, source => 1, destination => 1 }
218 );
219 }
220
221 sub manage_selection {
222 my ($self, %options) = @_;
223
224 my $oid_sysDescr = '.1.3.6.1.2.1.1.1.0'; # 'Data Domain OS 5.4.1.1-411752'
225 my $oid_replicationInfoEntry = '.1.3.6.1.4.1.19746.1.8.1.1.1';
226
227 my $snmp_result = $options{snmp}->get_leef(
228 oids => [ $oid_sysDescr ],
229 nothing_quit => 1
230 );
231
232 if (!($self->{os_version} = storage::emc::datadomain::snmp::lib::functions::get_version(value => $snmp_result->{$oid_sysDescr}))) {
233 $self->{output}->output_add(
234 severity => 'UNKNOWN',
235 short_msg => 'Cannot get DataDomain OS version.'
236 );
237 $self->{output}->display();
238 $self->{output}->exit();
239 }
240
241 $snmp_result = $options{snmp}->get_table(
242 oid => $oid_replicationInfoEntry,
243 nothing_quit => 1
244 );
245
246 my ($oid_replSource, $oid_replDestination, $oid_replState, $oid_replStatus);
247 my %map_state = (
248 1 => 'enabled', 2 => 'disabled', 3 => 'disabledNeedsResync',
249 );
250 my %map_status = (
251 1 => 'connected', 2 => 'disconnected', 3 => 'migrating',
252 4 => 'suspended', 5 => 'neverConnected', 6 => 'idle'
253 );
254 if (centreon::plugins::misc::minimal_version($self->{os_version}, '5.4')) {
255 %map_state = (
256 1 => 'initializing', 2 => 'normal', 3 => 'recovering', 4 => 'uninitialized',
257 );
258 $oid_replSource = '.1.3.6.1.4.1.19746.1.8.1.1.1.7';
259 $oid_replDestination = '.1.3.6.1.4.1.19746.1.8.1.1.1.8';
260 $oid_replStatus = '.1.3.6.1.4.1.19746.1.8.1.1.1.4';
261 $oid_replState = '.1.3.6.1.4.1.19746.1.8.1.1.1.3';
262 } elsif (centreon::plugins::misc::minimal_version($self->{os_version}, '5.0')) {
263 $oid_replSource = '.1.3.6.1.4.1.19746.1.8.1.1.1.7';
264 $oid_replDestination = '.1.3.6.1.4.1.19746.1.8.1.1.1.8';
265 $oid_replStatus = '.1.3.6.1.4.1.19746.1.8.1.1.1.4';
266 $oid_replState = '.1.3.6.1.4.1.19746.1.8.1.1.1.3';
267 } else {
268 $oid_replSource = '.1.3.6.1.4.1.19746.1.8.1.1.1.6';
269 $oid_replDestination = '.1.3.6.1.4.1.19746.1.8.1.1.1.7';
270 $oid_replStatus = '.1.3.6.1.4.1.19746.1.8.1.1.1.3';
271 $oid_replState = '.1.3.6.1.4.1.19746.1.8.1.1.1.2';
272 }
273
274 my $mapping = {
275 replState => { oid => $oid_replState, map => \%map_state },
276 replStatus => { oid => $oid_replStatus, map => \%map_status },
277 replSource => { oid => $oid_replSource },
278 replDestination => { oid => $oid_replDestination },
279 replPreCompBytesRemaining => { oid => '.1.3.6.1.4.1.19746.1.8.1.1.1.11' },
280 replSyncedAsOfTime => { oid => '.1.3.6.1.4.1.19746.1.8.1.1.1.14' }
281 };
282
283 my $ctime = time();
284
285 $self->{global} = { detected => 0 };
286 $self->{repl} = {};
287 foreach my $oid (keys %$snmp_result) {
288 next if ($oid !~ /^$mapping->{replState}->{oid}\.(.*)$/);
289 my $instance = $1;
290 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
291
292 $result->{replSource} =~ /^(.*?):\/\//;
293 my $type = $1;
294
295 $result->{replSource} =~ s/^(.*?):\/\///;
296 $result->{replDestination} =~ s/^(.*?):\/\///;
297
298 # /data/col1/ is always present (useless information)
299 $result->{replSource} =~ s/\/data\/col1//;
300 $result->{replDestination} =~ s/\/data\/col1//;
301
302 next if (defined($self->{option_results}->{filter_repl_index}) && $self->{option_results}->{filter_repl_index} ne '' &&
303 $instance !~ /$self->{option_results}->{filter_repl_index}/);
304 next if (defined($self->{option_results}->{filter_repl_source}) && $self->{option_results}->{filter_repl_source} ne '' &&
305 $result->{replSource} !~ /$self->{option_results}->{filter_repl_source}/);
306 next if (defined($self->{option_results}->{filter_repl_destination}) && $self->{option_results}->{filter_repl_destination} ne '' &&
307 $result->{replDestination} !~ /$self->{option_results}->{filter_repl_destination}/);
308
309 $self->{global}->{detected}++;
310
311 $self->{repl}->{$instance} = {
312 type => $type,
313 source => $result->{replSource},
314 destination => $result->{replDestination},
315 status => {
316 type => $type,
317 source => $result->{replSource},
318 destination => $result->{replDestination},
319 state => $result->{replState},
320 status => $result->{replStatus}
321 },
322 precomp => {
323 type => $type,
324 source => $result->{replSource},
325 destination => $result->{replDestination},
326 remaining => $result->{replPreCompBytesRemaining}
327 },
328 sync => {
329 type => $type,
330 source => $result->{replSource},
331 destination => $result->{replDestination}
332 }
333 };
334
335 $self->{repl}->{$instance}->{sync}->{offset_seconds} = $ctime - $result->{replSyncedAsOfTime};
336 $self->{repl}->{$instance}->{sync}->{offset_human} = centreon::plugins::misc::change_seconds(
337 value => $self->{repl}->{$instance}->{sync}->{offset_seconds}
338 );
339 }
340 }
341
342 1;
343
344 __END__
345
346 =head1 MODE
347
348 Check replication.
349
350 =over 8
351
352 =item B<--filter-counters>
353
354 Only display some counters (regexp can be used).
355 Example: --filter-counters='^status$'
356
357 =item B<--filter-repl-index>
358
359 Check replications by index.
360
361 =item B<--filter-repl-source>
362
363 Check replications by source.
364
365 =item B<--filter-repl-destination>
366
367 Check replications by destination.
368
369 =item B<--custom-perfdata-instances>
370
371 Customize the name composition rule for the instances the metrics will be attached to (default: '%(type) %(source) %(destination)').
372 You can use the following variables: %(type) %(source) %(destination)
373
374 =item B<--unit>
375
376 Select the time unit for thresholds. May be 's' for seconds, 'm' for minutes, 'h' for hours, 'd' for days, 'w' for weeks (default: 'd').
377
378 =item B<--unknown-status>
379
380 Define the conditions to match for the status to be UNKNOWN.
381 You can use the following variables: %{state}, %{status}, %{source}, %{destination}, %{type}
382
383 =item B<--warning-status>
384
385 Define the conditions to match for the status to be WARNING (default: '%{state} =~ /initializing|recovering/i').
386 You can use the following variables: %{state}, %{status}, %{source}, %{destination}, %{type}
387
388 =item B<--critical-status>
389
390 Define the conditions to match for the status to be CRITICAL (default: '%{state} =~ /disabledNeedsResync|uninitialized/i').
391 You can use the following variables: %{state}, %{status}, %{source}, %{destination}, %{type}
392
393 =item B<--warning-*> B<--critical-*>
394
395 Thresholds.
396 Can be: 'repl-detected', 'precompression-data-remaining', 'last-insync-time'.
397
398 =back
399
400 =cut