Debian Codegraph @

src/storage/dell/equallogic/snmp/mode/poolusage.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::poolusage;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_usage_perfdata {
29 my ($self, %options) = @_;
30
31 $self->{output}->perfdata_add(
32 label => 'used', unit => 'B',
33 instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
34 value => $self->{result_values}->{used},
35 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1),
36 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1),
37 min => 0, max => $self->{result_values}->{total}
38 );
39 }
40
41 sub custom_usage_threshold {
42 my ($self, %options) = @_;
43
44 my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
45 return $exit;
46 }
47
48 sub custom_usage_output {
49 my ($self, %options) = @_;
50
51 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
52 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
53 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
54
55 my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
56 $total_size_value . " " . $total_size_unit,
57 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
58 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
59 return $msg;
60 }
61
62 sub custom_usage_calc {
63 my ($self, %options) = @_;
64
65 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
66 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
67 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
68 $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
69 $self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total};
70 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
71 return 0;
72 }
73
74 sub set_counters {
75 my ($self, %options) = @_;
76
77 $self->{maps_counters_type} = [
78 { name => 'pool', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All Pool usages are ok' }
79 ];
80
81 $self->{maps_counters}->{pool} = [
82 { label => 'used', set => {
83 key_values => [ { name => 'display' }, { name => 'total' }, { name => 'used' } ],
84 closure_custom_calc => $self->can('custom_usage_calc'),
85 closure_custom_output => $self->can('custom_usage_output'),
86 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
87 closure_custom_threshold_check => $self->can('custom_usage_threshold'),
88 }
89 },
90 ];
91 }
92
93 sub prefix_pool_output {
94 my ($self, %options) = @_;
95
96 return "Pool '" . $options{instance_value}->{display} . "' ";
97 }
98
99 sub new {
100 my ($class, %options) = @_;
101 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
102 bless $self, $class;
103
104 $options{options}->add_options(arguments => {
105 "filter-name:s" => { name => 'filter_name' },
106 });
107
108 return $self;
109 }
110
111 my $mapping = {
112 eqlStoragePoolStatsSpace => { oid => '.1.3.6.1.4.1.12740.16.1.2.1.1' }, # MB
113 eqlStoragePoolStatsSpaceUsed => { oid => '.1.3.6.1.4.1.12740.16.1.2.1.2' }, # MB
114 };
115
116 sub manage_selection {
117 my ($self, %options) = @_;
118
119 if ($options{snmp}->is_snmpv1()) {
120 $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
121 $self->{output}->option_exit();
122 }
123
124 my $oid_eqlStoragePoolName = '.1.3.6.1.4.1.12740.16.1.1.1.3';
125
126 $self->{pool} = {};
127 my $snmp_result = $options{snmp}->get_table(oid => $oid_eqlStoragePoolName, nothing_quit => 1);
128 foreach my $oid (keys %{$snmp_result}) {
129 $oid =~ /^$oid_eqlStoragePoolName\.(.*)$/;
130 my $instance = $1;
131 my $name = $snmp_result->{$oid_eqlStoragePoolName . '.' . $instance};
132
133 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
134 $name !~ /$self->{option_results}->{filter_name}/) {
135 $self->{output}->output_add(long_msg => "skipping pool '" . $name . "'.", debug => 1);
136 next;
137 }
138
139 $self->{pool}->{$instance} = { display => $name };
140 }
141
142 if (scalar(keys %{$self->{pool}}) <= 0) {
143 $self->{output}->add_option_msg(short_msg => "No entry found.");
144 $self->{output}->option_exit();
145 }
146
147 $options{snmp}->load(oids => [
148 $mapping->{eqlStoragePoolStatsSpace}->{oid}, $mapping->{eqlStoragePoolStatsSpaceUsed}->{oid},
149 ],
150 instances => [keys %{$self->{pool}}], instance_regexp => '^(.*)$');
151 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
152
153 foreach (keys %{$self->{pool}}) {
154 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
155
156 if ($result->{eqlStoragePoolStatsSpace} == 0) {
157 $self->{output}->output_add(long_msg => "skipping pool '" . $_ . "'. Total size is 0", debug => 1);
158 next;
159 }
160
161 $self->{pool}->{$_}->{total} = $result->{eqlStoragePoolStatsSpace} * 1024 * 1024;
162 $self->{pool}->{$_}->{used} = $result->{eqlStoragePoolStatsSpaceUsed} * 1024 * 1024;
163 }
164 }
165
166 1;
167
168 __END__
169
170 =head1 MODE
171
172 Check pool usages.
173
174 =over 8
175
176 =item B<--warning-*>
177
178 Warning threshold.
179 Can be: 'used' (%).
180
181 =item B<--critical-*>
182
183 Critical threshold.
184 Can be: 'used' (%).
185
186 =item B<--filter-name>
187
188 Filter disk name (can be a regexp).
189
190 =back
191
192 =cut