From 3197e38819ed076e8a81ad7b2224464df1811ca3 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 13 Apr 2013 14:48:31 +0100 Subject: [PATCH 01/21] allow netdisco-do to do all acton --- Netdisco/bin/netdisco-do | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/Netdisco/bin/netdisco-do b/Netdisco/bin/netdisco-do index f88ef910..23c3f45b 100755 --- a/Netdisco/bin/netdisco-do +++ b/Netdisco/bin/netdisco-do @@ -30,32 +30,21 @@ my $result = GetOptions( 'debug|D' => \$debug, ) or exit(1); -# reconfigure logging to use console my $CONFIG = config(); $CONFIG->{logger} = 'console'; $CONFIG->{log} = ($debug ? 'debug' : 'info'); +# reconfigure logging to force console output Dancer::Logger->init('console', $CONFIG); -# check requested action +# get requested action my $action = shift @ARGV; -my $PERMITTED_ACTIONS = qr/(?:discover|discover_neighbors)/; if (!length $action) { error 'error: missing action!'; exit (1); } -if ($action !~ m/^$PERMITTED_ACTIONS$/) { - error sprintf 'error: netdisco-do cannot [%s]', $action; - exit (1); -} - -if (!length $device) { - error 'error: missing device!'; - exit (1); -} - # create worker (placeholder object for the role methods) { package MyWorker; @@ -64,6 +53,12 @@ if (!length $device) { } my $worker = MyWorker->new(); +# belt and braces check before we go ahead +if (not $worker->can( $action )) { + error sprintf 'error: %s is not a valid action', $action; + exit (1); +} + # static configuration for the in-memory local job queue setting('plugins')->{DBIC}->{daemon} = { dsn => 'dbi:SQLite:dbname=:memory:', @@ -85,12 +80,6 @@ my $job = schema('daemon')->resultset('Admin')->new_result({ subaction => $extra, }); -# belt and braces check before we go ahead -if (not $worker->can( $action )) { - error sprintf 'error: %s is not a valid action for netdisco-do', $action; - exit (1); -} - # do job my ($status, $log); try { From 8a5306e05693700d0dbb8f8eaa909a29f3ed9c7c Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 13 Apr 2013 14:50:10 +0100 Subject: [PATCH 02/21] rename Discover.pm to Device.pm --- Netdisco/bin/netdisco-do | 2 +- Netdisco/lib/App/Netdisco/Daemon/Worker/Poller.pm | 2 +- .../Netdisco/Daemon/Worker/Poller/{Discover.pm => Device.pm} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/{Discover.pm => Device.pm} (97%) diff --git a/Netdisco/bin/netdisco-do b/Netdisco/bin/netdisco-do index 23c3f45b..aade7701 100755 --- a/Netdisco/bin/netdisco-do +++ b/Netdisco/bin/netdisco-do @@ -49,7 +49,7 @@ if (!length $action) { { package MyWorker; use Moo; - with 'App::Netdisco::Daemon::Worker::Poller::Discover'; + with 'App::Netdisco::Daemon::Worker::Poller::Device'; } my $worker = MyWorker->new(); diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller.pm index 4eefde88..5b6ca4a9 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller.pm @@ -9,7 +9,7 @@ use Role::Tiny; use namespace::clean; # add dispatch methods for poller tasks -with 'App::Netdisco::Daemon::Worker::Poller::Discover'; +with 'App::Netdisco::Daemon::Worker::Poller::Device'; sub worker_body { my $self = shift; diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Discover.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm similarity index 97% rename from Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Discover.pm rename to Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm index abfeff9a..e7774a78 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Discover.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm @@ -1,4 +1,4 @@ -package App::Netdisco::Daemon::Worker::Poller::Discover; +package App::Netdisco::Daemon::Worker::Poller::Device; use Dancer qw/:moose :syntax :script/; use Dancer::Plugin::DBIC 'schema'; From 1b897e4aee4421d61f83a2adc0bde7f89bf9890c Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 13 Apr 2013 14:51:06 +0100 Subject: [PATCH 03/21] change debug log tag for store_device --- Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm b/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm index b1aaaf69..c7693d5d 100644 --- a/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm +++ b/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm @@ -63,7 +63,7 @@ sub store_device { ? NetAddr::IP::Lite->new($addr, $ip_netmask->{$addr})->network->cidr : undef; - debug sprintf ' [%s] store_device - aliased as %s', $device->ip, $addr; + debug sprintf ' [%s] device - aliased as %s', $device->ip, $addr; push @aliases, { alias => $addr, port => $port, @@ -100,11 +100,11 @@ sub store_device { schema('netdisco')->txn_do(sub { my $gone = $device->device_ips->delete; - debug sprintf ' [%s] store_device - removed %s aliases', + debug sprintf ' [%s] device - removed %s aliases', $device->ip, $gone; $device->update_or_insert; $device->device_ips->populate(\@aliases); - debug sprintf ' [%s] store_device - added %d new aliases', + debug sprintf ' [%s] device - added %d new aliases', $device->ip, scalar @aliases; }); } From ca9edd114a4c3176e31ff1b0a01bc29bcc871107 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 13 Apr 2013 15:23:52 +0100 Subject: [PATCH 04/21] rename discoverall to discovernew --- Netdisco/lib/App/Netdisco/Daemon/Queue.pm | 2 +- Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm | 2 +- Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm | 2 +- Netdisco/lib/App/Netdisco/Daemon/Worker/Scheduler.pm | 4 ++-- Netdisco/share/config.yml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/Daemon/Queue.pm b/Netdisco/lib/App/Netdisco/Daemon/Queue.pm index 95cbb30d..7dae68f3 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Queue.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Queue.pm @@ -33,7 +33,7 @@ sub capacity_for { debug "checking local capacity for action $action"; my $action_map = { - Poller => [qw/refresh discover discoverall discover_neighbors/], + Poller => [qw/refresh discover discovernew discover_neighbors/], Interactive => [qw/location contact portcontrol portname vlan power/], }; diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm index 1216b6ad..3a6871d3 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm @@ -14,7 +14,7 @@ my $fqdn = hostfqdn || 'localhost'; my $role_map = { (map {$_ => 'Poller'} - qw/refresh discover discoverall discover_neighbors/), + qw/refresh discover discovernew discover_neighbors/), (map {$_ => 'Interactive'} qw/location contact portcontrol portname vlan power/) }; diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm index e7774a78..8c8e1b6e 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm @@ -53,7 +53,7 @@ sub discover { # run find_neighbors on all known devices, and run discover on any # newly found devices. -sub discoverall { +sub discovernew { my ($self, $job) = @_; my $devices = schema('netdisco')->resultset('Device')->get_column('ip'); diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Scheduler.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Scheduler.pm index 98eabb43..f7ad185b 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Scheduler.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Scheduler.pm @@ -11,10 +11,10 @@ use namespace::clean; my $jobactions = { map {$_ => undef} qw/ + refresh + discovernew / # saveconfigs -# discoverall -# refresh # macwalk # arpwalk # nbtwalk diff --git a/Netdisco/share/config.yml b/Netdisco/share/config.yml index cc13a5ad..d0dd4f90 100644 --- a/Netdisco/share/config.yml +++ b/Netdisco/share/config.yml @@ -80,7 +80,7 @@ daemon_pollers: 2 # what housekeeping tasks should this node *schedule* # (it only does them if daemon_pollers is non-zero) #housekeeping: -# discoverall: +# discovernew: # device: '192.0.2.0' # when: # wday: 'wed' From 78554e55160f2b472cd665a3f8677278794b10b4 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 13 Apr 2013 19:07:44 +0100 Subject: [PATCH 05/21] refactor snmp_connect to handle versions and device classes --- .../lib/App/Netdisco/Util/DiscoverAndStore.pm | 2 +- Netdisco/lib/App/Netdisco/Util/SNMP.pm | 97 ++++++++++++++----- 2 files changed, 74 insertions(+), 25 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm b/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm index c7693d5d..60b80ca8 100644 --- a/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm +++ b/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm @@ -95,7 +95,7 @@ sub store_device { $device->$property( $snmp->$property ); } - $device->snmp_class( $snmp->class ); + $device->snmp_class( $snmp->device_type ); $device->last_discover(\'now()'); schema('netdisco')->txn_do(sub { diff --git a/Netdisco/lib/App/Netdisco/Util/SNMP.pm b/Netdisco/lib/App/Netdisco/Util/SNMP.pm index d233ac2c..6e62c85a 100644 --- a/Netdisco/lib/App/Netdisco/Util/SNMP.pm +++ b/Netdisco/lib/App/Netdisco/Util/SNMP.pm @@ -60,6 +60,30 @@ sub _snmp_connect_generic { # get device details from db my $device = get_device($ip); + # TODO: only supporing v2c at the moment + my %snmp_args = ( + DestHost => $device->ip, + Retries => (setting('snmpretries') || 2), + Timeout => (setting('snmptimeout') || 1000000), + MibDirs => [ _build_mibdirs() ], + IgnoreNetSNMPConf => 1, + Debug => ($ENV{INFO_TRACE} || 0), + ); + + # TODO: add version force support + # use existing SNMP version or try 2, 1 + my @versions = (($device->snmp_ver || setting('snmpver') || 2)); + push @versions, 1; + + # use existing or new device class + my @classes = ('SNMP::Info'); + if ($device->snmp_class) { + unshift @classes, $device->snmp_class; + } + else { + $snmp_args{AutoSpecity} = 1; + } + # get the community string(s) my $comm_type = pop; my @communities = @{ setting($comm_type) || []}; @@ -67,36 +91,61 @@ sub _snmp_connect_generic { if length $device->snmp_comm and length $comm_type and $comm_type eq 'community'; - # TODO: only supporing v2c at the moment - my %snmp_args = ( - DestHost => $device->ip, - Version => ($device->snmp_ver || setting('snmpver') || 2), - Retries => (setting('snmpretries') || 2), - Timeout => (setting('snmptimeout') || 1000000), - MibDirs => [ _build_mibdirs() ], - AutoSpecify => 1, - IgnoreNetSNMPConf => 1, - Debug => ($ENV{INFO_TRACE} || 0), - ); - my $info = undef; - my $last_comm = 0; - COMMUNITY: foreach my $c (@communities) { - next unless defined $c and length $c; - try { - $info = SNMP::Info->new(%snmp_args, Community => $c); - ++$last_comm if ( - $info - and (not defined $info->error) - and length $info->uptime - ); - }; - last COMMUNITY if $last_comm; + VERSION: foreach my $ver (@versions) { + next unless length $ver; + + CLASS: foreach my $class (@classes) { + next unless length $class; + + COMMUNITY: foreach my $comm (@communities) { + next unless length $comm; + + $info = _try_connect($ver, $class, $comm, \%snmp_args) + and last VERSION; + } + } } return $info; } +sub _try_connect { + my ($ver, $class, $comm, $snmp_args) = @_; + my $info = undef; + + try { + debug + sprintf '[%s] try_connect with ver: %s, class: %s, comm: %s', + $snmp_args->{DestHost}, $ver, $class, $comm; + eval "require $class"; + + $info = $class->new(%$snmp_args, Version => $ver, Community => $comm); + undef $info unless ( + (not defined $info->error) + and length $info->uptime + and ($info->layers or $info->description) + and $info->class + ); + + # first time a device is discovered, re-instantiate into specific class + if ($info and $info->device_type ne $class) { + $class = $info->device_type; + debug + sprintf '[%s] try_connect with ver: %s, new class: %s, comm: %s', + $snmp_args->{DestHost}, $ver, $class, $comm; + + eval "require $class"; + $info = $class->new(%$snmp_args, Version => $ver, Community => $comm); + } + } + catch { + debug $_; + }; + + return $info; +} + sub _build_mibdirs { return map { dir(setting('mibhome'), $_) } @{ setting('mibdirs') || [] }; From 4546036f4f061377f7730d4e2cb55c2b438ce58d Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 13 Apr 2013 19:23:55 +0100 Subject: [PATCH 06/21] bug fixes in getting wireless info --- Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm b/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm index 60b80ca8..6af50d07 100644 --- a/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm +++ b/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm @@ -241,13 +241,13 @@ sub store_wireless { my $ssidbcast = $snmp->i_ssidbcast; my $ssidmac = $snmp->i_ssidmac; my $channel = $snmp->i_80211channel; - my $power = $snmp->i_dot11_cur_tx_pwr_mw; + my $power = $snmp->dot11_cur_tx_pwr_mw; # build device ssid list suitable for DBIC my @ssids; foreach my $entry (keys %$ssidlist) { - $entry =~ s/\.\d+$//; - my $port = $interfaces->{$entry}; + (my $iid = $entry) =~ s/\.\d+$//; + my $port = $interfaces->{$iid}; if (not length $port) { debug sprintf ' [%s] wireless - ignoring %s (no port mapping)', @@ -275,7 +275,6 @@ sub store_wireless { # build device channel list suitable for DBIC my @channels; foreach my $entry (keys %$channel) { - $entry =~ s/\.\d+$//; my $port = $interfaces->{$entry}; if (not length $port) { From 8228e73f5bc6470938f6c7b64e4762ab17a26ec2 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 13 Apr 2013 19:47:23 +0100 Subject: [PATCH 07/21] better name for util package --- .../lib/App/Netdisco/Daemon/{Worker/Interactive => }/Util.pm | 2 +- .../App/Netdisco/Daemon/Worker/Interactive/DeviceActions.pm | 4 ++-- .../lib/App/Netdisco/Daemon/Worker/Interactive/PortActions.pm | 4 ++-- Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) rename Netdisco/lib/App/Netdisco/Daemon/{Worker/Interactive => }/Util.pm (81%) diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Interactive/Util.pm b/Netdisco/lib/App/Netdisco/Daemon/Util.pm similarity index 81% rename from Netdisco/lib/App/Netdisco/Daemon/Worker/Interactive/Util.pm rename to Netdisco/lib/App/Netdisco/Daemon/Util.pm index 4853ad3f..a807e181 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Interactive/Util.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Util.pm @@ -1,4 +1,4 @@ -package App::Netdisco::Daemon::Worker::Interactive::Util; +package App::Netdisco::Daemon::Util; # support utilities for Daemon Actions diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Interactive/DeviceActions.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Interactive/DeviceActions.pm index 70362313..af3e02a0 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Interactive/DeviceActions.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Interactive/DeviceActions.pm @@ -1,8 +1,8 @@ package App::Netdisco::Daemon::Worker::Interactive::DeviceActions; -use App::Netdisco::Util::SNMP ':all'; +use App::Netdisco::Util::SNMP 'snmp_connect_rw'; use App::Netdisco::Util::Device 'get_device'; -use App::Netdisco::Daemon::Worker::Interactive::Util ':all'; +use App::Netdisco::Daemon::Util ':all'; use Role::Tiny; use namespace::clean; diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Interactive/PortActions.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Interactive/PortActions.pm index 1e0c0e48..5d868c22 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Interactive/PortActions.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Interactive/PortActions.pm @@ -1,8 +1,8 @@ package App::Netdisco::Daemon::Worker::Interactive::PortActions; -use App::Netdisco::Util::SNMP ':all'; use App::Netdisco::Util::Port ':all'; -use App::Netdisco::Daemon::Worker::Interactive::Util ':all'; +use App::Netdisco::Util::SNMP 'snmp_connect_rw'; +use App::Netdisco::Daemon::Util ':all'; use Role::Tiny; use namespace::clean; diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm index 8c8e1b6e..d6c3dd25 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm @@ -6,7 +6,7 @@ use Dancer::Plugin::DBIC 'schema'; use App::Netdisco::Util::SNMP 'snmp_connect'; use App::Netdisco::Util::Device 'get_device'; use App::Netdisco::Util::DiscoverAndStore ':all'; -use App::Netdisco::Daemon::Worker::Interactive::Util ':all'; +use App::Netdisco::Daemon::Util ':all'; use NetAddr::IP::Lite ':lower'; From cb6f125c73d046ab58f0ca124f494588663ec735 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 13 Apr 2013 20:26:59 +0100 Subject: [PATCH 08/21] discover root_ip properly --- Netdisco/lib/App/Netdisco/Util/DNS.pm | 28 ++++++++++- .../lib/App/Netdisco/Util/DiscoverAndStore.pm | 46 +++++++++++++++++-- 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/Util/DNS.pm b/Netdisco/lib/App/Netdisco/Util/DNS.pm index 5e15dd1b..58377cc3 100644 --- a/Netdisco/lib/App/Netdisco/Util/DNS.pm +++ b/Netdisco/lib/App/Netdisco/Util/DNS.pm @@ -8,7 +8,7 @@ use Net::DNS; use base 'Exporter'; our @EXPORT = (); our @EXPORT_OK = qw/ - hostname_from_ip + hostname_from_ip ipv4_from_hostname /; our %EXPORT_TAGS = (all => \@EXPORT_OK); @@ -35,6 +35,7 @@ Returns C if no PTR record exists for the IP. sub hostname_from_ip { my $ip = shift; + return unless $ip; my $res = Net::DNS::Resolver->new; my $query = $res->search($ip); @@ -49,5 +50,30 @@ sub hostname_from_ip { return undef; } +=head2 ipv4_from_hostname( $name ) + +Given a host name will return the first IPv4 address. + +Returns C if no A record exists for the name. + +=cut + +sub ipv4_from_hostname { + my $name = shift; + return unless $name; + + my $res = Net::DNS::Resolver->new; + my $query = $res->search($name); + + if ($query) { + foreach my $rr ($query->answer) { + next unless $rr->type eq "A"; + return $rr->address; + } + } + + return undef; +} + 1; diff --git a/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm b/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm index 6af50d07..d759503f 100644 --- a/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm +++ b/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm @@ -4,7 +4,7 @@ use Dancer qw/:syntax :script/; use Dancer::Plugin::DBIC 'schema'; use App::Netdisco::Util::Device 'get_device'; -use App::Netdisco::Util::DNS 'hostname_from_ip'; +use App::Netdisco::Util::DNS ':all'; use NetAddr::IP::Lite ':lower'; use Try::Tiny; @@ -47,6 +47,12 @@ sub store_device { my $interfaces = $snmp->interfaces; my $ip_netmask = $snmp->ip_netmask; + # find root IP + _set_canonical_ip($device, $snmp); + + my $hostname = hostname_from_ip($device->ip); + $device->dns($hostname) if length $hostname; + # build device aliases suitable for DBIC my @aliases; foreach my $entry (keys %$ip_index) { @@ -79,9 +85,6 @@ sub store_device { $device->vtp_domain( (values %$vtpdomains)[-1] ); } - my $hostname = hostname_from_ip($device->ip); - $device->dns($hostname) if length $hostname; - my @properties = qw/ snmp_ver snmp_comm description uptime contact name location @@ -109,6 +112,41 @@ sub store_device { }); } +sub _set_canonical_ip { + my ($device, $snmp) = @_; + + my $oldip = $device->ip; + my $newip = $snmp->root_ip; + + if (length $newip) { + if ($oldip ne $newip) { + debug sprintf ' [%s] device - changing root IP to alt IP %s', + $oldip, $newip; + + # remove old device and aliases + schema('netdisco')->txn_do(sub { + my $gone = $device->device_ips->delete; + debug sprintf ' [%s] device - removed %s aliases', + $oldip, $gone; + $device->delete; + debug sprintf ' [%s] device - deleted self', $oldip; + }); + + $device->ip($newip); + } + + # either root_ip is changed or unchanged, but it exists + return; + } + + my $revname = ipv4_from_hostname($snmp->name); + if (setting('reverse_sysname') and $revname) { + debug sprintf ' [%s] device - changing root IP to revname %s', + $oldip, $revname; + $device->ip($revname); + } +} + =head2 store_interfaces( $device, $snmp ) Given a Device database object, and a working SNMP connection, discover and From d735cc657d39ea554e141a74e711059f5a429343 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Fri, 19 Apr 2013 23:04:05 +0100 Subject: [PATCH 09/21] specify dependency versions explicitly. By specifying version '0' we accidentally allowed some brokenness, with *other* broken modules which don't specify versions required. So, we do it ourselves as it's our users who feel the pain. BTW skipped this for JSON and for DBD::Pg which might have stable OS-installed versions, instead. --- Netdisco/Makefile.PL | 60 ++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/Netdisco/Makefile.PL b/Netdisco/Makefile.PL index db37bbb5..1d7c2bf7 100644 --- a/Netdisco/Makefile.PL +++ b/Netdisco/Makefile.PL @@ -4,38 +4,38 @@ name 'App-Netdisco'; license 'bsd'; all_from 'lib/App/Netdisco.pm'; -requires 'Algorithm::Cron' => 0; -requires 'App::cpanminus' => 0; -requires 'App::local::lib::helper' => 0; +requires 'Algorithm::Cron' => 0.07; +requires 'App::cpanminus' => 1.6108; +requires 'App::local::lib::helper' => 0.07; requires 'DBD::Pg' => 0; -requires 'DBD::SQLite' => 0; -requires 'DBIx::Class' => 0; -requires 'DBIx::Class::Helper::Row::SubClass' => 0; -requires 'Daemon::Control' => 0; -requires 'Dancer' => 1.3098; -requires 'Dancer::Plugin::DBIC' => 0; -requires 'File::ShareDir' => 0; -requires 'HTML::Entities' => 0; -requires 'HTTP::Tiny' => 0; +requires 'DBD::SQLite' => 1.37; +requires 'DBIx::Class' => 0.08210; +requires 'DBIx::Class::Helpers' => 2.016006; +requires 'Daemon::Control' => 0.001000; +requires 'Dancer' => 1.3112; +requires 'Dancer::Plugin::DBIC' => 0.1802; +requires 'File::ShareDir' => 1.03; +requires 'HTML::Parser' => 3.70; +requires 'HTTP::Tiny' => 0.029; requires 'JSON' => 0; -requires 'List::MoreUtils' => 0; -requires 'Moo' => 0; -requires 'MCE' => 1.405; -requires 'Net::DNS' => 0; -requires 'Net::MAC' => 0; -requires 'NetAddr::IP' => '4.059'; -requires 'Path::Class' => 0; -requires 'Plack' => 1.0006; -requires 'Plack::Middleware::Expires' => 0; -requires 'Role::Tiny' => 0; -requires 'Socket6' => 0; -requires 'Starman' => 0; -requires 'SNMP::Info' => '3.01'; -requires 'SQL::Translator' => 0; -requires 'Template' => 0; -requires 'YAML' => 0; -requires 'namespace::clean' => 0; -requires 'version' => 0.9901; +requires 'List::MoreUtils' => 0.33; +requires 'Moo' => 1.001000; +requires 'MCE' => 1.408; +requires 'Net::DNS' => 0.72; +requires 'Net::MAC' => 2.103622; +requires 'NetAddr::IP' => 4.068; +requires 'Path::Class' => 0.32; +requires 'Plack' => 1.0023; +requires 'Plack::Middleware::Expires' => 0.03; +requires 'Role::Tiny' => 1.002005; +requires 'Socket6' => 0.23; +requires 'Starman' => 0.3008; +requires 'SNMP::Info' => 3.01; +requires 'SQL::Translator' => 0.11016; +requires 'Template::Toolkit' => 2.24; +requires 'YAML' => 0.84; +requires 'namespace::clean' => 0.24; +requires 'version' => 0.9902; install_share 'share'; From 9875c70f41664bbec220b98d60f0f49b003aad14 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Fri, 19 Apr 2013 23:36:06 +0100 Subject: [PATCH 10/21] much better handling of mibhome --- Netdisco/bin/netdisco-deploy | 26 ++++++++++++++++----- Netdisco/lib/App/Netdisco/Util/SNMP.pm | 3 ++- Netdisco/share/config.yml | 11 ++++++--- Netdisco/share/environments/deployment.yml | 1 - Netdisco/share/environments/development.yml | 1 - 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Netdisco/bin/netdisco-deploy b/Netdisco/bin/netdisco-deploy index b3e9d863..a64c4493 100755 --- a/Netdisco/bin/netdisco-deploy +++ b/Netdisco/bin/netdisco-deploy @@ -96,15 +96,27 @@ deploy_db() if $bool; say ''; $bool = $term->ask_yn( - prompt => 'Would you like to download and update vendor MAC prefixes (OUI data)?', default => 'n', + prompt => 'Download and update vendor MAC prefixes (OUI data)?', default => 'n', ); deploy_oui() if $bool; say ''; -$bool = $term->ask_yn( - prompt => 'Would you like to download and update MIB files?', default => 'n', -); -deploy_mibs() if $bool; +my $default_mibhome = dir($home, 'netdisco-mibs'); +if (setting('mibhome') and setting('mibhome') ne $default_mibhome) { + my $mibhome = $term->get_reply( + print_me => "MIB home options:", + prompt => "Download and update MIB files to...?", + choices => [setting('mibhome'), $default_mibhome, 'Skip this.'], + default => 'Skip this.', + ); + deploy_mibs($mibhome) if $mibhome and $mibhome ne 'Skip this.'; +} +else { + $bool = $term->ask_yn( + prompt => "Download and update MIB files to $default_mibhome ?", default => 'n', + ); + deploy_mibs($default_mibhome) if $bool; +} sub deploy_db { system 'netdisco-db-deploy'; @@ -142,13 +154,15 @@ sub deploy_oui { } sub deploy_mibs { + my $mibhome = shift; + my $url = 'http://downloads.sourceforge.net/project/netdisco/netdisco-mibs/latest-snapshot/netdisco-mibs-snapshot.tar.gz'; my $file = file($home, 'netdisco-mibs-snapshot.tar.gz'); my $resp = HTTP::Tiny->new->mirror($url, $file); if ($resp->{success}) { my $ae = Archive::Extract->new(archive => $file, type => 'tgz'); - $ae->extract(to => $home); + $ae->extract(to => $mibhome); unlink $file; } diff --git a/Netdisco/lib/App/Netdisco/Util/SNMP.pm b/Netdisco/lib/App/Netdisco/Util/SNMP.pm index 6e62c85a..ee294a65 100644 --- a/Netdisco/lib/App/Netdisco/Util/SNMP.pm +++ b/Netdisco/lib/App/Netdisco/Util/SNMP.pm @@ -147,7 +147,8 @@ sub _try_connect { } sub _build_mibdirs { - return map { dir(setting('mibhome'), $_) } + my $home = (setting('mibhome') || $ENV{NETDISCO_HOME} || $ENV{HOME}); + return map { dir($home, $_) } @{ setting('mibdirs') || [] }; } diff --git a/Netdisco/share/config.yml b/Netdisco/share/config.yml index d0dd4f90..e8335960 100644 --- a/Netdisco/share/config.yml +++ b/Netdisco/share/config.yml @@ -3,7 +3,7 @@ # Web app env-related settings should go to environments/$env.yml -# Your application's name +# application's name appname: "Netdisco" # The default web layout to use for your application (located in @@ -33,7 +33,7 @@ engines: end_tag: '%]' PRE_CHOMP: 1 -# netdisco stuff (can be overidden in the environment .yml) +# Netdisco stuff (can be overidden in the environment .yml) web_plugins: - Inventory @@ -55,7 +55,12 @@ snmpver: 2 snmpretries: 2 snmptimeout: 1000000 -mibhome: /usr/share/netdisco/mibs +# If unset, Netdisco uses "NETDISCO_HOME/netdisco-mibs", assuming you're +# using the netdisco-deploy script to download MIBs there. Otherwise, set +# this, for example: +# +# mibhome: /usr/share/netdisco/mibs + mibdirs: - cisco - rfc diff --git a/Netdisco/share/environments/deployment.yml b/Netdisco/share/environments/deployment.yml index 4a86ea43..8015d90a 100644 --- a/Netdisco/share/environments/deployment.yml +++ b/Netdisco/share/environments/deployment.yml @@ -37,7 +37,6 @@ plugins: # local settings for Netdisco poller and port changes -mibhome: '/home/netdisco/netdisco-mibs' mibdirs: - cisco - rfc diff --git a/Netdisco/share/environments/development.yml b/Netdisco/share/environments/development.yml index 9bd1af97..9c08e46f 100644 --- a/Netdisco/share/environments/development.yml +++ b/Netdisco/share/environments/development.yml @@ -39,7 +39,6 @@ no_auth: 1 # local settings for Netdisco poller and port changes -mibhome: '/home/netdisco/netdisco-mibs' mibdirs: - cisco - rfc From 45a2f05b262c2f70705f189f7b85a79a07afc5f6 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 20 Apr 2013 00:07:50 +0100 Subject: [PATCH 11/21] fix bad assumption about mibs destination dir --- Netdisco/bin/netdisco-deploy | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Netdisco/bin/netdisco-deploy b/Netdisco/bin/netdisco-deploy index a64c4493..a03bf1f2 100755 --- a/Netdisco/bin/netdisco-deploy +++ b/Netdisco/bin/netdisco-deploy @@ -42,6 +42,7 @@ use Term::UI; use Term::ReadLine; use Archive::Extract; +$Archive::Extract::PREFER_BIN = 1; use HTTP::Tiny; use Try::Tiny; @@ -113,7 +114,7 @@ if (setting('mibhome') and setting('mibhome') ne $default_mibhome) { } else { $bool = $term->ask_yn( - prompt => "Download and update MIB files to $default_mibhome ?", default => 'n', + prompt => "Download and update MIB files?", default => 'n', ); deploy_mibs($default_mibhome) if $bool; } @@ -154,7 +155,7 @@ sub deploy_oui { } sub deploy_mibs { - my $mibhome = shift; + my $mibhome = dir(shift); my $url = 'http://downloads.sourceforge.net/project/netdisco/netdisco-mibs/latest-snapshot/netdisco-mibs-snapshot.tar.gz'; my $file = file($home, 'netdisco-mibs-snapshot.tar.gz'); @@ -162,7 +163,7 @@ sub deploy_mibs { if ($resp->{success}) { my $ae = Archive::Extract->new(archive => $file, type => 'tgz'); - $ae->extract(to => $mibhome); + $ae->extract(to => $mibhome->parent->stringify); unlink $file; } From e77affd7a1b5b76004f315ee474c3ae52fcdaaa7 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 22 Apr 2013 22:24:34 +0100 Subject: [PATCH 12/21] fix for jQuery 1.9 change in attr() handling --- Netdisco/share/views/js/search.js | 4 ++-- Netdisco/share/views/layouts/main.tt | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Netdisco/share/views/js/search.js b/Netdisco/share/views/js/search.js index e917e7cd..e44d4f7a 100644 --- a/Netdisco/share/views/js/search.js +++ b/Netdisco/share/views/js/search.js @@ -9,7 +9,7 @@ // if any field in Device Search Options has content, highlight in green // and strikethrough the navbar search function device_form_state(e) { - if (e.is('[value!=""]')) { + if (e.prop('value') != "") { if (e.attr('type') == 'text') { $('.field_copy_icon').hide(); } @@ -25,7 +25,7 @@ var id = '#' + e.attr('name') + '_clear_btn'; $(id).hide(); - if (! d_inputs.is('[value!=""]') ) { + if (! d_inputs.val() ) { $('#nq').css('text-decoration', 'none'); $('.field_copy_icon').show(); } diff --git a/Netdisco/share/views/layouts/main.tt b/Netdisco/share/views/layouts/main.tt index 187fb50b..f752a221 100644 --- a/Netdisco/share/views/layouts/main.tt +++ b/Netdisco/share/views/layouts/main.tt @@ -12,6 +12,7 @@ + From f1b27c2a83b4695a8fe63577a751d19961eefbf5 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 22 Apr 2013 22:44:13 +0100 Subject: [PATCH 13/21] hack for odd z-order of tips with navbar (boostrap bug?) --- Netdisco/share/views/sidebar/device/ports.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Netdisco/share/views/sidebar/device/ports.tt b/Netdisco/share/views/sidebar/device/ports.tt index 5dba23ae..79c5f9ac 100644 --- a/Netdisco/share/views/sidebar/device/ports.tt +++ b/Netdisco/share/views/sidebar/device/ports.tt @@ -2,7 +2,7 @@
+ rel="tooltip" data-placement="bottom" data-offset="3" data-title="Show all Ports"> Date: Mon, 22 Apr 2013 23:03:14 +0100 Subject: [PATCH 14/21] another hack for odd tooltip behaviour --- Netdisco/share/views/sidebar/device/ports.tt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Netdisco/share/views/sidebar/device/ports.tt b/Netdisco/share/views/sidebar/device/ports.tt index 79c5f9ac..e21c2a1d 100644 --- a/Netdisco/share/views/sidebar/device/ports.tt +++ b/Netdisco/share/views/sidebar/device/ports.tt @@ -76,15 +76,7 @@
  • - -
  • -
  • - + Mark as Free if Down for:
    -
    +
  • +
  • +
