enh(plugin)apps-haproxy-snmp metricsv2 (#2492)

This commit is contained in:
itoussies 2021-01-11 16:17:07 +01:00 committed by GitHub
parent 420669c0ab
commit 8b0f9e8e6b
3 changed files with 55 additions and 66 deletions

View File

@ -25,13 +25,18 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub prefix_backend_output {
my ($self, %options) = @_;
return "Backend '" . $options{instance_value}->{display} . "' ";
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'status : ' . $self->{result_values}->{status};
return $msg;
return sprintf("status : %s", $self->{result_values}->{status});
}
sub custom_status_calc {
@ -50,61 +55,65 @@ sub set_counters {
];
$self->{maps_counters}->{backend} = [
{ label => 'status', threshold => 0, set => {
{
label => 'status',
type => 2,
critical_default => '%{status} !~ /UP/i',
set => {
key_values => [ { name => 'alBackendStatus' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_threshold_check => \&catalog_status_threshold_ng,
}
},
{ label => 'current-queue', set => {
{ label => 'current-queue', nlabel => 'queue.current.count', set => {
key_values => [ { name => 'alBackendQueueCur' }, { name => 'display' } ],
output_template => 'Current queue : %s',
perfdatas => [
{ label => 'current_queue', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' },
],
min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'current-sessions', set => {
{ label => 'current-sessions', nlabel => 'sessions.current.count', set => {
key_values => [ { name => 'alBackendSessionCur' }, { name => 'display' } ],
output_template => 'Current sessions : %s',
perfdatas => [
{ label => 'current_sessions', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' },
],
min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'total-sessions', set => {
{ label => 'total-sessions', nlabel => 'sessions.total.count', set => {
key_values => [ { name => 'alBackendSessionTotal', diff => 1 }, { name => 'display' } ],
output_template => 'Total sessions : %s',
perfdatas => [
{ label => 'total_connections', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' },
],
min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'traffic-in', set => {
{ label => 'traffic-in', nlabel => 'backend.traffic.in.bitpersecond', set => {
key_values => [ { name => 'alBackendBytesIN', per_second => 1 }, { name => 'display' } ],
output_template => 'Traffic In : %s %s/s',
output_change_bytes => 2,
perfdatas => [
{ label => 'traffic_in', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
],
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'traffic-out', set => {
{ label => 'traffic-out', nlabel => 'backend.traffic.out.bitpersecond', set => {
key_values => [ { name => 'alBackendBytesOUT', per_second => 1 }, { name => 'display' } ],
output_template => 'Traffic Out : %s %s/s',
output_change_bytes => 2,
perfdatas => [
{ label => 'traffic_out', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
],
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
]
}
},
}
];
}
@ -114,27 +123,12 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /UP/i' }
'filter-name:s' => { name => 'filter_name' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub prefix_backend_output {
my ($self, %options) = @_;
return "Backend '" . $options{instance_value}->{display} . "' ";
}
my $mapping = {
entreprise => {
alBackendQueueCur => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.4' },

View File

@ -25,13 +25,18 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub prefix_frontend_output {
my ($self, %options) = @_;
return "Frontend '" . $options{instance_value}->{display} . "' ";
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'status : ' . $self->{result_values}->{status};
return $msg;
return sprintf("status : %s", $self->{result_values}->{status});
}
sub custom_status_calc {
@ -50,15 +55,19 @@ sub set_counters {
];
$self->{maps_counters}->{frontend} = [
{ label => 'status', threshold => 0, set => {
{
label => 'status',
type => 2,
critical_default => '%{status} !~ /OPEN/i',
set => {
key_values => [ { name => 'alFrontendStatus' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'current-sessions', set => {
{ label => 'current-sessions', nlabel => 'sessions.current.count', set => {
key_values => [ { name => 'alFrontendSessionCur' }, { name => 'display' } ],
output_template => 'Current sessions : %s',
perfdatas => [
@ -67,7 +76,7 @@ sub set_counters {
]
}
},
{ label => 'total-sessions', set => {
{ label => 'total-sessions', nlabel => 'sessions.total.count', set => {
key_values => [ { name => 'alFrontendSessionTotal', diff => 1 }, { name => 'display' } ],
output_template => 'Total sessions : %s',
perfdatas => [
@ -76,7 +85,7 @@ sub set_counters {
]
}
},
{ label => 'traffic-in', set => {
{ label => 'traffic-in', nlabel => 'frontend.traffic.in.bitpersecond', set => {
key_values => [ { name => 'alFrontendBytesIN', per_second => 1 }, { name => 'display' } ],
output_template => 'Traffic In : %s %s/s',
output_change_bytes => 2,
@ -86,7 +95,7 @@ sub set_counters {
]
}
},
{ label => 'traffic-out', set => {
{ label => 'traffic-out', nlabel => 'frontend.traffic.out.bitpersecond', set => {
key_values => [ { name => 'alFrontendBytesOUT', per_second => 1 }, { name => 'display' } ],
output_template => 'Traffic Out : %s %s/s',
output_change_bytes => 2,
@ -105,27 +114,12 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /OPEN/i' }
'filter-name:s' => { name => 'filter_name' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub prefix_frontend_output {
my ($self, %options) = @_;
return "Frontend '" . $options{instance_value}->{display} . "' ";
}
my $mapping = {
entreprise => {
alFrontendSessionCur => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.4' },
@ -142,6 +136,7 @@ my $mapping = {
alFrontendStatus => { oid => '.1.3.6.1.4.1.29385.106.1.0.17' },
},
};
my $mapping_name = {
csv => '.1.3.6.1.4.1.29385.106.1.0.0',
entreprise => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.3', # alFrontendName

View File

@ -30,10 +30,10 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
%{$self->{modes}} = (
'backend-usage' => 'apps::haproxy::snmp::mode::backendusage',
'frontend-usage' => 'apps::haproxy::snmp::mode::frontendusage',
);
$self->{modes} = {
'backend-usage' => 'apps::haproxy::snmp::mode::backendusage',
'frontend-usage' => 'apps::haproxy::snmp::mode::frontendusage'
};
return $self;
}