| 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::netapp::ontap::snmp::mode::snapvaultusage; |
| 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 |
use Digest::MD5 qw(md5_hex); |
| 29 |
|
| 30 |
sub custom_status_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
my $msg = 'status : ' . $self->{result_values}->{status} . ' [state : ' . $self->{result_values}->{state} . ']'; |
| 34 |
return $msg; |
| 35 |
} |
| 36 |
|
| 37 |
sub custom_status_calc { |
| 38 |
my ($self, %options) = @_; |
| 39 |
|
| 40 |
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_svStatus'}; |
| 41 |
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_svState'}; |
| 42 |
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; |
| 43 |
return 0; |
| 44 |
} |
| 45 |
|
| 46 |
sub set_counters { |
| 47 |
my ($self, %options) = @_; |
| 48 |
|
| 49 |
$self->{maps_counters_type} = [ |
| 50 |
{ name => 'snapvault', type => 1, cb_prefix_output => 'prefix_snapvault_output', message_multiple => 'All snapvault usages are ok', skipped_code => { -10 => 1, -11 => 1 } } |
| 51 |
]; |
| 52 |
|
| 53 |
$self->{maps_counters}->{snapvault} = [ |
| 54 |
{ label => 'status', threshold => 0, set => { |
| 55 |
key_values => [ { name => 'svState' }, { name => 'svStatus' }, { name => 'display' } ], |
| 56 |
closure_custom_calc => $self->can('custom_status_calc'), |
| 57 |
closure_custom_output => $self->can('custom_status_output'), |
| 58 |
closure_custom_perfdata => sub { return 0; }, |
| 59 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 60 |
} |
| 61 |
}, |
| 62 |
{ label => 'lag', set => { |
| 63 |
key_values => [ { name => 'svLag' }, { name => 'display' } ], |
| 64 |
output_template => 'lag : %s seconds', |
| 65 |
perfdatas => [ |
| 66 |
{ label => 'lag', template => '%s', min => 0, unit => 's', |
| 67 |
label_extra_instance => 1, instance_use => 'display' }, |
| 68 |
], |
| 69 |
} |
| 70 |
}, |
| 71 |
{ label => 'transfer-traffic', set => { |
| 72 |
key_values => [ { name => 'svTotalTransMBs', per_second => 1 }, { name => 'display' } ], |
| 73 |
output_template => 'transfer traffic : %s %s/s', |
| 74 |
output_change_bytes => 1, |
| 75 |
perfdatas => [ |
| 76 |
{ label => 'transfer_traffic', template => '%.2f', |
| 77 |
unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 78 |
], |
| 79 |
} |
| 80 |
}, |
| 81 |
{ label => 'transfer-succeed', display_ok => 0, set => { |
| 82 |
key_values => [ { name => 'svTotalSuccesses' }, { name => 'display' } ], |
| 83 |
output_template => 'transfer succeed : %s', |
| 84 |
perfdatas => [ |
| 85 |
{ label => 'transfer_succeed', template => '%s', min => 0, |
| 86 |
label_extra_instance => 1, instance_use => 'display' }, |
| 87 |
], |
| 88 |
} |
| 89 |
}, |
| 90 |
{ label => 'transfer-failed', display_ok => 0, set => { |
| 91 |
key_values => [ { name => 'svTotalFailures' }, { name => 'display' } ], |
| 92 |
output_template => 'transfer failed : %s', |
| 93 |
perfdatas => [ |
| 94 |
{ label => 'transfer_failed', template => '%s', min => 0, |
| 95 |
label_extra_instance => 1, instance_use => 'display' }, |
| 96 |
], |
| 97 |
} |
| 98 |
}, |
| 99 |
]; |
| 100 |
} |
| 101 |
|
| 102 |
sub prefix_snapvault_output { |
| 103 |
my ($self, %options) = @_; |
| 104 |
|
| 105 |
return "Snapvault '" . $options{instance_value}->{display} . "' "; |
| 106 |
} |
| 107 |
|
| 108 |
sub new { |
| 109 |
my ($class, %options) = @_; |
| 110 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); |
| 111 |
bless $self, $class; |
| 112 |
|
| 113 |
$options{options}->add_options(arguments => { |
| 114 |
'filter-name:s' => { name => 'filter_name' }, |
| 115 |
'unknown-status:s' => { name => 'unknown_status', default => '' }, |
| 116 |
'warning-status:s' => { name => 'warning_status', default => '' }, |
| 117 |
'critical-status:s' => { name => 'critical_status', default => '' }, |
| 118 |
}); |
| 119 |
|
| 120 |
return $self; |
| 121 |
} |
| 122 |
|
| 123 |
sub check_options { |
| 124 |
my ($self, %options) = @_; |
| 125 |
$self->SUPER::check_options(%options); |
| 126 |
|
| 127 |
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); |
| 128 |
} |
| 129 |
|
| 130 |
my $map_status = { |
| 131 |
1 => 'idle', 2 => 'transferring', 3 => 'pending', |
| 132 |
4 => 'aborting', 6 => 'quiescing', 7 => 'resyncing', |
| 133 |
12 => 'paused', |
| 134 |
}; |
| 135 |
|
| 136 |
my $map_state = { |
| 137 |
1 => 'uninitialized', 2 => 'snapvaulted', |
| 138 |
3 => 'brokenOff', 4 => 'quiesced', |
| 139 |
5 => 'source', 6 => 'unknown', 7 => 'restoring', |
| 140 |
}; |
| 141 |
|
| 142 |
my $mapping = { |
| 143 |
svStatus => { oid => '.1.3.6.1.4.1.789.1.19.11.1.4', map => $map_status }, |
| 144 |
svState => { oid => '.1.3.6.1.4.1.789.1.19.11.1.5', map => $map_state }, |
| 145 |
svLag => { oid => '.1.3.6.1.4.1.789.1.19.11.1.6' }, # timeticks |
| 146 |
svTotalSuccesses => { oid => '.1.3.6.1.4.1.789.1.19.11.1.7' }, |
| 147 |
svTotalFailures => { oid => '.1.3.6.1.4.1.789.1.19.11.1.9' }, |
| 148 |
svTotalTransMBs => { oid => '.1.3.6.1.4.1.789.1.19.11.1.11' }, |
| 149 |
}; |
| 150 |
|
| 151 |
sub manage_selection { |
| 152 |
my ($self, %options) = @_; |
| 153 |
|
| 154 |
my $oid_svOn = '.1.3.6.1.4.1.789.1.19.1.0'; |
| 155 |
|
| 156 |
my $snmp_result = $options{snmp}->get_leef(oids => [$oid_svOn]); |
| 157 |
if (!defined($snmp_result->{$oid_svOn}) || $snmp_result->{$oid_svOn} != 2) { |
| 158 |
$self->{output}->add_option_msg(short_msg => "snapvault is not turned on."); |
| 159 |
$self->{output}->option_exit(); |
| 160 |
} |
| 161 |
|
| 162 |
my $oid_svSrc = '.1.3.6.1.4.1.789.1.19.11.1.2'; |
| 163 |
my $oid_svDst = '.1.3.6.1.4.1.789.1.19.11.1.3'; |
| 164 |
|
| 165 |
$self->{snapvault} = {}; |
| 166 |
$snmp_result = $options{snmp}->get_multiple_table(oids => [{ oid => $oid_svSrc }, { oid => $oid_svDst }], return_type => 1, nothing_quit => 1); |
| 167 |
foreach my $oid (keys %{$snmp_result}) { |
| 168 |
next if ($oid !~ /^$oid_svSrc\.(.*)$/); |
| 169 |
my $instance = $1; |
| 170 |
my $name = $snmp_result->{$oid_svSrc . '.' . $instance} . '.' . $snmp_result->{$oid_svDst . '.' . $instance}; |
| 171 |
|
| 172 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 173 |
$name !~ /$self->{option_results}->{filter_name}/) { |
| 174 |
$self->{output}->output_add(long_msg => "skipping snapvault '" . $name . "'.", debug => 1); |
| 175 |
next; |
| 176 |
} |
| 177 |
|
| 178 |
$self->{snapvault}->{$instance} = { display => $name }; |
| 179 |
} |
| 180 |
|
| 181 |
if (scalar(keys %{$self->{snapvault}}) <= 0) { |
| 182 |
$self->{output}->add_option_msg(short_msg => "No entry found."); |
| 183 |
$self->{output}->option_exit(); |
| 184 |
} |
| 185 |
|
| 186 |
$options{snmp}->load(oids => [ |
| 187 |
map($_->{oid}, values(%$mapping)) |
| 188 |
], |
| 189 |
instances => [keys %{$self->{snapvault}}], instance_regexp => '^(.*)$'); |
| 190 |
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1); |
| 191 |
|
| 192 |
foreach (keys %{$self->{snapvault}}) { |
| 193 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); |
| 194 |
|
| 195 |
$result->{svTotalTransMBs} *= 1024 * 1024; |
| 196 |
$result->{svLag} = int($result->{svLag} / 100); |
| 197 |
|
| 198 |
$self->{snapvault}->{$_} = { %{$self->{snapvault}->{$_}}, %$result }; |
| 199 |
} |
| 200 |
|
| 201 |
$self->{cache_name} = "netapp_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . |
| 202 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . |
| 203 |
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); |
| 204 |
} |
| 205 |
|
| 206 |
1; |
| 207 |
|
| 208 |
__END__ |
| 209 |
|
| 210 |
=head1 MODE |
| 211 |
|
| 212 |
Check snapvault usage. |
| 213 |
|
| 214 |
=over 8 |
| 215 |
|
| 216 |
=item B<--filter-name> |
| 217 |
|
| 218 |
Filter snapvault name (can be a regexp). |
| 219 |
|
| 220 |
=item B<--unknown-status> |
| 221 |
|
| 222 |
Define the conditions to match for the status to be UNKNOWN (default: ''). |
| 223 |
You can use the following variables: %{state}, %{status}, %{display} |
| 224 |
|
| 225 |
=item B<--warning-status> |
| 226 |
|
| 227 |
Define the conditions to match for the status to be WARNING (default: ''). |
| 228 |
You can use the following variables: %{state}, %{status}, %{display} |
| 229 |
|
| 230 |
=item B<--critical-status> |
| 231 |
|
| 232 |
Define the conditions to match for the status to be CRITICAL (default: ''). |
| 233 |
You can use the following variables: %{state}, %{status}, %{display} |
| 234 |
|
| 235 |
=item B<--warning-*> B<--critical-*> |
| 236 |
|
| 237 |
Warning threshold. |
| 238 |
Can be: 'lag' (s), 'transfer-traffic' (B/s), 'transfer-succeed', |
| 239 |
'transfer-failed'. |
| 240 |
|
| 241 |
=back |
| 242 |
|
| 243 |
=cut |