Skip to content

Commit 562f357

Browse files
authored
enh(apps::haproxy::snmp): allow compatibility with new OIDs from v17 (#6001)
Refs: CTOR-2022
1 parent 3571bfc commit 562f357

File tree

8 files changed

+442
-52
lines changed

8 files changed

+442
-52
lines changed

src/apps/haproxy/snmp/mode/backendusage.pm

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2024 Centreon (http://www.centreon.com/)
2+
# Copyright 2026-Present Centreon (http://www.centreon.com/)
33
#
44
# Centreon is a full-fledged industry-strength solution that meets
55
# the needs in IT infrastructure and application monitoring for
@@ -26,6 +26,8 @@ use strict;
2626
use warnings;
2727
use Digest::MD5 qw(md5_hex);
2828
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
29+
use centreon::plugins::constants qw(:counters :values);
30+
use centreon::plugins::misc qw(is_excluded);
2931

3032
sub prefix_backend_output {
3133
my ($self, %options) = @_;
@@ -43,13 +45,13 @@ sub set_counters {
4345
my ($self, %options) = @_;
4446

4547
$self->{maps_counters_type} = [
46-
{ name => 'backend', type => 1, cb_prefix_output => 'prefix_backend_output', message_multiple => 'All backends are ok' }
48+
{ name => 'backend', type => COUNTER_TYPE_INSTANCE, cb_prefix_output => 'prefix_backend_output', message_multiple => 'All backends are ok' }
4749
];
4850

4951
$self->{maps_counters}->{backend} = [
5052
{
5153
label => 'status',
52-
type => 2,
54+
type => COUNTER_KIND_TEXT,
5355
critical_default => '%{status} !~ /UP/i',
5456
set => {
5557
key_values => [ { name => 'status' }, { name => 'display' } ],
@@ -132,19 +134,29 @@ my $mapping = {
132134
bytesOUT => { oid => '.1.3.6.1.4.1.29385.106.1.1.9' },
133135
status => { oid => '.1.3.6.1.4.1.29385.106.1.1.17' }
134136
},
135-
hapee => {
137+
hapee_legacy => {
136138
queueCur => { oid => '.1.3.6.1.4.1.23263.4.3.1.3.3.1.4' },
137139
sessionCur => { oid => '.1.3.6.1.4.1.23263.4.3.1.3.3.1.7' },
138140
sessionTotal => { oid => '.1.3.6.1.4.1.23263.4.3.1.3.3.1.10' },
139141
bytesIN => { oid => '.1.3.6.1.4.1.23263.4.3.1.3.3.1.12' },
140142
bytesOUT => { oid => '.1.3.6.1.4.1.23263.4.3.1.3.3.1.13' },
141143
status => { oid => '.1.3.6.1.4.1.23263.4.3.1.3.3.1.20' }
144+
},
145+
hapee => {
146+
queueCur => { oid => '.1.3.6.1.4.1.58750.4.3.1.3.3.1.4' },
147+
sessionCur => { oid => '.1.3.6.1.4.1.58750.4.3.1.3.3.1.7' },
148+
sessionTotal => { oid => '.1.3.6.1.4.1.58750.4.3.1.3.3.1.10' },
149+
bytesIN => { oid => '.1.3.6.1.4.1.58750.4.3.1.3.3.1.12' },
150+
bytesOUT => { oid => '.1.3.6.1.4.1.58750.4.3.1.3.3.1.13' },
151+
status => { oid => '.1.3.6.1.4.1.58750.4.3.1.3.3.1.20' }
142152
}
153+
143154
};
144155
my $mapping_name = {
145-
csv => '.1.3.6.1.4.1.29385.106.1.1.0',
146-
aloha => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.3', # alBackendName
147-
hapee => '.1.3.6.1.4.1.23263.4.3.1.3.3.1.3' # lbBackendName
156+
csv => '.1.3.6.1.4.1.29385.106.1.1.0',
157+
aloha => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.3', # alBackendName
158+
hapee_legacy => '.1.3.6.1.4.1.23263.4.3.1.3.3.1.3', # lbBackendName
159+
hapee => '.1.3.6.1.4.1.58750.4.3.1.3.3.1.3' # lbBackendName
148160
};
149161

150162
sub manage_selection {
@@ -156,18 +168,17 @@ sub manage_selection {
156168
}
157169

158170
my $snmp_result = $options{snmp}->get_multiple_table(
159-
oids => [
160-
{ oid => $mapping_name->{csv} },
161-
{ oid => $mapping_name->{aloha} },
162-
{ oid => $mapping_name->{hapee} }
163-
],
171+
oids => [ map { { oid => $_ } } values(%$mapping_name) ],
164172
nothing_quit => 1
165173
);
166174
my $branch = 'aloha';
167-
if (defined($snmp_result->{ $mapping_name->{csv} }) && scalar(keys %{$snmp_result->{ $mapping_name->{csv} }}) > 0) {
175+
176+
if (defined($snmp_result->{ $mapping_name->{csv} }) && keys %{$snmp_result->{ $mapping_name->{csv} }}) {
168177
$branch = 'csv';
169-
} elsif (defined($snmp_result->{ $mapping_name->{hapee} }) && scalar(keys %{$snmp_result->{ $mapping_name->{hapee} }}) > 0) {
178+
} elsif (defined($snmp_result->{ $mapping_name->{hapee} }) && keys %{$snmp_result->{ $mapping_name->{hapee} }}) {
170179
$branch = 'hapee';
180+
} elsif (defined($snmp_result->{ $mapping_name->{hapee_legacy} }) && keys %{$snmp_result->{ $mapping_name->{hapee_legacy} }}) {
181+
$branch = 'hapee_legacy';
171182
}
172183

173184
$self->{backend} = {};
@@ -176,19 +187,16 @@ sub manage_selection {
176187
my $instance = $1;
177188
my $name = $snmp_result->{$mapping_name->{$branch}}->{$oid};
178189

179-
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
180-
$name !~ /$self->{option_results}->{filter_name}/) {
190+
if (is_excluded($name, $self->{option_results}->{filter_name})) {
181191
$self->{output}->output_add(long_msg => "skipping backend '" . $name . "'.", debug => 1);
182192
next;
183193
}
184194

185195
$self->{backend}->{$instance} = { display => $name };
186196
}
187197

188-
if (scalar(keys %{$self->{backend}}) <= 0) {
189-
$self->{output}->add_option_msg(short_msg => "No backend found.");
190-
$self->{output}->option_exit();
191-
}
198+
$self->{output}->option_exit(short_msg => "No backend found.")
199+
unless keys %{$self->{backend}};
192200

193201
$options{snmp}->load(
194202
oids => [
@@ -242,11 +250,45 @@ You can use the following variables: %{status}, %{display}
242250
Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /UP/i').
243251
You can use the following variables: %{status}, %{display}
244252
245-
=item B<--warning-*> B<--critical-*>
253+
=item B<--warning-current-queue>
254+
255+
Threshold.
256+
257+
=item B<--critical-current-queue>
258+
259+
Threshold.
260+
261+
=item B<--warning-current-sessions>
262+
263+
Threshold.
264+
265+
=item B<--critical-current-sessions>
266+
267+
Threshold.
268+
269+
=item B<--warning-total-sessions>
270+
271+
Threshold.
272+
273+
=item B<--critical-total-sessions>
274+
275+
Threshold.
276+
277+
=item B<--warning-traffic-in>
278+
279+
Threshold in b/s.
280+
281+
=item B<--critical-traffic-in>
282+
283+
Threshold in b/s.
284+
285+
=item B<--warning-traffic-out>
286+
287+
Threshold in b/s.
288+
289+
=item B<--critical-traffic-out>
246290
247-
Thresholds.
248-
Can be: 'total-sessions', 'current-sessions', 'current-queue',
249-
'traffic-in' (b/s), 'traffic-out' (b/s).
291+
Threshold in b/s.
250292
251293
=back
252294

src/apps/haproxy/snmp/mode/frontendusage.pm

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2024 Centreon (http://www.centreon.com/)
2+
# Copyright 2026-Present Centreon (http://www.centreon.com/)
33
#
44
# Centreon is a full-fledged industry-strength solution that meets
55
# the needs in IT infrastructure and application monitoring for
@@ -26,6 +26,8 @@ use strict;
2626
use warnings;
2727
use Digest::MD5 qw(md5_hex);
2828
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
29+
use centreon::plugins::constants qw(:values :counters);
30+
use centreon::plugins::misc qw(is_excluded);
2931

3032
sub prefix_frontend_output {
3133
my ($self, %options) = @_;
@@ -43,13 +45,13 @@ sub set_counters {
4345
my ($self, %options) = @_;
4446

4547
$self->{maps_counters_type} = [
46-
{ name => 'frontend', type => 1, cb_prefix_output => 'prefix_frontend_output', message_multiple => 'All frontends are ok' }
48+
{ name => 'frontend', type => COUNTER_TYPE_INSTANCE, cb_prefix_output => 'prefix_frontend_output', message_multiple => 'All frontends are ok' }
4749
];
4850

4951
$self->{maps_counters}->{frontend} = [
5052
{
5153
label => 'status',
52-
type => 2,
54+
type => COUNTER_KIND_TEXT,
5355
critical_default => '%{status} !~ /OPEN/i',
5456
set => {
5557
key_values => [ { name => 'status' }, { name => 'display' } ],
@@ -122,43 +124,47 @@ my $mapping = {
122124
bytesOUT => { oid => '.1.3.6.1.4.1.29385.106.1.0.9' },
123125
status => { oid => '.1.3.6.1.4.1.29385.106.1.0.17' }
124126
},
125-
hapee => {
127+
hapee_legacy => {
126128
sessionCur => { oid => '.1.3.6.1.4.1.23263.4.3.1.3.2.1.4' },
127129
sessionTotal => { oid => '.1.3.6.1.4.1.23263.4.3.1.3.2.1.7' },
128130
bytesIN => { oid => '.1.3.6.1.4.1.23263.4.3.1.3.2.1.8' },
129131
bytesOUT => { oid => '.1.3.6.1.4.1.23263.4.3.1.3.2.1.9' },
130132
status => { oid => '.1.3.6.1.4.1.23263.4.3.1.3.2.1.13' }
133+
},
134+
hapee => {
135+
sessionCur => { oid => '.1.3.6.1.4.1.58750.4.3.1.3.2.1.4' },
136+
sessionTotal => { oid => '.1.3.6.1.4.1.58750.4.3.1.3.2.1.7' },
137+
bytesIN => { oid => '.1.3.6.1.4.1.58750.4.3.1.3.2.1.8' },
138+
bytesOUT => { oid => '.1.3.6.1.4.1.58750.4.3.1.3.2.1.9' },
139+
status => { oid => '.1.3.6.1.4.1.58750.4.3.1.3.2.1.13' }
131140
}
132141
};
133142

134143
my $mapping_name = {
135-
csv => '.1.3.6.1.4.1.29385.106.1.0.0',
136-
aloha => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.3', # alFrontendName
137-
hapee => '.1.3.6.1.4.1.23263.4.3.1.3.2.1.3' # lbFrontendName
144+
csv => '.1.3.6.1.4.1.29385.106.1.0.0',
145+
aloha => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.3', # alFrontendName
146+
hapee_legacy => '.1.3.6.1.4.1.23263.4.3.1.3.2.1.3', # lbFrontendName
147+
hapee => '.1.3.6.1.4.1.58750.4.3.1.3.2.1.3' # lbFrontendName
138148
};
139149

140150
sub manage_selection {
141151
my ($self, %options) = @_;
142152

143-
if ($options{snmp}->is_snmpv1()) {
144-
$self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
145-
$self->{output}->option_exit();
146-
}
153+
$self->{output}->option_exit(short_msg => "Need to use SNMP v2c or v3.")
154+
if $options{snmp}->is_snmpv1();
147155

148156
my $snmp_result = $options{snmp}->get_multiple_table(
149-
oids => [
150-
{ oid => $mapping_name->{csv} },
151-
{ oid => $mapping_name->{aloha} },
152-
{ oid => $mapping_name->{hapee} }
153-
],
157+
oids => [ map { { oid => $_ } } values(%$mapping_name) ],
154158
nothing_quit => 1
155159
);
156160

157161
my $branch = 'aloha';
158-
if (defined($snmp_result->{ $mapping_name->{csv} }) && scalar(keys %{$snmp_result->{ $mapping_name->{csv} }}) > 0) {
162+
if (defined($snmp_result->{ $mapping_name->{csv} }) && keys %{$snmp_result->{ $mapping_name->{csv} }}) {
159163
$branch = 'csv';
160-
} elsif (defined($snmp_result->{ $mapping_name->{hapee} }) && scalar(keys %{$snmp_result->{ $mapping_name->{hapee} }}) > 0) {
164+
} elsif (defined($snmp_result->{ $mapping_name->{hapee} }) && keys %{$snmp_result->{ $mapping_name->{hapee} }}) {
161165
$branch = 'hapee';
166+
} elsif (defined($snmp_result->{ $mapping_name->{hapee_legacy} }) && keys %{$snmp_result->{ $mapping_name->{hapee_legacy} }}) {
167+
$branch = 'hapee_legacy';
162168
}
163169

164170
$self->{frontend} = {};
@@ -167,19 +173,16 @@ sub manage_selection {
167173
my $instance = $1;
168174
my $name = $snmp_result->{$mapping_name->{$branch}}->{$oid};
169175

170-
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
171-
$name !~ /$self->{option_results}->{filter_name}/) {
176+
if (is_excluded($name, $self->{option_results}->{filter_name})) {
172177
$self->{output}->output_add(long_msg => "skipping frontend '" . $name . "'.", debug => 1);
173178
next;
174179
}
175180

176181
$self->{frontend}->{$instance} = { display => $name };
177182
}
178183

179-
if (scalar(keys %{$self->{frontend}}) <= 0) {
180-
$self->{output}->add_option_msg(short_msg => "No frontend found.");
181-
$self->{output}->option_exit();
182-
}
184+
$self->{output}->option_exit(short_msg => "No frontend found.")
185+
unless keys %{$self->{frontend}};
183186

184187
$options{snmp}->load(
185188
oids => [
@@ -233,11 +236,37 @@ You can use the following variables: %{status}, %{display}
233236
Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /OPEN/i').
234237
You can use the following variables: %{status}, %{display}
235238
236-
=item B<--warning-*> B<--critical-*>
239+
=item B<--warning-current-sessions>
240+
241+
Threshold.
242+
243+
=item B<--critical-current-sessions>
244+
245+
Threshold.
246+
247+
=item B<--warning-total-sessions>
248+
249+
Threshold.
250+
251+
=item B<--critical-total-sessions>
252+
253+
Threshold.
254+
255+
=item B<--warning-traffic-in>
256+
257+
Threshold in b/s.
258+
259+
=item B<--critical-traffic-in>
260+
261+
Threshold in b/s.
262+
263+
=item B<--warning-traffic-out>
264+
265+
Threshold in b/s.
266+
267+
=item B<--critical-traffic-out>
237268
238-
Thresholds.
239-
Can be: 'total-sessions', 'current-sessions',
240-
'traffic-in' (b/s), 'traffic-out' (b/s).
269+
Threshold in b/s.
241270
242271
=back
243272

0 commit comments

Comments
 (0)