| 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 apps::pfsense::snmp::mode::listpfinterfaces; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
my $oid_pfInterfacesIfDescr = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.2'; |
| 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 |
return $self; |
| 39 |
} |
| 40 |
|
| 41 |
sub check_options { |
| 42 |
my ($self, %options) = @_; |
| 43 |
$self->SUPER::init(%options); |
| 44 |
} |
| 45 |
|
| 46 |
sub manage_selection { |
| 47 |
my ($self, %options) = @_; |
| 48 |
|
| 49 |
my $snmp_result = $self->{snmp}->get_table(oid => $oid_pfInterfacesIfDescr, nothing_quit => 1); |
| 50 |
$self->{pfint} = {}; |
| 51 |
foreach my $oid (keys %{$snmp_result}) { |
| 52 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 53 |
$snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) { |
| 54 |
$self->{output}->output_add(long_msg => "skipping pfInteface '" . $snmp_result->{$oid} . "'.", debug => 1); |
| 55 |
next; |
| 56 |
} |
| 57 |
|
| 58 |
$self->{pfint}->{$snmp_result->{$oid}} = { name => $snmp_result->{$oid} }; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
sub run { |
| 63 |
my ($self, %options) = @_; |
| 64 |
$self->{snmp} = $options{snmp}; |
| 65 |
|
| 66 |
$self->manage_selection(); |
| 67 |
foreach my $name (sort keys %{$self->{pfint}}) { |
| 68 |
$self->{output}->output_add(long_msg => "'" . $name . "'"); |
| 69 |
} |
| 70 |
|
| 71 |
$self->{output}->output_add(severity => 'OK', |
| 72 |
short_msg => 'List pfIntefaces:'); |
| 73 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); |
| 74 |
$self->{output}->exit(); |
| 75 |
} |
| 76 |
|
| 77 |
sub disco_format { |
| 78 |
my ($self, %options) = @_; |
| 79 |
|
| 80 |
$self->{output}->add_disco_format(elements => ['name']); |
| 81 |
} |
| 82 |
|
| 83 |
sub disco_show { |
| 84 |
my ($self, %options) = @_; |
| 85 |
$self->{snmp} = $options{snmp}; |
| 86 |
|
| 87 |
$self->manage_selection(); |
| 88 |
foreach my $name (sort keys %{$self->{pfint}}) { |
| 89 |
$self->{output}->add_disco_entry(name => $name); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
1; |
| 94 |
|
| 95 |
__END__ |
| 96 |
|
| 97 |
=head1 MODE |
| 98 |
|
| 99 |
List pfInteface. |
| 100 |
|
| 101 |
=over 8 |
| 102 |
|
| 103 |
=item B<--filter-name> |
| 104 |
|
| 105 |
Filter by pfinterface name. |
| 106 |
|
| 107 |
=back |
| 108 |
|
| 109 |
=cut |
| 110 |
|