Debian Codegraph @

src/storage/emc/isilon/snmp/mode/clusterusage.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::emc::isilon::snmp::mode::clusterusage;
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);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 my $msg = 'status: ' . $self->{result_values}->{status};
33 return $msg;
34 }
35
36 sub custom_status_calc {
37 my ($self, %options) = @_;
38
39 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
40 return 0;
41 }
42
43 sub custom_usage_perfdata {
44 my ($self, %options) = @_;
45
46 my $label = 'ifs_used';
47 my $value_perf = $self->{result_values}->{used};
48 if (defined($self->{instance_mode}->{option_results}->{free})) {
49 $label = 'ifs_free';
50 $value_perf = $self->{result_values}->{free};
51 }
52
53 my %total_options = ();
54 if ($self->{instance_mode}->{option_results}->{units} eq '%') {
55 $total_options{total} = $self->{result_values}->{total};
56 $total_options{cast_int} = 1;
57 }
58
59 $self->{output}->perfdata_add(label => $label, unit => 'B',
60 value => $value_perf,
61 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
62 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
63 min => 0, max => $self->{result_values}->{total});
64 }
65
66 sub custom_usage_threshold {
67 my ($self, %options) = @_;
68
69 my ($exit, $threshold_value);
70 $threshold_value = $self->{result_values}->{used};
71 $threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free}));
72 if ($self->{instance_mode}->{option_results}->{units} eq '%') {
73 $threshold_value = $self->{result_values}->{prct_used};
74 $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free}));
75 }
76 $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
77 return $exit;
78 }
79
80 sub custom_usage_output {
81 my ($self, %options) = @_;
82
83 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
84 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
85 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
86 my $msg = sprintf("IFS Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
87 $total_size_value . " " . $total_size_unit,
88 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
89 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
90 return $msg;
91 }
92
93 sub custom_usage_calc {
94 my ($self, %options) = @_;
95
96 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
97 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
98 $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
99 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
100 $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
101
102 return 0;
103 }
104
105 sub set_counters {
106 my ($self, %options) = @_;
107
108 $self->{maps_counters_type} = [
109 { name => 'cluster', type => 0, cb_prefix_output => 'prefix_cluster_output', message_separator => ' - ' },
110 ];
111
112 $self->{maps_counters}->{cluster} = [
113 { label => 'status', threshold => 0, set => {
114 key_values => [ { name => 'status' } ],
115 closure_custom_calc => $self->can('custom_status_calc'),
116 closure_custom_output => $self->can('custom_status_output'),
117 closure_custom_perfdata => sub { return 0; },
118 closure_custom_threshold_check => \&catalog_status_threshold,
119 }
120 },
121 { label => 'health', set => {
122 key_values => [ { name => 'health' } ],
123 output_template => 'Node health: %.2f%%',
124 perfdatas => [
125 { label => 'health', value => 'health', template => '%.2f',
126 min => 0, max => 100, unit => '%' },
127 ],
128 }
129 },
130 { label => 'ifs-usage', set => {
131 key_values => [ { name => 'used' }, { name => 'total' } ],
132 closure_custom_calc => $self->can('custom_usage_calc'),
133 closure_custom_output => $self->can('custom_usage_output'),
134 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
135 closure_custom_threshold_check => $self->can('custom_usage_threshold'),
136 }
137 },
138 ];
139 }
140
141 sub new {
142 my ($class, %options) = @_;
143 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
144 bless $self, $class;
145
146 $options{options}->add_options(arguments => {
147 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /attn/' },
148 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /down|invalid/' },
149 'units:s' => { name => 'units', default => '%' },
150 'free' => { name => 'free' },
151 });
152
153 return $self;
154 }
155
156 sub check_options {
157 my ($self, %options) = @_;
158 $self->SUPER::check_options(%options);
159
160 $self->change_macros(macros => ['warning_status', 'critical_status']);
161 }
162
163 sub prefix_cluster_output {
164 my ($self, %options) = @_;
165
166 return "Cluster ";
167 }
168
169 my %mapping_health = (
170 0 => 'ok',
171 1 => 'attn',
172 2 => 'down',
173 3 => 'invalid',
174 );
175
176 my $mapping = {
177 clusterHealth => { oid => '.1.3.6.1.4.1.12124.1.1.2', map => \%mapping_health },
178 nodeCount => { oid => '.1.3.6.1.4.1.12124.1.1.4' },
179 onlineNodes => { oid => '.1.3.6.1.4.1.12124.1.1.6' },
180 ifsTotalBytes => { oid => '.1.3.6.1.4.1.12124.1.3.1' },
181 ifsUsedBytes => { oid => '.1.3.6.1.4.1.12124.1.3.2' },
182 ifsAvailableBytes => { oid => '.1.3.6.1.4.1.12124.1.3.3' },
183 };
184
185 my $oid_clusterStatus = '.1.3.6.1.4.1.12124.1.1';
186 my $oid_ifsFilesystem = '.1.3.6.1.4.1.12124.1.3';
187
188 sub manage_selection {
189 my ($self, %options) = @_;
190
191 $self->{results} = $options{snmp}->get_multiple_table(oids => [{ oid => $oid_clusterStatus },
192 { oid => $oid_ifsFilesystem },
193 ],
194 nothing_quit => 1, return_type => 1);
195
196 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => '0');
197
198 my @online_nodes = split(/,/, $result->{onlineNodes});
199 my $health = scalar(@online_nodes) * 100 / $result->{nodeCount};
200
201 $self->{cluster} = {
202 status => $result->{clusterHealth},
203 health => $health,
204 total => $result->{ifsTotalBytes},
205 used => $result->{ifsUsedBytes},
206 };
207 }
208
209 1;
210
211 __END__
212
213 =head1 MODE
214
215 Check cluster usages.
216
217 =over 8
218
219 =item B<--filter-counters>
220
221 Only display some counters (regexp can be used).
222 Example: --filter-counters='^status$'
223
224 =item B<--warning-status>
225
226 Define the conditions to match for the status to be WARNING (default: '%{status} =~ /attn/).
227 You can use the following variables: %{status}
228
229 =item B<--critical-status>
230
231 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /down|invalid/').
232 You can use the following variables: %{status}
233
234 =item B<--warning-*>
235
236 Warning threshold.
237 Can be: 'ifs-usage', 'health'.
238
239 =item B<--critical-*>
240
241 Critical threshold.
242 Can be: 'ifs-usage', 'health'.
243
244 =item B<--units>
245
246 Units of thresholds (default: '%') ('%', 'B').
247
248 =item B<--free>
249
250 Thresholds are on free space left.
251
252 =back
253
254 =cut