Debian Codegraph @

src/network/kemp/snmp/mode/listvs.pm

raw
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::kemp::snmp::mode::listvs;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 sub new {
29 my ($class, %options) = @_;
30 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
31 bless $self, $class;
32
33 $options{options}->add_options(arguments =>
34 {
35 "filter-name:s" => { name => 'filter_name' },
36 });
37 $self->{vs_id_selected} = [];
38
39 return $self;
40 }
41
42 sub check_options {
43 my ($self, %options) = @_;
44 $self->SUPER::init(%options);
45 }
46
47 my %map_state = (
48 1 => 'inService',
49 2 => 'outOfService',
50 4 => 'disabled',
51 5 => 'sorry',
52 6 => 'redirect',
53 7 => 'errormsg',
54 );
55 my $mapping = {
56 vSname => { oid => '.1.3.6.1.4.1.12196.13.1.1.13' },
57 vSstate => { oid => '.1.3.6.1.4.1.12196.13.1.1.14', map => \%map_state },
58 };
59
60 sub manage_selection {
61 my ($self, %options) = @_;
62
63 $self->{results} = $self->{snmp}->get_multiple_table(oids => [ { oid => $mapping->{vSname}->{oid} }, { oid => $mapping->{vSstate}->{oid} } ],
64 nothing_quit => 1, return_type => 1);
65 foreach my $oid (keys %{$self->{results}}) {
66 next if ($oid !~ /^$mapping->{vSname}->{oid}\.(.*)$/);
67 my $instance = $1;
68 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance);
69
70 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
71 $result->{vSname} !~ /$self->{option_results}->{filter_name}/) {
72 $self->{output}->output_add(long_msg => "skipping '" . $result->{vSname} . "': no matching filter.", debug => 1);
73 next;
74 }
75
76 push @{$self->{vs_id_selected}}, $instance;
77 }
78 }
79
80 sub run {
81 my ($self, %options) = @_;
82
83 $self->{snmp} = $options{snmp};
84 $self->manage_selection();
85 foreach my $instance (sort @{$self->{vs_id_selected}}) {
86 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance);
87
88 $self->{output}->output_add(long_msg => "'" . $result->{vSname} . "' [state = " . $result->{vSstate} . "]");
89 }
90
91 $self->{output}->output_add(severity => 'OK',
92 short_msg => 'List Virtual Servers:');
93 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
94 $self->{output}->exit();
95 }
96
97 sub disco_format {
98 my ($self, %options) = @_;
99
100 $self->{output}->add_disco_format(elements => ['name', 'state']);
101 }
102
103 sub disco_show {
104 my ($self, %options) = @_;
105 $self->{snmp} = $options{snmp};
106
107 $self->manage_selection(disco => 1);
108 foreach my $instance (sort @{$self->{vs_id_selected}}) {
109 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance);
110
111 $self->{output}->add_disco_entry(name => $result->{vSname}, state => $result->{vSstate});
112 }
113 }
114
115 1;
116
117 __END__
118
119 =head1 MODE
120
121 List virtual servers.
122
123 =over 8
124
125 =item B<--filter-name>
126
127 Set the virtual server name.
128
129 =back
130
131 =cut
132