Debian Codegraph @

src/storage/hitachi/hcp/snmp/mode/volumes.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::hitachi::hcp::snmp::mode::volumes;
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_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 "status: %s",
34 $self->{result_values}->{status}
35 );
36 }
37
38 sub custom_space_usage_output {
39 my ($self, %options) = @_;
40
41 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
42 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
43 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
44 return sprintf(
45 "space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)",
46 $total_size_value . " " . $total_size_unit,
47 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
48 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
49 );
50 }
51
52 sub volume_long_output {
53 my ($self, %options) = @_;
54
55 return sprintf(
56 "checking volume '%s' [node: %s]",
57 $options{instance_value}->{label},
58 $options{instance_value}->{node_id}
59 );
60 }
61
62 sub prefix_volume_output {
63 my ($self, %options) = @_;
64
65 return sprintf(
66 "volume '%s' [node: %s] ",
67 $options{instance_value}->{label},
68 $options{instance_value}->{node_id}
69 );
70 }
71
72 sub set_counters {
73 my ($self, %options) = @_;
74
75 $self->{maps_counters_type} = [
76 { name => 'volumes', type => 3, cb_prefix_output => 'prefix_volume_output', cb_long_output => 'volume_long_output',
77 indent_long_output => ' ', message_multiple => 'All volumes are ok',
78 group => [
79 { name => 'status', type => 0, skipped_code => { -10 => 1 } },
80 { name => 'space', type => 0, skipped_code => { -10 => 1 } }
81 ]
82 }
83 ];
84
85 $self->{maps_counters}->{status} = [
86 {
87 label => 'volume-status',
88 type => 2,
89 warning_default => '%{status} =~ /degraded/',
90 critical_default => '%{status} =~ /broken/',
91 set => {
92 key_values => [
93 { name => 'status' }, { name => 'node_id' }, { name => 'label' }
94 ],
95 closure_custom_output => $self->can('custom_status_output'),
96 closure_custom_perfdata => sub { return 0; },
97 closure_custom_threshold_check => \&catalog_status_threshold_ng
98 }
99 }
100 ];
101
102 $self->{maps_counters}->{space} = [
103 { label => 'space-usage', nlabel => 'volume.space.usage.bytes', set => {
104 key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'name' } ],
105 closure_custom_output => $self->can('custom_space_usage_output'),
106 perfdatas => [
107 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'name' }
108 ]
109 }
110 },
111 { label => 'space-usage-free', display_ok => 0, nlabel => 'volume.space.free.bytes', set => {
112 key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'name' } ],
113 closure_custom_output => $self->can('custom_space_usage_output'),
114 perfdatas => [
115 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'name' }
116 ]
117 }
118 },
119 { label => 'space-usage-prct', display_ok => 0, nlabel => 'volume.space.usage.percentage', set => {
120 key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' }, { name => 'name' } ],
121 closure_custom_output => $self->can('custom_space_usage_output'),
122 perfdatas => [
123 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'name' }
124 ]
125 }
126 }
127 ];
128 }
129
130 sub new {
131 my ($class, %options) = @_;
132 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
133 bless $self, $class;
134
135 $options{options}->add_options(arguments => {
136 'filter-node-id:s' => { name => 'filter_node_id' },
137 'filter-label:s' => { name => 'filter_label' }
138 });
139
140 return $self;
141 }
142
143 my $map_volume_status = {
144 0 => 'unavailable', 1 => 'broken',
145 2 => 'suspended', 3 => 'initialized',
146 4 => 'available', 5 => 'degraded'
147 };
148 my $mapping = {
149 space_free => { oid => '.1.3.6.1.4.1.116.5.46.2.1.1.4' }, # storageAvailability
150 space_total => { oid => '.1.3.6.1.4.1.116.5.46.2.1.1.5' }, # storageCapacity
151 status => { oid => '.1.3.6.1.4.1.116.5.46.2.1.1.7', map => $map_volume_status } # storageStatus
152 };
153
154 sub manage_selection {
155 my ($self, %options) = @_;
156
157 my $oid_node_id = '.1.3.6.1.4.1.116.5.46.2.1.1.2'; # storageNodeNumber
158 my $oid_label = '.1.3.6.1.4.1.116.5.46.2.1.1.6'; # storageChannelUnit
159 my $snmp_result = $options{snmp}->get_multiple_table(
160 oids => [
161 { oid => $oid_node_id },
162 { oid => $oid_label }
163 ],
164 return_type => 1,
165 nothing_quit => 1
166 );
167
168 $self->{volumes} = {};
169 foreach (keys %$snmp_result) {
170 next if (! /$oid_node_id\.(.*)$/);
171 my $instance = $1;
172 my $node_id = $snmp_result->{$_};
173 my $label = $snmp_result->{ $oid_label . '.' . $instance };
174
175 my $fullname = $node_id . ':' . $label;
176 if (defined($self->{option_results}->{filter_node_id}) && $self->{option_results}->{filter_node_id} ne '' &&
177 $node_id !~ /$self->{option_results}->{filter_node_id}/) {
178 $self->{output}->output_add(long_msg => "skipping volume '$fullname'.", debug => 1);
179 next;
180 }
181 if (defined($self->{option_results}->{filter_label}) && $self->{option_results}->{filter_label} ne '' &&
182 $label !~ /$self->{option_results}->{filter_label}/) {
183 $self->{output}->output_add(long_msg => "skipping volume '$fullname'.", debug => 1);
184 next;
185 }
186
187 $self->{volumes}->{$instance} = {
188 node_id => $node_id,
189 label => $label,
190 status => { node_id => $node_id, label => $label },
191 space => { name => $fullname }
192 };
193 }
194
195 return if (scalar(keys %{$self->{volumes}}) <= 0);
196
197 $options{snmp}->load(
198 oids => [ map($_->{oid}, values(%$mapping)) ],
199 instances => [ keys %{$self->{volumes}} ],
200 instance_regexp => '^(.*)$'
201 );
202 $snmp_result = $options{snmp}->get_leef();
203 foreach (keys %{$self->{volumes}}) {
204 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
205
206 $self->{volumes}->{$_}->{status}->{status} = $result->{status};
207
208 next if (!defined($result->{space_total}));
209
210 $self->{volumes}->{$_}->{space}->{total} = $result->{space_total};
211 $self->{volumes}->{$_}->{space}->{free} = $result->{space_free};
212 $self->{volumes}->{$_}->{space}->{used} = $result->{space_total} - $result->{space_free};
213 $self->{volumes}->{$_}->{space}->{prct_free} = $result->{space_free} * 100 / $result->{space_total};
214 $self->{volumes}->{$_}->{space}->{prct_used} = 100 - $self->{volumes}->{$_}->{space}->{prct_free};
215 }
216 }
217
218 1;
219
220 __END__
221
222 =head1 MODE
223
224 Check volumes.
225
226 =over 8
227
228 =item B<--filter-node-id>
229
230 Filter volumes by node ID (can be a regexp).
231
232 =item B<--unknown-volume-status>
233
234 Define the conditions to match for the status to be UNKNOWN.
235 You can use the following variables: %{status}, %{node_id}, %{label}
236
237 =item B<--warning-volume-status>
238
239 Define the conditions to match for the status to be WARNING (default: '%{status} =~ /degraded/').
240 You can use the following variables: %{status}, %{node_id}, %{label}
241
242 =item B<--critical-volume-status>
243
244 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /broken/').
245 You can use the following variables: %{status}, %{node_id}, %{label}
246
247 =item B<--warning-*> B<--critical-*>
248
249 Thresholds.
250 Can be: 'space-usage-prct', 'space-usage', 'space-usage-free'.
251
252 =back
253
254 =cut