minor fix

This commit is contained in:
garnier-quentin 2021-01-11 16:20:16 +01:00
parent b2c0869a02
commit fbc3f0f11a
4 changed files with 38 additions and 59 deletions

View File

@ -51,7 +51,7 @@ sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'backend', type => 1, cb_prefix_output => 'prefix_backend_output', message_multiple => 'All backends are ok' }, { name => 'backend', type => 1, cb_prefix_output => 'prefix_backend_output', message_multiple => 'All backends are ok' }
]; ];
$self->{maps_counters}->{backend} = [ $self->{maps_counters}->{backend} = [
@ -64,10 +64,10 @@ sub set_counters {
closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng, closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, },
{ label => 'current-queue', nlabel => 'queue.current.count', set => { { label => 'current-queue', nlabel => 'backend.queue.current.count', set => {
key_values => [ { name => 'alBackendQueueCur' }, { name => 'display' } ], key_values => [ { name => 'alBackendQueueCur' }, { name => 'display' } ],
output_template => 'Current queue : %s', output_template => 'Current queue : %s',
perfdatas => [ perfdatas => [
@ -76,7 +76,7 @@ sub set_counters {
] ]
} }
}, },
{ label => 'current-sessions', nlabel => 'sessions.current.count', set => { { label => 'current-sessions', nlabel => 'backend.sessions.current.count', set => {
key_values => [ { name => 'alBackendSessionCur' }, { name => 'display' } ], key_values => [ { name => 'alBackendSessionCur' }, { name => 'display' } ],
output_template => 'Current sessions : %s', output_template => 'Current sessions : %s',
perfdatas => [ perfdatas => [
@ -85,7 +85,7 @@ sub set_counters {
] ]
} }
}, },
{ label => 'total-sessions', nlabel => 'sessions.total.count', set => { { label => 'total-sessions', nlabel => 'backend.sessions.total.count', set => {
key_values => [ { name => 'alBackendSessionTotal', diff => 1 }, { name => 'display' } ], key_values => [ { name => 'alBackendSessionTotal', diff => 1 }, { name => 'display' } ],
output_template => 'Total sessions : %s', output_template => 'Total sessions : %s',
perfdatas => [ perfdatas => [
@ -123,7 +123,7 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' } 'filter-name:s' => { name => 'filter_name' }
}); });
return $self; return $self;
@ -136,7 +136,7 @@ my $mapping = {
alBackendSessionTotal => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.10' }, alBackendSessionTotal => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.10' },
alBackendBytesIN => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.12' }, alBackendBytesIN => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.12' },
alBackendBytesOUT => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.13' }, alBackendBytesOUT => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.13' },
alBackendStatus => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.20' }, alBackendStatus => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.20' }
}, },
csv => { csv => {
alBackendQueueCur => { oid => '.1.3.6.1.4.1.29385.106.1.1.2' }, alBackendQueueCur => { oid => '.1.3.6.1.4.1.29385.106.1.1.2' },
@ -144,7 +144,7 @@ my $mapping = {
alBackendSessionTotal => { oid => '.1.3.6.1.4.1.29385.106.1.1.7' }, alBackendSessionTotal => { oid => '.1.3.6.1.4.1.29385.106.1.1.7' },
alBackendBytesIN => { oid => '.1.3.6.1.4.1.29385.106.1.1.8' }, alBackendBytesIN => { oid => '.1.3.6.1.4.1.29385.106.1.1.8' },
alBackendBytesOUT => { oid => '.1.3.6.1.4.1.29385.106.1.1.9' }, alBackendBytesOUT => { oid => '.1.3.6.1.4.1.29385.106.1.1.9' },
alBackendStatus => { oid => '.1.3.6.1.4.1.29385.106.1.1.17' }, alBackendStatus => { oid => '.1.3.6.1.4.1.29385.106.1.1.17' }
}, },
}; };
my $mapping_name = { my $mapping_name = {
@ -159,15 +159,14 @@ sub manage_selection {
$self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{backend} = {};
my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $mapping_name->{csv} }, { oid => $mapping_name->{entreprise} } ], nothing_quit => 1); my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $mapping_name->{csv} }, { oid => $mapping_name->{entreprise} } ], nothing_quit => 1);
my $branch = 'entreprise'; my $branch = 'entreprise';
if (defined($snmp_result->{ $mapping_name->{csv} }) && scalar(keys %{$snmp_result->{ $mapping_name->{csv} }}) > 0) { if (defined($snmp_result->{ $mapping_name->{csv} }) && scalar(keys %{$snmp_result->{ $mapping_name->{csv} }}) > 0) {
$branch = 'csv'; $branch = 'csv';
} }
$self->{backend} = {};
foreach my $oid (keys %{$snmp_result->{ $mapping_name->{$branch} }}) { foreach my $oid (keys %{$snmp_result->{ $mapping_name->{$branch} }}) {
$oid =~ /^$mapping_name->{$branch}\.(.*)$/; $oid =~ /^$mapping_name->{$branch}\.(.*)$/;
my $instance = $1; my $instance = $1;
@ -195,7 +194,7 @@ sub manage_selection {
instance_regexp => '^(.*)$' instance_regexp => '^(.*)$'
); );
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1); $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
foreach (keys %{$self->{backend}}) { foreach (keys %{$self->{backend}}) {
my $result = $options{snmp}->map_instance(mapping => $mapping->{$branch}, results => $snmp_result, instance => $_); my $result = $options{snmp}->map_instance(mapping => $mapping->{$branch}, results => $snmp_result, instance => $_);
@ -205,7 +204,7 @@ sub manage_selection {
$self->{backend}->{$_} = { %{$self->{backend}->{$_}}, %$result }; $self->{backend}->{$_} = { %{$self->{backend}->{$_}}, %$result };
} }
$self->{cache_name} = "haproxy_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{cache_name} = 'haproxy_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
} }
@ -239,15 +238,9 @@ Can used special variables like: %{status}, %{display}
Set critical threshold for status (Default: '%{status} !~ /UP/i'). Set critical threshold for status (Default: '%{status} !~ /UP/i').
Can used special variables like: %{status}, %{display} Can used special variables like: %{status}, %{display}
=item B<--warning-*> =item B<--warning-*> B<--critical-*>
Threshold warning. Thresholds.
Can be: 'total-sessions', 'current-sessions', 'current-queue',
'traffic-in' (b/s), 'traffic-out' (b/s).
=item B<--critical-*>
Threshold critical.
Can be: 'total-sessions', 'current-sessions', 'current-queue', Can be: 'total-sessions', 'current-sessions', 'current-queue',
'traffic-in' (b/s), 'traffic-out' (b/s). 'traffic-in' (b/s), 'traffic-out' (b/s).

