Debian Codegraph @

src/network/citrix/netscaler/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::citrix::netscaler::snmp::mode::listvservers;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 my $oid_vsvrFullName = '.1.3.6.1.4.1.5951.4.1.3.1.1.59';
29 my $oid_vsvrEntityType = '.1.3.6.1.4.1.5951.4.1.3.1.1.64';
30
31 my %map_vs_type = (
32 0 => 'unknown',
33 1 => 'loadbalancing',
34 2 => 'loadbalancinggroup',
35 3 => 'sslvpn',
36 4 => 'contentswitching',
37 5 => 'cacheredirection'
38 );
39
40 sub new {
41 my ($class, %options) = @_;
42 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
43 bless $self, $class;
44
45 $options{options}->add_options(arguments => {
46 'name:s' => { name => 'name' },
47 'regexp' => { name => 'use_regexp' },
48 'filter-type:s' => { name => 'filter_type' }
49 });
50
51 $self->{vs_id_selected} = [];
52
53 return $self;
54 }
55
56 sub check_options {
57 my ($self, %options) = @_;
58 $self->SUPER::init(%options);
59 }
60
61 sub manage_selection {
62 my ($self, %options) = @_;
63
64 $self->{results} = $self->{snmp}->get_multiple_table(oids => [ { oid => $oid_vsvrFullName}, { oid => $oid_vsvrEntityType } ], nothing_quit => 1);
65 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_vsvrFullName}})) {
66 next if ($oid !~ /^$oid_vsvrFullName\.(.*)$/);
67 my $instance = $1;
68 my $name = $self->{results}->{$oid_vsvrFullName}->{$oid};
69 my $type = $self->{results}->{$oid_vsvrEntityType}->{$oid_vsvrEntityType . '.' . $instance};
70
71 next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
72 $map_vs_type{$type} !~ /$self->{option_results}->{filter_type}/);
73
74 # Get all without a name
75 if (!defined($self->{option_results}->{name})) {
76 push @{$self->{vs_id_selected}}, $instance;
77 next;
78 }
79
80 $name = $self->{output}->decode($name);
81 if (!defined($self->{option_results}->{use_regexp}) && $name eq $self->{option_results}->{name}) {
82 push @{$self->{vs_id_selected}}, $instance;
83 next;
84 }
85 if (defined($self->{option_results}->{use_regexp}) && $name =~ /$self->{option_results}->{name}/) {
86 push @{$self->{vs_id_selected}}, $instance;
87 next;
88 }
89
90 $self->{output}->output_add(long_msg => "Skipping virtual server '" . $name . "': no matching filter name");
91 }
92 }
93
94 sub run {
95 my ($self, %options) = @_;
96 $self->{snmp} = $options{snmp};
97
98 $self->manage_selection();
99 foreach my $instance (sort @{$self->{vs_id_selected}}) {
100 my $name = $self->{results}->{$oid_vsvrFullName}->{$oid_vsvrFullName . '.' . $instance};
101 my $type = $self->{results}->{$oid_vsvrEntityType}->{$oid_vsvrEntityType . '.' . $instance};
102
103 $self->{output}->output_add(long_msg => "'" . $name . "' [type = '" . $map_vs_type{$type} . "']");
104 }
105
106 $self->{output}->output_add(severity => 'OK',
107 short_msg => 'List Virtual Servers:');
108 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
109 $self->{output}->exit();
110 }
111
112 sub disco_format {
113 my ($self, %options) = @_;
114
115 $self->{output}->add_disco_format(elements => ['name', 'type']);
116 }
117
118 sub disco_show {
119 my ($self, %options) = @_;
120 $self->{snmp} = $options{snmp};
121
122 $self->manage_selection();
123 foreach my $instance (sort @{$self->{vs_id_selected}}) {
124 my $name = $self->{results}->{$oid_vsvrFullName}->{$oid_vsvrFullName . '.' . $instance};
125 my $type = $self->{results}->{$oid_vsvrEntityType}->{$oid_vsvrEntityType . '.' . $instance};
126
127 $self->{output}->add_disco_entry(name => $name, type => $map_vs_type{$type});
128 }
129 }
130
131 1;
132
133 __END__
134
135 =head1 MODE
136
137 List Virtual Servers.
138
139 =over 8
140
141 =item B<--name>
142
143 Set the virtual server name.
144
145 =item B<--regexp>
146
147 Allows to use regexp to filter virtual server name (with option --name).
148
149 =item B<--filter-type>
150
151 Filter which type of vserver (can be a regexp).
152
153 =back
154
155 =cut
156