Debian Codegraph @

src/network/athonet/epc/snmp/mode/interfacesga.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::athonet::epc::snmp::mode::interfacesga;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 'status: %s',
34 $self->{result_values}->{status}
35 );
36 }
37
38 sub prefix_interface_output {
39 my ($self, %options) = @_;
40
41 return sprintf(
42 "Ga interface '%s' [local: %s] [peer: %s] [type: %s] ",
43 $options{instance_value}->{name},
44 $options{instance_value}->{local_address},
45 $options{instance_value}->{peer_address},
46 $options{instance_value}->{type}
47 );
48 }
49
50 sub set_counters {
51 my ($self, %options) = @_;
52
53 $self->{maps_counters_type} = [
54 { name => 'global', type => 0 },
55 { name => 'interfaces', type => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All ga interfaces are ok' }
56 ];
57
58 $self->{maps_counters}->{global} = [
59 { label => 'total', nlabel => 'ga.interfaces.total.count', display_ok => 0, set => {
60 key_values => [ { name => 'total' } ],
61 output_template => 'total interfaces: %s',
62 perfdatas => [
63 { template => '%s', min => 0 }
64 ]
65 }
66 }
67 ];
68
69 $self->{maps_counters}->{interfaces} = [
70 {
71 label => 'status', type => 2, critical_default => '%{status} =~ /down/i',
72 set => {
73 key_values => [
74 { name => 'status' }, { name => 'peer_address' },
75 { name => 'local_address' }, { name => 'name' } ],
76 closure_custom_output => $self->can('custom_status_output'),
77 closure_custom_perfdata => sub { return 0; },
78 closure_custom_threshold_check => \&catalog_status_threshold_ng
79 }
80 }
81 ];
82 }
83
84 sub new {
85 my ($class, %options) = @_;
86 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
87 bless $self, $class;
88
89 $options{options}->add_options(arguments => {
90 'filter-name:s' => { name => 'filter_name' },
91 'filter-local-address:s' => { name => 'filter_local_address' },
92 'filter-peer-address:s' => { name => 'filter_peer_address' }
93 });
94
95 return $self;
96 }
97
98 my $map_status = { 0 => 'down', 1 => 'up' };
99 my $map_transport_type = { 0 => 'sctp', 1 => 'tcp', 2 => 'udp' };
100
101 my $mapping = {
102 local_address => { oid => '.1.3.6.1.4.1.35805.10.2.12.10.1.2' }, # iGaLinkLocalAddress
103 peer_address => { oid => '.1.3.6.1.4.1.35805.10.2.12.10.1.3' }, # iGaLinkPeerAddress
104 type => { oid => '.1.3.6.1.4.1.35805.10.2.12.10.1.4', map => $map_transport_type }, # iGaLinkTransportType
105 status => { oid => '.1.3.6.1.4.1.35805.10.2.12.10.1.5', map => $map_status }, # iGaLinkState
106 name => { oid => '.1.3.6.1.4.1.35805.10.2.12.10.1.7' }, # iGaLinkName
107 };
108
109 sub manage_selection {
110 my ($self, %options) = @_;
111
112 my $oid_gaLinksEntry = '.1.3.6.1.4.1.35805.10.2.12.10.1';
113 my $snmp_result = $options{snmp}->get_table(
114 oid => $oid_gaLinksEntry,
115 nothing_quit => 1
116 );
117
118 $self->{interfaces} = {};
119 foreach (keys %$snmp_result) {
120 next if (! /^$mapping->{local_address}->{oid}\.(.*)$/);
121 my $instance = $1;
122
123 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
124 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
125 $result->{name} !~ /$self->{option_results}->{filter_name}/) {
126 $self->{output}->output_add(long_msg => "skipping '" . $result->{name} . "': no matching filter.", debug => 1);
127 next;
128 }
129 if (defined($self->{option_results}->{filter_local_address}) && $self->{option_results}->{filter_local_address} ne '' &&
130 $result->{local_address} !~ /$self->{option_results}->{filter_local_address}/) {
131 $self->{output}->output_add(long_msg => "skipping '" . $result->{local_address} . "': no matching filter.", debug => 1);
132 next;
133 }
134 if (defined($self->{option_results}->{filter_peer_address}) && $self->{option_results}->{filter_peer_address} ne '' &&
135 $result->{peer_address} !~ /$self->{option_results}->{filter_peer_address}/) {
136 $self->{output}->output_add(long_msg => "skipping '" . $result->{peer_address} . "': no matching filter.", debug => 1);
137 next;
138 }
139
140 $self->{interfaces}->{$instance} = $result;
141 }
142
143 $self->{global} = { total => scalar(keys %{$self->{interfaces}}) };
144 }
145
146 1;
147
148 __END__
149
150 =head1 MODE
151
152 Check GA interfaces.
153
154 =over 8
155
156 =item B<--filter-name>
157
158 Filter interfaces by name (can be a regexp).
159
160 =item B<--filter-local-address>
161
162 Filter interfaces by local address (can be a regexp).
163
164 =item B<--filter-peer-address>
165
166 Filter interfaces by peer address (can be a regexp).
167
168 =item B<--unknown-status>
169
170 Define the conditions to match for the status to be UNKNOWN.
171 You can use the following variables: %{status}, %{local_address}, %{peer_address}, %{name}
172
173 =item B<--warning-status>
174
175 Define the conditions to match for the status to be WARNING.
176 You can use the following variables: %{status}, %{local_address}, %{peer_address}, %{name}
177
178 =item B<--critical-status>
179
180 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /down/i').
181 You can use the following variables: %{status}, %{local_address}, %{peer_address}, %{name}
182
183 =item B<--warning-*> B<--critical-*>
184
185 Thresholds.
186 Can be: 'total'.
187
188 =back
189
190 =cut