View File

@ -67,7 +67,7 @@ sub set_counters {
closure_custom_threshold_check => \&catalog_status_threshold_ng closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, },
{ label => 'current-sessions', nlabel => 'sessions.current.count', set => { { label => 'current-sessions', nlabel => 'frontend.sessions.current.count', set => {
key_values => [ { name => 'alFrontendSessionCur' }, { name => 'display' } ], key_values => [ { name => 'alFrontendSessionCur' }, { name => 'display' } ],
output_template => 'Current sessions : %s', output_template => 'Current sessions : %s',
perfdatas => [ perfdatas => [
@ -76,7 +76,7 @@ sub set_counters {
] ]
} }
}, },
{ label => 'total-sessions', nlabel => 'sessions.total.count', set => { { label => 'total-sessions', nlabel => 'frontend.sessions.total.count', set => {
key_values => [ { name => 'alFrontendSessionTotal', diff => 1 }, { name => 'display' } ], key_values => [ { name => 'alFrontendSessionTotal', diff => 1 }, { name => 'display' } ],
output_template => 'Total sessions : %s', output_template => 'Total sessions : %s',
perfdatas => [ perfdatas => [
@ -101,7 +101,7 @@ sub set_counters {
output_change_bytes => 2, output_change_bytes => 2,
perfdatas => [ perfdatas => [
{ label => 'traffic_out', template => '%.2f', { 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' }
] ]
} }
} }
@ -126,20 +126,20 @@ my $mapping = {
alFrontendSessionTotal => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.7' }, alFrontendSessionTotal => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.7' },
alFrontendBytesIN => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.8' }, alFrontendBytesIN => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.8' },
alFrontendBytesOUT => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.9' }, alFrontendBytesOUT => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.9' },
alFrontendStatus => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.13' }, alFrontendStatus => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.13' }
}, },
csv => { csv => {
alFrontendSessionCur => { oid => '.1.3.6.1.4.1.29385.106.1.0.4' }, alFrontendSessionCur => { oid => '.1.3.6.1.4.1.29385.106.1.0.4' },
alFrontendSessionTotal => { oid => '.1.3.6.1.4.1.29385.106.1.0.7' }, alFrontendSessionTotal => { oid => '.1.3.6.1.4.1.29385.106.1.0.7' },
alFrontendBytesIN => { oid => '.1.3.6.1.4.1.29385.106.1.0.8' }, alFrontendBytesIN => { oid => '.1.3.6.1.4.1.29385.106.1.0.8' },
alFrontendBytesOUT => { oid => '.1.3.6.1.4.1.29385.106.1.0.9' }, alFrontendBytesOUT => { oid => '.1.3.6.1.4.1.29385.106.1.0.9' },
alFrontendStatus => { oid => '.1.3.6.1.4.1.29385.106.1.0.17' }, alFrontendStatus => { oid => '.1.3.6.1.4.1.29385.106.1.0.17' }
}, },
}; };
my $mapping_name = { my $mapping_name = {
csv => '.1.3.6.1.4.1.29385.106.1.0.0', 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 entreprise => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.3' # alFrontendName
}; };
sub manage_selection { sub manage_selection {
@ -149,15 +149,14 @@ sub manage_selection {
$self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{frontend} = {};
my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $mapping_name->{csv} }, { oid => $mapping_name->{entreprise} } ], nothing_quit => 1); my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $mapping_name->{csv} }, { oid => $mapping_name->{entreprise} } ], nothing_quit => 1);
my $branch = 'entreprise'; my $branch = 'entreprise';
if (defined($snmp_result->{ $mapping_name->{csv} }) && scalar(keys %{$snmp_result->{ $mapping_name->{csv} }}) > 0) { if (defined($snmp_result->{ $mapping_name->{csv} }) && scalar(keys %{$snmp_result->{ $mapping_name->{csv} }}) > 0) {
$branch = 'csv'; $branch = 'csv';
} }
$self->{frontend} = {};
foreach my $oid (keys %{$snmp_result->{ $mapping_name->{$branch} }}) { foreach my $oid (keys %{$snmp_result->{ $mapping_name->{$branch} }}) {
$oid =~ /^$mapping_name->{$branch}\.(.*)$/; $oid =~ /^$mapping_name->{$branch}\.(.*)$/;
my $instance = $1; my $instance = $1;
@ -185,7 +184,7 @@ sub manage_selection {
instance_regexp => '^(.*)$' instance_regexp => '^(.*)$'
); );
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1); $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
foreach (keys %{$self->{frontend}}) { foreach (keys %{$self->{frontend}}) {
my $result = $options{snmp}->map_instance(mapping => $mapping->{$branch}, results => $snmp_result, instance => $_); my $result = $options{snmp}->map_instance(mapping => $mapping->{$branch}, results => $snmp_result, instance => $_);
@ -194,8 +193,8 @@ sub manage_selection {
$self->{frontend}->{$_} = { %{$self->{frontend}->{$_}}, %$result }; $self->{frontend}->{$_} = { %{$self->{frontend}->{$_}}, %$result };
} }
$self->{cache_name} = "haproxy_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{cache_name} = 'haproxy_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
} }
@ -229,15 +228,9 @@ Can used special variables like: %{status}, %{display}
Set critical threshold for status (Default: '%{status} !~ /OPEN/i'). Set critical threshold for status (Default: '%{status} !~ /OPEN/i').
Can used special variables like: %{status}, %{display} Can used special variables like: %{status}, %{display}
=item B<--warning-*> =item B<--warning-*> B<--critical-*>
Threshold warning. Thresholds.
Can be: 'total-sessions', 'current-sessions',
'traffic-in' (b/s), 'traffic-out' (b/s).
=item B<--critical-*>
Threshold critical.
Can be: 'total-sessions', 'current-sessions', Can be: 'total-sessions', 'current-sessions',
'traffic-in' (b/s), 'traffic-out' (b/s). 'traffic-in' (b/s), 'traffic-out' (b/s).

