| 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 centreon::common::aruba::snmp::mode::controllerstatus; |
| 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 = sprintf("Status is '%s', Role is '%s' [Ip: %s][Version: %s][Location: %s]", |
| 33 |
$self->{result_values}->{status}, |
| 34 |
$self->{result_values}->{role}, |
| 35 |
$self->{result_values}->{ip}, |
| 36 |
$self->{result_values}->{version}, |
| 37 |
$self->{result_values}->{location}); |
| 38 |
return $msg; |
| 39 |
} |
| 40 |
|
| 41 |
sub custom_status_calc { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_sysExtSwitchName'}; |
| 45 |
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_sysExtSwitchStatus'}; |
| 46 |
$self->{result_values}->{role} = $options{new_datas}->{$self->{instance} . '_sysExtSwitchRole'}; |
| 47 |
$self->{result_values}->{ip} = $options{new_datas}->{$self->{instance} . '_sysExtSwitchIPAddress'}; |
| 48 |
$self->{result_values}->{version} = $options{new_datas}->{$self->{instance} . '_sysExtSwitchSWVersion'}; |
| 49 |
$self->{result_values}->{location} = $options{new_datas}->{$self->{instance} . '_sysExtSwitchLocation'}; |
| 50 |
return 0; |
| 51 |
} |
| 52 |
|
| 53 |
sub set_counters { |
| 54 |
my ($self, %options) = @_; |
| 55 |
|
| 56 |
$self->{maps_counters_type} = [ |
| 57 |
{ name => 'global', type => 0, cb_init => 'skip_global' }, |
| 58 |
{ name => 'controllers', type => 1, cb_prefix_output => 'prefix_output', |
| 59 |
message_multiple => 'All controllers status are ok' }, |
| 60 |
]; |
| 61 |
|
| 62 |
$self->{maps_counters}->{global} = [ |
| 63 |
{ label => 'connected-current', nlabel => 'controllers.connected.current.count', set => { |
| 64 |
key_values => [ { name => 'current' } ], |
| 65 |
output_template => 'Total controllers: %d', |
| 66 |
perfdatas => [ |
| 67 |
{ value => 'current', template => '%d', min => 0 }, |
| 68 |
], |
| 69 |
} |
| 70 |
}, |
| 71 |
]; |
| 72 |
|
| 73 |
$self->{maps_counters}->{controllers} = [ |
| 74 |
{ label => 'status', threshold => 0, set => { |
| 75 |
key_values => [ { name => 'sysExtSwitchIPAddress' }, { name => 'sysExtSwitchName' }, |
| 76 |
{ name => 'sysExtSwitchLocation' }, { name => 'sysExtSwitchSWVersion' }, |
| 77 |
{ name => 'sysExtSwitchRole' }, { name => 'sysExtSwitchStatus' } ], |
| 78 |
closure_custom_calc => $self->can('custom_status_calc'), |
| 79 |
closure_custom_output => $self->can('custom_status_output'), |
| 80 |
closure_custom_perfdata => sub { return 0; }, |
| 81 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 82 |
} |
| 83 |
}, |
| 84 |
]; |
| 85 |
} |
| 86 |
|
| 87 |
sub skip_global { |
| 88 |
my ($self, %options) = @_; |
| 89 |
|
| 90 |
scalar(keys %{$self->{controllers}}) > 1 ? return(0) : return(1); |
| 91 |
} |
| 92 |
|
| 93 |
sub prefix_output { |
| 94 |
my ($self, %options) = @_; |
| 95 |
|
| 96 |
return "Controller '" . $options{instance_value}->{sysExtSwitchName} . "' "; |
| 97 |
} |
| 98 |
|
| 99 |
sub new { |
| 100 |
my ($class, %options) = @_; |
| 101 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 102 |
bless $self, $class; |
| 103 |
|
| 104 |
$options{options}->add_options(arguments => { |
| 105 |
"filter-name:s" => { name => 'filter_name' }, |
| 106 |
"filter-ip:s" => { name => 'filter_ip' }, |
| 107 |
"filter-location:s" => { name => 'filter_location' }, |
| 108 |
"warning-status:s" => { name => 'warning_status' }, |
| 109 |
"critical-status:s" => { name => 'critical_status', default => '%{status} !~ /active/i' }, |
| 110 |
}); |
| 111 |
|
| 112 |
return $self; |
| 113 |
} |
| 114 |
|
| 115 |
sub check_options { |
| 116 |
my ($self, %options) = @_; |
| 117 |
$self->SUPER::check_options(%options); |
| 118 |
|
| 119 |
$self->change_macros(macros => ['warning_status', 'critical_status']); |
| 120 |
} |
| 121 |
|
| 122 |
my %map_status = ( |
| 123 |
1 => 'active', 2 => 'inactive' |
| 124 |
); |
| 125 |
my %map_role = ( |
| 126 |
1 => 'master', 2 => 'local', 3 => 'backupmaster' |
| 127 |
); |
| 128 |
|
| 129 |
my $oid_wlsxSysExtSwitchListTable = '.1.3.6.1.4.1.14823.2.2.1.2.1.19.1'; |
| 130 |
|
| 131 |
my $mapping = { |
| 132 |
sysExtSwitchRole => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.19.1.2', map => \%map_role }, |
| 133 |
sysExtSwitchLocation=> { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.19.1.3' }, |
| 134 |
sysExtSwitchSWVersion => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.19.1.4' }, |
| 135 |
sysExtSwitchStatus => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.19.1.5', map => \%map_status }, |
| 136 |
sysExtSwitchName => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.19.1.6' }, |
| 137 |
}; |
| 138 |
sub manage_selection { |
| 139 |
my ($self, %options) = @_; |
| 140 |
|
| 141 |
my $snmp_result = $options{snmp}->get_table( |
| 142 |
oid => $oid_wlsxSysExtSwitchListTable, |
| 143 |
start => $mapping->{sysExtSwitchRole}->{oid}, |
| 144 |
end => $mapping->{sysExtSwitchName}->{oid}, |
| 145 |
nothing_quit => 1 |
| 146 |
); |
| 147 |
|
| 148 |
$self->{global}->{current} = 0; |
| 149 |
$self->{controllers} = {}; |
| 150 |
|
| 151 |
foreach my $oid (keys %{$snmp_result}) { |
| 152 |
next if ($oid !~ /^$mapping->{sysExtSwitchRole}->{oid}\.(.*)/); |
| 153 |
my $instance = $1; |
| 154 |
|
| 155 |
my $result = $options{snmp}->map_instance( |
| 156 |
mapping => $mapping, |
| 157 |
results => $snmp_result, |
| 158 |
instance => $instance |
| 159 |
); |
| 160 |
$result->{sysExtSwitchIPAddress} = $instance; |
| 161 |
|
| 162 |
if (defined($self->{option_results}->{filter_ip}) && $self->{option_results}->{filter_ip} ne '' && |
| 163 |
$result->{sysExtSwitchIPAddress} !~ /$self->{option_results}->{filter_ip}/) { |
| 164 |
$self->{output}->output_add(long_msg => "skipping '" . $result->{sysExtSwitchIPAddress} . "': no matching filter ip.", debug => 1); |
| 165 |
next; |
| 166 |
} |
| 167 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 168 |
$result->{sysExtSwitchName} !~ /$self->{option_results}->{filter_name}/) { |
| 169 |
$self->{output}->output_add(long_msg => "skipping '" . $result->{sysExtSwitchName} . "': no matching filter name.", debug => 1); |
| 170 |
next; |
| 171 |
} |
| 172 |
if (defined($self->{option_results}->{filter_location}) && $self->{option_results}->{filter_location} ne '' && |
| 173 |
$result->{sysExtSwitchLocation} !~ /$self->{option_results}->{filter_location}/) { |
| 174 |
$self->{output}->output_add(long_msg => "skipping '" . $result->{sysExtSwitchLocation} . "': no matching filter location.", debug => 1); |
| 175 |
next; |
| 176 |
} |
| 177 |
|
| 178 |
$self->{controllers}->{$result->{sysExtSwitchName}} = { %{$result} }; |
| 179 |
$self->{global}->{current}++; |
| 180 |
} |
| 181 |
|
| 182 |
if (scalar(keys %{$self->{controllers}}) <= 0) { |
| 183 |
$self->{output}->add_option_msg(short_msg => "No controller found."); |
| 184 |
$self->{output}->option_exit(); |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
1; |
| 189 |
|
| 190 |
__END__ |
| 191 |
|
| 192 |
=head1 MODE |
| 193 |
|
| 194 |
Check controller status (WLSX-SYSTEMEXT-MIB). |
| 195 |
(Works only on master controller). |
| 196 |
|
| 197 |
=over 8 |
| 198 |
|
| 199 |
=item B<--warning-*> |
| 200 |
|
| 201 |
Warning threshold. |
| 202 |
Can be: 'connected-current' (global), 'status' (per controller). |
| 203 |
'status' can use special variables like: %{name}, |
| 204 |
%{status}, %{ip}, %{role}, %{location} (default: '') |
| 205 |
|
| 206 |
=item B<--critical-*> |
| 207 |
|
| 208 |
Critical threshold. |
| 209 |
Can be: 'connected-current' (global), 'status' (per controller). |
| 210 |
'status' can use special variables like: %{name}, |
| 211 |
%{status}, %{ip}, %{role}, %{location} (default: '%{status} !~ /active/i') |
| 212 |
|
| 213 |
=item B<--filter-*> |
| 214 |
|
| 215 |
Filter by 'ip', 'name', 'location' (regexp can be used). |
| 216 |
|
| 217 |
=back |
| 218 |
|
| 219 |
=cut |