enh(snmp_standard): arp mode - add mac/ip filter options (#3234)
This commit is contained in:
parent
8824c3cd4c
commit
f17c9f9341
|
@ -29,7 +29,7 @@ sub set_counters {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{maps_counters_type} = [
|
$self->{maps_counters_type} = [
|
||||||
{ name => 'global', type => 0, message_separator => ' - ' },
|
{ name => 'global', type => 0, message_separator => ' - ' }
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{global} = [
|
$self->{maps_counters}->{global} = [
|
||||||
|
@ -37,26 +37,26 @@ sub set_counters {
|
||||||
key_values => [ { name => 'total' } ],
|
key_values => [ { name => 'total' } ],
|
||||||
output_template => 'total entries %s',
|
output_template => 'total entries %s',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ value => 'total', template => '%s', min => 0 },
|
{ template => '%s', min => 0 }
|
||||||
],
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ label => 'duplicate-macaddr', nlabel => 'arp.duplicate.macaddr.count', set => {
|
{ label => 'duplicate-macaddr', nlabel => 'arp.duplicate.macaddr.count', set => {
|
||||||
key_values => [ { name => 'duplicate_macaddress' } ],
|
key_values => [ { name => 'duplicate_macaddress' } ],
|
||||||
output_template => 'duplicate mac address %s',
|
output_template => 'duplicate mac address %s',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ value => 'duplicate_macaddress', template => '%s', min => 0 },
|
{ template => '%s', min => 0 }
|
||||||
],
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ label => 'duplicate-ipaddr', nlabel => 'arp.duplicate.ipaddr.count', set => {
|
{ label => 'duplicate-ipaddr', nlabel => 'arp.duplicate.ipaddr.count', set => {
|
||||||
key_values => [ { name => 'duplicate_ipaddress' } ],
|
key_values => [ { name => 'duplicate_ipaddress' } ],
|
||||||
output_template => 'duplicate ip address %s',
|
output_template => 'duplicate ip address %s',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ value => 'duplicate_ipaddress', template => '%s', min => 0 },
|
{ template => '%s', min => 0 }
|
||||||
],
|
]
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +66,8 @@ sub new {
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments => {
|
$options{options}->add_options(arguments => {
|
||||||
|
'filter-macaddr:s' => { name => 'filter_macaddr' },
|
||||||
|
'filter-ipaddr:s' => { name => 'filter_ipaddr' }
|
||||||
});
|
});
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
|
@ -97,13 +99,26 @@ sub check_arp {
|
||||||
$self->{global} = { total => 0, duplicate_macaddress => 0, duplicate_ipaddress => 0 };
|
$self->{global} = { total => 0, duplicate_macaddress => 0, duplicate_ipaddress => 0 };
|
||||||
my $duplicate = { mac => { }, ip => {} };
|
my $duplicate = { mac => { }, ip => {} };
|
||||||
foreach (keys %{$options{result}}) {
|
foreach (keys %{$options{result}}) {
|
||||||
$self->{global}->{total}++;
|
|
||||||
my $mac = join(':', unpack('(H2)*', $options{result}->{$_}));
|
my $mac = join(':', unpack('(H2)*', $options{result}->{$_}));
|
||||||
/^$options{oid}\.(\d+)\.(.*)$/;
|
/^$options{oid}\.(\d+)\.(.*)$/;
|
||||||
$duplicate->{ip}->{$2} = [] if (!defined($duplicate->{ip}->{$2}));
|
my $ipaddr = $2;
|
||||||
push @{$duplicate->{ip}->{$2}}, $mac;
|
|
||||||
|
if (defined($self->{option_results}->{filter_macaddr}) && $self->{option_results}->{filter_macaddr} ne '' &&
|
||||||
|
$mac !~ /$self->{option_results}->{filter_macaddr}/) {
|
||||||
|
$self->{output}->output_add(long_msg => "skipping mac addr '" . $mac . "': no matching filter.", debug => 1);
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
if (defined($self->{option_results}->{filter_ipaddr}) && $self->{option_results}->{filter_ipaddr} ne '' &&
|
||||||
|
$ipaddr !~ /$self->{option_results}->{filter_ipaddr}/) {
|
||||||
|
$self->{output}->output_add(long_msg => "skipping ip addr '" . $ipaddr . "': no matching filter.", debug => 1);
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{global}->{total}++;
|
||||||
|
$duplicate->{ip}->{$ipaddr} = [] if (!defined($duplicate->{ip}->{$ipaddr}));
|
||||||
|
push @{$duplicate->{ip}->{$ipaddr}}, $mac;
|
||||||
$duplicate->{mac}->{$mac} = [] if (!defined($duplicate->{mac}->{$mac}));
|
$duplicate->{mac}->{$mac} = [] if (!defined($duplicate->{mac}->{$mac}));
|
||||||
push @{$duplicate->{mac}->{$mac}}, $2;
|
push @{$duplicate->{mac}->{$mac}}, $ipaddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->test_duplicate(duplicate => $duplicate);
|
$self->test_duplicate(duplicate => $duplicate);
|
||||||
|
@ -146,6 +161,14 @@ Check arp table.
|
||||||
|
|
||||||
=over 8
|
=over 8
|
||||||
|
|
||||||
|
=item B<--filter-macaddr>
|
||||||
|
|
||||||
|
Filter mac addresses (can be a regexp).
|
||||||
|
|
||||||
|
=item B<--filter-ipaddr>
|
||||||
|
|
||||||
|
Filter ip addresses (can be a regexp).
|
||||||
|
|
||||||
=item B<--warning-*> B<--critical-*>
|
=item B<--warning-*> B<--critical-*>
|
||||||
|
|
||||||
Thresholds.
|
Thresholds.
|
||||||
|
|
Loading…
Reference in New Issue