| 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::aruba::aoscx::snmp::mode::vsf; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use Digest::MD5 qw(md5_hex); |
| 28 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 29 |
|
| 30 |
sub custom_status_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
return sprintf( |
| 34 |
'vsf operational status: %s', |
| 35 |
$self->{result_values}->{status} |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
sub custom_member_status_output { |
| 40 |
my ($self, %options) = @_; |
| 41 |
|
| 42 |
return sprintf( |
| 43 |
'role: %s [status: %s]', |
| 44 |
$self->{result_values}->{role}, |
| 45 |
$self->{result_values}->{status} |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
sub custom_member_status_calc { |
| 50 |
my ($self, %options) = @_; |
| 51 |
|
| 52 |
$self->{result_values}->{roleLast} = $options{old_datas}->{$self->{instance} . '_role'}; |
| 53 |
$self->{result_values}->{role} = $options{new_datas}->{$self->{instance} . '_role'}; |
| 54 |
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; |
| 55 |
$self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'}; |
| 56 |
if (!defined($options{old_datas}->{$self->{instance} . '_role'})) { |
| 57 |
$self->{error_msg} = "buffer creation"; |
| 58 |
return -2; |
| 59 |
} |
| 60 |
|
| 61 |
return 0; |
| 62 |
} |
| 63 |
|
| 64 |
sub member_long_output { |
| 65 |
my ($self, %options) = @_; |
| 66 |
|
| 67 |
return "checking stack member '" . $options{instance_value}->{id} . "'"; |
| 68 |
} |
| 69 |
|
| 70 |
sub prefix_member_output { |
| 71 |
my ($self, %options) = @_; |
| 72 |
|
| 73 |
return "stack member '" . $options{instance_value}->{id} . "' "; |
| 74 |
} |
| 75 |
|
| 76 |
sub set_counters { |
| 77 |
my ($self, %options) = @_; |
| 78 |
|
| 79 |
$self->{maps_counters_type} = [ |
| 80 |
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, |
| 81 |
{ name => 'members', type => 3, cb_prefix_output => 'prefix_member_output', cb_long_output => 'member_long_output', indent_long_output => ' ', message_multiple => 'All stack members are ok', |
| 82 |
group => [ |
| 83 |
{ name => 'status', type => 0, skipped_code => { -10 => 1 } }, |
| 84 |
{ name => 'cpu', type => 0, skipped_code => { -10 => 1 } }, |
| 85 |
{ name => 'memory', type => 0, skipped_code => { -10 => 1 } } |
| 86 |
] |
| 87 |
} |
| 88 |
]; |
| 89 |
|
| 90 |
$self->{maps_counters}->{global} = [ |
| 91 |
{ label => 'status', type => 2, critical_default => '%{status} !~ /no_split/i', set => { |
| 92 |
key_values => [ { name => 'status' } ], |
| 93 |
closure_custom_output => $self->can('custom_status_output'), |
| 94 |
closure_custom_perfdata => sub { return 0; }, |
| 95 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 96 |
} |
| 97 |
}, |
| 98 |
{ label => 'members-total', nlabel => 'stack.members.total.count', display_ok => '0', set => { |
| 99 |
key_values => [ { name => 'members'} ], |
| 100 |
output_template => 'total members: %s', |
| 101 |
perfdatas => [ |
| 102 |
{ value => 'members', template => '%s', min => 0 }, |
| 103 |
] |
| 104 |
} |
| 105 |
} |
| 106 |
]; |
| 107 |
|
| 108 |
$self->{maps_counters}->{status} = [ |
| 109 |
{ label => 'member-status', type => 2, critical_default => '%{role} ne %{roleLast} || %{status} !~ /ready|booting/i', set => { |
| 110 |
key_values => [ { name => 'role' }, { name => 'status' }, { name => 'id' } ], |
| 111 |
closure_custom_calc => $self->can('custom_member_status_calc'), |
| 112 |
closure_custom_output => $self->can('custom_member_status_output'), |
| 113 |
closure_custom_perfdata => sub { return 0; }, |
| 114 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 115 |
} |
| 116 |
} |
| 117 |
]; |
| 118 |
|
| 119 |
$self->{maps_counters}->{cpu} = [ |
| 120 |
{ label => 'cpu-utilization', nlabel => 'member.cpu.utilization.percentage', set => { |
| 121 |
key_values => [ { name => 'cpu_util' } ], |
| 122 |
output_template => 'cpu usage: %.2f%%', |
| 123 |
perfdatas => [ |
| 124 |
{ template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 } |
| 125 |
] |
| 126 |
} |
| 127 |
} |
| 128 |
]; |
| 129 |
|
| 130 |
$self->{maps_counters}->{memory} = [ |
| 131 |
{ label => 'memory-usage-prct', nlabel => 'member.memory.usage.percentage', set => { |
| 132 |
key_values => [ { name => 'mem_used' } ], |
| 133 |
output_template => 'memory used: %.2f %%', |
| 134 |
perfdatas => [ |
| 135 |
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } |
| 136 |
] |
| 137 |
} |
| 138 |
} |
| 139 |
]; |
| 140 |
} |
| 141 |
|
| 142 |
sub new { |
| 143 |
my ($class, %options) = @_; |
| 144 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); |
| 145 |
bless $self, $class; |
| 146 |
|
| 147 |
$options{options}->add_options(arguments => { |
| 148 |
}); |
| 149 |
|
| 150 |
return $self; |
| 151 |
} |
| 152 |
|
| 153 |
my $mapping_member = { |
| 154 |
vsf => { |
| 155 |
status => { oid => '.1.3.6.1.4.1.47196.4.1.1.3.10.0.3.1.3' }, # arubaWiredVsfMemberStatus |
| 156 |
cpu_util => { oid => '.1.3.6.1.4.1.47196.4.1.1.3.10.0.3.1.9' }, # arubaWiredVsfMemberCpuUtil |
| 157 |
mem_used => { oid => '.1.3.6.1.4.1.47196.4.1.1.3.10.0.3.1.10' } # arubaWiredVsfMemberMemoryUtil |
| 158 |
}, |
| 159 |
vsfv2 => { |
| 160 |
status => { oid => '.1.3.6.1.4.1.47196.4.1.1.3.15.1.2.1.3' }, # arubaWiredVsfv2MemberStatus |
| 161 |
cpu_util => { oid => '.1.3.6.1.4.1.47196.4.1.1.3.15.1.2.1.9' }, # arubaWiredVsfv2MemberCpuUtil |
| 162 |
mem_used => { oid => '.1.3.6.1.4.1.47196.4.1.1.3.15.1.2.1.10' } # arubaWiredVsfv2MemberMemoryUtil |
| 163 |
} |
| 164 |
}; |
| 165 |
my $branches = { |
| 166 |
vsf => { |
| 167 |
stack_status => '.1.3.6.1.4.1.47196.4.1.1.3.10.0.2.1', # arubaWiredVsfOperStatus |
| 168 |
member_role => '.1.3.6.1.4.1.47196.4.1.1.3.10.0.3.1.2' # arubaWiredVsfMemberRole |
| 169 |
}, |
| 170 |
vsfv2 => { |
| 171 |
stack_status => '.1.3.6.1.4.1.47196.4.1.1.3.15.1.1.1', # arubaWiredVsfv2OperStatus |
| 172 |
member_role => '.1.3.6.1.4.1.47196.4.1.1.3.15.1.2.1.2' # arubaWiredVsfv2MemberRole |
| 173 |
} |
| 174 |
}; |
| 175 |
|
| 176 |
sub manage_selection { |
| 177 |
my ($self, %options) = @_; |
| 178 |
|
| 179 |
$self->{cache_name} = 'aruba_aoscx_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . |
| 180 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); |
| 181 |
|
| 182 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 183 |
oids => [ |
| 184 |
{ oid => $branches->{vsf}->{stack_status} }, |
| 185 |
{ oid => $branches->{vsf}->{member_role} }, |
| 186 |
{ oid => $branches->{vsfv2}->{stack_status} }, |
| 187 |
{ oid => $branches->{vsfv2}->{member_role} } |
| 188 |
], |
| 189 |
nothing_quit => 1 |
| 190 |
); |
| 191 |
|
| 192 |
my $branch = 'vsf'; |
| 193 |
if (defined($snmp_result->{ $branches->{vsfv2}->{stack_status} }) && scalar(keys %{$snmp_result->{ $branches->{vsfv2}->{stack_status} }}) > 0) { |
| 194 |
$branch = 'vsfv2'; |
| 195 |
} |
| 196 |
|
| 197 |
$self->{global} = { status => $snmp_result->{ $branches->{$branch}->{stack_status} }->{ $branches->{$branch}->{stack_status} . '.0' } }; |
| 198 |
$self->{members} = {}; |
| 199 |
foreach (keys %{$snmp_result->{ $branches->{$branch}->{member_role} }}) { |
| 200 |
/\.(\d+)$/; |
| 201 |
my $number = $1; |
| 202 |
$self->{members}->{$number} = { |
| 203 |
id => $number, |
| 204 |
status => { id => $number, role => $snmp_result->{ $branches->{$branch}->{member_role} }->{$_} }, |
| 205 |
}; |
| 206 |
} |
| 207 |
|
| 208 |
return if (scalar(keys %{$self->{members}}) <= 0); |
| 209 |
|
| 210 |
$options{snmp}->load( |
| 211 |
oids => [ map($_->{oid}, values(%{$mapping_member->{$branch}})) ], |
| 212 |
instances => [ keys %{$self->{members}} ], |
| 213 |
instance_regexp => '^(.*)$' |
| 214 |
); |
| 215 |
$snmp_result = $options{snmp}->get_leef(); |
| 216 |
foreach (keys %{$self->{members}}) { |
| 217 |
my $result = $options{snmp}->map_instance(mapping => $mapping_member->{$branch}, results => $snmp_result, instance => $_); |
| 218 |
|
| 219 |
$self->{members}->{$_}->{status}->{status} = $result->{status}; |
| 220 |
$self->{members}->{$_}->{cpu}->{cpu_util} = $result->{cpu_util}; |
| 221 |
$self->{members}->{$_}->{memory}->{mem_used} = $result->{mem_used}; |
| 222 |
} |
| 223 |
|
| 224 |
} |
| 225 |
|
| 226 |
1; |
| 227 |
|
| 228 |
__END__ |
| 229 |
|
| 230 |
=head1 MODE |
| 231 |
|
| 232 |
Check vsf virtual chassis. |
| 233 |
|
| 234 |
=over 8 |
| 235 |
|
| 236 |
=item B<--unknown-status> |
| 237 |
|
| 238 |
Define the conditions to match for the status to be UNKNOWN. |
| 239 |
You can use the following variables: %{status} |
| 240 |
|
| 241 |
=item B<--warning-status> |
| 242 |
|
| 243 |
Define the conditions to match for the status to be WARNING. |
| 244 |
You can use the following variables: %{status} |
| 245 |
|
| 246 |
=item B<--critical-status> |
| 247 |
|
| 248 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /no_split/i'). |
| 249 |
You can use the following variables: %{status} |
| 250 |
|
| 251 |
=item B<--unknown-member-status> |
| 252 |
|
| 253 |
Define the conditions to match for the status to be UNKNOWN. |
| 254 |
You can use the following variables: %{status}, %{role}, %{roleLast}, %{id} |
| 255 |
|
| 256 |
=item B<--warning-member-status> |
| 257 |
|
| 258 |
Define the conditions to match for the status to be WARNING. |
| 259 |
You can use the following variables: %{status}, %{role}, %{roleLast}, %{id} |
| 260 |
|
| 261 |
=item B<--critical-member-status> |
| 262 |
|
| 263 |
Define the conditions to match for the status to be CRITICAL (default: '%{role} ne %{roleLast} || %{status} !~ /ready|booting/i'). |
| 264 |
You can use the following variables: %{status}, %{role}, %{roleLast}, %{id} |
| 265 |
|
| 266 |
=item B<--warning-*> B<--critical-*> |
| 267 |
|
| 268 |
Thresholds. |
| 269 |
Can be: 'members-total', 'memory-usage-prct', 'cpu-utilization'. |
| 270 |
|
| 271 |
=back |
| 272 |
|
| 273 |
=cut |