Debian Codegraph @

src/network/radware/alteon/snmp/mode/listvservers.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::radware::alteon::snmp::mode::listvservers;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 my %map_state = (
29 2 => 'enabled',
30 3 => 'disabled',
31 );
32
33 my $mapping = {
34 slbCurCfgVirtServerState => { oid => '.1.3.6.1.4.1.1872.2.5.4.1.1.4.2.1.4', map => \%map_state },
35 slbCurCfgVirtServerVname => { oid => '.1.3.6.1.4.1.1872.2.5.4.1.1.4.2.1.10' },
36 };
37
38 sub new {
39 my ($class, %options) = @_;
40 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
41 bless $self, $class;
42
43 $options{options}->add_options(arguments =>
44 {
45 "filter-name:s" => { name => 'filter_name' },
46 });
47 return $self;
48 }
49
50 sub check_options {
51 my ($self, %options) = @_;
52 $self->SUPER::init(%options);
53 }
54
55 sub manage_selection {
56 my ($self, %options) = @_;
57
58 my $snmp_result = $self->{snmp}->get_multiple_table(oids => [
59 { oid => $mapping->{slbCurCfgVirtServerState}->{oid} },
60 { oid => $mapping->{slbCurCfgVirtServerVname}->{oid} },
61 ], return_type => 1, nothing_quit => 1);
62 $self->{vservers} = {};
63 foreach my $oid (keys %{$snmp_result}) {
64 next if ($oid !~ /^$mapping->{slbCurCfgVirtServerVname}->{oid}\.(.*)$/);
65 my $instance = $1;
66 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
67
68 if (!defined($result->{slbCurCfgVirtServerVname}) || $result->{slbCurCfgVirtServerVname} eq '') {
69 $self->{output}->output_add(long_msg => "skipping Virtual Server '$instance': cannot get a name. please set it.", debug => 1);
70 next;
71 }
72 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
73 $result->{slbCurCfgVirtServerVname} !~ /$self->{option_results}->{filter_name}/) {
74 $self->{output}->output_add(long_msg => "skipping Virtual Server '" . $result->{slbCurCfgVirtServerVname} . "'.", debug => 1);
75 next;
76 }
77
78 $self->{vservers}->{$instance} = { name => $result->{slbCurCfgVirtServerVname}, state => $result->{slbCurCfgVirtServerState} };
79 }
80 }
81
82 sub run {
83 my ($self, %options) = @_;
84 $self->{snmp} = $options{snmp};
85
86 $self->manage_selection();
87 foreach my $instance (sort keys %{$self->{vservers}}) {
88 $self->{output}->output_add(long_msg => "'" . $self->{vservers}->{$instance}->{name} . "' [state = '" . $self->{vservers}->{$instance}->{state} . "']");
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();
108 foreach my $instance (sort keys %{$self->{vservers}}) {
109 $self->{output}->add_disco_entry(name => $self->{vservers}->{$instance}->{name}, state => $self->{vservers}->{$instance}->{state});
110 }
111 }
112
113 1;
114
115 __END__
116
117 =head1 MODE
118
119 List Virtual Servers.
120
121 =over 8
122
123 =item B<--filter-name>
124
125 Filter by virtual server name.
126
127 =back
128
129 =cut
130