Debian Codegraph @

src/storage/netapp/santricity/restapi/mode/storagecontrollers.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::netapp::santricity::restapi::mode::storagecontrollers;
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 use Digest::MD5 qw(md5_hex);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 return sprintf(
34 'status: %s',
35 $self->{result_values}->{status}
36 );
37 }
38
39 sub ss_long_output {
40 my ($self, %options) = @_;
41
42 return "checking storage system '" . $options{instance_value}->{display} . "'";
43 }
44
45 sub prefix_ss_output {
46 my ($self, %options) = @_;
47
48 return "storage system '" . $options{instance_value}->{display} . "' ";
49 }
50
51 sub prefix_controller_output {
52 my ($self, %options) = @_;
53
54 return "controller '" . $options{instance_value}->{display} . "' ";
55 }
56
57 sub set_counters {
58 my ($self, %options) = @_;
59
60 $self->{maps_counters_type} = [
61 { name => 'ss', type => 3, cb_prefix_output => 'prefix_ss_output', cb_long_output => 'ss_long_output', indent_long_output => ' ', message_multiple => 'All storage systems are ok',
62 group => [
63 { name => 'controllers', display_long => 1, cb_prefix_output => 'prefix_controller_output', message_multiple => 'controllers are ok', type => 1, skipped_code => { -10 => 1 } }
64 ]
65 }
66 ];
67
68 $self->{maps_counters}->{controllers} = [
69 {
70 label => 'controller-status',
71 type => 2,
72 unknown_default => '%{status} =~ /unknown/i',
73 warning_default => '%{status} =~ /rpaParErr|degraded/i',
74 critical_default => '%{status} =~ /failed/i',
75 set => {
76 key_values => [ { name => 'status' }, { name => 'display' } ],
77 closure_custom_output => $self->can('custom_status_output'),
78 closure_custom_perfdata => sub { return 0; },
79 closure_custom_threshold_check => \&catalog_status_threshold_ng
80 }
81 },
82 { label => 'cpu-utilization', nlabel => 'volume.cpu.utilization.percentage', set => {
83 key_values => [ { name => 'cpu_util', per_second => 1 }, { name => 'display' } ],
84 output_template => 'cpu usage: %.2f %%',
85 perfdatas => [
86 { template => '%d', unit => '%', label_extra_instance => 1 }
87 ]
88 }
89 },
90 { label => 'read', nlabel => 'volume.io.read.usage.bytespersecond', set => {
91 key_values => [ { name => 'read_bytes', per_second => 1 }, { name => 'display' } ],
92 output_template => 'read: %s %s/s',
93 output_change_bytes => 1,
94 perfdatas => [
95 { template => '%d', unit => 'B/s', label_extra_instance => 1 }
96 ]
97 }
98 },
99 { label => 'write', nlabel => 'volume.io.write.usage.bytespersecond', set => {
100 key_values => [ { name => 'write_bytes', per_second => 1 }, { name => 'display' } ],
101 output_template => 'write: %s %s/s',
102 output_change_bytes => 1,
103 perfdatas => [
104 { template => '%d', unit => 'B/s', min => 0, label_extra_instance => 1 }
105 ]
106 }
107 },
108 { label => 'read-iops', nlabel => 'system.io.read.usage.iops', set => {
109 key_values => [ { name => 'read_iops', per_second => 1 }, { name => 'display' } ],
110 output_template => 'read: %.2f iops',
111 perfdatas => [
112 { template => '%.2f', unit => 'iops', min => 0, label_extra_instance => 1 }
113 ]
114 }
115 },
116 { label => 'write-iops', nlabel => 'system.io.write.usage.iops', set => {
117 key_values => [ { name => 'write_iops', per_second => 1 }, { name => 'display' } ],
118 output_template => 'write: %.2f iops',
119 perfdatas => [
120 { template => '%.2f', unit => 'iops', min => 0, label_extra_instance => 1 }
121 ]
122 }
123 }
124 ];
125 }
126
127 sub new {
128 my ($class, %options) = @_;
129 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
130 bless $self, $class;
131
132 $options{options}->add_options(arguments => {
133 'filter-storage-name:s' => { name => 'filter_storage_name' },
134 'filter-controller-name:s' => { name => 'filter_controller_name' }
135 });
136
137 return $self;
138 }
139
140 sub manage_selection {
141 my ($self, %options) = @_;
142
143 my $results = $options{custom}->execute_storages_request(
144 endpoints => [
145 { endpoint => '/controllers' },
146 { endpoint => '/controller-statistics', get_param => 'usecache=false' }
147 ],
148 filter_name => $self->{option_results}->{filter_storage_name}
149 );
150
151 my $mapping_controller = {};
152 $self->{ss} = {};
153 foreach (@{$results->{storages}}) {
154 my $storage_name = $_->{name};
155
156 $self->{ss}->{$storage_name} = {
157 display => $storage_name,
158 controllers => {}
159 };
160
161 next if (!defined($_->{'/controllers'}));
162
163 foreach my $entry (@{$_->{'/controllers'}}) {
164 my $name = $entry->{physicalLocation}->{label} ne '' ? $entry->{physicalLocation}->{label} :
165 $entry->{physicalLocation}->{locationPosition} . ':' . $entry->{physicalLocation}->{slot};
166
167 next if (defined($options{filter_controller_name}) && $options{filter_controller_name} ne '' &&
168 $name !~ /$options{filter_controller_name}/);
169
170 $mapping_controller->{ $entry->{id} } = $name;
171 $self->{ss}->{$storage_name}->{controllers}->{ $name } = {
172 display => $name,
173 status => $entry->{status}
174 };
175 }
176
177 foreach my $entry (@{$_->{'/controller-statistics'}}) {
178 next if (!defined($mapping_controller->{ $entry->{controllerId} }));
179
180 $self->{ss}->{$storage_name}->{controllers}->{ $mapping_controller->{ $entry->{controllerId} } }->{write_bytes} = $entry->{writeBytesTotal};
181 $self->{ss}->{$storage_name}->{controllers}->{ $mapping_controller->{ $entry->{controllerId} } }->{read_bytes} = $entry->{readBytesTotal};
182 $self->{ss}->{$storage_name}->{controllers}->{ $mapping_controller->{ $entry->{controllerId} } }->{read_iops} = $entry->{readIopsTotal};
183 $self->{ss}->{$storage_name}->{controllers}->{ $mapping_controller->{ $entry->{controllerId} } }->{write_iops} = $entry->{writeIopsTotal};
184 $self->{ss}->{$storage_name}->{controllers}->{ $mapping_controller->{ $entry->{controllerId} } }->{cpu_util} = $entry->{cpuUtilizationStats}->[0]->{sumCpuUtilization};
185 }
186 }
187
188 $self->{cache_name} = 'netapp_santricity_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' .
189 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
190 (defined($self->{option_results}->{filter_storage_name}) ? md5_hex($self->{option_results}->{filter_storage_name}) : md5_hex('all')) . '_' .
191 (defined($self->{option_results}->{filter_controller_name}) ? md5_hex($self->{option_results}->{filter_controller_name}) : md5_hex('all'));
192 }
193
194 1;
195
196 __END__
197
198 =head1 MODE
199
200 Check storage controllers.
201
202 =over 8
203
204 =item B<--filter-counters>
205
206 Only display some counters (regexp can be used).
207 Example: --filter-counters='controller-status'
208
209 =item B<--filter-storage-name>
210
211 Filter storage name (can be a regexp).
212
213 =item B<--filter-controller-name>
214
215 Filter controller name (can be a regexp).
216
217 =item B<--unknown-controller-status>
218
219 Define the conditions to match for the status to be UNKNOWN (default: '%{status} =~ /unknown/i').
220 You can use the following variables: %{status}, %{display}
221
222 =item B<--warning-controller-status>
223
224 Define the conditions to match for the status to be WARNING (default: '%{status} =~ /rpaParErr|degraded/i').
225 You can use the following variables: %{status}, %{display}
226
227 =item B<--critical-controller-status>
228
229 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /failed/i').
230 You can use the following variables: %{status}, %{display}
231
232 =item B<--warning-*> B<--critical-*>
233
234 Thresholds.
235 Can be: 'cpu-utilization' (%), 'read' (B/s), 'write' (B/s), 'read-iops', 'write-iops'.
236
237 =back
238
239 =cut