Debian Codegraph @

src/storage/exagrid/snmp/mode/serverusage.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::exagrid::snmp::mode::serverusage;
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_ng);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 return 'Server Status : ' . $self->{result_values}->{status};
33 }
34
35 sub custom_usage_perfdata {
36 my ($self, %options) = @_;
37
38 my $label = 'used';
39 my $value_perf = $self->{result_values}->{used};
40 my %total_options = ( total => $self->{result_values}->{total}, cast_int => 1);
41
42 $self->{output}->perfdata_add(
43 label => $self->{result_values}->{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,
48 max => $self->{result_values}->{total}
49 );
50 }
51
52 sub custom_usage_threshold {
53 my ($self, %options) = @_;
54
55 my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]);
56 return $exit;
57 }
58
59 sub custom_usage_output {
60 my ($self, %options) = @_;
61
62 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
63 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
64 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
65 return sprintf(
66 '%s Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
67 ucfirst($self->{result_values}->{label}),
68 $total_size_value . " " . $total_size_unit,
69 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
70 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
71 );
72 }
73
74 sub custom_usage_calc {
75 my ($self, %options) = @_;
76
77 $self->{result_values}->{label} = $options{extra_options}->{label_ref};
78 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{label} . '_total'};
79 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{label} . '_used'};
80
81 if ($self->{result_values}->{total} != 0) {
82 $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
83 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
84 $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
85 } else {
86 $self->{result_values}->{free} = 0;
87 $self->{result_values}->{prct_used} = 0;
88 $self->{result_values}->{prct_free} = 0;
89 }
90 return 0;
91 }
92
93 sub set_counters {
94 my ($self, %options) = @_;
95
96 $self->{maps_counters_type} = [
97 { name => 'server', type => 0, message_separator => ' - ' }
98 ];
99
100 $self->{maps_counters}->{server} = [
101 {
102 label => 'status',
103 type => 2,
104 warning_default => '%{status} =~ /warning/i',
105 critical_default => '%{status} =~ /error/i',
106 set => {
107 key_values => [ { name => 'status' } ],
108 closure_custom_output => $self->can('custom_status_output'),
109 closure_custom_perfdata => sub { return 0; },
110 closure_custom_threshold_check => \&catalog_status_threshold_ng
111 }
112 },
113 { label => 'landing-usage', set => {
114 key_values => [ { name => 'landing_used' }, { name => 'landing_total' } ],
115 closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'landing' },
116 closure_custom_output => $self->can('custom_usage_output'),
117 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
118 closure_custom_threshold_check => $self->can('custom_usage_threshold')
119 }
120 },
121 { label => 'retention-usage', set => {
122 key_values => [ { name => 'retention_used' }, { name => 'retention_total' } ],
123 closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'retention' },
124 closure_custom_output => $self->can('custom_usage_output'),
125 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
126 closure_custom_threshold_check => $self->can('custom_usage_threshold')
127 }
128 },
129 ];
130 }
131
132 sub new {
133 my ($class, %options) = @_;
134 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
135 bless $self, $class;
136
137 $options{options}->add_options(arguments => {
138 });
139
140 return $self;
141 }
142
143 my $map_status = {
144 1 => 'ok',
145 2 => 'warning',
146 3 => 'error'
147 };
148
149 my $mapping = {
150 egLandingSpaceConfiguredWholeGigabytes => { oid => '.1.3.6.1.4.1.14941.4.1.1' },
151 egLandingSpaceAvailableWholeGigabytes => { oid => '.1.3.6.1.4.1.14941.4.1.3' },
152 egRetentionSpaceConfiguredWholeGigabytes => { oid => '.1.3.6.1.4.1.14941.4.2.1' },
153 egRetentionSpaceAvailableWholeGigabytes => { oid => '.1.3.6.1.4.1.14941.4.2.3' },
154 egServerAlarmState => { oid => '.1.3.6.1.4.1.14941.4.6.1', map => $map_status }
155 };
156 my $oid_exagridServerData = '.1.3.6.1.4.1.14941.4';
157
158 sub manage_selection {
159 my ($self, %options) = @_;
160
161 my $snmp_result = $options{snmp}->get_table(
162 oid => $oid_exagridServerData,
163 nothing_quit => 1
164 );
165 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0');
166 $self->{server} = {
167 status => $result->{egServerAlarmState},
168 retention_total => $result->{egRetentionSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000,
169 retention_used => $result->{egRetentionSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000 - $result->{egRetentionSpaceAvailableWholeGigabytes} * 1000 * 1000 * 1000,
170 landing_total => $result->{egLandingSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000,
171 landing_used => $result->{egLandingSpaceConfiguredWholeGigabytes} * 1000 * 1000 * 1000 - $result->{egLandingSpaceAvailableWholeGigabytes} * 1000 * 1000 * 1000
172 };
173 }
174
175 1;
176
177 __END__
178
179 =head1 MODE
180
181 Check server status and usage.
182
183 =over 8
184
185 =item B<--filter-counters>
186
187 Only display some counters (regexp can be used).
188 Example: --filter-counters='^status$'
189
190 =item B<--warning-status>
191
192 Define the conditions to match for the status to be WARNING (default: '%{status} =~ /warning/i').
193 You can use the following variables: %{status}
194
195 =item B<--critical-status>
196
197 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /error/i').
198 You can use the following variables: %{status}
199
200 =item B<--warning-*> B<--critical-*>
201
202 Thresholds.
203 Can be: 'retention-usage' (%), 'landing-usage' (%).
204
205 =back
206
207 =cut