| 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 network::citrix::sdx::snmp::mode::srusage; |
| 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} . '_srStatus'}; |
| 40 |
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; |
| 41 |
return 0; |
| 42 |
} |
| 43 |
|
| 44 |
sub custom_usage_perfdata { |
| 45 |
my ($self, %options) = @_; |
| 46 |
|
| 47 |
my $label = 'used'; |
| 48 |
my $value_perf = $self->{result_values}->{used}; |
| 49 |
if (defined($self->{instance_mode}->{option_results}->{free})) { |
| 50 |
$label = 'free'; |
| 51 |
$value_perf = $self->{result_values}->{free}; |
| 52 |
} |
| 53 |
|
| 54 |
my %total_options = (); |
| 55 |
if ($self->{instance_mode}->{option_results}->{units} eq '%') { |
| 56 |
$total_options{total} = $self->{result_values}->{total}; |
| 57 |
$total_options{cast_int} = 1; |
| 58 |
} |
| 59 |
|
| 60 |
$self->{output}->perfdata_add( |
| 61 |
label => $label, unit => 'B', |
| 62 |
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, |
| 63 |
value => $value_perf, |
| 64 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options), |
| 65 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options), |
| 66 |
min => 0, max => $self->{result_values}->{total} |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 70 |
sub custom_usage_threshold { |
| 71 |
my ($self, %options) = @_; |
| 72 |
|
| 73 |
my ($exit, $threshold_value); |
| 74 |
$threshold_value = $self->{result_values}->{used}; |
| 75 |
$threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free})); |
| 76 |
if ($self->{instance_mode}->{option_results}->{units} eq '%') { |
| 77 |
$threshold_value = $self->{result_values}->{prct_used}; |
| 78 |
$threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free})); |
| 79 |
} |
| 80 |
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]); |
| 81 |
return $exit; |
| 82 |
} |
| 83 |
|
| 84 |
sub custom_usage_output { |
| 85 |
my ($self, %options) = @_; |
| 86 |
|
| 87 |
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); |
| 88 |
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); |
| 89 |
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); |
| 90 |
my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", |
| 91 |
$total_size_value . " " . $total_size_unit, |
| 92 |
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, |
| 93 |
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); |
| 94 |
return $msg; |
| 95 |
} |
| 96 |
|
| 97 |
sub custom_usage_calc { |
| 98 |
my ($self, %options) = @_; |
| 99 |
|
| 100 |
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; |
| 101 |
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; |
| 102 |
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; |
| 103 |
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; |
| 104 |
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; |
| 105 |
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; |
| 106 |
|
| 107 |
return 0; |
| 108 |
} |
| 109 |
|
| 110 |
sub set_counters { |
| 111 |
my ($self, %options) = @_; |
| 112 |
|
| 113 |
$self->{maps_counters_type} = [ |
| 114 |
{ name => 'sr', type => 1, cb_prefix_output => 'prefix_sr_output', message_multiple => 'All storage repositories are ok' } |
| 115 |
]; |
| 116 |
|
| 117 |
$self->{maps_counters}->{sr} = [ |
| 118 |
{ label => 'status', threshold => 0, set => { |
| 119 |
key_values => [ { name => 'srStatus' }, { name => 'display' } ], |
| 120 |
closure_custom_calc => $self->can('custom_status_calc'), |
| 121 |
closure_custom_output => $self->can('custom_status_output'), |
| 122 |
closure_custom_perfdata => sub { return 0; }, |
| 123 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 124 |
} |
| 125 |
}, |
| 126 |
{ label => 'usage', set => { |
| 127 |
key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' } ], |
| 128 |
closure_custom_calc => $self->can('custom_usage_calc'), |
| 129 |
closure_custom_output => $self->can('custom_usage_output'), |
| 130 |
closure_custom_perfdata => $self->can('custom_usage_perfdata'), |
| 131 |
closure_custom_threshold_check => $self->can('custom_usage_threshold'), |
| 132 |
} |
| 133 |
}, |
| 134 |
]; |
| 135 |
} |
| 136 |
|
| 137 |
sub new { |
| 138 |
my ($class, %options) = @_; |
| 139 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 140 |
bless $self, $class; |
| 141 |
|
| 142 |
$options{options}->add_options(arguments => |
| 143 |
{ |
| 144 |
"filter-name:s" => { name => 'filter_name' }, |
| 145 |
"warning-status:s" => { name => 'warning_status', default => '' }, |
| 146 |
"critical-status:s" => { name => 'critical_status', default => '%{status} !~ /good/i' }, |
| 147 |
"units:s" => { name => 'units', default => '%' }, |
| 148 |
"free" => { name => 'free' }, |
| 149 |
}); |
| 150 |
|
| 151 |
return $self; |
| 152 |
} |
| 153 |
|
| 154 |
sub check_options { |
| 155 |
my ($self, %options) = @_; |
| 156 |
$self->SUPER::check_options(%options); |
| 157 |
|
| 158 |
$self->change_macros(macros => ['warning_status', 'critical_status']); |
| 159 |
} |
| 160 |
|
| 161 |
sub prefix_sr_output { |
| 162 |
my ($self, %options) = @_; |
| 163 |
|
| 164 |
return "Storage repository '" . $options{instance_value}->{display} . "' "; |
| 165 |
} |
| 166 |
|
| 167 |
my $mapping = { |
| 168 |
srName => { oid => '.1.3.6.1.4.1.5951.6.2.1000.4.1.1' }, |
| 169 |
srUtilized => { oid => '.1.3.6.1.4.1.5951.6.2.1000.4.1.5' }, |
| 170 |
srSize => { oid => '.1.3.6.1.4.1.5951.6.2.1000.4.1.6' }, |
| 171 |
srStatus => { oid => '.1.3.6.1.4.1.5951.6.2.1000.4.1.7' }, |
| 172 |
}; |
| 173 |
|
| 174 |
my $oid_srEntry = '.1.3.6.1.4.1.5951.6.2.1000.4.1'; |
| 175 |
|
| 176 |
sub manage_selection { |
| 177 |
my ($self, %options) = @_; |
| 178 |
|
| 179 |
$self->{sr} = {}; |
| 180 |
my $snmp_result = $options{snmp}->get_table(oid => $oid_srEntry, |
| 181 |
nothing_quit => 1); |
| 182 |
|
| 183 |
|
| 184 |
foreach my $oid (keys %{$snmp_result}) { |
| 185 |
next if ($oid !~ /^$mapping->{srName}->{oid}\.(.*)$/); |
| 186 |
my $instance = $1; |
| 187 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 188 |
|
| 189 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 190 |
$result->{srName} !~ /$self->{option_results}->{filter_name}/) { |
| 191 |
$self->{output}->output_add(long_msg => "skipping '" . $result->{srName} . "': no matching filter.", debug => 1); |
| 192 |
next; |
| 193 |
} |
| 194 |
|
| 195 |
$self->{sr}->{$instance} = { |
| 196 |
display => $result->{srName}, |
| 197 |
total => $result->{srSize}, |
| 198 |
used => $result->{srUtilized}, |
| 199 |
%$result |
| 200 |
}; |
| 201 |
} |
| 202 |
|
| 203 |
if (scalar(keys %{$self->{sr}}) <= 0) { |
| 204 |
$self->{output}->add_option_msg(short_msg => "No storage repository found."); |
| 205 |
$self->{output}->option_exit(); |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
1; |
| 210 |
|
| 211 |
__END__ |
| 212 |
|
| 213 |
=head1 MODE |
| 214 |
|
| 215 |
Check storage repositories. |
| 216 |
|
| 217 |
=over 8 |
| 218 |
|
| 219 |
=item B<--filter-counters> |
| 220 |
|
| 221 |
Only display some counters (regexp can be used). |
| 222 |
Example: --filter-counters='^read|write$' |
| 223 |
|
| 224 |
=item B<--filter-name> |
| 225 |
|
| 226 |
Filter storage repository name (can be a regexp). |
| 227 |
|
| 228 |
=item B<--warning-status> |
| 229 |
|
| 230 |
Define the conditions to match for the status to be WARNING. |
| 231 |
You can use the following variables: %{status}, %{display} |
| 232 |
|
| 233 |
=item B<--critical-status> |
| 234 |
|
| 235 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /good/i'). |
| 236 |
You can use the following variables: %{status}, %{display} |
| 237 |
|
| 238 |
=item B<--warning-*> |
| 239 |
|
| 240 |
Warning threshold. |
| 241 |
Can be: 'usage'. |
| 242 |
|
| 243 |
=item B<--critical-*> |
| 244 |
|
| 245 |
Critical threshold. |
| 246 |
Can be: 'usage'. |
| 247 |
|
| 248 |
=item B<--units> |
| 249 |
|
| 250 |
Units of thresholds (default: '%') ('%', 'B'). |
| 251 |
|
| 252 |
=item B<--free> |
| 253 |
|
| 254 |
Thresholds are on free space left. |
| 255 |
|
| 256 |
=back |
| 257 |
|
| 258 |
=cut |