From 9663fb5f2ad33faa6d839e9a3f6f36fc5282cffb Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 23 Apr 2013 22:32:19 +0100 Subject: [PATCH 15/21] refactor for shared green highlighting in port and search --- Netdisco/share/public/css/netdisco.css | 19 ++++++++- Netdisco/share/public/javascripts/netdisco.js | 36 ++++++++++++++++ Netdisco/share/views/js/device.js | 31 +++++--------- Netdisco/share/views/js/search.js | 42 +------------------ Netdisco/share/views/sidebar/device/ports.tt | 8 ++-- 5 files changed, 69 insertions(+), 67 deletions(-) diff --git a/Netdisco/share/public/css/netdisco.css b/Netdisco/share/public/css/netdisco.css index 654ddf30..1e332d39 100644 --- a/Netdisco/share/public/css/netdisco.css +++ b/Netdisco/share/public/css/netdisco.css @@ -266,13 +266,28 @@ td { /* little icon inside of search input fields */ .field_clear_icon, .field_copy_icon { position: absolute; - margin-left: 132px; + margin-left: 140px; + margin-top: 5px; z-index: 1; - padding: 7px; + padding: 0px; cursor: pointer; +} + +.field_copy_icon { color: #999; } +.field_clear_icon { + background-color: #A9DBA9; + color: #3A87AD; +} + + /* for the ports form, but the positioning is slightly different */ +#ports_form .field_clear_icon { + margin-left: 149px; + margin-top: 5px; +} + /* change highlighting for form fields which are being used in a search */ form .clearfix.success select { background-color: #A9DBA9; diff --git a/Netdisco/share/public/javascripts/netdisco.js b/Netdisco/share/public/javascripts/netdisco.js index 137996fd..6cc9da3a 100644 --- a/Netdisco/share/public/javascripts/netdisco.js +++ b/Netdisco/share/public/javascripts/netdisco.js @@ -135,7 +135,43 @@ if (window.History && window.History.enabled) { }); } +// if any field in Search Options has content, highlight in green +function device_form_state(e) { + if (e.prop('value') != "") { + e.parent(".clearfix").addClass('success'); + + if (e.parents('#device_form').length) { + $('#nq').css('text-decoration', 'line-through'); + + if (e.attr('type') == 'text') { + $('.field_copy_icon').hide(); + } + } + + var id = '#' + e.attr('name') + '_clear_btn'; + $(id).show(); + } + else { + e.parent(".clearfix").removeClass('success'); + var id = '#' + e.attr('name') + '_clear_btn'; + $(id).hide(); + + var num_empty = $.grep(form_inputs, + function(n,i) {return($(n).val() != "")}).length; + if (num_empty === 3) { + $('#nq').css('text-decoration', 'none'); + $('.field_copy_icon').show(); + } + } +} + $(document).ready(function() { + // sidebar form fields should change colour and have bin/copy icon + $('.field_copy_icon').hide(); + $('.field_clear_icon').hide(); + form_inputs.each(function() {device_form_state($(this))}); + form_inputs.change(function() {device_form_state($(this))}); + // activate typeahead on the main search box, for device names only $('#nq').typeahead({ source: function (query, process) { diff --git a/Netdisco/share/views/js/device.js b/Netdisco/share/views/js/device.js index 354a6d1f..bfcf9ee1 100644 --- a/Netdisco/share/views/js/device.js +++ b/Netdisco/share/views/js/device.js @@ -2,6 +2,10 @@ // ajax content is loaded var path = 'device'; + // fields in the Device Search Options form (Device tab) + var form_inputs = $("#ports_form .clearfix input").not('[type="checkbox"]') + .add("#ports_form .clearfix select"); + function inner_view_processing(tab) { // LT wanted the page title to reflect what's on the page :) document.title = $('#nd_device_name').text() @@ -106,28 +110,12 @@ .toggleClass('icon-chevron-up icon-chevron-down'); }); - // show or hide sweeping brush icon when field has content - var sweep = $('#ports_form').find("input[name=f]"); - - if (sweep.val() === "") { - $('.field_clear_icon').hide(); - } else { - $('.field_clear_icon').show(); - } - - sweep.change(function() { - if ($(this).val() === "") { - $('.field_clear_icon').hide(); - } else { - $('.field_clear_icon').show(); - } - }); - - // handler for sweeping brush icon in port filter box + // handler for bin icon in port filter box + var portfilter = $('#ports_form').find("input[name=f]"); $('.field_clear_icon').click(function() { - sweep.val(''); - $('.field_clear_icon').hide(); + portfilter.val(''); $('#ports_form').trigger('submit'); + device_form_state(portfilter); // will hide copy icons }); // clickable device port names can simply resubmit AJAX rather than @@ -137,9 +125,10 @@ var port = $(this).text(); port = $.trim(port); - sweep.val(port); + portfilter.val(port); $('.field_clear_icon').show(); $('#ports_form').trigger('submit'); + device_form_state(portfilter); // will hide copy icons }); }); diff --git a/Netdisco/share/views/js/search.js b/Netdisco/share/views/js/search.js index e44d4f7a..927d6b01 100644 --- a/Netdisco/share/views/js/search.js +++ b/Netdisco/share/views/js/search.js @@ -3,55 +3,17 @@ var path = 'search'; // fields in the Device Search Options form (Device tab) - var d_inputs = $("#device_form .clearfix input").not('[type="checkbox"]') + var form_inputs = $("#device_form .clearfix input").not('[type="checkbox"]') .add("#device_form .clearfix select"); - // if any field in Device Search Options has content, highlight in green - // and strikethrough the navbar search - function device_form_state(e) { - if (e.prop('value') != "") { - if (e.attr('type') == 'text') { - $('.field_copy_icon').hide(); - } - - e.parent(".clearfix").addClass('success'); - $('#nq').css('text-decoration', 'line-through'); - - var id = '#' + e.attr('name') + '_clear_btn'; - $(id).show(); - } - else { - e.parent(".clearfix").removeClass('success'); - var id = '#' + e.attr('name') + '_clear_btn'; - $(id).hide(); - - if (! d_inputs.val() ) { - $('#nq').css('text-decoration', 'none'); - $('.field_copy_icon').show(); - } - } - } - // this is called by do_search to support local code // here, when tab changes need to strike/unstrike the navbar search function inner_view_processing(tab) { - if (tab == 'device') { - d_inputs.each(function() {device_form_state($(this))}); - } - else { - $('#nq').css('text-decoration', 'none'); - } } // on load, check initial Device Search Options form state, // and on each change to the form fields $(document).ready(function() { - $('.field_copy_icon').hide(); - $('.field_clear_icon').hide(); - - d_inputs.each(function() {device_form_state($(this))}); - d_inputs.change(function() {device_form_state($(this))}); - // handler for copy icon in search option $('.field_copy_icon').click(function() { var name = $(this).data('btn-for'); @@ -65,6 +27,6 @@ var name = $(this).data('btn-for'); var input = $('#device_form [name=' + name + ']'); input.val(''); - device_form_state(input); + device_form_state(input); // will hide copy icons }); }); diff --git a/Netdisco/share/views/sidebar/device/ports.tt b/Netdisco/share/views/sidebar/device/ports.tt index e21c2a1d..ea432913 100644 --- a/Netdisco/share/views/sidebar/device/ports.tt +++ b/Netdisco/share/views/sidebar/device/ports.tt @@ -1,9 +1,9 @@
- - + @@ -92,7 +92,7 @@ From 7940e1aedab3d6ca4a6fda0abeb3ba3c11697108 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 23 Apr 2013 22:49:00 +0100 Subject: [PATCH 16/21] fix for form_inputs not being defined --- Netdisco/share/public/javascripts/netdisco.js | 2 -- Netdisco/share/views/js/device.js | 4 ++++ Netdisco/share/views/js/search.js | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Netdisco/share/public/javascripts/netdisco.js b/Netdisco/share/public/javascripts/netdisco.js index 6cc9da3a..865eb60e 100644 --- a/Netdisco/share/public/javascripts/netdisco.js +++ b/Netdisco/share/public/javascripts/netdisco.js @@ -169,8 +169,6 @@ $(document).ready(function() { // sidebar form fields should change colour and have bin/copy icon $('.field_copy_icon').hide(); $('.field_clear_icon').hide(); - form_inputs.each(function() {device_form_state($(this))}); - form_inputs.change(function() {device_form_state($(this))}); // activate typeahead on the main search box, for device names only $('#nq').typeahead({ diff --git a/Netdisco/share/views/js/device.js b/Netdisco/share/views/js/device.js index bfcf9ee1..fe1dd136 100644 --- a/Netdisco/share/views/js/device.js +++ b/Netdisco/share/views/js/device.js @@ -99,6 +99,10 @@ } $(document).ready(function() { + // sidebar form fields should change colour and have bin/copy icon + form_inputs.each(function() {device_form_state($(this))}); + form_inputs.change(function() {device_form_state($(this))}); + // sidebar collapser events trigger change of up/down arrow $('.collapse').on('show', function() { $(this).siblings().find('.arrow-up-down') diff --git a/Netdisco/share/views/js/search.js b/Netdisco/share/views/js/search.js index 927d6b01..32193ce4 100644 --- a/Netdisco/share/views/js/search.js +++ b/Netdisco/share/views/js/search.js @@ -14,6 +14,10 @@ // on load, check initial Device Search Options form state, // and on each change to the form fields $(document).ready(function() { + // sidebar form fields should change colour and have bin/copy icon + form_inputs.each(function() {device_form_state($(this))}); + form_inputs.change(function() {device_form_state($(this))}); + // handler for copy icon in search option $('.field_copy_icon').click(function() { var name = $(this).data('btn-for'); From 407a3eb270512c1220fda4f6472b883c8aaf4818 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 23 Apr 2013 22:50:10 +0100 Subject: [PATCH 17/21] make navbar search fuzzier --- Netdisco/lib/App/Netdisco/Web/Search.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Netdisco/lib/App/Netdisco/Web/Search.pm b/Netdisco/lib/App/Netdisco/Web/Search.pm index 4c09c038..939e071b 100644 --- a/Netdisco/lib/App/Netdisco/Web/Search.pm +++ b/Netdisco/lib/App/Netdisco/Web/Search.pm @@ -75,7 +75,7 @@ get '/search' => sub { params->{'tab'} = 'vlan'; } else { - my $nd = $s->resultset('Device')->search_aliases($q); + my $nd = $s->resultset('Device')->search_fuzzy($q); if ($nd and $nd->count) { if ($nd->count == 1) { From 0c20d4191ffb783160999fa858dc1352e29f7cef Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 23 Apr 2013 23:03:02 +0100 Subject: [PATCH 18/21] fix bug dupe id in Partial Name checks --- Netdisco/share/views/sidebar/search/node.tt | 4 ++-- Netdisco/share/views/sidebar/search/port.tt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Netdisco/share/views/sidebar/search/node.tt b/Netdisco/share/views/sidebar/search/node.tt index 58f32eb4..40460c62 100644 --- a/Netdisco/share/views/sidebar/search/node.tt +++ b/Netdisco/share/views/sidebar/search/node.tt @@ -31,10 +31,10 @@
-
diff --git a/Netdisco/share/views/sidebar/search/port.tt b/Netdisco/share/views/sidebar/search/port.tt index 53c667f0..fa17b3f1 100644 --- a/Netdisco/share/views/sidebar/search/port.tt +++ b/Netdisco/share/views/sidebar/search/port.tt @@ -3,10 +3,10 @@
-
From 558184d8ac6795af1a6671c6f10754359ebbe3e1 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 24 Apr 2013 21:10:01 +0100 Subject: [PATCH 19/21] update TODO and Changes --- Netdisco/Changes | 10 ++++++++-- TODO | 16 ++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index b13b6360..0e17d402 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -1,17 +1,23 @@ 2.007000_002 - - * NOTE this version requires SNMP::Info 3.x - [NEW FEATURES] * Finally we have a discover/refresh daemon job :) * Also... a Scheduler which removes need for crontab installation * The netdisco-do script can run a one-off discover for a device + [ENHANCEMENTS] + + * SNMP connection now uses cached info if available + * Better handling of MIBs home location in deploy script + * Port filter in device port display is now highlighted green + * Navbar search is fuzzier + [BUG FIXES] * Rename plugins developer doc to .pod * Update to latest Bootstrap and JQuery, and temp. fix #7326 in Bootstrap + * Partial Name in Port search now working 2.007000_001 - 2013-03-17 diff --git a/TODO b/TODO index 68d09f01..25f14631 100644 --- a/TODO +++ b/TODO @@ -1,23 +1,27 @@ - -** in no particular order... ** -** names by tasks indicate who's "taken" them ** - FRONTEND ======== * UI for topo DB table editing - drop topo file support and use DB only -* Port/Name/VLAN box should be green when filled * Choice of MAC address formats -* Empty inventory should trigger request to discover +* No devices - trigger first discover splash page * (jeneric) device module tab DAEMON ====== +* macsuck/arpnip + CORE ==== * pseudo-device support * VRF support + +DOCS +==== + +* Scheduler +* Discover/Refresh jobs +* netdisco-do From 8dca426e92f9b424120ecb4038c2b6bfebe9977a Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 24 Apr 2013 22:18:04 +0100 Subject: [PATCH 20/21] select MAC Address display format on Node and Device Port search --- Netdisco/Changes | 1 + Netdisco/lib/App/Netdisco/DB/Result/Node.pm | 10 ++++++++++ Netdisco/lib/App/Netdisco/DB/Result/NodeIp.pm | 10 ++++++++++ Netdisco/lib/App/Netdisco/Web/Device.pm | 6 ++++++ Netdisco/share/public/css/netdisco.css | 13 +++++++++++++ Netdisco/share/views/ajax/device/ports.tt | 3 ++- Netdisco/share/views/ajax/search/node_by_ip.tt | 3 ++- Netdisco/share/views/ajax/search/node_by_mac.tt | 6 ++++-- Netdisco/share/views/sidebar/device/ports.tt | 10 +++++++++- Netdisco/share/views/sidebar/search/node.tt | 8 ++++++++ 10 files changed, 65 insertions(+), 5 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index 0e17d402..af8e62d0 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -5,6 +5,7 @@ * Finally we have a discover/refresh daemon job :) * Also... a Scheduler which removes need for crontab installation * The netdisco-do script can run a one-off discover for a device + * Can select MAC Address display format on Node and Device Port search [ENHANCEMENTS] diff --git a/Netdisco/lib/App/Netdisco/DB/Result/Node.pm b/Netdisco/lib/App/Netdisco/DB/Result/Node.pm index bd91a6da..746e277e 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/Node.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/Node.pm @@ -7,6 +7,8 @@ package App::Netdisco::DB::Result::Node; use strict; use warnings; +use Net::MAC; + use base 'DBIx::Class::Core'; __PACKAGE__->table("node"); __PACKAGE__->add_columns( @@ -134,4 +136,12 @@ between the date stamp and time stamp. That is: sub time_last_stamp { return (shift)->get_column('time_last_stamp') } +=head2 net_mac + +Returns the C column instantiated into a L object. + +=cut + +sub net_mac { return Net::MAC->new(mac => (shift)->mac) } + 1; diff --git a/Netdisco/lib/App/Netdisco/DB/Result/NodeIp.pm b/Netdisco/lib/App/Netdisco/DB/Result/NodeIp.pm index 6711fbd9..2d451c63 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/NodeIp.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/NodeIp.pm @@ -7,6 +7,8 @@ package App::Netdisco::DB::Result::NodeIp; use strict; use warnings; +use Net::MAC; + use base 'DBIx::Class::Core'; __PACKAGE__->table("node_ip"); __PACKAGE__->add_columns( @@ -206,4 +208,12 @@ between the date stamp and time stamp. That is: sub time_last_stamp { return (shift)->get_column('time_last_stamp') } +=head2 net_mac + +Returns the C column instantiated into a L object. + +=cut + +sub net_mac { return Net::MAC->new(mac => (shift)->mac) } + 1; diff --git a/Netdisco/lib/App/Netdisco/Web/Device.pm b/Netdisco/lib/App/Netdisco/Web/Device.pm index 7155747b..7f2a5c66 100644 --- a/Netdisco/lib/App/Netdisco/Web/Device.pm +++ b/Netdisco/lib/App/Netdisco/Web/Device.pm @@ -51,6 +51,7 @@ hook 'before' => sub { if (not param('tab') or param('tab') ne 'ports') { params->{'age_num'} = 3; params->{'age_unit'} = 'months'; + params->{'mac_format'} = 'IEEE'; } }; @@ -62,8 +63,13 @@ hook 'before_template' => sub { tab => 'ports', age_num => 3, age_unit => 'months', + mac_format => 'IEEE', }); + # for Net::MAC method + $tokens->{mac_format_call} = 'as_'. params->{'mac_format'} + if params->{'mac_format'}; + foreach my $col (@{ var('port_columns') }) { next unless $col->{default} eq 'on'; $tokens->{device_ports}->query_param($col->{name}, 'checked'); diff --git a/Netdisco/share/public/css/netdisco.css b/Netdisco/share/public/css/netdisco.css index 1e332d39..feaa9188 100644 --- a/Netdisco/share/public/css/netdisco.css +++ b/Netdisco/share/public/css/netdisco.css @@ -252,6 +252,19 @@ td { width: 95px; } +/* set the MAC format drop-down width */ +#nd_mac_format { + margin-top: 4px; + width: 154px; +} + +/* set the MAC format drop-down width */ +#nd_node_mac_format { + margin-left: -2px; + margin-top: 4px; + width: 165px; +} + /* sidebar submit button width and spacing from Node Props */ .sidebar button { margin-top: 9px; diff --git a/Netdisco/share/views/ajax/device/ports.tt b/Netdisco/share/views/ajax/device/ports.tt index c854ea72..7205e38f 100644 --- a/Netdisco/share/views/ajax/device/ports.tt +++ b/Netdisco/share/views/ajax/device/ports.tt @@ -196,7 +196,8 @@ [% FOREACH node IN row.$nodes %] [% '
' IF row.remote_ip OR NOT loop.first %] [% 'A  ' IF NOT node.active %] - [% node.mac | html_entity %] + + [% node.net_mac.$mac_format_call | html_entity %] [% ' (' _ node.time_last_age _ ')' IF params.n_age %] [% IF params.n_ip %] [% FOREACH ip IN node.ips %] diff --git a/Netdisco/share/views/ajax/search/node_by_ip.tt b/Netdisco/share/views/ajax/search/node_by_ip.tt index 896ab5a9..6a994705 100644 --- a/Netdisco/share/views/ajax/search/node_by_ip.tt +++ b/Netdisco/share/views/ajax/search/node_by_ip.tt @@ -17,7 +17,8 @@ [% WHILE (row = macs.next) %] [% row.mac | html_entity %] + href="[% search_node %]&q=[% row.net_mac.$mac_format_call | uri %]"> + [% row.net_mac.$mac_format_call | html_entity %] [% IF params.vendor %] [% row.oui.company | html_entity %] [% END %] diff --git a/Netdisco/share/views/ajax/search/node_by_mac.tt b/Netdisco/share/views/ajax/search/node_by_mac.tt index 63638d80..34e445b9 100644 --- a/Netdisco/share/views/ajax/search/node_by_mac.tt +++ b/Netdisco/share/views/ajax/search/node_by_mac.tt @@ -20,7 +20,8 @@ [% IF first_row %] [% row.mac | html_entity %] + href="[% search_node %]&q=[% row.net_mac.$mac_format_call | uri %]"> + [% row.net_mac.$mac_format_call | html_entity %] [% ELSE %]   [% END %] @@ -51,7 +52,8 @@ [% IF first_row %] [% node.mac | html_entity %] + href="[% search_node %]&q=[% node.net_mac.$mac_format_call | uri %]"> + [% node.net_mac.$mac_format_call | html_entity %] [% ELSE %]   [% END %] diff --git a/Netdisco/share/views/sidebar/device/ports.tt b/Netdisco/share/views/sidebar/device/ports.tt index ea432913..ced30ea8 100644 --- a/Netdisco/share/views/sidebar/device/ports.tt +++ b/Netdisco/share/views/sidebar/device/ports.tt @@ -76,7 +76,7 @@
  • - Mark as Free if Down for:
    + Mark as Free if Down for:
    + [% FOREACH format IN [ 'IEEE', 'Cisco', 'Microsoft', 'Sun' ] %] + [% format %] + [% END %] + +
  • [% FOREACH item IN vars.connected_properties %]
+
+ MAC address format:
+ +
From 8eee83e12a5b6107066ec91eb400c7b96b136807 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 24 Apr 2013 22:29:37 +0100 Subject: [PATCH 21/21] Phone node icon is a little phone handset --- Netdisco/Changes | 1 + Netdisco/share/public/css/netdisco.css | 5 +++++ Netdisco/share/views/sidebar/device/ports.tt | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index af8e62d0..5beaec8e 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -13,6 +13,7 @@ * Better handling of MIBs home location in deploy script * Port filter in device port display is now highlighted green * Navbar search is fuzzier + * Phone node icon is a little phone handset [BUG FIXES] diff --git a/Netdisco/share/public/css/netdisco.css b/Netdisco/share/public/css/netdisco.css index feaa9188..dd486147 100644 --- a/Netdisco/share/public/css/netdisco.css +++ b/Netdisco/share/public/css/netdisco.css @@ -322,6 +322,11 @@ form .clearfix.success input { margin-bottom: 1px; } +.inputs-list i { + margin-right: 5px; + margin-left: 2px; +} + /* nudge content closer to the header labels in the sidebar */ .inputs-list li:first-child { padding-top: 3px !important; diff --git a/Netdisco/share/views/sidebar/device/ports.tt b/Netdisco/share/views/sidebar/device/ports.tt index ced30ea8..ec1521bb 100644 --- a/Netdisco/share/views/sidebar/device/ports.tt +++ b/Netdisco/share/views/sidebar/device/ports.tt @@ -28,7 +28,7 @@ B  Blocking
  • - P  IP Phone +   IP Phone
  • N  Neighbor Inacessible