From 9875c70f41664bbec220b98d60f0f49b003aad14 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Fri, 19 Apr 2013 23:36:06 +0100 Subject: [PATCH] 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