Debian Codegraph @

src/storage/emc/xtremio/restapi/mode/clusterhealth.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::xtremio::restapi::mode::clusterhealth;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 my $thresholds = {
29 'consistency-state' => [
30 ['healthy', 'OK'],
31 ['.*', 'CRITICAL'],
32 ],
33 'free-ud-ssd-space-level' => [
34 ['healthy', 'OK'],
35 ['.*', 'CRITICAL'],
36 ],
37 'shared-memory-efficiency-level' => [
38 ['healthy', 'OK'],
39 ['.*', 'CRITICAL'],
40 ],
41 'free-ud-ssd-space-level' => [
42 ['healthy', 'OK'],
43 ['.*', 'CRITICAL'],
44 ],
45 'vaai-tp-limit-crossing' => [
46 ['healthy', 'OK'],
47 ['.*', 'CRITICAL'],
48 ],
49 'shared-memory-in-use-ratio-level' => [
50 ['healthy', 'OK'],
51 ['.*', 'CRITICAL'],
52 ],
53 'sys-health-state' => [
54 ['healthy', 'OK'],
55 ['.*', 'CRITICAL'],
56 ],
57 };
58
59 sub new {
60 my ($class, %options) = @_;
61 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
62 bless $self, $class;
63
64 $options{options}->add_options(arguments =>
65 {
66 "filter:s@" => { name => 'filter' },
67 "threshold-overload:s@" => { name => 'threshold_overload' },
68 });
69
70 return $self;
71 }
72
73 sub check_options {
74 my ($self, %options) = @_;
75 $self->SUPER::init(%options);
76
77 $self->{filter} = [];
78 foreach my $val (@{$self->{option_results}->{filter}}) {
79 next if (!defined($val) || $val eq '');
80 my @values = split (/,/, $val);
81 push @{$self->{filter}}, { filter => $values[0], instance => $values[1] };
82 }
83
84 $self->{overload_th} = {};
85 foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
86 next if (!defined($val) || $val eq '');
87 my @values = split (/,/, $val);
88 if (scalar(@values) < 3) {
89 $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
90 $self->{output}->option_exit();
91 }
92 my ($section, $instance, $status, $filter);
93 if (scalar(@values) == 3) {
94 ($section, $status, $filter) = @values;
95 $instance = '.*';
96 } else {
97 ($section, $instance, $status, $filter) = @values;
98 }
99 if (!defined $thresholds->{$section}) {
100 $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload section '" . $val . "'.");
101 $self->{output}->option_exit();
102 }
103 if ($self->{output}->is_litteral_status(status => $status) == 0) {
104 $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
105 $self->{output}->option_exit();
106 }
107 $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
108 push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance };
109 }
110 }
111
112 sub run {
113 my ($self, %options) = @_;
114 my $xtremio = $options{custom};
115
116 my $urlbase = '/api/json/types/';
117 my @items = $xtremio->get_items(url => $urlbase,
118 obj => 'clusters');
119
120 my @sensors = ('consistency-state','shared-memory-efficiency-level','free-ud-ssd-space-level',
121 'vaai-tp-limit-crossing', 'shared-memory-in-use-ratio-level', 'sys-health-state');
122
123 $self->{output}->output_add(severity => 'OK',
124 short_msg => 'Health is OK');
125
126 foreach my $item (@items) {
127 next if ($self->check_filter(section => 'cluster', instance => $item));
128 my $details = $xtremio->get_details(url => $urlbase,
129 obj => 'clusters',
130 name => $item);
131
132 foreach my $sensor (@sensors) {
133 next if (!defined($details->{$sensor}) || $details->{$sensor} eq '');
134 $self->{output}->output_add(long_msg => sprintf("Sensor '%s' state is '%s'",
135 $sensor, $details->{$sensor}));
136
137 my $exit = $self->get_severity(section => $sensor, value => $details->{$sensor});
138 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
139 $self->{output}->output_add(severity => $exit,
140 short_msg => sprintf("Sensor '%s' state is '%s'",
141 $sensor, $details->{$sensor}));
142 }
143
144 }
145
146 }
147
148 $self->{output}->display();
149 $self->{output}->exit();
150 }
151
152 sub check_filter {
153 my ($self, %options) = @_;
154
155 foreach (@{$self->{filter}}) {
156 if ($options{section} =~ /$_->{filter}/) {
157 if (!defined($options{instance}) && !defined($_->{instance})) {
158 $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
159 return 1;
160 } elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) {
161 $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
162 return 1;
163 }
164 }
165 }
166
167 return 0;
168 }
169
170 sub get_severity {
171 my ($self, %options) = @_;
172 my $status = 'UNKNOWN'; # default
173
174 if (defined($self->{overload_th}->{$options{section}})) {
175 foreach (@{$self->{overload_th}->{$options{section}}}) {
176 if ($options{value} =~ /$_->{filter}/i &&
177 (!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) {
178 $status = $_->{status};
179 return $status;
180 }
181 }
182 }
183 my $label = defined($options{label}) ? $options{label} : $options{section};
184 foreach (@{$thresholds->{$label}}) {
185 if ($options{value} =~ /$$_[0]/i) {
186 $status = $$_[1];
187 return $status;
188 }
189 }
190
191 return $status;
192 }
193
194
195 1;
196
197 __END__
198
199 =head1 MODE
200
201 Check cluster health indicators ('consistency-state','shared-memory-efficiency-level','free-ud-ssd-space-level', 'vaai-tp-limit-crossing', 'shared-memory-in-use-ratio-level', 'sys-health-state');
202
203 =over 8
204
205 =item B<--filter>
206
207 Filter some parts (comma separated list)
208 You can also exclude items from specific instances: --filter=cluster,CLUSTER-NAME
209
210 =item B<--threshold-overload>
211
212 Overload a specific threshold. Example: --threshold-overload="consistency-state,Xtremio,CRITICAL,healthy"
213
214 =back
215
216 =cut