Debian Codegraph @

src/network/nokia/timos/snmp/mode/listsap.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::nokia::timos::snmp::mode::listsap;
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 return $self;
38 }
39
40 sub check_options {
41 my ($self, %options) = @_;
42 $self->SUPER::init(%options);
43 }
44
45 my %map_admin_status = (1 => 'up', 2 => 'down');
46 my %map_oper_status = (1 => 'up', 2 => 'down', 3 => 'ingressQosMismatch',
47 4 => 'egressQosMismatch', 5 => 'portMtuTooSmall', 6 => 'svcAdminDown',
48 7 => 'iesIfAdminDown',
49 );
50 my $mapping = {
51 sapDescription => { oid => '.1.3.6.1.4.1.6527.3.1.2.4.3.2.1.5' },
52 sapAdminStatus => { oid => '.1.3.6.1.4.1.6527.3.1.2.4.3.2.1.6', map => \%map_admin_status },
53 sapOperStatus => { oid => '.1.3.6.1.4.1.6527.3.1.2.4.3.2.1.7', map => \%map_oper_status },
54 };
55
56 sub manage_selection {
57 my ($self, %options) = @_;
58
59 my $snmp_result = $options{snmp}->get_multiple_table(oids => [
60 { oid => $mapping->{sapDescription}->{oid} },
61 { oid => $mapping->{sapAdminStatus}->{oid} },
62 { oid => $mapping->{sapOperStatus}->{oid} },
63 ],
64 return_type => 1, nothing_quit => 1);
65 $self->{sap} = {};
66 foreach my $oid (keys %{$snmp_result}) {
67 next if ($oid !~ /^$mapping->{sapOperStatus}->{oid}\.(.*)$/);
68 my $instance = $1;
69 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
70
71 if (!defined($result->{sapDescription}) || $result->{sapDescription} eq '') {
72 $self->{output}->output_add(long_msg => "skipping sap '$instance': cannot get a description. please set it.", debug => 1);
73 next;
74 }
75 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
76 $result->{sapDescription} !~ /$self->{option_results}->{filter_name}/) {
77 $self->{output}->output_add(long_msg => "skipping '" . $result->{sapDescription} . "': no matching filter.", debug => 1);
78 next;
79 }
80
81 $self->{sap}->{$instance} = { description => $result->{sapDescription},
82 admin_state => $result->{sapAdminStatus}, oper_state => $result->{sapOperStatus} };
83 }
84 }
85
86 sub run {
87 my ($self, %options) = @_;
88
89 $self->manage_selection(%options);
90 foreach my $instance (sort keys %{$self->{sap}}) {
91 $self->{output}->output_add(long_msg => '[description = ' . $self->{sap}->{$instance}->{description} .
92 "] [admin = '" . $self->{sap}->{$instance}->{admin_state} .
93 "'] [oper = '" . $self->{sap}->{$instance}->{oper_state} . '"]');
94 }
95
96 $self->{output}->output_add(severity => 'OK',
97 short_msg => 'List SAPs:');
98 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
99 $self->{output}->exit();
100 }
101
102 sub disco_format {
103 my ($self, %options) = @_;
104
105 $self->{output}->add_disco_format(elements => ['description', 'admin', 'oper']);
106 }
107
108 sub disco_show {
109 my ($self, %options) = @_;
110
111 $self->manage_selection(%options);
112 foreach my $instance (sort keys %{$self->{sap}}) {
113 $self->{output}->add_disco_entry(description => $self->{sap}->{$instance}->{description},
114 admin => $self->{sap}->{$instance}->{admin_state},
115 oper => $self->{sap}->{$instance}->{oper_state},
116 );
117 }
118 }
119
120 1;
121
122 __END__
123
124 =head1 MODE
125
126 List Service Access Points.
127
128 =over 8
129
130 =item B<--filter-name>
131
132 Filter by sap description (can be a regexp).
133
134 =back
135
136 =cut
137