mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-26 23:24:27 +02:00
enh(infoblox/snmp): dhcp-usage mode - add cache option (#3215)
This commit is contained in:
parent
180f3fcaa8
commit
c01470e857
@ -24,18 +24,19 @@ use base qw(centreon::plugins::templates::counter);
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
use centreon::plugins::statefile;
|
||||||
use Digest::MD5 qw(md5_hex);
|
use Digest::MD5 qw(md5_hex);
|
||||||
|
|
||||||
sub prefix_global_output {
|
sub prefix_global_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
return "Total ";
|
return 'Total ';
|
||||||
}
|
}
|
||||||
|
|
||||||
sub prefix_dhcp_output {
|
sub prefix_dhcp_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
return "Subnet '" . $options{instance_value}->{display} . "' ";
|
return "Subnet '" . $options{instance_value}->{name} . "' ";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub set_counters {
|
sub set_counters {
|
||||||
@ -73,10 +74,10 @@ sub set_counters {
|
|||||||
|
|
||||||
$self->{maps_counters}->{dhcp} = [
|
$self->{maps_counters}->{dhcp} = [
|
||||||
{ label => 'subnet-used', nlabel => 'subnet.addresses.usage.percentage', set => {
|
{ label => 'subnet-used', nlabel => 'subnet.addresses.usage.percentage', set => {
|
||||||
key_values => [ { name => 'ibDHCPSubnetPercentUsed' }, { name => 'display' } ],
|
key_values => [ { name => 'subnet_used' }, { name => 'name' } ],
|
||||||
output_template => 'used: %.2f %%',
|
output_template => 'used: %.2f %%',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }
|
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'name' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,12 +90,25 @@ 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' },
|
||||||
|
'cache' => { name => 'cache' },
|
||||||
|
'cache-time:s' => { name => 'cache_time', default => 180 }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$self->{lcache} = centreon::plugins::statefile->new(%options);
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub check_options {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
$self->SUPER::check_options(%options);
|
||||||
|
|
||||||
|
if (defined($self->{option_results}->{cache})) {
|
||||||
|
$self->{lcache}->check_options(option_results => $self->{option_results});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
my $mapping = {
|
my $mapping = {
|
||||||
ibDhcpTotalNoOfDiscovers => { oid => '.1.3.6.1.4.1.7779.3.1.1.4.1.3.1' },
|
ibDhcpTotalNoOfDiscovers => { oid => '.1.3.6.1.4.1.7779.3.1.1.4.1.3.1' },
|
||||||
ibDhcpTotalNoOfRequests => { oid => '.1.3.6.1.4.1.7779.3.1.1.4.1.3.2' },
|
ibDhcpTotalNoOfRequests => { oid => '.1.3.6.1.4.1.7779.3.1.1.4.1.3.2' },
|
||||||
@ -107,32 +121,57 @@ my $mapping = {
|
|||||||
ibDhcpTotalNoOfOthers => { oid => '.1.3.6.1.4.1.7779.3.1.1.4.1.3.9' }
|
ibDhcpTotalNoOfOthers => { oid => '.1.3.6.1.4.1.7779.3.1.1.4.1.3.9' }
|
||||||
};
|
};
|
||||||
my $mapping2 = {
|
my $mapping2 = {
|
||||||
ibDHCPSubnetNetworkAddress => { oid => '.1.3.6.1.4.1.7779.3.1.1.4.1.1.1.1' },
|
address => { oid => '.1.3.6.1.4.1.7779.3.1.1.4.1.1.1.1' }, # ibDHCPSubnetNetworkAddress
|
||||||
ibDHCPSubnetNetworkMask => { oid => '.1.3.6.1.4.1.7779.3.1.1.4.1.1.1.2' },
|
mask => { oid => '.1.3.6.1.4.1.7779.3.1.1.4.1.1.1.2' } # ibDHCPSubnetNetworkMask
|
||||||
ibDHCPSubnetPercentUsed => { oid => '.1.3.6.1.4.1.7779.3.1.1.4.1.1.1.3' }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
my $oid_ibDHCPStatistics = '.1.3.6.1.4.1.7779.3.1.1.4.1.3';
|
|
||||||
my $oid_ibDHCPSubnetEntry = '.1.3.6.1.4.1.7779.3.1.1.4.1.1.1';
|
my $oid_ibDHCPSubnetEntry = '.1.3.6.1.4.1.7779.3.1.1.4.1.1.1';
|
||||||
|
my $oid_subnet_prct_used = '.1.3.6.1.4.1.7779.3.1.1.4.1.1.1.3'; # ibDHCPSubnetPercentUsed
|
||||||
|
|
||||||
|
sub get_snmp_subnets {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return $options{snmp}->get_table(
|
||||||
|
oid => $oid_ibDHCPSubnetEntry,
|
||||||
|
end => $mapping2->{mask}->{oid},
|
||||||
|
nothing_quit => 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub get_subnets {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $subnets;
|
||||||
|
if (defined($self->{option_results}->{cache})) {
|
||||||
|
my $has_cache_file = $self->{lcache}->read(statefile => 'infoblox_cache_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port());
|
||||||
|
my $infos = $self->{lcache}->get(name => 'infos');
|
||||||
|
if ($has_cache_file == 0 ||
|
||||||
|
!defined($infos->{updated}) ||
|
||||||
|
((time() - $infos->{updated}) > (($self->{option_results}->{cache_time}) * 60))) {
|
||||||
|
$subnets = $self->get_snmp_subnets(snmp => $options{snmp});
|
||||||
|
$self->{lcache}->write(data => { updated => time(), snmp_result => $subnets });
|
||||||
|
} else {
|
||||||
|
$subnets = $infos->{snmp_result};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$subnets = $self->get_snmp_subnets(snmp => $options{snmp});
|
||||||
|
}
|
||||||
|
|
||||||
|
return $subnets;
|
||||||
|
}
|
||||||
|
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $snmp_result = $options{snmp}->get_multiple_table(
|
my $subnets = $self->get_subnets(snmp => $options{snmp});
|
||||||
oids => [
|
|
||||||
{ oid => $oid_ibDHCPStatistics },
|
|
||||||
{ oid => $oid_ibDHCPSubnetEntry }
|
|
||||||
],
|
|
||||||
nothing_quit => 1
|
|
||||||
);
|
|
||||||
|
|
||||||
$self->{dhcp} = {};
|
$self->{dhcp} = {};
|
||||||
foreach my $oid (keys %{$snmp_result->{$oid_ibDHCPSubnetEntry}}) {
|
foreach my $oid (keys %$subnets) {
|
||||||
next if ($oid !~ /^$mapping2->{ibDHCPSubnetNetworkAddress}->{oid}\.(.*)$/);
|
next if ($oid !~ /^$mapping2->{address}->{oid}\.(.*)$/);
|
||||||
my $instance = $1;
|
my $instance = $1;
|
||||||
my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_ibDHCPSubnetEntry}, instance => $instance);
|
my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $subnets, instance => $instance);
|
||||||
|
|
||||||
my $name = $result->{ibDHCPSubnetNetworkAddress} . '/' . $result->{ibDHCPSubnetNetworkMask};
|
my $name = $result->{address} . '/' . $result->{mask};
|
||||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||||
$name !~ /$self->{option_results}->{filter_name}/) {
|
$name !~ /$self->{option_results}->{filter_name}/) {
|
||||||
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
|
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
|
||||||
@ -140,12 +179,28 @@ sub manage_selection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$self->{dhcp}->{$instance} = {
|
$self->{dhcp}->{$instance} = {
|
||||||
display => $name,
|
name => $name,
|
||||||
%$result
|
%$result
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{global} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_ibDHCPStatistics}, instance => 0);
|
$options{snmp}->load(
|
||||||
|
oids => [ map($_->{oid}, values(%$mapping)) ],
|
||||||
|
instances => [0],
|
||||||
|
instance_regexp => '^(.*)$'
|
||||||
|
);
|
||||||
|
$options{snmp}->load(
|
||||||
|
oids => [$oid_subnet_prct_used],
|
||||||
|
instances => [ map($_, keys(%{$self->{dhcp}})) ],
|
||||||
|
instance_regexp => '^(.*)$'
|
||||||
|
);
|
||||||
|
my $snmp_result = $options{snmp}->get_leef();
|
||||||
|
foreach (keys %{$self->{dhcp}}) {
|
||||||
|
$self->{dhcp}->{$_}->{subnet_used} = $snmp_result->{ $oid_subnet_prct_used . '.' . $_ }
|
||||||
|
if (defined($snmp_result->{ $oid_subnet_prct_used . '.' . $_ }));
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{global} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0);
|
||||||
|
|
||||||
$self->{cache_name} = 'infoblox_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
|
$self->{cache_name} = 'infoblox_' . $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')) . '_' .
|
||||||
@ -171,6 +226,14 @@ Example: --filter-counters='total-requests'
|
|||||||
|
|
||||||
Filter dhcp subnet name (can be a regexp).
|
Filter dhcp subnet name (can be a regexp).
|
||||||
|
|
||||||
|
=item B<--cache>
|
||||||
|
|
||||||
|
Use cache file to store subnets.
|
||||||
|
|
||||||
|
=item B<--cache-time>
|
||||||
|
|
||||||
|
Time in minutes before reloading cache file (default: 180).
|
||||||
|
|
||||||
=item B<--warning-*>
|
=item B<--warning-*>
|
||||||
|
|
||||||
ibDhcpTotalNoOfDiscovers
|
ibDhcpTotalNoOfDiscovers
|
||||||
|
116
network/infoblox/snmp/mode/listdhcpsubnets.pm
Normal file
116
network/infoblox/snmp/mode/listdhcpsubnets.pm
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2021 Centreon (http://www.centreon.com/)
|
||||||
|
#
|
||||||
|
# Centreon is a full-fledged industry-strength solution that meets
|
||||||
|
# the needs in IT infrastructure and application monitoring for
|
||||||
|
# service performance.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
package network::infoblox::snmp::mode::listdhcpsubnets;
|
||||||
|
|
||||||
|
use base qw(centreon::plugins::mode);
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my ($class, %options) = @_;
|
||||||
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
|
bless $self, $class;
|
||||||
|
|
||||||
|
$options{options}->add_options(arguments => {
|
||||||
|
});
|
||||||
|
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub check_options {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
$self->SUPER::init(%options);
|
||||||
|
}
|
||||||
|
|
||||||
|
my $mapping = {
|
||||||
|
address => { oid => '.1.3.6.1.4.1.7779.3.1.1.4.1.1.1.1' }, # ibDHCPSubnetNetworkAddress
|
||||||
|
mask => { oid => '.1.3.6.1.4.1.7779.3.1.1.4.1.1.1.2' } # ibDHCPSubnetNetworkMask
|
||||||
|
};
|
||||||
|
my $oid_ibDHCPSubnetEntry = '.1.3.6.1.4.1.7779.3.1.1.4.1.1.1';
|
||||||
|
|
||||||
|
sub manage_selection {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $snmp_result = $options{snmp}->get_table(
|
||||||
|
oid => $oid_ibDHCPSubnetEntry,
|
||||||
|
end => $mapping->{mask}->{oid},
|
||||||
|
);
|
||||||
|
|
||||||
|
my $subnets = {};
|
||||||
|
foreach my $oid (keys %$snmp_result) {
|
||||||
|
next if ($oid !~ /^$mapping->{address}->{oid}\.(.*)$/);
|
||||||
|
$subnets->{$1} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $subnets;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub run {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $subnets = $self->manage_selection(%options);
|
||||||
|
foreach (keys %$subnets) {
|
||||||
|
$self->{output}->output_add(
|
||||||
|
long_msg => sprintf(
|
||||||
|
'[address: %s][mask: %s]',
|
||||||
|
$subnets->{$_}->{address},
|
||||||
|
$subnets->{$_}->{mask}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{output}->output_add(
|
||||||
|
severity => 'OK',
|
||||||
|
short_msg => 'List subnets:'
|
||||||
|
);
|
||||||
|
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||||
|
$self->{output}->exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
sub disco_format {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->{output}->add_disco_format(elements => ['address', 'mask']);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub disco_show {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $subnets = $self->manage_selection(%options);
|
||||||
|
foreach (keys %$subnets) {
|
||||||
|
$self->{output}->add_disco_entry(%{$subnets->{$_}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=head1 MODE
|
||||||
|
|
||||||
|
List DHCP subnets.
|
||||||
|
|
||||||
|
=over 8
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=cut
|
@ -34,6 +34,7 @@ sub new {
|
|||||||
'dhcp-usage' => 'network::infoblox::snmp::mode::dhcpusage',
|
'dhcp-usage' => 'network::infoblox::snmp::mode::dhcpusage',
|
||||||
'dns-usage' => 'network::infoblox::snmp::mode::dnsusage',
|
'dns-usage' => 'network::infoblox::snmp::mode::dnsusage',
|
||||||
'interfaces' => 'snmp_standard::mode::interfaces',
|
'interfaces' => 'snmp_standard::mode::interfaces',
|
||||||
|
'list-dhcp-subnets' => 'network::infoblox::snmp::mode::listdhcpsubnets',
|
||||||
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
|
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
|
||||||
'services' => 'network::infoblox::snmp::mode::services',
|
'services' => 'network::infoblox::snmp::mode::services',
|
||||||
'system' => 'network::infoblox::snmp::mode::system'
|
'system' => 'network::infoblox::snmp::mode::system'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user