Debian Codegraph @

src/apps/inin/mediaserver/snmp/mode/diskusage.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 apps::inin::mediaserver::snmp::mode::diskusage;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub set_counters {
29 my ($self, %options) = @_;
30
31 $self->{maps_counters_type} = [
32 { name => 'disktracelog', type => 0 },
33 { name => 'diskhttpcache', type => 0 },
34 ];
35
36 $self->{maps_counters}->{disktracelog} = [
37 { label => 'tracelog-usage', set => {
38 key_values => [ { name => 'free' }, { name => 'total' }, { name => 'display' } ],
39 closure_custom_calc => $self->can('custom_usage_calc'),
40 closure_custom_output => $self->can('custom_usage_output'),
41 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
42 closure_custom_threshold_check => $self->can('custom_usage_threshold'),
43 }
44 },
45 ];
46 $self->{maps_counters}->{diskhttpcache} = [
47 { label => 'httpcache-usage', set => {
48 key_values => [ { name => 'free' }, { name => 'total' }, { name => 'display' } ],
49 closure_custom_calc => $self->can('custom_usage_calc'),
50 closure_custom_output => $self->can('custom_usage_output'),
51 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
52 closure_custom_threshold_check => $self->can('custom_usage_threshold'),
53 }
54 },
55 ];
56 }
57
58 sub custom_usage_perfdata {
59 my ($self, %options) = @_;
60
61 my $label = 'used_' . $self->{result_values}->{display};
62 my $value_perf = $self->{result_values}->{used};
63 if (defined($self->{instance_mode}->{option_results}->{free})) {
64 $label = 'free_' . $self->{result_values}->{display};
65 $value_perf = $self->{result_values}->{free};
66 }
67 my %total_options = ();
68 if ($self->{instance_mode}->{option_results}->{units} eq '%') {
69 $total_options{total} = $self->{result_values}->{total};
70 $total_options{cast_int} = 1;
71 }
72
73 $self->{output}->perfdata_add(label => $label, unit => 'B',
74 value => $value_perf,
75 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
76 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
77 min => 0, max => $self->{result_values}->{total});
78 }
79
80 sub custom_usage_threshold {
81 my ($self, %options) = @_;
82
83 my ($exit, $threshold_value);
84 $threshold_value = $self->{result_values}->{used};
85 $threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free}));
86 if ($self->{instance_mode}->{option_results}->{units} eq '%') {
87 $threshold_value = $self->{result_values}->{prct_used};
88 $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free}));
89 }
90 $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
91 return $exit;
92 }
93
94 sub custom_usage_output {
95 my ($self, %options) = @_;
96
97 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
98 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
99 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
100 my $msg = sprintf("Disk '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
101 $self->{result_values}->{display},
102 $total_size_value . " " . $total_size_unit,
103 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
104 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
105 return $msg;
106 }
107
108 sub custom_usage_calc {
109 my ($self, %options) = @_;
110
111 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
112 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
113 $self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_free'};
114 $self->{result_values}->{used} = $self->{result_values}->{total} - $self->{result_values}->{free};
115
116 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
117 $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
118
119 return 0;
120 }
121
122 sub new {
123 my ($class, %options) = @_;
124 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
125 bless $self, $class;
126
127 $options{options}->add_options(arguments => {
128 "units:s" => { name => 'units', default => '%' },
129 "free" => { name => 'free' },
130 });
131
132 return $self;
133 }
134
135 sub manage_selection {
136 my ($self, %options) = @_;
137
138 my $oid_i3MsGeneralInfoTracelogFreeDiskSpace = '.1.3.6.1.4.1.2793.8227.1.12.0'; # MiB
139 my $oid_i3MsGeneralInfoTracelogTotalDiskSpace = '.1.3.6.1.4.1.2793.8227.1.13.0'; # MiB
140 my $oid_i3MsGeneralInfoHttpCacheFreeDiskSpace = '.1.3.6.1.4.1.2793.8227.1.15.0'; # MiB
141 my $oid_i3MsGeneralInfoHttpCacheTotalDiskSpace = '.1.3.6.1.4.1.2793.8227.1.16.0'; # MiB
142
143 my $snmp_result = $options{snmp}->get_leef(oids => [
144 $oid_i3MsGeneralInfoTracelogFreeDiskSpace, $oid_i3MsGeneralInfoTracelogTotalDiskSpace,
145 $oid_i3MsGeneralInfoHttpCacheFreeDiskSpace, $oid_i3MsGeneralInfoHttpCacheTotalDiskSpace
146 ], nothing_quit => 1);
147
148 $self->{disktracelog} = {
149 free => $snmp_result->{$oid_i3MsGeneralInfoTracelogFreeDiskSpace} * 1024 * 1024,
150 total => $snmp_result->{$oid_i3MsGeneralInfoTracelogTotalDiskSpace} * 1024 * 1024,
151 display => 'tracelog'
152 };
153 $self->{diskhttpcache} = {
154 free => $snmp_result->{$oid_i3MsGeneralInfoHttpCacheFreeDiskSpace} * 1024 * 1024,
155 total => $snmp_result->{$oid_i3MsGeneralInfoHttpCacheTotalDiskSpace} * 1024 * 1024,
156 display => 'httpcache'
157 };
158 }
159
160 1;
161
162 __END__
163
164 =head1 MODE
165
166 Check disk usages.
167
168 =over 8
169
170 =item B<--warning-*>
171
172 Warning threshold.
173 Can be: 'httpcache-usage', 'tracelog-usage'.
174
175 =item B<--critical-*>
176
177 Critical threshold.
178 Can be: 'httpcache-usage', 'tracelog-usage'.
179
180 =item B<--units>
181
182 Default is '%', can be 'B'
183
184 =item B<--free>
185
186 Thresholds are on free space left.
187
188 =back
189
190 =cut