Debian Codegraph @

src/network/ruckus/scg/snmp/mode/apusage.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::apusage;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28
29 sub set_counters {
30 my ($self, %options) = @_;
31
32 $self->{maps_counters_type} = [
33 { name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All APs are ok' },
34 ];
35
36 $self->{maps_counters}->{ap} = [
37 { label => 'users-count', set => {
38 key_values => [ { name => 'ruckusSCGAPNumSta' }, { name => 'display' } ],
39 output_template => 'Users count: %s',
40 perfdatas => [
41 { label => 'users_count', template => '%s',
42 unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'display' },
43 ],
44 }
45 },
46 { label => 'traffic-in', set => {
47 key_values => [ { name => 'ruckusSCGAPRXBytes', per_second => 1 }, { name => 'display' } ],
48 output_template => 'Traffic In: %s %s/s',
49 output_change_bytes => 2,
50 perfdatas => [
51 { label => 'traffic_in', template => '%s',
52 min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
53 ],
54 }
55 },
56 { label => 'traffic-out', set => {
57 key_values => [ { name => 'ruckusSCGAPTXBytes', per_second => 1 }, { name => 'display' } ],
58 output_template => 'Traffic Out: %s %s/s',
59 output_change_bytes => 2,
60 perfdatas => [
61 { label => 'traffic_out', template => '%s',
62 min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
63 ],
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, statefile => 1);
78 bless $self, $class;
79
80 $options{options}->add_options(arguments => {
81 'filter-name:s' => { name => 'filter_name' }
82 });
83
84 return $self;
85 }
86
87 sub check_options {
88 my ($self, %options) = @_;
89 $self->SUPER::check_options(%options);
90 }
91
92 my $oid_ruckusSCGAPName = '.1.3.6.1.4.1.25053.1.3.2.1.1.2.2.1.5',
93 my $mapping = {
94 ruckusSCGAPNumSta => { oid => '.1.3.6.1.4.1.25053.1.3.2.1.1.2.2.1.15' },
95 ruckusSCGAPRXBytes => { oid => '.1.3.6.1.4.1.25053.1.3.2.1.1.2.2.1.30' },
96 ruckusSCGAPTXBytes => { oid => '.1.3.6.1.4.1.25053.1.3.2.1.1.2.2.1.31' },
97 };
98
99 sub manage_selection {
100 my ($self, %options) = @_;
101
102 if ($options{snmp}->is_snmpv1()) {
103 $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
104 $self->{output}->option_exit();
105 }
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->{ruckusSCGAPNumSta}->{oid},
122 $mapping->{ruckusSCGAPRXBytes}->{oid},
123 $mapping->{ruckusSCGAPTXBytes}->{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 $self->{cache_name} = "ruckus_scg_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
142 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
143 }
144
145 1;
146
147 __END__
148
149 =head1 MODE
150
151 Check AP connected users and traffic.
152
153 =over 8
154
155 =item B<--filter-name>
156
157 Filter by AP name (can be a regexp).
158
159 =item B<--warning-*>
160
161 Warning threshold.
162 Can be: 'users-count', 'traffic-in', 'traffic-out'.
163
164 =item B<--critical-*>
165
166 Critical threshold.
167 Can be: 'users-count', 'traffic-in', 'traffic-out'.
168
169 =back
170
171 =cut
172