#591 domain_suffix can be list and supports (simple) regexp
Squashed commit of the following: commit975e4c6afcAuthor: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 3 13:35:26 2019 +0100 also support regexp in domain_suffix commit0a2b5c8fa2Author: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 3 13:17:17 2019 +0100 fix rancid, graph, and nodemonitor commit6d881de3ffAuthor: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 3 13:11:54 2019 +0100 improve docs and set default domain_suffix to be list commit1dcafc08a8Merge:9a752e0214ac69dcAuthor: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 3 13:00:39 2019 +0100 Merge branch 'master' into og-multiple-domain-suffix commit9a752e0298Merge:c836619f82a99ea9Author: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 3 09:45:25 2019 +0100 Merge branch 'master' into og-multiple-domain-suffix commitc836619f8cAuthor: Oliver Gorwits <oliver@cpan.org> Date: Thu Jun 13 07:52:45 2019 +0100 hokey fix for nodes with domains commitfed14bd810Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Jun 13 07:02:09 2019 +0100 basic implementation, rancid graph and nodemonitor missing
This commit is contained in:
@@ -46,7 +46,7 @@ use App::Netdisco::Util::Permission ':all';
|
|||||||
exit(0) unless setting('use_legacy_rancidexport');
|
exit(0) unless setting('use_legacy_rancidexport');
|
||||||
|
|
||||||
my $settings = setting( 'rancid' );
|
my $settings = setting( 'rancid' );
|
||||||
my $domain_suffix = setting( 'domain_suffix' ) || '';
|
my $domain_suffix = setting( 'domain_suffix' );
|
||||||
my $delimiter = $settings->{ 'delimiter' } || ':';
|
my $delimiter = $settings->{ 'delimiter' } || ':';
|
||||||
my $down_age = $settings->{ 'down_age' } || '1 day';
|
my $down_age = $settings->{ 'down_age' } || '1 day';
|
||||||
my $rancidhome = $settings->{ 'rancid_home' } || '/var/lib/rancid';
|
my $rancidhome = $settings->{ 'rancid_home' } || '/var/lib/rancid';
|
||||||
@@ -110,7 +110,7 @@ foreach my $group (keys %$list) {
|
|||||||
$name = ($dev->dns || $dev->name);
|
$name = ($dev->dns || $dev->name);
|
||||||
}
|
}
|
||||||
if ($by_hostname->{$group}) {
|
if ($by_hostname->{$group}) {
|
||||||
$name =~ s/$domain_suffix$//;
|
$name =~ s/$domain_suffix//;
|
||||||
}
|
}
|
||||||
printf ROUTER "%s$delimiter%s$delimiter%s\n", $name, $vendor,
|
printf ROUTER "%s$delimiter%s$delimiter%s\n", $name, $vendor,
|
||||||
$dev->get_column( 'old' ) ? "down" : "up";
|
$dev->get_column( 'old' ) ? "down" : "up";
|
||||||
|
|||||||
@@ -135,6 +135,21 @@ if ($ENV{NETDISCO_DOMAIN}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# convert domain_suffix from scalar or list to regexp
|
||||||
|
|
||||||
|
config->{'domain_suffix'} = [setting('domain_suffix')]
|
||||||
|
if ref [] ne ref setting('domain_suffix');
|
||||||
|
|
||||||
|
if (scalar @{ setting('domain_suffix') }) {
|
||||||
|
my @suffixes = map { (ref qr// eq ref $_) ? $_ : quotemeta }
|
||||||
|
@{ setting('domain_suffix') };
|
||||||
|
my $buildref = '(?:'. (join '|', @suffixes) .')$';
|
||||||
|
config->{'domain_suffix'} = qr/$buildref/;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
config->{'domain_suffix'} = qr//;
|
||||||
|
}
|
||||||
|
|
||||||
# support unordered dictionary as if it were a single item list
|
# support unordered dictionary as if it were a single item list
|
||||||
if (ref {} eq ref setting('device_identity')) {
|
if (ref {} eq ref setting('device_identity')) {
|
||||||
config->{'device_identity'} = [ setting('device_identity') ];
|
config->{'device_identity'} = [ setting('device_identity') ];
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ SELECT *
|
|||||||
FROM device
|
FROM device
|
||||||
WHERE dns IS NULL
|
WHERE dns IS NULL
|
||||||
OR name IS NULL
|
OR name IS NULL
|
||||||
OR regexp_replace(lower(dns), ? || '$', '')
|
OR regexp_replace(lower(dns), ?, '')
|
||||||
!= regexp_replace(lower(name), ? || '$', '')
|
!= regexp_replace(lower(name), ?, '')
|
||||||
ENDSQL
|
ENDSQL
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|||||||
@@ -97,9 +97,13 @@ sub search_by_ip {
|
|||||||
->search($cond, $attrs);
|
->search($cond, $attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
=head1 search_by_name( \%cond, \%attrs? )
|
=head1 search_by_dns( \%cond, \%attrs? )
|
||||||
|
|
||||||
my $set = $rs->search_by_name({dns => 'foo.example.com', active => 1});
|
my $set = $rs->search_by_dns({
|
||||||
|
dns => 'foo.example.com',
|
||||||
|
suffix => qr/(?:\.example\..com|\.local)$/,
|
||||||
|
active => 1
|
||||||
|
});
|
||||||
|
|
||||||
Like C<search()>, this returns a ResultSet of matching rows from the
|
Like C<search()>, this returns a ResultSet of matching rows from the
|
||||||
NodeIp table.
|
NodeIp table.
|
||||||
@@ -118,6 +122,11 @@ to search for. The value may optionally include SQL wildcard characters.
|
|||||||
|
|
||||||
=item *
|
=item *
|
||||||
|
|
||||||
|
The C<cond> parameter may optionally have a C<suffix> parameter which is a
|
||||||
|
regular expression of domain names - one of which must match the results.
|
||||||
|
|
||||||
|
=item *
|
||||||
|
|
||||||
Results are ordered by time last seen.
|
Results are ordered by time last seen.
|
||||||
|
|
||||||
=item *
|
=item *
|
||||||
@@ -141,7 +150,13 @@ sub search_by_dns {
|
|||||||
die "dns field required for search_by_dns\n"
|
die "dns field required for search_by_dns\n"
|
||||||
if ref {} ne ref $cond or !exists $cond->{dns};
|
if ref {} ne ref $cond or !exists $cond->{dns};
|
||||||
|
|
||||||
$cond->{dns} = { '-ilike' => delete $cond->{dns} };
|
(my $suffix = (delete $cond->{suffix} || ''))
|
||||||
|
=~ s|\Q(?^\Eu?|(?|g;
|
||||||
|
|
||||||
|
$cond->{dns} = [ -and =>
|
||||||
|
{ '-ilike' => delete $cond->{dns} },
|
||||||
|
{ '~*' => "***:$suffix" },
|
||||||
|
];
|
||||||
|
|
||||||
return $rs
|
return $rs
|
||||||
->search_rs({}, $search_attr)
|
->search_rs({}, $search_attr)
|
||||||
|
|||||||
@@ -298,8 +298,8 @@ sub graph_addnode {
|
|||||||
$devloc = $GRAPH{$ip}->{location};
|
$devloc = $GRAPH{$ip}->{location};
|
||||||
|
|
||||||
$label = "($ip)" unless defined $label;
|
$label = "($ip)" unless defined $label;
|
||||||
my $domain_suffix = setting('domain_suffix') || '';
|
my $domain_suffix = setting('domain_suffix');
|
||||||
$label =~ s/$domain_suffix$//;
|
$label =~ s/$domain_suffix//;
|
||||||
$node{label} = $label;
|
$node{label} = $label;
|
||||||
|
|
||||||
# Dereferencing the scalar by name below
|
# Dereferencing the scalar by name below
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use App::Netdisco;
|
|||||||
use Dancer qw/:syntax :script/;
|
use Dancer qw/:syntax :script/;
|
||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
|
|
||||||
|
use Net::Domain 'hostfqdn';
|
||||||
use App::Netdisco::Util::DNS qw/hostname_from_ip ipv4_from_hostname/;
|
use App::Netdisco::Util::DNS qw/hostname_from_ip ipv4_from_hostname/;
|
||||||
|
|
||||||
use base 'Exporter';
|
use base 'Exporter';
|
||||||
@@ -16,8 +17,7 @@ our %EXPORT_TAGS = (all => \@EXPORT_OK);
|
|||||||
sub _email {
|
sub _email {
|
||||||
my ($to, $subject, $body) = @_;
|
my ($to, $subject, $body) = @_;
|
||||||
return unless $to;
|
return unless $to;
|
||||||
my $domain = setting('domain_suffix') || 'localhost';
|
$domain =~ (hostfqdn || 'fqdn-undefined');
|
||||||
$domain =~ s/^\.//;
|
|
||||||
|
|
||||||
my $SENDMAIL = '/usr/sbin/sendmail';
|
my $SENDMAIL = '/usr/sbin/sendmail';
|
||||||
open (SENDMAIL, "| $SENDMAIL -t") or die "Can't open sendmail at $SENDMAIL.\n";
|
open (SENDMAIL, "| $SENDMAIL -t") or die "Can't open sendmail at $SENDMAIL.\n";
|
||||||
|
|||||||
@@ -121,9 +121,9 @@ sub make_node_infostring {
|
|||||||
sub make_link_infostring {
|
sub make_link_infostring {
|
||||||
my $link = shift or return '';
|
my $link = shift or return '';
|
||||||
|
|
||||||
my $domain = quotemeta( setting('domain_suffix') || '' );
|
my $domains = setting('domain_suffix');
|
||||||
(my $left_name = lc($link->{left_dns} || $link->{left_name} || $link->{left_ip})) =~ s/$domain$//;
|
(my $left_name = lc($link->{left_dns} || $link->{left_name} || $link->{left_ip})) =~ s/$domains//;
|
||||||
(my $right_name = lc($link->{right_dns} || $link->{right_name} || $link->{right_ip})) =~ s/$domain$//;
|
(my $right_name = lc($link->{right_dns} || $link->{right_name} || $link->{right_ip})) =~ s/$domains//;
|
||||||
|
|
||||||
my @zipped = List::MoreUtils::zip6
|
my @zipped = List::MoreUtils::zip6
|
||||||
@{$link->{left_port}}, @{$link->{left_descr}},
|
@{$link->{left_port}}, @{$link->{left_descr}},
|
||||||
@@ -163,7 +163,7 @@ ajax '/ajax/data/device/netmap' => require_login sub {
|
|||||||
my %logvals = ();
|
my %logvals = ();
|
||||||
my %metadata = ();
|
my %metadata = ();
|
||||||
my %data = ( nodes => [], links => [] );
|
my %data = ( nodes => [], links => [] );
|
||||||
my $domain = quotemeta( setting('domain_suffix') || '' );
|
my $domains = setting('domain_suffix');
|
||||||
|
|
||||||
# LINKS
|
# LINKS
|
||||||
|
|
||||||
@@ -236,7 +236,7 @@ ajax '/ajax/data/device/netmap' => require_login sub {
|
|||||||
keys %{ setting('host_group_displaynames') || {} };
|
keys %{ setting('host_group_displaynames') || {} };
|
||||||
|
|
||||||
++$logvals{ $device->get_column('log') || 1 };
|
++$logvals{ $device->get_column('log') || 1 };
|
||||||
(my $name = lc($device->dns || $device->name || $device->ip)) =~ s/$domain$//;
|
(my $name = lc($device->dns || $device->name || $device->ip)) =~ s/$domains//;
|
||||||
|
|
||||||
my %color_lkp = (
|
my %color_lkp = (
|
||||||
speed => (($device->get_column('log') || 1) * 1000),
|
speed => (($device->get_column('log') || 1) * 1000),
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ register_report(
|
|||||||
|
|
||||||
get '/ajax/content/report/devicednsmismatch' => require_login sub {
|
get '/ajax/content/report/devicednsmismatch' => require_login sub {
|
||||||
|
|
||||||
my $suffix = setting('domain_suffix') || '';
|
my $suffix = setting('domain_suffix');
|
||||||
|
|
||||||
my @results
|
my @results
|
||||||
= schema('netdisco')->resultset('Virtual::DeviceDnsMismatch')
|
= schema('netdisco')->resultset('Virtual::DeviceDnsMismatch')
|
||||||
|
|||||||
@@ -171,11 +171,14 @@ ajax '/ajax/content/search/node' => require_login sub {
|
|||||||
->search_by_ip({ip => $ip, @active, @times});
|
->search_by_ip({ip => $ip, @active, @times});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$likeval .= setting('domain_suffix')
|
|
||||||
if index($node, setting('domain_suffix')) == -1;
|
|
||||||
|
|
||||||
$set = schema('netdisco')->resultset('NodeIp')
|
$set = schema('netdisco')->resultset('NodeIp')
|
||||||
->search_by_dns({dns => $likeval, @active, @times});
|
->search_by_dns({
|
||||||
|
($using_wildcards ? (dns => $likeval) :
|
||||||
|
(dns => "${likeval}.\%",
|
||||||
|
suffix => setting('domain_suffix'))),
|
||||||
|
@active,
|
||||||
|
@times,
|
||||||
|
});
|
||||||
|
|
||||||
# if the user selects Vendor search opt, then
|
# if the user selects Vendor search opt, then
|
||||||
# we'll try the OUI company name as a fallback
|
# we'll try the OUI company name as a fallback
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ register_worker({ phase => 'main' }, sub {
|
|||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
my $config = setting('rancid') || {};
|
my $config = setting('rancid') || {};
|
||||||
|
|
||||||
my $domain_suffix = setting('domain_suffix') || '';
|
my $domain_suffix = setting('domain_suffix');
|
||||||
my $delimiter = $config->{delimiter} || ';';
|
my $delimiter = $config->{delimiter} || ';';
|
||||||
my $down_age = $config->{down_age} || '1 day';
|
my $down_age = $config->{down_age} || '1 day';
|
||||||
my $default_group = $config->{default_group} || 'default';
|
my $default_group = $config->{default_group} || 'default';
|
||||||
@@ -65,7 +65,7 @@ register_worker({ phase => 'main' }, sub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $name = check_acl_no($d, $config->{by_ip}) ? $d->ip : ($d->dns || $d->name);
|
my $name = check_acl_no($d, $config->{by_ip}) ? $d->ip : ($d->dns || $d->name);
|
||||||
$name =~ s/$domain_suffix$// if check_acl_no($d, $config->{by_hostname});
|
$name =~ s/$domain_suffix// if check_acl_no($d, $config->{by_hostname});
|
||||||
|
|
||||||
my ($group) =
|
my ($group) =
|
||||||
(pairkeys pairfirst { check_acl_no($d, $b) } %{ $config->{groups} }) || $default_group;
|
(pairkeys pairfirst { check_acl_no($d, $b) } %{ $config->{groups} }) || $default_group;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ external_databases: []
|
|||||||
# WEB FRONTEND
|
# WEB FRONTEND
|
||||||
# ------------
|
# ------------
|
||||||
|
|
||||||
domain_suffix: ""
|
domain_suffix: []
|
||||||
no_auth: false
|
no_auth: false
|
||||||
suggest_guest: false
|
suggest_guest: false
|
||||||
navbar_autocomplete: true
|
navbar_autocomplete: true
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ device_auth:
|
|||||||
# will be stripped from fqdn when displayed in the web UI
|
# will be stripped from fqdn when displayed in the web UI
|
||||||
# also, do not forget the leading dot.
|
# also, do not forget the leading dot.
|
||||||
# ```````````````````````````````````````````````````````
|
# ```````````````````````````````````````````````````````
|
||||||
#domain_suffix: '.example.com'
|
#domain_suffix: ['.example.com']
|
||||||
|
|
||||||
|
|
||||||
# ¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸
|
# ¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸
|
||||||
|
|||||||
Reference in New Issue
Block a user