Debian Codegraph @

src/storage/avid/isis/snmp/mode/usage.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::avid::isis::snmp::mode::usage;
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 my %total_options = ();
38 if ($self->{instance_mode}->{option_results}->{units} eq '%') {
39 $total_options{total} = $self->{result_values}->{allocated};
40 $total_options{cast_int} = 1;
41 }
42
43 $self->{output}->perfdata_add(label => $label, unit => 'B',
44 value => $value_perf,
45 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
46 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
47 min => 0, max => $self->{result_values}->{allocated});
48
49 $self->{output}->perfdata_add(label => 'allocated', unit => 'B',
50 value => $self->{result_values}->{allocated},
51 min => 0, max => $self->{result_values}->{total});
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->{label}, exit_litteral => 'critical' },
65 { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
66 return $exit;
67 }
68
69 sub custom_usage_output {
70 my ($self, %options) = @_;
71
72 my $msg;
73 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
74 my ($total_allocated_value, $total_allocated_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{allocated});
75 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
76 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
77 $msg = sprintf("Total: %s Allocated: %s (%.2f%%) Used: %s (%.2f%%) Free: %s (%.2f%%)",
78 $total_size_value . " " . $total_size_unit,
79 $total_allocated_value . " " . $total_allocated_unit, $self->{result_values}->{prct_allocated},,
80 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
81 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
82 return $msg;
83 }
84
85 sub custom_usage_calc {
86 my ($self, %options) = @_;
87
88 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_TotalSystemMB'} * 1024 * 1024;
89 $self->{result_values}->{allocated} = $options{new_datas}->{$self->{instance} . '_TotalAllocatedMB'} * 1024 * 1024;
90 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_TotalUsedMB'} * 1024 * 1024;
91
92 $self->{result_values}->{prct_allocated} = $self->{result_values}->{allocated} * 100 / $self->{result_values}->{total};
93 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{allocated};
94
95 $self->{result_values}->{free} = $self->{result_values}->{allocated} - $self->{result_values}->{used};
96 $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
97
98 return 0;
99 }
100
101 sub set_counters {
102 my ($self, %options) = @_;
103
104 $self->{maps_counters_type} = [
105 { name => 'global', type => 0 },
106 ];
107
108 $self->{maps_counters}->{global} = [
109 { label => 'usage', set => {
110 key_values => [ { name => 'TotalSystemMB' }, { name => 'TotalAllocatedMB' }, { name => 'TotalUsedMB' } ],
111 closure_custom_calc => $self->can('custom_usage_calc'),
112 closure_custom_output => $self->can('custom_usage_output'),
113 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
114 closure_custom_threshold_check => $self->can('custom_usage_threshold'),
115 }
116 },
117 { label => 'workspace-count', set => {
118 key_values => [ { name => 'WorkspaceCount' } ],
119 output_template => 'Workspace count: %d',
120 perfdatas => [
121 { label => 'workspace_count', value => 'WorkspaceCount',
122 template => '%d', min => 0 },
123 ],
124 }
125 },
126 { label => 'folder-count', set => {
127 key_values => [ { name => 'FolderCount' } ],
128 output_template => 'Folder count: %d',
129 perfdatas => [
130 { label => 'folder_count', value => 'FolderCount',
131 template => '%d', min => 0 },
132 ],
133 }
134 },
135 { label => 'file-count', set => {
136 key_values => [ { name => 'FileCount' } ],
137 output_template => 'File count: %d',
138 perfdatas => [
139 { label => 'file_count', value => 'FileCount',
140 template => '%d', min => 0 },
141 ],
142 }
143 },
144 ];
145 }
146
147 sub new {
148 my ($class, %options) = @_;
149 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
150 bless $self, $class;
151
152 $options{options}->add_options(arguments => {
153 "units:s" => { name => 'units', default => '%' },
154 "free" => { name => 'free' },
155 });
156
157 return $self;
158 }
159
160 my $oid_TotalSystemMB = '.1.3.6.1.4.1.526.20.4.2.0';
161 my $oid_TotalAllocatedMB = '.1.3.6.1.4.1.526.20.4.3.0';
162 my $oid_TotalUsedMB = '.1.3.6.1.4.1.526.20.4.4.0';
163 my $oid_FileCount = '.1.3.6.1.4.1.526.20.4.5.0';
164 my $oid_FolderCount = '.1.3.6.1.4.1.526.20.4.6.0';
165 my $oid_WorkspaceCount = '.1.3.6.1.4.1.526.20.4.7.0';
166
167 sub manage_selection {
168 my ($self, %options) = @_;
169
170 my $results = $options{snmp}->get_leef(oids => [ $oid_TotalSystemMB, $oid_TotalAllocatedMB,
171 $oid_TotalUsedMB, $oid_FileCount,
172 $oid_FolderCount, $oid_WorkspaceCount ],
173 nothing_quit => 1);
174
175 $self->{global} = {};
176
177 $self->{global} = {
178 TotalSystemMB => $results->{$oid_TotalSystemMB},
179 TotalAllocatedMB => $results->{$oid_TotalAllocatedMB},
180 TotalUsedMB => $results->{$oid_TotalUsedMB},
181 FileCount => $results->{$oid_FileCount},
182 FolderCount => $results->{$oid_FolderCount},
183 WorkspaceCount => $results->{$oid_WorkspaceCount},
184 };
185 }
186
187 1;
188
189 __END__
190
191 =head1 MODE
192
193 Check storage usage.
194
195 =over 8
196
197 =item B<--warning-usage>
198
199 Warning threshold for used allocated storage.
200
201 =item B<--critical-usage>
202
203 Critical threshold for used allocated storage.
204
205 =item B<--units>
206
207 Units of thresholds (default: '%') ('%', 'B').
208
209 =item B<--free>
210
211 Thresholds are on free space left.
212
213 =back
214
215 =cut