Debian Codegraph @

src/storage/wd/nas/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::wd::nas::snmp::mode::volumes;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::misc;
28
29 sub custom_space_usage_output {
30 my ($self, %options) = @_;
31
32 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
33 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
34 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
35 return sprintf(
36 "space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)",
37 $total_size_value . " " . $total_size_unit,
38 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
39 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
40 );
41 }
42
43 sub prefix_volume_output {
44 my ($self, %options) = @_;
45
46 return sprintf(
47 "volume '%s' ",
48 $options{instance_value}->{name}
49 );
50 }
51
52 sub set_counters {
53 my ($self, %options) = @_;
54
55 $self->{maps_counters_type} = [
56 { name => 'volumes', type => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'All volumes are ok' }
57 ];
58
59 $self->{maps_counters}->{volumes} = [
60 { label => 'space-usage', nlabel => 'volume.space.usage.bytes', set => {
61 key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'name' } ],
62 closure_custom_output => $self->can('custom_space_usage_output'),
63 perfdatas => [
64 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'name' }
65 ]
66 }
67 },
68 { label => 'space-usage-free', display_ok => 0, nlabel => 'volume.space.free.bytes', set => {
69 key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'name' } ],
70 closure_custom_output => $self->can('custom_space_usage_output'),
71 perfdatas => [
72 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'name' }
73 ]
74 }
75 },
76 { label => 'space-usage-prct', display_ok => 0, nlabel => 'volume.space.usage.percentage', set => {
77 key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' }, { name => 'name' } ],
78 closure_custom_output => $self->can('custom_space_usage_output'),
79 perfdatas => [
80 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'name' }
81 ]
82 }
83 }
84 ];
85 }
86
87 sub new {
88 my ($class, %options) = @_;
89 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
90 bless $self, $class;
91
92 $options{options}->add_options(arguments => {
93 'filter-name:s' => { name => 'filter_name' }
94 });
95
96 return $self;
97 }
98
99 sub manage_selection {
100 my ($self, %options) = @_;
101
102 my $nas = {
103 ex2 => {
104 volumeTable => '.1.3.6.1.4.1.5127.1.1.1.2.1.9.1',
105 volume => {
106 name => { oid => '.1.3.6.1.4.1.5127.1.1.1.2.1.9.1.2' },
107 total => { oid => '.1.3.6.1.4.1.5127.1.1.1.2.1.9.1.5' },
108 free => { oid => '.1.3.6.1.4.1.5127.1.1.1.2.1.9.1.6' }
109 }
110 },
111 ex2ultra => {
112 volumeTable => '.1.3.6.1.4.1.5127.1.1.1.8.1.9.1',
113 volume => {
114 name => { oid => '.1.3.6.1.4.1.5127.1.1.1.8.1.9.1.2' },
115 total => { oid => '.1.3.6.1.4.1.5127.1.1.1.8.1.9.1.5' },
116 free => { oid => '.1.3.6.1.4.1.5127.1.1.1.8.1.9.1.6' }
117 }
118 },
119 ex4100 => {
120 volumeTable => '.1.3.6.1.4.1.5127.1.1.1.6.1.9.1',
121 volume => {
122 name => { oid => '.1.3.6.1.4.1.5127.1.1.1.6.1.9.1.2' },
123 total => { oid => '.1.3.6.1.4.1.5127.1.1.1.6.1.9.1.5' },
124 free => { oid => '.1.3.6.1.4.1.5127.1.1.1.6.1.9.1.6' }
125 }
126 },
127 pr2100 => {
128 volumeTable => '.1.3.6.1.4.1.5127.1.1.1.9.1.9.1',
129 volume => {
130 name => { oid => '.1.3.6.1.4.1.5127.1.1.1.9.1.9.1.2' },
131 total => { oid => '.1.3.6.1.4.1.5127.1.1.1.9.1.9.1.5' },
132 free => { oid => '.1.3.6.1.4.1.5127.1.1.1.9.1.9.1.6' }
133 }
134 },
135 pr4100 => {
136 volumeTable => '.1.3.6.1.4.1.5127.1.1.1.10.1.9.1',
137 volume => {
138 name => { oid => '.1.3.6.1.4.1.5127.1.1.1.10.1.9.1.2' },
139 total => { oid => '.1.3.6.1.4.1.5127.1.1.1.10.1.9.1.5' },
140 free => { oid => '.1.3.6.1.4.1.5127.1.1.1.10.1.9.1.6' }
141 }
142 }
143 };
144
145 my $snmp_result = $options{snmp}->get_multiple_table(
146 oids => [
147 { oid => $nas->{ex2}->{volumeTable} },
148 { oid => $nas->{ex2ultra}->{volumeTable} },
149 { oid => $nas->{ex4100}->{volumeTable} },
150 { oid => $nas->{pr2100}->{volumeTable} },
151 { oid => $nas->{pr4100}->{volumeTable} }
152 ],
153 nothing_quit => 1
154 );
155
156 $self->{volumes} = {};
157 foreach my $type (keys %$nas) {
158 next if (scalar(keys %{$snmp_result->{ $nas->{$type}->{volumeTable} }}) <= 0);
159
160 foreach (keys %{$snmp_result->{ $nas->{$type}->{volumeTable} }}) {
161 next if (! /^$nas->{$type}->{volume}->{name}->{oid}\.(\d+)$/);
162
163 my $result = $options{snmp}->map_instance(mapping => $nas->{$type}->{volume}, results => $snmp_result->{ $nas->{$type}->{volumeTable} }, instance => $1);
164 next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
165 $result->{name} !~ /$self->{option_results}->{filter_name}/);
166
167 $result->{total} =~ /^([0-9\.]+)\s*(\S+)/;
168 $result->{total} = centreon::plugins::misc::convert_bytes(value => $1, unit => $2 . 'B');
169
170 $result->{free} =~ /^([0-9\.]+)\s*(\S+)/;
171 $result->{free} = centreon::plugins::misc::convert_bytes(value => $1, unit => $2 . 'B');
172
173 $self->{volumes}->{ $result->{name} } = {
174 name => $result->{name},
175 total => $result->{total},
176 free => $result->{free},
177 used => $result->{total} - $result->{free},
178 prct_used => ($result->{total} - $result->{free}) * 100 / $result->{total},
179 prct_free => $result->{free} * 100 / $result->{total}
180 };
181 }
182 }
183 }
184
185 1;
186
187 __END__
188
189 =head1 MODE
190
191 Check volumes.
192
193 =over 8
194
195 =item B<--filter-name>
196
197 Filter volumes by name (can be a regexp).
198
199 =item B<--warning-*> B<--critical-*>
200
201 Thresholds.
202 Can be: 'space-usage-prct', 'space-usage', 'space-usage-free'.
203
204 =back
205
206 =cut