Debian Codegraph @

src/network/cambium/cnpilot/snmp/mode/connectionstatus.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 package network::cambium::cnpilot::snmp::mode::connectionstatus;
21
22 use base qw(centreon::plugins::templates::counter);
23
24 use strict;
25 use warnings;
26 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
27
28 sub prefix_connection_output {
29 my ($self, %options) = @_;
30
31 return "Access point '" . $options{instance_value}->{name} . "' ";
32 }
33
34 sub custom_connection_output {
35 my ($self, %options) = @_;
36
37 return sprintf(
38 'connection status: %s',
39 $self->{result_values}->{connection_status}
40 );
41 }
42
43 sub set_counters {
44 my ($self, %options) = @_;
45
46 $self->{maps_counters_type} = [
47 { name => 'connection', type => 1, cb_prefix_output => 'prefix_connection_output', message_multiple => 'All connection status are ok' }
48 ];
49
50 $self->{maps_counters}->{connection} = [
51 { label => 'connection-status', type => 2,
52 set => {
53 key_values => [ { name => 'connection_status' }, { name => 'name' } ],
54 closure_custom_output => $self->can('custom_connection_output'),
55 closure_custom_perfdata => sub { return 0; },
56 closure_custom_threshold_check => \&catalog_status_threshold_ng
57 }
58 },
59 ];
60 }
61
62 sub new {
63 my ($class, %options) = @_;
64 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
65 bless $self, $class;
66
67 $options{options}->add_options(arguments => {
68 'filter-ap:s' => { name => 'filter_ap' }
69 });
70
71 return $self;
72 }
73
74 sub manage_selection {
75 my ($self, %options) = @_;
76
77 my $mapping = {
78 cambiumAPName => { oid => '.1.3.6.1.4.1.17713.22.1.1.1.2' },
79 cambiumAPCnmConstaus => { oid => '.1.3.6.1.4.1.17713.22.1.1.1.12' }
80 };
81
82 # Point at the begining of the table
83 my $oid_cambiumAccessPointEntry = '.1.3.6.1.4.1.17713.22.1.1.1';
84
85 my $connectionstatus_result = $options{snmp}->get_table(
86 oid => $oid_cambiumAccessPointEntry,
87 nothing_quit => 1
88 );
89
90 $self->{connection} = {};
91 foreach my $oid (keys %{$connectionstatus_result}) {
92 next if ($oid !~ /^$mapping->{cambiumAPName}->{oid}\.(.*)$/);
93 # Catch instance in table
94 my $instance = $1;
95 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $connectionstatus_result, instance => $instance);
96
97 if (defined($self->{option_results}->{filter_ap}) && $self->{option_results}->{filter_ap} ne '' &&
98 $result->{cambiumAPName} !~ /$self->{option_results}->{filter_ap}/) {
99 $self->{output}->output_add(long_msg => "skipping '" . $result->{cambiumAPName} . "': no matching filter.", debug => 1);
100 next;
101 }
102
103 $self->{connection}->{$instance} = {
104 name => $result->{cambiumAPName},
105 connection_status => $result->{cambiumAPCnmConstaus}
106 };
107
108 }
109
110 if (scalar(keys %{$self->{connection}}) <= 0) {
111 $self->{output}->add_option_msg(short_msg => "No AP matching with filter found.");
112 $self->{output}->option_exit();
113 }
114 }
115
116 1;
117
118 __END__
119
120 =head1 MODE
121
122 Check Connection status.
123
124 =over 8
125
126 =item B<--filter-ap>
127
128 Filter on one or several AP.
129
130 =item B<--warning-connection-status>
131
132 Define the conditions to match for the status to be WARNING.
133 Can used special variables like: %{status}, %{name}
134
135 =item B<--critical-connection-status>
136
137 Define the conditions to match for the status to be CRITICAL.
138 Can used special variables like: %{status}, %{name}
139
140 =back
141
142 =cut