View File

@ -28,11 +28,11 @@ use Digest::MD5 qw(md5_hex);
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0 } { name => 'global', type => 0 }
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'num-clients', nlabel => 'clients.current.count',set => { { label => 'num-clients', nlabel => 'clients.current.count',set => {
key_values => [ { name => 'num_clients' } ], key_values => [ { name => 'num_clients' } ],
@ -47,8 +47,7 @@ sub set_counters {
output_change_bytes => 2, output_change_bytes => 2,
output_template => 'Traffic In: %s %s/s', output_template => 'Traffic In: %s %s/s',
perfdatas => [ perfdatas => [
{ label => 'traffic_in', template => '%.2f', { label => 'traffic_in', template => '%.2f', min => 0, unit => 'b/s' }
min => 0, unit => 'b/s' }
] ]
} }
}, },
@ -57,8 +56,7 @@ sub set_counters {
output_change_bytes => 2, output_change_bytes => 2,
output_template => 'Traffic Out: %s %s/s', output_template => 'Traffic Out: %s %s/s',
perfdatas => [ perfdatas => [
{ label => 'traffic_out', template => '%.2f', { label => 'traffic_out', template => '%.2f', min => 0, unit => 'b/s' }
min => 0, unit => 'b/s' }
] ]
} }
} }
@ -81,12 +79,12 @@ sub manage_selection {
my $result = $options{custom}->command(cmd => 'load-stats'); my $result = $options{custom}->command(cmd => 'load-stats');
# SUCCESS: nclients=6,bytesin=7765329961,bytesout=18435500727 # SUCCESS: nclients=6,bytesin=7765329961,bytesout=18435500727
$self->{global} = { num_clients => 0, traffic_in => 0, traffic_out => 0 }; $self->{global} = { num_clients => 0, traffic_in => 0, traffic_out => 0 };
if ($result =~ /nclients=(\d+),bytesin=(\d+),bytesout=(\d+)/) { if ($result =~ /nclients=(\d+),bytesin=(\d+),bytesout=(\d+)/) {
$self->{global} = { num_clients => $1, traffic_in => $2 * 8, traffic_out => $3 * 8 }; $self->{global} = { num_clients => $1, traffic_in => $2 * 8, traffic_out => $3 * 8 };
} }
#status #status
#OpenVPN CLIENT LIST #OpenVPN CLIENT LIST
#Updated,Thu Jan 10 16:05:32 2019 #Updated,Thu Jan 10 16:05:32 2019
@ -112,8 +110,8 @@ sub manage_selection {
} }
} }
} }
$self->{cache_name} = "openvpn" . '_' . $self->{mode} . '_' . $options{custom}->get_connect_info() . '_' . $self->{cache_name} = 'openvpn_' . $self->{mode} . '_' . $options{custom}->get_connect_info() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
} }
@ -128,14 +126,9 @@ Check server usage.
=over 8 =over 8
=item B<--warning-*> =item B<--warning-*> B<--critical-*>
Threshold warning. Thresholds.
Can be: 'num-clients', 'traffic-in', 'traffic-out'.
=item B<--critical-*>
Threshold critical.
Can be: 'num-clients', 'traffic-in', 'traffic-out'. Can be: 'num-clients', 'traffic-in', 'traffic-out'.
=back =back

View File

@ -34,7 +34,7 @@ sub new {
'server-usage' => 'apps::openvpn::omi::mode::serverusage', 'server-usage' => 'apps::openvpn::omi::mode::serverusage',
}; };
$self->{custom_modes}{api} = 'apps::openvpn::omi::custom::api'; $self->{custom_modes}->{api} = 'apps::openvpn::omi::custom::api';
return $self; return $self;
} }