eradicate checks for dns column in node_ip table - now assumed to be there

This commit is contained in:
Oliver Gorwits
2012-12-01 22:42:17 +00:00
parent 8bf63007dc
commit d14f8db355
6 changed files with 36 additions and 118 deletions

View File

@@ -4,6 +4,10 @@
* Network Map now shows all device neighbors and allows click-through nav
[ENHANCEMENTS]
* eradicate checks for dns column in node_ip table - now assumed to be there
[BUG FIXES]
* port cotrol user log check now looks for all actions

View File

@@ -14,6 +14,8 @@ __PACKAGE__->add_columns(
{ data_type => "macaddr", is_nullable => 0 },
"ip",
{ data_type => "inet", is_nullable => 0 },
"dns",
{ data_type => "text", is_nullable => 1 },
"active",
{ data_type => "boolean", is_nullable => 1 },
"time_first",
@@ -37,43 +39,6 @@ __PACKAGE__->set_primary_key("mac", "ip");
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9+CuvuVWH88WxAf6IBij8g
=head1 GENERAL NOTES
This Result Class for the C<node_ip> table supports sites that have customized
their table to include a C<dns> column, containing a cached DNS record for the
Node at the time of discovery.
Calling the C<dns()> accessor will either return the content of that field if
the field is configured and installed, or else perform a live DNS lookup on
the IP field within the record (returning the first PTR, or undef).
To enable this feature, set the C<HAVE_NODEIP_DNS_COL> environment variable to
a true value. In the Netdisco web app you can activate the column using the
C<have_nodeip_dns_col> application setting, instead.
=cut
__PACKAGE__->add_column("dns" =>
{ data_type => "text", is_nullable => 1, accessor => undef });
# some customize their node_ip table to have a dns column which
# is the cached record at the time of discovery
sub dns {
my $row = shift;
return $row->get_column('dns')
if $row->result_source->has_column('dns');
use Net::DNS ();
my $q = Net::DNS::Resolver->new->query($row->ip);
if ($q) {
foreach my $rr ($q->answer) {
next unless $rr->type eq 'PTR';
return $rr->ptrdname;
}
}
return undef;
}
=head1 RELATIONSHIPS
=head2 oui
@@ -167,8 +132,6 @@ sub ip_aliases {
my ($row, $cond, $attrs) = @_;
my $rs = $row->node_ips({ip => { '!=' => $row->ip }});
$rs = $rs->search_rs({}, {'+columns' => 'dns'})
if $rs->has_dns_col;
return $rs
->search_rs({}, $search_attr)

View File

@@ -4,24 +4,6 @@ use base 'DBIx::Class::ResultSet';
use strict;
use warnings FATAL => 'all';
# some customize their node_ip table to have a dns column which
# is the cached record at the time of discovery
=head1 has_dns_col
Some sites customize their C<node_ip> table to include a C<dns> field which is
the cached record at the time of node discovery.
This method returns True if the C<node_ip> table is configured with a C<dns>
column.
=cut
sub has_dns_col {
my $rs = shift;
return $rs->result_source->has_column('dns');
}
my $search_attr = {
order_by => {'-desc' => 'time_last'},
'+columns' => [
@@ -82,9 +64,6 @@ sub search_by_ip {
}
$cond->{ip} = { $op => $ip };
$rs = $rs->search_rs({}, {'+columns' => 'dns'})
if $rs->has_dns_col;
return $rs
->search_rs({}, $search_attr)
->search($cond, $attrs);
@@ -131,16 +110,12 @@ To limit results only to active IPs, set C<< {active => 1} >> in C<cond>.
sub search_by_dns {
my ($rs, $cond, $attrs) = @_;
die "search_by_dns requires a dns col on the node_ip table.\n"
if not $rs->has_dns_col;
die "dns field required for search_by_dns\n"
if ref {} ne ref $cond or !exists $cond->{dns};
$cond->{dns} = { '-ilike' => delete $cond->{dns} };
return $rs
->search_rs({}, {'+columns' => 'dns'})
->search_rs({}, $search_attr)
->search($cond, $attrs);
}
@@ -184,9 +159,6 @@ sub search_by_mac {
die "mac address required for search_by_mac\n"
if ref {} ne ref $cond or !exists $cond->{mac};
$rs = $rs->search_rs({}, {'+columns' => 'dns'})
if $rs->has_dns_col;
return $rs
->search_rs({}, $search_attr)
->search($cond, $attrs);

View File

@@ -118,33 +118,15 @@ ajax '/ajax/content/search/node' => sub {
->search_by_ip({ip => $ip, @active});
}
else {
if (schema('netdisco')->resultset('NodeIp')->has_dns_col) {
if (param('partial')) {
$node = "\%$node\%";
}
elsif (setting('domain_suffix')) {
$node .= setting('domain_suffix')
if index($node, setting('domain_suffix')) == -1;
}
$set = schema('netdisco')->resultset('NodeIp')
->search_by_dns({dns => $node, @active});
if (param('partial')) {
$node = "\%$node\%";
}
elsif (setting('domain_suffix')) {
$node .= setting('domain_suffix')
if index($node, setting('domain_suffix')) == -1;
my $q = Net::DNS::Resolver->new->query($node);
if ($q) {
foreach my $rr ($q->answer) {
next unless $rr->type eq 'A';
$node = $rr->address;
}
}
else {
return;
}
$set = schema('netdisco')->resultset('NodeIp')
->search_by_ip({ip => $node, @active});
}
$set = schema('netdisco')->resultset('NodeIp')
->search_by_dns({dns => $node, @active});
}
return unless $set and $set->count;
@@ -263,9 +245,6 @@ get '/search' => sub {
{ id => 'port', label => 'Port' },
]);
var('node_ip_has_dns_col' =>
schema('netdisco')->resultset('NodeIp')->has_dns_col);
template 'search';
};

View File

@@ -29,7 +29,6 @@
Archived Data <span class="nd_legendlabel label label-warning">A</span></span>
</label>
</div>
[% IF vars.node_ip_has_dns_col %]
<div class="clearfix input-prepend">
<label class="add-on">
<input type="checkbox" id="partial"
@@ -39,5 +38,4 @@
<span class="nd_searchcheckbox uneditable-input">Partial Name</span>
</label>
</div>
[% END %]
<button id="[% tab.id %]_submit" type="submit" class="btn btn-info">Search Again</button>

View File

@@ -17,22 +17,16 @@ system has access to your Netdisco database.
Edit the C<Netdisco/environments/development.yml> file to have the correct
credentials and settings (host name) for your own Netdisco database.
In the same file, uncomment the C<no_auth> setting if you use Apache auth.
Currently the frontend only works with the built-in Netdisco authentication.
In the same file, uncomment the C<no_auth> setting if you use Apache auth, or
simply want to use Netdisco without logging in. Currently the frontend only
works with the built-in Netdisco authentication.
Optionally, in the same file uncomment and edit the C<domain_suffix> setting
to be appropriate for your local site (same as the C<domain> setting in
C<netdisco.conf>).
If you have a C<dns> column in your C<node_ip> table then set the
C<have_nodeip_dns_col> option also. Note that this can also enable a "live"
DNS lookup but you probably don't want the performance hit.
=head2 Dependencies
You will need to have Netdisco itself installed on the system as this module
will try to load the C<netdisco.pm> library.
To avoid muddying your system, use the following shell script to download and
install Perl dependencies into a custom library path:
@@ -42,7 +36,7 @@ install Perl dependencies into a custom library path:
Dancer \
DBIx::Class \
DBIx::Class::Helper::Row::SubClass \
DBD::Pg \
SQL::Translator \
Dancer::Plugin::DBIC \
NetAddr::IP \
Net::MAC \
@@ -53,16 +47,31 @@ install Perl dependencies into a custom library path:
Template::Toolkit \
YAML
In case you were wondering, the vast majority of dependencies come from
In case you were wondering, the majority of dependencies come from
L<DBIx::Class>.
B<Note> that to install L<DBD::Pg> you need the PostgreSQL development libraries
also installed. Best advice is to omit that item from the above script and try
to install a prebuilt DBD::Pg package for your OS. The following command will
test for the existence of DBD::Pg on your system:
B<Note> You also need to install L<DBD::Pg>. Best advice is to install a
prebuilt DBD::Pg package for your OS. The following command will test for the
existence of DBD::Pg on your system:
perl -MDBD::Pg\ 999
=head2 Database Update
You will need the latest Netdisco DB schema in your PostgreSQL server. Most
important is to have a C<dns> column in your C<node_ip> table. This
distribution includes scripts which can upgrade the DB schema for you, but
B<please> do take backups beforehand!
Whether you have no existing DB schema, or an existing DB schema without the
latest updates, simply run the following script in this distribution:
bin/upgrade_netdisco_schema_version.pl
The script should detect what needs to be done in your database and apply the
necessary changes. It will also add a table to keep track of what's changed,
so that you can run the script again in the future and receive more updates.
=head1 STARTUP
There's a simple web server built-in. This is sufficient for
@@ -94,11 +103,6 @@ For SQL debugging, and better performance, try the following command:
=head1 FUTURE WORK
At the moment the ability to just hit Enter in the title-bar Search is a
I<hack> because there's no other way to list all Inventory. When the Reports
code is added, the Inventory will be a part of that. It's understood that
simply hitting enter should return no results, not all results.
The intention is to support "plugins" for additonal features, most notably
columns in the Device Port listing, but also new menu items and tabs. The
design of this is sketched out but not implemented. The goal is to avoid
@@ -106,10 +110,8 @@ patching core code to add localizations or less widely used features. One
could imagine a C<Netdisco::Web::Plugin::> namespace for these.
Bundled with this app is a L<DBIx::Class> layer for the Netdisco database.
This could be a starting point for an "official" DBIC layer, but be warned
that at the moment it's a bit messy. Helper functions and canned searches have
been thrown together to support the web interface with little thought for
style or consistency or performance. That will come later.
This could be a starting point for an "official" DBIC layer. Helper functions
and canned searches have been added to support the web interface.
=head1 CAVEATS