Debian Codegraph @

src/storage/hp/storeonce/4/restapi/mode/stores.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::stores;
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 store_long_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 "checking catalyst store '%s'",
34 $options{instance_value}->{name}
35 );
36 }
37
38 sub prefix_store_output {
39 my ($self, %options) = @_;
40
41 return sprintf(
42 "catalyst store '%s' ",
43 $options{instance_value}->{name}
44 );
45 }
46
47 sub prefix_global_output {
48 my ($self, %options) = @_;
49
50 return 'Number of catalyst stores ';
51 }
52
53 sub set_counters {
54 my ($self, %options) = @_;
55
56 $self->{maps_counters_type} = [
57 { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
58 {
59 name => 'stores', type => 3, cb_prefix_output => 'prefix_store_output', cb_long_output => 'store_long_output', indent_long_output => ' ', message_multiple => 'All catalyst stores are ok',
60 group => [
61 { name => 'health', type => 0 },
62 { name => 'space', type => 0 },
63 { name => 'dedup', type => 0 }
64 ]
65 }
66 ];
67
68 $self->{maps_counters}->{global} = [
69 { label => 'stores-detected', display_ok => 0, nlabel => 'stores.detected.count', set => {
70 key_values => [ { name => 'detected' } ],
71 output_template => 'detected: %s',
72 perfdatas => [
73 { template => '%s', min => 0 }
74 ]
75 }
76 }
77 ];
78
79 $self->{maps_counters}->{health} = [
80 {
81 label => 'health',
82 type => 2,
83 unknown_default => '%{health} =~ /unknown/i',
84 warning_default => '%{health} =~ /warning/i',
85 critical_default => '%{health} =~ /critical/i',
86 set => {
87 key_values => [ { name => 'health' }, { name => 'name' } ],
88 output_template => 'health: %s',
89 closure_custom_perfdata => sub { return 0; },
90 closure_custom_threshold_check => \&catalog_status_threshold_ng
91 }
92 }
93 ];
94
95 $self->{maps_counters}->{space} = [
96 { label => 'disk-space-usage', nlabel => 'store.disk.space.usage.bytes', set => {
97 key_values => [ { name => 'disk_used' }, { name => 'name' } ],
98 output_template => 'disk space used: %s%s',
99 output_change_bytes => 1,
100 perfdatas => [
101 { template => '%s', min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'name' }
102 ]
103 }
104 },
105 { label => 'user-space-usage', nlabel => 'store.user.space.usage.bytes', set => {
106 key_values => [ { name => 'user_used' }, { name => 'name' } ],
107 output_template => 'user space used: %s%s',
108 output_change_bytes => 1,
109 perfdatas => [
110 { template => '%s', min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'name' }
111 ]
112 }
113 }
114 ];
115
116 $self->{maps_counters}->{dedup} = [
117 { label => 'dedup', nlabel => 'store.deduplication.ratio.count', set => {
118 key_values => [ { name => 'dedup' }, { name => 'name' } ],
119 output_template => 'deduplication ratio: %.2f',
120 perfdatas => [
121 { template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'name' }
122 ]
123 }
124 }
125 ];
126 }
127
128 sub new {
129 my ($class, %options) = @_;
130 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
131 bless $self, $class;
132
133 $options{options}->add_options(arguments => {
134 'filter-id:s' => { name => 'filter_id' },
135 'filter-name:s' => { name => 'filter_name' }
136 });
137
138 return $self;
139 }
140
141 my %mapping_health_level = (
142 0 => 'unknown',
143 1 => 'ok',
144 2 => 'information',
145 3 => 'warning',
146 4 => 'critical'
147 );
148
149 sub manage_selection {
150 my ($self, %options) = @_;
151
152 my $members = $options{custom}->request_api(endpoint => '/api/v1/data-services/cat/stores');
153
154 $self->{global} = { detected => 0 };
155 $self->{stores} = {};
156
157 foreach my $member (@{$members->{members}}) {
158 next if (defined($self->{option_results}->{filter_id}) && $self->{option_results}->{filter_id} ne '' &&
159 $member->{id} !~ /$self->{option_results}->{filter_id}/);
160 next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
161 $member->{name} !~ /$self->{option_results}->{filter_name}/);
162
163 $self->{global}->{detected}++;
164
165 $self->{stores}->{ $member->{id} } = {
166 name => $member->{name},
167 health => {
168 name => $member->{name},
169 health => $mapping_health_level{ $member->{healthLevel} }
170 },
171 space => {
172 name => $member->{name},
173 disk_used => $member->{diskBytes},
174 user_used => $member->{userBytes}
175 },
176 dedup => {
177 name => $member->{name},
178 dedup => $member->{dedupeRatio}
179 }
180 };
181 }
182 }
183
184 1;
185
186 __END__
187
188 =head1 MODE
189
190 Check catalyst stores.
191
192 =over 8
193
194 =item B<--filter-id>
195
196 Filter stores by id.
197
198 =item B<--filter-name>
199
200 Filter stores by hostname.
201
202 =item B<--unknown-health>
203
204 Define the conditions to match for the status to be UNKNOWN (default: '%{health} =~ /unknown/i').
205 You can use the following variables: %{health}, %{name}
206
207 =item B<--warning-health>
208
209 Define the conditions to match for the status to be WARNING (default: '%{health} =~ /warning/i').
210 You can use the following variables: %{health}, %{name}
211
212 =item B<--critical-health>
213
214 Define the conditions to match for the status to be CRITICAL (default: '%{health} =~ /critical/i').
215 You can use the following variables: %{health}, %{name}
216
217 =item B<--warning-*> B<--critical-*>
218
219 Thresholds.
220 Can be: 'stores-detected', 'disk-space-usage, 'user-space-usage', 'dedup'.
221
222 =back
223
224 =cut