| 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::cisco::wap::snmp::mode::virtualaccesspoints; |
| 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 sprintf( |
| 33 |
'operational status: %s [admin: %s]', |
| 34 |
$self->{result_values}->{operational_status}, |
| 35 |
$self->{result_values}->{admin_status} |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
sub prefix_vap_output { |
| 40 |
my ($self, %options) = @_; |
| 41 |
|
| 42 |
return sprintf( |
| 43 |
"Virtual access point '%s' ", |
| 44 |
$options{instance_value}->{description} |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
sub set_counters { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
$self->{maps_counters_type} = [ |
| 52 |
{ name => 'global', type => 0 }, |
| 53 |
{ name => 'vaps', type => 1, cb_prefix_output => 'prefix_vap_output', message_multiple => 'All virtual access points are ok' } |
| 54 |
]; |
| 55 |
|
| 56 |
$self->{maps_counters}->{global} = [ |
| 57 |
{ label => 'total', nlabel => 'virtual_access_points.total.count', display_ok => 0, set => { |
| 58 |
key_values => [ { name => 'total' } ], |
| 59 |
output_template => 'total: %s', |
| 60 |
perfdatas => [ |
| 61 |
{ template => '%s', min => 0 } |
| 62 |
] |
| 63 |
} |
| 64 |
} |
| 65 |
]; |
| 66 |
|
| 67 |
$self->{maps_counters}->{vaps} = [ |
| 68 |
{ |
| 69 |
label => 'status', type => 2, critical_default => '%{admin_status} eq "up" and %{operational_status} eq "down"', |
| 70 |
set => { |
| 71 |
key_values => [ |
| 72 |
{ name => 'description' }, { name => 'admin_status' }, |
| 73 |
{ name => 'operational_status' } |
| 74 |
], |
| 75 |
closure_custom_output => $self->can('custom_status_output'), |
| 76 |
closure_custom_perfdata => sub { return 0; }, |
| 77 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 78 |
} |
| 79 |
} |
| 80 |
]; |
| 81 |
} |
| 82 |
|
| 83 |
sub new { |
| 84 |
my ($class, %options) = @_; |
| 85 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 86 |
bless $self, $class; |
| 87 |
|
| 88 |
$options{options}->add_options(arguments => { |
| 89 |
'filter-description:s' => { name => 'filter_description' } |
| 90 |
}); |
| 91 |
|
| 92 |
return $self; |
| 93 |
} |
| 94 |
|
| 95 |
my $map_status = { 0 => 'down', 1 => 'up' }; |
| 96 |
|
| 97 |
my $mapping = { |
| 98 |
admin_status => { oid => '.1.3.6.1.4.1.9.6.1.104.1.4.1.1.3', map => $map_status }, # apVapStatus |
| 99 |
operational_status => { oid => '.1.3.6.1.4.1.9.6.1.104.1.4.1.1.14', map => $map_status }, # apVapOperationalStatus |
| 100 |
}; |
| 101 |
|
| 102 |
sub manage_selection { |
| 103 |
my ($self, %options) = @_; |
| 104 |
|
| 105 |
my $oid_description = '.1.3.6.1.4.1.9.6.1.104.1.4.1.1.5'; # apVapDescription |
| 106 |
my $snmp_result = $options{snmp}->get_table( |
| 107 |
oid => $oid_description, |
| 108 |
nothing_quit => 1 |
| 109 |
); |
| 110 |
|
| 111 |
$self->{vaps} = {}; |
| 112 |
foreach (keys %$snmp_result) { |
| 113 |
/^$oid_description\.(.*)$/; |
| 114 |
my $instance = $1; |
| 115 |
|
| 116 |
if (defined($self->{option_results}->{filter_description}) && $self->{option_results}->{filter_description} ne '' && |
| 117 |
$snmp_result->{$_} !~ /$self->{option_results}->{filter_description}/) { |
| 118 |
$self->{output}->output_add(long_msg => "skipping '" . $snmp_result->{$_} . "': no matching filter.", debug => 1); |
| 119 |
next; |
| 120 |
} |
| 121 |
|
| 122 |
$self->{vaps}->{$instance} = { |
| 123 |
description => $snmp_result->{$_} |
| 124 |
}; |
| 125 |
} |
| 126 |
|
| 127 |
$self->{global} = { total => scalar(keys %{$self->{vaps}}) }; |
| 128 |
|
| 129 |
return if (scalar(keys %{$self->{vaps}}) <= 0); |
| 130 |
|
| 131 |
$options{snmp}->load(oids => [ |
| 132 |
map($_->{oid}, values(%$mapping)) |
| 133 |
], |
| 134 |
instances => [keys %{$self->{vaps}}], |
| 135 |
instance_regexp => '^(.*)$' |
| 136 |
); |
| 137 |
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1); |
| 138 |
|
| 139 |
foreach (keys %{$self->{vaps}}) { |
| 140 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); |
| 141 |
|
| 142 |
$self->{vaps}->{$_} = { %{$self->{vaps}->{$_}}, %$result }; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
1; |
| 147 |
|
| 148 |
__END__ |
| 149 |
|
| 150 |
=head1 MODE |
| 151 |
|
| 152 |
Check virtual access points. |
| 153 |
|
| 154 |
=over 8 |
| 155 |
|
| 156 |
=item B<--filter-counters> |
| 157 |
|
| 158 |
Only display some counters (regexp can be used). |
| 159 |
Example: --filter-counters='status' |
| 160 |
|
| 161 |
=item B<--filter-description> |
| 162 |
|
| 163 |
Filter virtual access points by description (can be a regexp). |
| 164 |
|
| 165 |
=item B<--unknown-status> |
| 166 |
|
| 167 |
Define the conditions to match for the status to be UNKNOWN. |
| 168 |
You can use the following variables: %{description}, %{admin_status}, %{operational_status} |
| 169 |
|
| 170 |
=item B<--warning-status> |
| 171 |
|
| 172 |
Define the conditions to match for the status to be WARNING. |
| 173 |
You can use the following variables: %{description}, %{admin_status}, %{operational_status} |
| 174 |
|
| 175 |
=item B<--critical-status> |
| 176 |
|
| 177 |
Define the conditions to match for the status to be CRITICAL (default: '%{admin_status} eq "up" and %{operational_status} eq "down"'). |
| 178 |
You can use the following variables: %{description}, %{admin_status}, %{operational_status} |
| 179 |
|
| 180 |
=item B<--warning-*> B<--critical-*> |
| 181 |
|
| 182 |
Thresholds. |
| 183 |
Can be: 'total'. |
| 184 |
|
| 185 |
=back |
| 186 |
|
| 187 |
=cut |