Debian Codegraph @

src/centreon/common/fortinet/fortigate/snmp/mode/listvirtualdomains.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 centreon::common::fortinet::fortigate::snmp::mode::listvirtualdomains;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 my $oid_fgVdEntName = '.1.3.6.1.4.1.12356.101.3.2.1.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 'name:s' => { name => 'name' },
37 'regexp' => { name => 'use_regexp' }
38 });
39 $self->{virtualdomain_id_selected} = [];
40
41 return $self;
42 }
43
44 sub check_options {
45 my ($self, %options) = @_;
46 $self->SUPER::init(%options);
47 }
48
49 sub manage_selection {
50 my ($self, %options) = @_;
51
52 $self->{result_names} = $self->{snmp}->get_table(oid => $oid_fgVdEntName, nothing_quit => 1);
53 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{result_names}})) {
54 next if ($oid !~ /\.([0-9]+)$/);
55 my $instance = $1;
56
57 # Get all without a name
58 if (!defined($self->{option_results}->{name})) {
59 push @{$self->{virtualdomain_id_selected}}, $instance;
60 next;
61 }
62
63 if (!defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} ne $self->{option_results}->{name}) {
64 $self->{output}->output_add(long_msg => "Skipping virtualdomain '" . $self->{result_names}->{$oid} . "': no matching filter name");
65 next;
66 }
67 if (defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} !~ /$self->{option_results}->{name}/) {
68 $self->{output}->output_add(long_msg => "Skipping virtualdomain '" . $self->{result_names}->{$oid} . "': no matching filter name (regexp)");
69 next;
70 }
71
72 push @{$self->{virtualdomain_id_selected}}, $instance;
73 }
74 }
75
76 sub run {
77 my ($self, %options) = @_;
78 $self->{snmp} = $options{snmp};
79
80 $self->manage_selection();
81 foreach my $instance (sort @{$self->{virtualdomain_id_selected}}) {
82 my $name = $self->{result_names}->{$oid_fgVdEntName . '.' . $instance};
83
84 $self->{output}->output_add(long_msg => "'" . $name . "'");
85 }
86
87 $self->{output}->output_add(
88 severity => 'OK',
89 short_msg => 'List virtualdomains:'
90 );
91 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
92 $self->{output}->exit();
93 }
94
95 sub disco_format {
96 my ($self, %options) = @_;
97
98 $self->{output}->add_disco_format(elements => ['name']);
99 }
100
101 sub disco_show {
102 my ($self, %options) = @_;
103 $self->{snmp} = $options{snmp};
104
105 $self->manage_selection();
106 foreach my $instance (sort @{$self->{virtualdomain_id_selected}}) {
107 my $name = $self->{result_names}->{$oid_fgVdEntName . '.' . $instance};
108 $self->{output}->add_disco_entry(name => $name);
109 }
110 }
111
112 1;
113
114 __END__
115
116 =head1 MODE
117
118 List filesystems (volumes and aggregates also).
119
120 =over 8
121
122 =item B<--name>
123
124 Set the virtualdomain name.
125
126 =item B<--regexp>
127
128 Allows to use regexp to filter virtualdomain name (with option --name).
129
130 =back
131
132 =cut