Debian Codegraph @

src/storage/ibm/storwize/ssh/mode/replication.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::ibm::storwize::ssh::mode::replication;
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_replication_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 'Volume %s [group: %s, vdisk: %s] ',
34 $options{instance_value}->{name},
35 $options{instance_value}->{group_name},
36 $options{instance_value}->{vdisk_name}
37 );
38 }
39
40 sub set_counters {
41 my ($self, %options) = @_;
42
43 $self->{maps_counters_type} = [
44 { name => 'replication', type => 1, cb_prefix_output => 'prefix_replication_output', message_multiple => 'All volumes are in consistent_synchronized state'}
45 ];
46
47 $self->{maps_counters}->{replication} = [
48 {
49 label => 'status',
50 type => 2,
51 warning_default => '%{status} =~ /idling/i',
52 set => {
53 key_values => [ { name => 'status' } ],
54 output_template => 'status: %s',
55 closure_custom_perfdata => sub { return 0; },
56 closure_custom_threshold_check => \&catalog_status_threshold_ng
57 }
58 }
59 ];
60 }
61
62 sub new {
63 my ($class, %options) = @_;
64 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
65 bless $self, $class;
66
67 $options{options}->add_options(arguments => {
68 'filter-consistency-group-name:s' => { name => 'filter_group' }
69 });
70
71 return $self;
72 }
73
74 sub manage_selection {
75 my ($self, %options) = @_;
76
77 my ($content) = $options{custom}->execute_command(command => 'lsrcrelationship -delim :');
78 my $result = $options{custom}->get_hasharray(content => $content, delim => ':');
79
80 $self->{replication} = {};
81 foreach my $item (@$result) {
82 next if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' &&
83 $item->{consistency_group_name} !~ /$self->{option_results}->{filter_group}/);
84
85 $self->{replication}->{ $item->{id} } = {
86 name => $item->{name},
87 vdisk_name => $item->{aux_vdisk_name},
88 group_name => $item->{consistency_group_name},
89 status => $item->{state}
90 };
91 }
92
93 if (scalar(keys %{$self->{replication}}) <= 0){
94 $self->{output}->add_option_msg(short_msg => 'No volume found.');
95 $self->{output}->option_exit();
96 }
97 }
98
99 1;
100
101 __END__
102
103 =head1 MODE
104
105 Check replication usages.
106
107 =over 8
108
109 =item B<--filter-consistency-group-name>
110
111 Filter group name (can be a regexp).
112
113 =item B<--warning-status>
114
115 Define the conditions to match for the status to be WARNING (default: '%{status} =~ /idling/i').
116 You can use the following variables: %{status}
117
118 =item B<--critical-status>
119
120 Define the conditions to match for the status to be CRITICAL.
121 You can use the following variables: %{status}
122
123 =back
124
125 =cut