Debian Codegraph @

src/network/ruckus/scg/snmp/mode/apstatus.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::ruckus::scg::snmp::mode::apstatus;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 my $msg = "connection status is '" . $self->{result_values}->{connection_status} . "'";
34 $msg .= ", registration status is '" . $self->{result_values}->{registration_status} . "'";
35 $msg .= ", configuration status is '" . $self->{result_values}->{configuration_status} . "'";
36 return $msg;
37 }
38
39 sub custom_status_calc {
40 my ($self, %options) = @_;
41
42 $self->{result_values}->{connection_status} = $options{new_datas}->{$self->{instance} . '_ruckusSCGAPConnStatus'};
43 $self->{result_values}->{registration_status} = $options{new_datas}->{$self->{instance} . '_ruckusSCGAPRegStatus'};
44 $self->{result_values}->{configuration_status} = $options{new_datas}->{$self->{instance} . '_ruckusSCGAPConfigStatus'};
45 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
46 return 0;
47 }
48
49 sub set_counters {
50 my ($self, %options) = @_;
51
52 $self->{maps_counters_type} = [
53 { name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All APs are ok' }
54 ];
55
56 $self->{maps_counters}->{ap} = [
57 { label => 'status', threshold => 0, set => {
58 key_values => [ { name => 'ruckusSCGAPConnStatus' }, { name => 'ruckusSCGAPRegStatus' },
59 { name => 'ruckusSCGAPConfigStatus' }, { name => 'display' } ],
60 closure_custom_calc => $self->can('custom_status_calc'),
61 closure_custom_output => $self->can('custom_status_output'),
62 closure_custom_perfdata => sub { return 0; },
63 closure_custom_threshold_check => \&catalog_status_threshold,
64 }
65 },
66 ];
67 }
68
69 sub prefix_ap_output {
70 my ($self, %options) = @_;
71
72 return "AP '" . $options{instance_value}->{display} . "' ";
73 }
74
75 sub new {
76 my ($class, %options) = @_;
77 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
78 bless $self, $class;
79
80 $options{options}->add_options(arguments =>
81 {
82 "filter-name:s" => { name => 'filter_name' },
83 "warning-status:s" => { name => 'warning_status', default => '%{configuration_status} !~ /^Up-to-date$/i' },
84 "critical-status:s" => { name => 'critical_status', default => '%{connection_status} =~ /^Disconnect$/i' },
85 });
86
87 return $self;
88 }
89
90 sub check_options {
91 my ($self, %options) = @_;
92 $self->SUPER::check_options(%options);
93
94 $self->change_macros(macros => ['warning_status', 'critical_status']);
95 }
96
97 my $oid_ruckusSCGAPName = '.1.3.6.1.4.1.25053.1.3.2.1.1.2.2.1.5',
98 my $mapping = {
99 ruckusSCGAPConnStatus => { oid => '.1.3.6.1.4.1.25053.1.3.2.1.1.2.2.1.16' },
100 ruckusSCGAPRegStatus => { oid => '.1.3.6.1.4.1.25053.1.3.2.1.1.2.2.1.17' },
101 ruckusSCGAPConfigStatus => { oid => '.1.3.6.1.4.1.25053.1.3.2.1.1.2.2.1.18' },
102 };
103
104 sub manage_selection {
105 my ($self, %options) = @_;
106
107 $self->{ap} = {};
108 my $snmp_result = $options{snmp}->get_table(oid => $oid_ruckusSCGAPName, nothing_quit => 1);
109 foreach my $oid (keys %{$snmp_result}) {
110 $oid =~ /^$oid_ruckusSCGAPName\.(.*)$/;
111 my $instance = $1;
112 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
113 $snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) {
114 $self->{output}->output_add(long_msg => "skipping '" . $snmp_result->{$oid} . "'.", debug => 1);
115 next;
116 }
117
118 $self->{ap}->{$instance} = { display => $snmp_result->{$oid} };
119 }
120
121 $options{snmp}->load(oids => [ $mapping->{ruckusSCGAPConnStatus}->{oid},
122 $mapping->{ruckusSCGAPRegStatus}->{oid},
123 $mapping->{ruckusSCGAPConfigStatus}->{oid} ],
124 instances => [ keys %{$self->{ap}} ],
125 instance_regexp => '^(.*)$');
126 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
127
128 foreach (keys %{$self->{ap}}) {
129 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
130
131 foreach my $name (keys %$mapping) {
132 $self->{ap}->{$_}->{$name} = $result->{$name};
133 }
134 }
135
136 if (scalar(keys %{$self->{ap}}) <= 0) {
137 $self->{output}->add_option_msg(short_msg => "No AP found.");
138 $self->{output}->option_exit();
139 }
140 }
141
142 1;
143
144 __END__
145
146 =head1 MODE
147
148 Check AP status.
149
150 =over 8
151
152 =item B<--filter-name>
153
154 Filter by AP name (can be a regexp).
155
156 =item B<--warning-status>
157
158 Define the conditions to match for the status to be WARNING (default: '%{configuration_status} !~ /^Up-to-date$/i').
159 You can use the following variables: %{connection_status}, %{registration_status}, %{configuration_status}, %{display}
160
161 =item B<--critical-status>
162
163 Define the conditions to match for the status to be CRITICAL (default: '%{connection_status} =~ /^Disconnect$/i').
164 You can use the following variables: %{connection_status}, %{registration_status}, %{configuration_status}, %{display}
165
166 =back
167
168 =cut