Fix dhcp snmp disable (#2706)

This commit is contained in:
qgarnier 2021-04-14 14:19:21 +02:00 committed by GitHub
parent 8225df9be9
commit e0513b1608
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 15 deletions

View File

@ -41,22 +41,30 @@ sub check_options {
$self->SUPER::init(%options); $self->SUPER::init(%options);
} }
my $oid_subnetAdd = '.1.3.6.1.4.1.311.1.3.2.1.1.1'; my $mapping = {
address => { oid => '.1.3.6.1.4.1.311.1.3.2.1.1.1' }, # subnetAdd
used => { oid => '.1.3.6.1.4.1.311.1.3.2.1.1.2' }, # noAddInUse
free => { oid => '.1.3.6.1.4.1.311.1.3.2.1.1.3' }, # noAddFree
pending_offers => { oid => '.1.3.6.1.4.1.311.1.3.2.1.1.4' } # noPendingOffers
};
my $oid_scope_table = '.1.3.6.1.4.1.311.1.3.2.1.1';
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $snmp_result = $options{snmp}->get_table( my $snmp_result = $options{snmp}->get_table(oid => $oid_scope_table);
oid => $oid_subnetAdd,
nothing_quit => 1
);
my $results = {}; my $results = {};
foreach (keys %$snmp_result) { foreach (keys %$snmp_result) {
/^$oid_subnetAdd\.(.*)$/; next if (! /^$mapping->{address}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1);
$results->{$instance} = { name => $snmp_result->{$_} }; my $status = 'enabled';
if ($result->{free} == 0 && $result->{used} == 0 && $result->{pending_offers} == 0) {
$status = 'disabled';
}
$results->{$instance} = { address => $result->{address}, status => $status };
} }
return $results; return $results;
@ -69,8 +77,9 @@ sub run {
foreach (sort keys %$results) { foreach (sort keys %$results) {
$self->{output}->output_add(long_msg => $self->{output}->output_add(long_msg =>
sprintf( sprintf(
'[address = %s]', '[address: %s][status: %s]',
$results->{$_}->{name} $results->{$_}->{address},
$results->{$_}->{status}
) )
); );
} }
@ -86,7 +95,7 @@ sub run {
sub disco_format { sub disco_format {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['address']); $self->{output}->add_disco_format(elements => ['address', 'status']);
} }
sub disco_show { sub disco_show {
@ -94,9 +103,7 @@ sub disco_show {
my $results = $self->manage_selection(snmp => $options{snmp}); my $results = $self->manage_selection(snmp => $options{snmp});
foreach (sort keys %$results) { foreach (sort keys %$results) {
$self->{output}->add_disco_entry( $self->{output}->add_disco_entry(%{$results->{$_}});
address => $results->{$_}->{name}
);
} }
} }

View File

@ -24,6 +24,16 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
'status: %s',
$self->{result_values}->{status}
);
}
sub custom_usage_output { sub custom_usage_output {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -49,10 +59,20 @@ sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'subnets', type => 1, cb_prefix_output => 'prefix_subnet_output', message_multiple => 'All subnets are ok' } { name => 'subnets', type => 1, cb_prefix_output => 'prefix_subnet_output', message_multiple => 'All subnets are ok', skipped_code => { -10 => 1 } }
]; ];
$self->{maps_counters}->{subnets} = [ $self->{maps_counters}->{subnets} = [
{
label => 'status', type => 2, set => {
key_values => [
{ name => 'status' }, { name => 'name' }
],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'addresses-usage', nlabel => 'subnet.addresses.usage.count', set => { { label => 'addresses-usage', nlabel => 'subnet.addresses.usage.count', set => {
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_usage_output'), closure_custom_output => $self->can('custom_usage_output'),
@ -101,7 +121,7 @@ sub new {
} }
my $mapping = { my $mapping = {
used => { oid => '.1.3.6.1.4.1.311.1.3.2.1.1.2' }, # noAddInUse used => { oid => '.1.3.6.1.4.1.311.1.3.2.1.1.2' }, # noAddInUse
free => { oid => '.1.3.6.1.4.1.311.1.3.2.1.1.3' }, # noAddFree free => { oid => '.1.3.6.1.4.1.311.1.3.2.1.1.3' }, # noAddFree
pending_offers => { oid => '.1.3.6.1.4.1.311.1.3.2.1.1.4' } # noPendingOffers pending_offers => { oid => '.1.3.6.1.4.1.311.1.3.2.1.1.4' } # noPendingOffers
}; };
@ -146,6 +166,11 @@ sub manage_selection {
foreach (keys %{$self->{subnets}}) { foreach (keys %{$self->{subnets}}) {
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
$self->{subnets}->{$_}->{status} = 'enabled';
if ($result->{free} == 0 && $result->{used} == 0 && $result->{pending_offers} == 0) {
$self->{subnets}->{$_}->{status} = 'disabled';
next;
}
$self->{subnets}->{$_}->{pending_offers} = $result->{pending_offers}; $self->{subnets}->{$_}->{pending_offers} = $result->{pending_offers};
$self->{subnets}->{$_}->{free} = $result->{free}; $self->{subnets}->{$_}->{free} = $result->{free};
$self->{subnets}->{$_}->{used} = $result->{used}; $self->{subnets}->{$_}->{used} = $result->{used};
@ -174,6 +199,21 @@ Example: --filter-counters='pending'
Filter subnets by address (can be a regexp). Filter subnets by address (can be a regexp).
=item B<--unknown-status>
Set unknown threshold for status.
Can used special variables like: %{status}, %{name}
=item B<--warning-status>
Set warning threshold for status.
Can used special variables like: %{status}, %{name}
=item B<--critical-status>
Set critical threshold for status.
Can used special variables like: %{status}, %{name}
=item B<--warning-*> B<--critical-*> =item B<--warning-*> B<--critical-*>
Thresholds. Thresholds.