| 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::aggregates; |
| 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 prefix_agg_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return "Aggregate '" . $options{instance_value}->{name} . "' "; |
| 33 |
} |
| 34 |
|
| 35 |
sub set_counters { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
$self->{maps_counters_type} = [ |
| 39 |
{ name => 'agg', type => 1, cb_prefix_output => 'prefix_agg_output', message_multiple => 'All aggregates are ok', skipped_code => { -10 => 1 } } |
| 40 |
]; |
| 41 |
|
| 42 |
$self->{maps_counters}->{agg} = [ |
| 43 |
{ label => 'state', type => 2, critical_default => '%{state} =~ /offline/i',set => { |
| 44 |
key_values => [ { name => 'state' }, { name => 'name' } ], |
| 45 |
output_template => "state: %s", |
| 46 |
closure_custom_perfdata => sub { return 0; }, |
| 47 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 48 |
} |
| 49 |
}, |
| 50 |
{ label => 'status', type => 2, critical_default => '%{status} !~ /normal|mirrored/i', set => { |
| 51 |
key_values => [ { name => 'status' }, { name => 'name' } ], |
| 52 |
output_template => "status: '%s'", |
| 53 |
closure_custom_perfdata => sub { return 0; }, |
| 54 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 55 |
} |
| 56 |
} |
| 57 |
]; |
| 58 |
} |
| 59 |
|
| 60 |
sub new { |
| 61 |
my ($class, %options) = @_; |
| 62 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 63 |
bless $self, $class; |
| 64 |
|
| 65 |
$options{options}->add_options(arguments => { |
| 66 |
'filter-name:s' => { name => 'filter_name' } |
| 67 |
}); |
| 68 |
|
| 69 |
return $self; |
| 70 |
} |
| 71 |
|
| 72 |
my $mapping = { |
| 73 |
state => { oid => '.1.3.6.1.4.1.789.1.5.11.1.5' }, # aggrState |
| 74 |
status => { oid => '.1.3.6.1.4.1.789.1.5.11.1.6' } # aggrStatus |
| 75 |
}; |
| 76 |
|
| 77 |
sub manage_selection { |
| 78 |
my ($self, %options) = @_; |
| 79 |
|
| 80 |
my $oid_aggrName = '.1.3.6.1.4.1.789.1.5.11.1.2'; |
| 81 |
|
| 82 |
$self->{agg} = {}; |
| 83 |
my $snmp_result = $options{snmp}->get_table(oid => $oid_aggrName, nothing_quit => 1); |
| 84 |
foreach my $oid (keys %$snmp_result) { |
| 85 |
$oid =~ /^$oid_aggrName\.(.*)$/; |
| 86 |
my $instance = $1; |
| 87 |
my $name = $snmp_result->{$oid}; |
| 88 |
|
| 89 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 90 |
$name !~ /$self->{option_results}->{filter_name}/) { |
| 91 |
$self->{output}->output_add(long_msg => "skipping aggregatge '" . $name . "'.", debug => 1); |
| 92 |
next; |
| 93 |
} |
| 94 |
|
| 95 |
$self->{agg}->{$instance} = { name => $name }; |
| 96 |
} |
| 97 |
|
| 98 |
if (scalar(keys %{$self->{agg}}) <= 0) { |
| 99 |
$self->{output}->add_option_msg(short_msg => "No aggregate found"); |
| 100 |
$self->{output}->option_exit(); |
| 101 |
} |
| 102 |
|
| 103 |
$options{snmp}->load( |
| 104 |
oids => [ |
| 105 |
map($_->{oid}, values(%$mapping)) |
| 106 |
], |
| 107 |
instances => [keys %{$self->{agg}}], |
| 108 |
instance_regexp => '^(.*)$' |
| 109 |
); |
| 110 |
$snmp_result = $options{snmp}->get_leef(); |
| 111 |
|
| 112 |
foreach (keys %{$self->{agg}}) { |
| 113 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); |
| 114 |
|
| 115 |
$self->{agg}->{$_}->{state} = $result->{state}; |
| 116 |
$self->{agg}->{$_}->{status} = $result->{status}; |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
1; |
| 121 |
|
| 122 |
__END__ |
| 123 |
|
| 124 |
=head1 MODE |
| 125 |
|
| 126 |
Check aggregates. |
| 127 |
|
| 128 |
=over 8 |
| 129 |
|
| 130 |
=item B<--filter-name> |
| 131 |
|
| 132 |
Filter aggregates by name. |
| 133 |
|
| 134 |
=item B<--unknown-status> |
| 135 |
|
| 136 |
Define the conditions to match for the status to be UNKNOWN. |
| 137 |
You can use the following variables: %{status}, %{name} |
| 138 |
|
| 139 |
=item B<--warning-status> |
| 140 |
|
| 141 |
Define the conditions to match for the status to be WARNING. |
| 142 |
You can use the following variables: %{status}, %{name} |
| 143 |
|
| 144 |
=item B<--critical-status> |
| 145 |
|
| 146 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /normal|mirrored/i'). |
| 147 |
You can use the following variables: %{status}, %{name} |
| 148 |
|
| 149 |
=item B<--unknown-state> |
| 150 |
|
| 151 |
Set unknown threshold for state. |
| 152 |
You can use the following variables: %{state}, %{name} |
| 153 |
|
| 154 |
=item B<--warning-state> |
| 155 |
|
| 156 |
Set warning threshold for state. |
| 157 |
You can use the following variables: %{state}, %{name} |
| 158 |
|
| 159 |
=item B<--critical-state> |
| 160 |
|
| 161 |
Set critical threshold for state (default: '%{state} =~ /offline/i'). |
| 162 |
You can use the following variables: %{state}, %{name} |
| 163 |
|
| 164 |
=back |
| 165 |
|
| 166 |
=cut |