Debian Codegraph @

src/storage/dell/fluidfs/snmp/mode/volumeusage.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::fluidfs::snmp::mode::volumeusage;
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 my $label = 'used';
32 my $value_perf = $self->{result_values}->{used};
33 if (defined($self->{instance_mode}->{option_results}->{free})) {
34 $label = 'free';
35 $value_perf = $self->{result_values}->{free};
36 }
37
38 my %total_options = ();
39 if ($self->{instance_mode}->{option_results}->{units} eq '%') {
40 $total_options{total} = $self->{result_values}->{total};
41 $total_options{cast_int} = 1;
42 }
43
44 $self->{output}->perfdata_add(
45 label => $label, unit => 'B',
46 instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
47 value => $value_perf,
48 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
49 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
50 min => 0, max => $self->{result_values}->{total}
51 );
52 }
53
54 sub custom_usage_threshold {
55 my ($self, %options) = @_;
56
57 my ($exit, $threshold_value);
58 $threshold_value = $self->{result_values}->{used};
59 $threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free}));
60 if ($self->{instance_mode}->{option_results}->{units} eq '%') {
61 $threshold_value = $self->{result_values}->{prct_used};
62 $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free}));
63 }
64 $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]);
65 return $exit;
66 }
67
68 sub custom_usage_output {
69 my ($self, %options) = @_;
70
71 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
72 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
73 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
74 my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
75 $total_size_value . " " . $total_size_unit,
76 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
77 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
78 return $msg;
79 }
80
81 sub custom_usage_calc {
82 my ($self, %options) = @_;
83
84 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
85 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
86 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
87 $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
88 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
89 $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
90
91 return 0;
92 }
93
94
95 sub set_counters {
96 my ($self, %options) = @_;
97
98 $self->{maps_counters_type} = [
99 { name => 'volume', type => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'All volumes are ok' }
100 ];
101
102 $self->{maps_counters}->{volume} = [
103 { label => 'usage', set => {
104 key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' } ],
105 closure_custom_calc => $self->can('custom_usage_calc'),
106 closure_custom_output => $self->can('custom_usage_output'),
107 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
108 closure_custom_threshold_check => $self->can('custom_usage_threshold'),
109 }
110 },
111 ];
112 }
113
114 sub new {
115 my ($class, %options) = @_;
116 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
117 bless $self, $class;
118
119 $options{options}->add_options(arguments => {
120 "filter-name:s" => { name => 'filter_name' },
121 "units:s" => { name => 'units', default => '%' },
122 "free" => { name => 'free' },
123 });
124
125 return $self;
126 }
127
128 sub prefix_volume_output {
129 my ($self, %options) = @_;
130
131 return "Volume '" . $options{instance_value}->{display} . "' ";
132 }
133
134 my $mapping = {
135 fluidFSNASVolumeVolumeName => { oid => '.1.3.6.1.4.1.674.11000.2000.200.1.41.1.2' },
136 fluidFSNASVolumeSizeMB => { oid => '.1.3.6.1.4.1.674.11000.2000.200.1.41.1.3' },
137 fluidFSNASVolumeUsedSpaceMB => { oid => '.1.3.6.1.4.1.674.11000.2000.200.1.41.1.4' },
138 };
139
140 my $oid_fluidFSNASVolumeEntry = '.1.3.6.1.4.1.674.11000.2000.200.1.41.1';
141
142 sub manage_selection {
143 my ($self, %options) = @_;
144
145 $self->{volume} = {};
146 my $snmp_result = $options{snmp}->get_table(oid => $oid_fluidFSNASVolumeEntry,
147 nothing_quit => 1);
148
149 foreach my $oid (keys %{$snmp_result}) {
150 next if ($oid !~ /^$mapping->{fluidFSNASVolumeVolumeName}->{oid}\.(.*)$/);
151 my $instance = $1;
152 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
153
154 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
155 $result->{fluidFSNASVolumeVolumeName} !~ /$self->{option_results}->{filter_name}/) {
156 $self->{output}->output_add(long_msg => "skipping '" . $result->{fluidFSNASVolumeVolumeName} . "': no matching filter.", debug => 1);
157 next;
158 }
159
160 $self->{volume}->{$instance} = {
161 display => $result->{fluidFSNASVolumeVolumeName},
162 total => $result->{fluidFSNASVolumeSizeMB} * 1024 * 1024,
163 used => $result->{fluidFSNASVolumeUsedSpaceMB} * 1024 * 1024,
164 };
165 }
166
167 if (scalar(keys %{$self->{volume}}) <= 0) {
168 $self->{output}->add_option_msg(short_msg => "No volume found.");
169 $self->{output}->option_exit();
170 }
171 }
172
173 1;
174
175 __END__
176
177 =head1 MODE
178
179 Check volumes.
180
181 =over 8
182
183 =item B<--filter-name>
184
185 Filter volume name (can be a regexp).
186
187 =item B<--warning-*>
188
189 Warning threshold.
190 Can be: 'usage'.
191
192 =item B<--critical-*>
193
194 Critical threshold.
195 Can be: 'usage'.
196
197 =item B<--units>
198
199 Units of thresholds (default: '%') ('%', 'B').
200
201 =item B<--free>
202
203 Thresholds are on free space left.
204
205 =back
206
207 =cut