basic implementation, rancid graph and nodemonitor missing

This commit is contained in:
Oliver Gorwits
2019-06-13 07:02:09 +01:00
parent 039527c26a
commit fed14bd810
6 changed files with 42 additions and 15 deletions

View File

@@ -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;

View File

@@ -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)