Debian Codegraph @

src/storage/hp/storeonce/4/restapi/mode/appliances.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::hp::storeonce::4::restapi::mode::appliances;
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 custom_disk_usage_output {
30 my ($self, %options) = @_;
31
32 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
33 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
34 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
35 return sprintf(
36 'disk space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
37 $total_size_value . " " . $total_size_unit,
38 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
39 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
40 );
41 }
42
43 sub appliance_long_output {
44 my ($self, %options) = @_;
45
46 return sprintf(
47 "checking appliance '%s'",
48 $options{instance_value}->{name}
49 );
50 }
51
52 sub prefix_appliance_output {
53 my ($self, %options) = @_;
54
55 return sprintf(
56 "appliance '%s' ",
57 $options{instance_value}->{name}
58 );
59 }
60
61 sub prefix_global_output {
62 my ($self, %options) = @_;
63
64 return 'Number of appliances ';
65 }
66
67 sub prefix_service_output {
68 my ($self, %options) = @_;
69
70 return sprintf(
71 "service '%s' ",
72 $options{instance_value}->{service}
73 );
74 }
75
76 sub set_counters {
77 my ($self, %options) = @_;
78
79 $self->{maps_counters_type} = [
80 { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
81 {
82 name => 'appliances', type => 3, cb_prefix_output => 'prefix_appliance_output', cb_long_output => 'appliance_long_output', indent_long_output => ' ', message_multiple => 'All appliances are ok',
83 group => [
84 { name => 'disk', type => 0 },
85 { name => 'dedup', type => 0 },
86 { name => 'services', type => 1, cb_prefix_output => 'prefix_service_output', message_multiple => 'services are ok', display_long => 1, skipped_code => { -10 => 1 } },
87 ]
88 }
89 ];
90
91 $self->{maps_counters}->{global} = [
92 { label => 'appliances-detected', display_ok => 0, nlabel => 'appliances.detected.count', set => {
93 key_values => [ { name => 'detected' } ],
94 output_template => 'detected: %s',
95 perfdatas => [
96 { template => '%s', min => 0 }
97 ]
98 }
99 }
100 ];
101
102 $self->{maps_counters}->{services} = [
103 {
104 label => 'service-status',
105 type => 2,
106 warning_default => '%{status} =~ /warning/i',
107 critical_default => '%{status} =~ /critical/i',
108 set => {
109 key_values => [
110 { name => 'status' }, { name => 'service' }
111 ],
112 output_template => "status: %s",
113 closure_custom_perfdata => sub { return 0; },
114 closure_custom_threshold_check => \&catalog_status_threshold_ng
115 }
116 }
117 ];
118
119 $self->{maps_counters}->{disk} = [
120 { label => 'disk-space-usage', nlabel => 'appliance.disk.space.usage.bytes', set => {
121 key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'name' } ],
122 closure_custom_output => $self->can('custom_disk_usage_output'),
123 perfdatas => [
124 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'name' }
125 ]
126 }
127 },
128 { label => 'disk-space-usage-free', nlabel => 'appliance.disk.space.free.bytes', display_ok => 0, set => {
129 key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'name' } ],
130 closure_custom_output => $self->can('custom_disk_usage_output'),
131 perfdatas => [
132 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'name' }
133 ]
134 }
135 },
136 { label => 'disk-space-usage-prct', nlabel => 'appliance.disk.space.usage.percentage', display_ok => 0, set => {
137 key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' }, { name => 'name' } ],
138 closure_custom_output => $self->can('custom_disk_usage_output'),
139 perfdatas => [
140 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'name' }
141 ]
142 }
143 }
144 ];
145
146 $self->{maps_counters}->{dedup} = [
147 { label => 'dedup', nlabel => 'appliance.deduplication.ratio.count', set => {
148 key_values => [ { name => 'dedup' }, { name => 'name' } ],
149 output_template => 'deduplication ratio: %.2f',
150 perfdatas => [
151 { template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'name' }
152 ]
153 }
154 }
155 ];
156 }
157
158 sub new {
159 my ($class, %options) = @_;
160 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
161 bless $self, $class;
162
163 $options{options}->add_options(arguments => {
164 'filter-uuid:s' => { name => 'filter_uuid' },
165 'filter-hostname:s' => { name => 'filter_hostname' }
166 });
167
168 return $self;
169 }
170
171 sub manage_selection {
172 my ($self, %options) = @_;
173
174 my $members = $options{custom}->request_api(endpoint => '/api/v1/management-services/federation/members');
175
176 $self->{global} = { detected => 0 };
177 $self->{appliances} = {};
178
179 foreach my $member (@{$members->{members}}) {
180 next if (defined($self->{option_results}->{filter_uuid}) && $self->{option_results}->{filter_uuid} ne '' &&
181 $member->{uuid} !~ /$self->{option_results}->{filter_uuid}/);
182 next if (defined($self->{option_results}->{filter_hostname}) && $self->{option_results}->{filter_hostname} ne '' &&
183 $member->{hostname} !~ /$self->{option_results}->{filter_hostname}/);
184
185 $self->{global}->{detected}++;
186
187 my $appliance = $options{custom}->request_api(endpoint => '/api/v1/data-services/dashboard/appliance/' . $member->{uuid});
188
189 $self->{appliances}->{ $member->{uuid} } = {
190 name => $member->{hostname},
191 services => {
192 dataServices => { service => 'dataServices', status => lc($appliance->{dataServicesStatus}) },
193 license => { service => 'license', status => lc($appliance->{licenseStatus}) },
194 userStorage => { service => 'userStorage', status => lc($appliance->{userStorageStatus}) },
195 hardware => { service => 'hardware', status => lc($appliance->{hardwareStatus}) },
196 remoteSupport => { service => 'remoteSupport', status => lc($appliance->{remoteSupportStatus}) }
197 },
198 disk => {
199 name => $member->{hostname},
200 total => $appliance->{localCapacityBytes},
201 used => $appliance->{localCapacityBytes} - $appliance->{localFreeBytes},
202 free => $appliance->{localFreeBytes},
203 prct_used => 100 - ($appliance->{localFreeBytes} * 100 / $appliance->{localCapacityBytes}),
204 prct_free => $appliance->{localFreeBytes} * 100 / $appliance->{localCapacityBytes}
205 },
206 dedup => {
207 name => $member->{hostname},
208 dedup => $appliance->{dedupeRatio}
209 }
210 };
211 }
212 }
213
214 1;
215
216 __END__
217
218 =head1 MODE
219
220 Check appliances.
221
222 =over 8
223
224 =item B<--filter-uuid>
225
226 Filter appliances by UUID.
227
228 =item B<--filter-name>
229
230 Filter appliances by hostname.
231
232 =item B<--unknown-service-status>
233
234 Define the conditions to match for the status to be UNKNOWN.
235 You can use the following variables: %{service}, %{status}
236
237 =item B<--warning-service-status>
238
239 Define the conditions to match for the status to be WARNING (default: '%{status} =~ /warning/i').
240 You can use the following variables: %{service}, %{status}
241
242 =item B<--critical-service-status>
243
244 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /critical/i').
245 You can use the following variables: %{service}, %{status}
246
247 =item B<--warning-*> B<--critical-*>
248
249 Thresholds.
250 Can be: 'appliances-detected', 'disk-space-usage, 'disk-space-usage-free',
251 'disk-space-usage-prct', 'dedup'.
252
253 =back
254
255 =cut