basic implementation, rancid graph and nodemonitor missing
This commit is contained in:
@@ -135,6 +135,20 @@ 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 { 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
|
||||
if (ref {} eq ref setting('device_identity')) {
|
||||
config->{'device_identity'} = [ setting('device_identity') ];
|
||||
|
||||
@@ -17,8 +17,8 @@ SELECT *
|
||||
FROM device
|
||||
WHERE dns IS NULL
|
||||
OR name IS NULL
|
||||
OR regexp_replace(lower(dns), ? || '$', '')
|
||||
!= regexp_replace(lower(name), ? || '$', '')
|
||||
OR regexp_replace(lower(dns), ?, '')
|
||||
!= regexp_replace(lower(name), ?, '')
|
||||
ENDSQL
|
||||
|
||||
1;
|
||||
|
||||
@@ -97,9 +97,9 @@ sub search_by_ip {
|
||||
->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', active => 1});
|
||||
|
||||
Like C<search()>, this returns a ResultSet of matching rows from the
|
||||
NodeIp table.
|
||||
@@ -118,6 +118,11 @@ to search for. The value may optionally include SQL wildcard characters.
|
||||
|
||||
=item *
|
||||
|
||||
The C<cond> parameter may optionally have a suffix parameter which is a
|
||||
regular expression of domain names that must also match the results.
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by time last seen.
|
||||
|
||||
=item *
|
||||
@@ -141,7 +146,13 @@ sub search_by_dns {
|
||||
die "dns field required for search_by_dns\n"
|
||||
if ref {} ne ref $cond or !exists $cond->{dns};
|
||||
|
||||
$cond->{dns} = { '-ilike' => delete $cond->{dns} };
|
||||
(my $suffix = (delete $cond->{suffix} || ''))
|
||||
=~ s|^\Q(?^\E|***:(?|;
|
||||
|
||||
$cond->{dns} = [ -and =>
|
||||
{ '-ilike' => delete $cond->{dns} },
|
||||
{ '~*' => "$suffix" },
|
||||
];
|
||||
|
||||
return $rs
|
||||
->search_rs({}, $search_attr)
|
||||
|
||||
@@ -121,9 +121,9 @@ sub make_node_infostring {
|
||||
sub make_link_infostring {
|
||||
my $link = shift or return '';
|
||||
|
||||
my $domain = quotemeta( setting('domain_suffix') || '' );
|
||||
(my $left_name = lc($link->{left_dns} || $link->{left_name} || $link->{left_ip})) =~ s/$domain$//;
|
||||
(my $right_name = lc($link->{right_dns} || $link->{right_name} || $link->{right_ip})) =~ s/$domain$//;
|
||||
my $domains = setting('domain_suffix');
|
||||
(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/$domains//;
|
||||
|
||||
my @zipped = List::MoreUtils::zip6
|
||||
@{$link->{left_port}}, @{$link->{left_descr}},
|
||||
@@ -163,7 +163,7 @@ ajax '/ajax/data/device/netmap' => require_login sub {
|
||||
my %logvals = ();
|
||||
my %metadata = ();
|
||||
my %data = ( nodes => [], links => [] );
|
||||
my $domain = quotemeta( setting('domain_suffix') || '' );
|
||||
my $domains = setting('domain_suffix');
|
||||
|
||||
# LINKS
|
||||
|
||||
@@ -236,7 +236,7 @@ ajax '/ajax/data/device/netmap' => require_login sub {
|
||||
keys %{ setting('host_group_displaynames') || {} };
|
||||
|
||||
++$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 = (
|
||||
speed => (($device->get_column('log') || 1) * 1000),
|
||||
|
||||
@@ -16,7 +16,7 @@ register_report(
|
||||
|
||||
get '/ajax/content/report/devicednsmismatch' => require_login sub {
|
||||
|
||||
my $suffix = setting('domain_suffix') || '';
|
||||
my $suffix = setting('domain_suffix');
|
||||
|
||||
my @results
|
||||
= schema('netdisco')->resultset('Virtual::DeviceDnsMismatch')
|
||||
|
||||
@@ -166,11 +166,13 @@ ajax '/ajax/content/search/node' => require_login sub {
|
||||
->search_by_ip({ip => $ip, @active, @times});
|
||||
}
|
||||
else {
|
||||
$likeval .= setting('domain_suffix')
|
||||
if index($node, setting('domain_suffix')) == -1;
|
||||
|
||||
$set = schema('netdisco')->resultset('NodeIp')
|
||||
->search_by_dns({dns => $likeval, @active, @times});
|
||||
->search_by_dns({
|
||||
dns => $likeval,
|
||||
suffix => setting('domain_suffix'),
|
||||
@active,
|
||||
@times,
|
||||
});
|
||||
|
||||
# if the user selects Vendor search opt, then
|
||||
# we'll try the OUI company name as a fallback
|
||||
|
||||
Reference in New Issue
Block a user