Debian Codegraph @

src/storage/dell/equallogic/snmp/mode/diskusage.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::dell::equallogic::snmp::mode::diskusage;
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 'status: ' . $self->{result_values}->{status} . ' [smart health: ' . $self->{result_values}->{health} . ']';
34 }
35
36 sub prefix_disk_output {
37 my ($self, %options) = @_;
38
39 return "Disk '" . $options{instance_value}->{display} . "' ";
40 }
41
42 sub set_counters {
43 my ($self, %options) = @_;
44
45 $self->{maps_counters_type} = [
46 { name => 'disk', type => 1, cb_prefix_output => 'prefix_disk_output', message_multiple => 'All disk usages are ok', skipped_code => { -10 => 1 } }
47 ];
48
49 $self->{maps_counters}->{disk} = [
50 { label => 'status', type => 2, critical_default => '%{status} !~ /on-line|spare|off-line/i', set => {
51 key_values => [ { name => 'health' }, { name => 'status' }, { name => 'display' } ],
52 closure_custom_output => $self->can('custom_status_output'),
53 closure_custom_perfdata => sub { return 0; },
54 closure_custom_threshold_check => \&catalog_status_threshold_ng
55 }
56 },
57 { label => 'read', set => {
58 key_values => [ { name => 'bytes_read', per_second => 1 }, { name => 'display' } ],
59 output_template => 'read: %s %s/s',
60 output_change_bytes => 1,
61 perfdatas => [
62 { label => 'read_iops', template => '%.2f',
63 unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display' }
64 ]
65 }
66 },
67 { label => 'write', set => {
68 key_values => [ { name => 'bytes_written', per_second => 1 }, { name => 'display' } ],
69 output_template => 'write: %s %s/s',
70 output_change_bytes => 1,
71 perfdatas => [
72 { label => 'write', template => '%.2f',
73 unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display' }
74 ]
75 }
76 },
77 { label => 'busy-time', set => {
78 key_values => [ { name => 'busy_time', diff => 1 }, { name => 'display' } ],
79 output_template => 'time busy: %s sec',
80 perfdatas => [
81 { label => 'busy_time', template => '%s',
82 unit => 's', min => 0, label_extra_instance => 1, instance_use => 'display' }
83 ]
84 }
85 }
86 ];
87 }
88
89 sub new {
90 my ($class, %options) = @_;
91 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
92 bless $self, $class;
93
94 $options{options}->add_options(arguments => {
95 'filter-name:s' => { name => 'filter_name' }
96 });
97
98 return $self;
99 }
100
101 my $map_disk_status = {
102 1 => 'on-line', 2 => 'spare', 3 => 'failed', 4 => 'off-line',
103 5 => 'alt-sig', 6 => 'too-small', 7 => 'history-of-failures',
104 8 => 'unsupported-version', 9 => 'unhealthy', 10 => 'replacement',
105 11 => 'encrypted', 12 => 'notApproved', 13 => 'preempt-failed'
106 };
107
108 my $map_disk_health = {
109 0 => 'smart-status-not-available',
110 1 => 'smart-ok',
111 2 => 'smart-tripped'
112 };
113
114 my $mapping = {
115 health => { oid => '.1.3.6.1.4.1.12740.3.1.1.1.17', map => $map_disk_health }, # eqlDiskHealth
116 bytes_read => { oid => '.1.3.6.1.4.1.12740.3.1.2.1.2' }, # eqlDiskStatusBytesRead [MB]
117 bytes_written => { oid => '.1.3.6.1.4.1.12740.3.1.2.1.3' }, # eqlDiskStatusBytesWritten [MB]
118 busy_time => { oid => '.1.3.6.1.4.1.12740.3.1.2.1.4' }, # eqlDiskStatusBusyTime [seconds]
119 };
120
121 sub manage_selection {
122 my ($self, %options) = @_;
123
124 if ($options{snmp}->is_snmpv1()) {
125 $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
126 $self->{output}->option_exit();
127 }
128
129 my $oid_eqlMemberName = '.1.3.6.1.4.1.12740.2.1.1.1.9';
130 my $oid_eqlDiskStatus = '.1.3.6.1.4.1.12740.3.1.1.1.8';
131
132 $self->{disk} = {};
133 my $snmp_result = $options{snmp}->get_multiple_table(oids => [{ oid => $oid_eqlMemberName }, { oid => $oid_eqlDiskStatus }], return_type => 1, nothing_quit => 1);
134 foreach my $oid (keys %{$snmp_result}) {
135 next if ($oid !~ /^$oid_eqlDiskStatus\.(\d+)\.(\d+)\.(\d+)$/);
136 my $instance = $1 . '.' . $2 . '.' . $3;
137 my $array_name = $snmp_result->{$oid_eqlMemberName . '.' . $1 . '.' . $2};
138 my $name = $array_name . '.' . $3;
139
140 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
141 $name !~ /$self->{option_results}->{filter_name}/) {
142 $self->{output}->output_add(long_msg => "skipping disk '" . $name . "'.", debug => 1);
143 next;
144 }
145
146 $self->{disk}->{$instance} = { display => $name, status => $map_disk_status->{ $snmp_result->{$oid} } };
147 }
148
149 if (scalar(keys %{$self->{disk}}) <= 0) {
150 $self->{output}->add_option_msg(short_msg => "No entry found.");
151 $self->{output}->option_exit();
152 }
153
154 $options{snmp}->load(
155 oids => [
156 map($_->{oid}, values(%$mapping))
157 ],
158 instances => [keys %{$self->{disk}}],
159 instance_regexp => '^(.*)$'
160 );
161 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
162
163 foreach (keys %{$self->{disk}}) {
164 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
165
166 $result->{bytes_read} *= 1024 * 1024;
167 $result->{bytes_written} *= 1024 * 1024;
168 $result->{health} = 'n/a' if (!defined($result->{health}));
169
170 $self->{disk}->{$_} = { %{$self->{disk}->{$_}}, %$result };
171 }
172
173 $self->{cache_name} = 'dell_equallogic_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
174 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
175 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
176 }
177
178 1;
179
180 __END__
181
182 =head1 MODE
183
184 Check disk usage.
185
186 =over 8
187
188 =item B<--filter-name>
189
190 Filter disk name (can be a regexp).
191
192 =item B<--unknown-status>
193
194 Define the conditions to match for the status to be UNKNOWN (default: '').
195 You can use the following variables: %{health}, %{status}, %{display}
196
197 =item B<--warning-status>
198
199 Define the conditions to match for the status to be WARNING (default: '').
200 You can use the following variables: %{health}, %{status}, %{display}
201
202 =item B<--critical-status>
203
204 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /on-line|spare|off-line/i').
205 You can use the following variables: %{health}, %{status}, %{display}
206
207 =item B<--warning-*> B<--critical-*>
208
209 Thresholds.
210 Can be: 'busy-time' (s), 'read-iops' (iops), 'write-iops' (iops).
211
212 =back
213
214 =cut