From c1295ad1c0fd6f41ae494bed6d8f45c213448d6f Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 11 Jan 2014 13:25:22 +0000 Subject: [PATCH] [#14] Support partial DNS names in *_only/*_no (via regexp) --- Netdisco/Changes | 1 + .../lib/App/Netdisco/Manual/Configuration.pod | 31 +++++++++++-------- Netdisco/lib/App/Netdisco/Util/Device.pm | 19 ++++++++++++ 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index d8344491..2a00df1d 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -4,6 +4,7 @@ * [#81] Identify wireless nodes and provide information when available * [#13] Support IP address ranges in *_only/*_no configuration + * [#14] Support partial DNS names in *_only/*_no (via regexp) [ENHANCEMENTS] diff --git a/Netdisco/lib/App/Netdisco/Manual/Configuration.pod b/Netdisco/lib/App/Netdisco/Manual/Configuration.pod index 58d77899..6f7ba875 100644 --- a/Netdisco/lib/App/Netdisco/Manual/Configuration.pod +++ b/Netdisco/lib/App/Netdisco/Manual/Configuration.pod @@ -381,8 +381,9 @@ devices. For more fine-grained control see the C setting. Value: List of Network Identifiers or Device Properties. Default: Empty List. IP addresses in the list will use C (and not C). You can -include hostnames, IP addresses, subnets (IPv4 or IPv6), and address ranges -(using a hyphen and no whitespace) in the list. +include hostnames, IP addresses, subnets (IPv4 or IPv6), YAML Regexp to match +the DNS name, and address ranges (using a hyphen and no whitespace) in the +list. Alternatively include a "C" entry to match the named property of the device. The regex must match the complete value. @@ -446,8 +447,9 @@ Number of times to retry connecting to a device before giving up. Value: List of Network Identifiers or Device Properties. Default: Empty List. IP addresses in the list will not be visited during device discovery. You can -include hostnames, IP addresses, subnets (IPv4 or IPv6), and address ranges -(using a hyphen and no whitespace) in the list. +include hostnames, IP addresses, subnets (IPv4 or IPv6), YAML Regexp to match +the DNS name, and address ranges (using a hyphen and no whitespace) in the +list. Alternatively include a "C" entry to match the named property of the device. The regex must match the complete value. @@ -458,7 +460,8 @@ Value: List of Network Identifiers or Device Properties. Default: Empty List. If present, device discovery will be limited to IP addresses matching entries in this list. You can include hostnames, IP addresses, subnets (IPv4 and -IPv6), and address ranges (using a hyphen and no whitespace). +IPv6), YAML Regexp to match the DNS name, and address ranges (using a hyphen +and no whitespace). Alternatively include a "C" entry to match the named property of the device. The regex must match the complete value. @@ -488,8 +491,8 @@ discover jobs for a device. Value: List of Network Identifiers or Device Properties. Default: Empty List. IP addresses in the list will not be visited for macsuck. You can include -hostnames, IP addresses, subnets (IPv4 or IPv6), and address ranges (using a -hyphen and no whitespace) in the list. +hostnames, IP addresses, subnets (IPv4 or IPv6), YAML Regexp to match the DNS +name, and address ranges (using a hyphen and no whitespace) in the list. Alternatively include a "C" entry to match the named property of the device. The regex must match the complete value. @@ -499,8 +502,9 @@ of the device. The regex must match the complete value. Value: List of Network Identifiers or Device Properties. Default: Empty List. If present, macsuck will be limited to IP addresses matching entries in this -list. You can include hostnames, IP addresses, subnets (IPv4 and IPv6), and -address ranges (using a hyphen and no whitespace). +list. You can include hostnames, IP addresses, subnets (IPv4 and IPv6), YAML +Regexp to match the DNS name, and address ranges (using a hyphen and no +whitespace). Alternatively include a "C" entry to match the named property of the device. The regex must match the complete value. @@ -556,8 +560,8 @@ macsuck jobs for a device. Value: List of Network Identifiers or Device Properties. Default: Empty List. IP addresses in the list will not be visited for arpnip. You can include -hostnames, IP addresses, subnets (IPv4 or IPv6), and address ranges (using a -hyphen and no whitespace) in the list. +hostnames, IP addresses, subnets (IPv4 or IPv6), YAML Regexp to match the DNS +name, and address ranges (using a hyphen and no whitespace) in the list. Alternatively include a "C" entry to match the named property of the device. The regex must match the complete value. @@ -567,8 +571,9 @@ of the device. The regex must match the complete value. Value: List of Network Identifiers or Device Properties. Default: Empty List. If present, arpnip will be limited to IP addresses matching entries in this -list. You can include hostnames, IP addresses, subnets (IPv4 and IPv6), and -address ranges (using a hyphen and no whitespace). +list. You can include hostnames, IP addresses, subnets (IPv4 and IPv6), YAML +Regexp to match the DNS name, and address ranges (using a hyphen and no +whitespace). Alternatively include a "C" entry to match the named property of the device. The regex must match the complete value. diff --git a/Netdisco/lib/App/Netdisco/Util/Device.pm b/Netdisco/lib/App/Netdisco/Util/Device.pm index a95c9a0d..bb5f78be 100644 --- a/Netdisco/lib/App/Netdisco/Util/Device.pm +++ b/Netdisco/lib/App/Netdisco/Util/Device.pm @@ -4,6 +4,7 @@ use Dancer qw/:syntax :script/; use Dancer::Plugin::DBIC 'schema'; use NetAddr::IP::Lite ':lower'; +use App::Netdisco::Util::DNS 'hostname_from_ip'; use base 'Exporter'; our @EXPORT = (); @@ -76,6 +77,12 @@ sub check_acl { my $addr = NetAddr::IP::Lite->new($device->ip); foreach my $item (@$config) { + if (ref qr// eq ref $item) { + my $name = hostname_from_ip($addr->addr) or next; + return 1 if $name =~ $item; + next; + } + if ($item =~ m/^([^:]+)\s*:\s*([^:]+)$/) { my $prop = $1; my $match = $2; @@ -155,6 +162,12 @@ IP address range, using a hyphen and no whitespace =item * +Regular Expression in YAML format which will match the device DNS name, e.g.: + + - !!perl/regexp ^sep0.*$ + +=item * + C<"model:regex"> - matched against the device model =item * @@ -200,6 +213,12 @@ IP address range, using a hyphen and no whitespace =item * +Regular Expression in YAML format which will match the device DNS name, e.g.: + + - !!perl/regexp ^sep0.*$ + +=item * + C<"model:regex"> - matched against the device model =item *