Debian Codegraph @

src/storage/emc/unisphere/restapi/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::unisphere::restapi::mode::replications;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use storage::emc::unisphere::restapi::mode::components::resources qw($replication_status $health_status);
28 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
29
30 sub custom_health_status_output {
31 my ($self, %options) = @_;
32
33 return 'health status: ' . $self->{result_values}->{health_status};
34 }
35
36 sub custom_replication_status_output {
37 my ($self, %options) = @_;
38
39 return 'replication status: ' . $self->{result_values}->{repl_status};
40 }
41
42 sub set_counters {
43 my ($self, %options) = @_;
44
45 $self->{maps_counters_type} = [
46 { name => 'replication', type => 1, cb_prefix_output => 'prefix_replication_output', message_multiple => 'All replications are ok' }
47 ];
48
49 $self->{maps_counters}->{replication} = [
50 {
51 label => 'health-status',
52 type => 2,
53 unknown_default => '%{health_status} =~ /unknown/i',
54 warning_default => '%{health_status} =~ /ok_but|degraded|minor/i',
55 critical_default => '%{health_status} =~ /major|critical|non_recoverable/i',
56 set => {
57 key_values => [ { name => 'health_status' }, { name => 'display' } ],
58 closure_custom_output => $self->can('custom_health_status_output'),
59 closure_custom_perfdata => sub { return 0; },
60 closure_custom_threshold_check => \&catalog_status_threshold_ng
61 }
62 },
63 {
64 label => 'replication-status',
65 type => 2,
66 unknown_default => '%{repl_status} =~ /unknown/i',
67 warning_default => '%{repl_status} =~ /syncing/i',
68 critical_default => '%{repl_status} =~ /inconsistent/i',
69 set => {
70 key_values => [ { name => 'repl_status' }, { name => 'display' } ],
71 closure_custom_output => $self->can('custom_replication_status_output'),
72 closure_custom_perfdata => sub { return 0; },
73 closure_custom_threshold_check => \&catalog_status_threshold_ng
74 }
75 }
76 ];
77 }
78
79 sub new {
80 my ($class, %options) = @_;
81 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
82 bless $self, $class;
83
84 $options{options}->add_options(arguments => {
85 'filter-name:s' => { name => 'filter_name' }
86 });
87
88 return $self;
89 }
90
91 sub prefix_replication_output {
92 my ($self, %options) = @_;
93
94 return "Replication '" . $options{instance_value}->{display} . "' ";
95 }
96
97 sub manage_selection {
98 my ($self, %options) = @_;
99
100 my $results = $options{custom}->request_api(url_path => '/api/types/replicationSession/instances?fields=name,health,syncState');
101
102 $self->{replication} = {};
103 foreach (@{$results->{entries}}) {
104 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
105 $_->{content}->{name} !~ /$self->{option_results}->{filter_name}/) {
106 $self->{output}->output_add(long_msg => "skipping replication '" . $_->{content}->{name} . "': no matching filter.", debug => 1);
107 next;
108 }
109
110 $self->{replication}->{ $_->{content}->{id} } = {
111 display => $_->{content}->{name},
112 health_status => $health_status->{ $_->{content}->{health}->{value} },
113 repl_status => $replication_status->{ $_->{content}->{syncState} },
114 };
115 }
116
117 if (scalar(keys %{$self->{replication}}) <= 0) {
118 $self->{output}->add_option_msg(short_msg => "No replications found");
119 $self->{output}->option_exit();
120 }
121 }
122
123 1;
124
125 __END__
126
127 =head1 MODE
128
129 Check replication status.
130
131 =over 8
132
133 =item B<--filter-counters>
134
135 Only display some counters (regexp can be used).
136 Example: --filter-counters='^health'
137
138 =item B<--filter-name>
139
140 Filter replication name (can be a regexp).
141
142 =item B<--unknown-health-status>
143
144 Define the conditions to match for the status to be UNKNOWN (default: '%{health_status} =~ /unknown/i').
145 You can use the following variables: %{health_status}, %{display}
146
147 =item B<--warning-health-status>
148
149 Define the conditions to match for the status to be WARNING (default: '%{health_status} =~ /ok_but|degraded|minor/i').
150 You can use the following variables: %{health_status}, %{display}
151
152 =item B<--critical-health-status>
153
154 Define the conditions to match for the status to be CRITICAL (default: '%{health_status} =~ /major|critical|non_recoverable/i').
155 You can use the following variables: %{health_status}, %{display}
156
157 =item B<--unknown-repl-status>
158
159 Define the conditions to match for the status to be UNKNOWN (default: '%{repl_status} =~ /unknown/i').
160 You can use the following variables: %{repl_status}, %{display}
161
162 =item B<--warning-repl-status>
163
164 Define the conditions to match for the status to be WARNING (default: '%{repl_status} =~ /syncing/i').
165 You can use the following variables: %{repl_status}, %{display}
166
167 =item B<--critical-repl-status>
168
169 Define the conditions to match for the status to be CRITICAL (default: '%{repl_status} =~ /inconsistent/i').
170 You can use the following variables: %{repl_status}, %{display}
171
172 =back
173
174 =cut