From d14f8db3558e024ae989ee529c227fa1aea04210 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 1 Dec 2012 22:42:17 +0000 Subject: [PATCH] eradicate checks for dns column in node_ip table - now assumed to be there --- Changes | 4 ++ Netdisco/lib/Netdisco/DB/Result/NodeIp.pm | 41 +--------------- Netdisco/lib/Netdisco/DB/ResultSet/NodeIp.pm | 28 ----------- Netdisco/lib/Netdisco/Web/Search.pm | 29 ++---------- Netdisco/views/sidebar/search/node.tt | 2 - README.pod | 50 ++++++++++---------- 6 files changed, 36 insertions(+), 118 deletions(-) diff --git a/Changes b/Changes index 0f3252dc..cfa0dcdf 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/Netdisco/lib/Netdisco/DB/Result/NodeIp.pm b/Netdisco/lib/Netdisco/DB/Result/NodeIp.pm index e2cf9e38..1a2faf9e 100644 --- a/Netdisco/lib/Netdisco/DB/Result/NodeIp.pm +++ b/Netdisco/lib/Netdisco/DB/Result/NodeIp.pm @@ -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 table supports sites that have customized -their table to include a C column, containing a cached DNS record for the -Node at the time of discovery. - -Calling the C 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 environment variable to -a true value. In the Netdisco web app you can activate the column using the -C 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) diff --git a/Netdisco/lib/Netdisco/DB/ResultSet/NodeIp.pm b/Netdisco/lib/Netdisco/DB/ResultSet/NodeIp.pm index 3a31f272..c4e2c978 100644 --- a/Netdisco/lib/Netdisco/DB/ResultSet/NodeIp.pm +++ b/Netdisco/lib/Netdisco/DB/ResultSet/NodeIp.pm @@ -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 table to include a C field which is -the cached record at the time of node discovery. - -This method returns True if the C table is configured with a C -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. 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); diff --git a/Netdisco/lib/Netdisco/Web/Search.pm b/Netdisco/lib/Netdisco/Web/Search.pm index e5f134b0..0fb00f8e 100644 --- a/Netdisco/lib/Netdisco/Web/Search.pm +++ b/Netdisco/lib/Netdisco/Web/Search.pm @@ -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'; }; diff --git a/Netdisco/views/sidebar/search/node.tt b/Netdisco/views/sidebar/search/node.tt index 17c234d8..4aac3142 100644 --- a/Netdisco/views/sidebar/search/node.tt +++ b/Netdisco/views/sidebar/search/node.tt @@ -29,7 +29,6 @@ Archived Data A - [% IF vars.node_ip_has_dns_col %]
- [% END %] diff --git a/README.pod b/README.pod index 7cf7d967..7a0918d6 100644 --- a/README.pod +++ b/README.pod @@ -17,22 +17,16 @@ system has access to your Netdisco database. Edit the C file to have the correct credentials and settings (host name) for your own Netdisco database. -In the same file, uncomment the C setting if you use Apache auth. -Currently the frontend only works with the built-in Netdisco authentication. +In the same file, uncomment the C 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 setting to be appropriate for your local site (same as the C setting in C). -If you have a C column in your C table then set the -C 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 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. -B that to install L 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 You also need to install L. 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 column in your C table. This +distribution includes scripts which can upgrade the DB schema for you, but +B 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 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 namespace for these. Bundled with this app is a L 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