Debian Codegraph @

src/network/oracle/infiniband/snmp/mode/listinfinibands.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::oracle::infiniband::snmp::mode::listinfinibands;
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-ib-name:s" => { name => 'filter_ib_name' },
36 "filter-ibgw-:s" => { name => 'filter_ibgw_name' },
37 });
38 $self->{shares} = {};
39
40 return $self;
41 }
42
43 sub check_options {
44 my ($self, %options) = @_;
45 $self->SUPER::init(%options);
46 }
47
48 my %map_link_state = (1 => 'down', 2 => 'init', 3 => 'armed', 4 => 'active', 5 => 'other');
49 my %map_gw_link_state = (0 => 'down', 1 => 'up');
50 my $mapping = {
51 ibSmaPortLinkState => { oid => '.1.3.6.1.4.1.42.2.135.2.2.5.1.1.6', map => \%map_link_state },
52 };
53 my $mapping2 = {
54 gwPortLongName => { oid => '.1.3.6.1.4.1.42.2.135.2.8.1.1.1.3' },
55 gwPortLinkState => { oid => '.1.3.6.1.4.1.42.2.135.2.8.1.1.1.5', map => \%map_gw_link_state },
56 };
57 my $oid_ibPmaExtPortConnector = '.1.3.6.1.4.1.42.2.135.2.6.1.2.1.11';
58 my $oid_gwPortStateEntry = '.1.3.6.1.4.1.42.2.135.2.8.1.1.1';
59
60 sub manage_selection {
61 my ($self, %options) = @_;
62
63 my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $mapping->{ibSmaPortLinkState}->{oid} },
64 { oid => $oid_ibPmaExtPortConnector },
65 { oid => $oid_gwPortStateEntry, end => $mapping2->{gwPortLinkState}->{oid} },
66 ],
67 nothing_quit => 1);
68 foreach my $oid (keys %{$snmp_result->{ $oid_ibPmaExtPortConnector }}) {
69 next if ($oid !~ /^$oid_ibPmaExtPortConnector\.(.*)$/);
70 my $instance = $1;
71 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{ $mapping->{ibSmaPortLinkState}->{oid} }, instance => $instance);
72
73 $snmp_result->{ $oid_ibPmaExtPortConnector }->{$oid} =~ s/\x00//g;
74 if (defined($self->{option_results}->{filter_ib_name}) && $self->{option_results}->{filter_ib_name} ne '' &&
75 $snmp_result->{ $oid_ibPmaExtPortConnector }->{$oid} !~ /$self->{option_results}->{filter_ib_name}/) {
76 $self->{output}->output_add(long_msg => "skipping '" . $snmp_result->{ $oid_ibPmaExtPortConnector }->{$oid} . "': no matching filter.", debug => 1);
77 next;
78 }
79
80 $self->{infinibands}->{'ib_' . $instance} = {
81 name => $snmp_result->{ $oid_ibPmaExtPortConnector }->{$oid}, type => 'ib', status => $result->{ibSmaPortLinkState} };
82 }
83
84 foreach my $oid (keys %{$snmp_result->{ $oid_gwPortStateEntry }}) {
85 next if ($oid !~ /^$mapping2->{gwPortLongName}->{oid}\.(.*)$/);
86 my $instance = $1;
87 my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{ $oid_gwPortStateEntry }, instance => $instance);
88
89 $result->{gwPortLongName} =~ s/\x00//g;
90 if (defined($self->{option_results}->{filter_ibgw_name}) && $self->{option_results}->{filter_ibgw_name} ne '' &&
91 $result->{gwPortLongName} !~ /$self->{option_results}->{filter_ibgw_name}/) {
92 $self->{output}->output_add(long_msg => "skipping '" . $result->{gwPortLongName} . "': no matching filter.", debug => 1);
93 next;
94 }
95
96 $self->{infinibands}->{'ibgw_' . $instance} = {
97 name => $result->{gwPortLongName}, type => 'ibgw', status => $result->{gwPortLinkState} };
98 }
99 }
100
101 sub run {
102 my ($self, %options) = @_;
103
104 $self->manage_selection(%options);
105 foreach my $instance (sort keys %{$self->{infinibands}}) {
106 $self->{output}->output_add(long_msg => '[name = ' . $self->{infinibands}->{$instance}->{name} .
107 "] [status = " . $self->{infinibands}->{$instance}->{status} . '] [type = ' . $self->{infinibands}->{$instance}->{type} . ']'
108 );
109 }
110
111 $self->{output}->output_add(severity => 'OK',
112 short_msg => 'List infinibands:');
113 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
114 $self->{output}->exit();
115 }
116
117 sub disco_format {
118 my ($self, %options) = @_;
119
120 $self->{output}->add_disco_format(elements => ['name', 'type', 'status']);
121 }
122
123 sub disco_show {
124 my ($self, %options) = @_;
125
126 $self->manage_selection(%options);
127 foreach my $instance (sort keys %{$self->{infinibands}}) {
128 $self->{output}->add_disco_entry(name => $self->{infinibands}->{$instance}->{name},
129 status => $self->{infinibands}->{$instance}->{status}, type => $self->{infinibands}->{$instance}->{type});
130 }
131 }
132
133 1;
134
135 __END__
136
137 =head1 MODE
138
139 List infiniband interfaces.
140
141 =over 8
142
143 =item B<--filter-ib-name>
144
145 Filter by infiniband name (can be a regexp).
146
147 =item B<--filter-ibgw-name>
148
149 Filter by infiniband gateway name (can be a regexp).
150
151 =back
152
153 =cut
154