| 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::f5::bigip::snmp::mode::listpools; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
my $oid_ltmPoolStatusName = '.1.3.6.1.4.1.3375.2.2.5.5.2.1.1'; |
| 29 |
|
| 30 |
sub new { |
| 31 |
my ($class, %options) = @_; |
| 32 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 33 |
bless $self, $class; |
| 34 |
|
| 35 |
$options{options}->add_options(arguments => { |
| 36 |
'filter-name:s' => { name => 'filter_name' } |
| 37 |
}); |
| 38 |
|
| 39 |
return $self; |
| 40 |
} |
| 41 |
|
| 42 |
sub check_options { |
| 43 |
my ($self, %options) = @_; |
| 44 |
$self->SUPER::init(%options); |
| 45 |
} |
| 46 |
|
| 47 |
sub manage_selection { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
my $map_pool_status = { |
| 51 |
0 => 'none', 1 => 'green', |
| 52 |
2 => 'yellow', 3 => 'red', |
| 53 |
4 => 'blue', 5 => 'gray', |
| 54 |
}; |
| 55 |
my $map_pool_enabled = { |
| 56 |
0 => 'none', 1 => 'enabled', 2 => 'disabled', 3 => 'disabledbyparent', |
| 57 |
}; |
| 58 |
my $mapping = { |
| 59 |
AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.5.5.2.1.2', map => $map_pool_status }, |
| 60 |
EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.5.5.2.1.3', map => $map_pool_enabled }, |
| 61 |
}; |
| 62 |
my $oid_ltmPoolStatusEntry = '.1.3.6.1.4.1.3375.2.2.5.5.2.1'; |
| 63 |
|
| 64 |
my $snmp_result = $options{snmp}->get_table( |
| 65 |
oid => $oid_ltmPoolStatusEntry, |
| 66 |
start => $mapping->{AvailState}->{oid}, |
| 67 |
end => $mapping->{EnabledState}->{oid}, |
| 68 |
nothing_quit => 1 |
| 69 |
); |
| 70 |
my $results = {}; |
| 71 |
foreach my $oid (keys %$snmp_result) { |
| 72 |
next if ($oid !~ /^$mapping->{AvailState}->{oid}\.(.*?)\.(.*)$/); |
| 73 |
my ($num, $index) = ($1, $2); |
| 74 |
|
| 75 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $num . '.' . $index); |
| 76 |
my $name = $self->{output}->decode(join('', map(chr($_), split(/\./, $index)))); |
| 77 |
|
| 78 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 79 |
$name !~ /$self->{option_results}->{filter_name}/) { |
| 80 |
$self->{output}->output_add(long_msg => "skipping pool '" . $name . "'.", debug => 1); |
| 81 |
next; |
| 82 |
} |
| 83 |
|
| 84 |
$results->{$name} = { |
| 85 |
status => $result->{AvailState}, |
| 86 |
state => $result->{EnabledState}, |
| 87 |
}; |
| 88 |
} |
| 89 |
|
| 90 |
return $results; |
| 91 |
} |
| 92 |
|
| 93 |
sub run { |
| 94 |
my ($self, %options) = @_; |
| 95 |
$self->{snmp} = $options{snmp}; |
| 96 |
|
| 97 |
my $results = $self->manage_selection(snmp => $options{snmp}); |
| 98 |
foreach my $name (sort keys %$results) { |
| 99 |
$self->{output}->output_add( |
| 100 |
long_msg => sprintf( |
| 101 |
'[name: %s] [status: %s] [state: %s]', |
| 102 |
$name, |
| 103 |
$results->{$name}->{status}, |
| 104 |
$results->{$name}->{state}, |
| 105 |
) |
| 106 |
); |
| 107 |
} |
| 108 |
|
| 109 |
$self->{output}->output_add(severity => 'OK', |
| 110 |
short_msg => 'List pools:'); |
| 111 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); |
| 112 |
$self->{output}->exit(); |
| 113 |
} |
| 114 |
|
| 115 |
sub disco_format { |
| 116 |
my ($self, %options) = @_; |
| 117 |
|
| 118 |
$self->{output}->add_disco_format(elements => ['name', 'status', 'state']); |
| 119 |
} |
| 120 |
|
| 121 |
sub disco_show { |
| 122 |
my ($self, %options) = @_; |
| 123 |
|
| 124 |
my $results = $self->manage_selection(snmp => $options{snmp}); |
| 125 |
foreach my $name (sort keys %$results) { |
| 126 |
$self->{output}->add_disco_entry( |
| 127 |
name => $name, |
| 128 |
status => $results->{$name}->{status}, |
| 129 |
state => $results->{$name}->{state} |
| 130 |
); |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
1; |
| 135 |
|
| 136 |
__END__ |
| 137 |
|
| 138 |
=head1 MODE |
| 139 |
|
| 140 |
List F-5 Pools. |
| 141 |
|
| 142 |
=over 8 |
| 143 |
|
| 144 |
=item B<--filter-name> |
| 145 |
|
| 146 |
Filter pool name. |
| 147 |
|
| 148 |
=back |
| 149 |
|
| 150 |
=cut |
| 151 |
|