diff --git a/Netdisco/bin/netdisco-daemon b/Netdisco/bin/netdisco-daemon index a6665625..c5ab4eb5 100755 --- a/Netdisco/bin/netdisco-daemon +++ b/Netdisco/bin/netdisco-daemon @@ -15,21 +15,15 @@ with "Netdisco::Daemon::Actions::$_" newdaemon( progname => 'netdisco-daemon', ($> != 0 ? (pidbase => './') : ()), - configfile => '/etc/netdisco/netdisco.conf', logpriority => 'daemon.info', ); sub gd_preconfig { my $self = shift; - my $config = load_nd_config($self->{configfile}); + # FIXME: only for Actions should this be checked $self->gd_error("No read-write community string has been set.") - unless length $config->{_}->{community_rw}; - - # add local settings - $config->{loc} = { - sleep_time => 5, - }; + unless length setting('community_rw'); return (); # important } @@ -66,7 +60,7 @@ sub gd_run_body { } } - $self->gd_sleep( var('nd_config')->{loc}->{sleep_time} ); + $self->gd_sleep( setting('daemon_sleep_time') || 5 ); } sub revert_job { diff --git a/Netdisco/lib/Netdisco/Util/Connect.pm b/Netdisco/lib/Netdisco/Util/Connect.pm index 3d479b77..bd76ed14 100644 --- a/Netdisco/lib/Netdisco/Util/Connect.pm +++ b/Netdisco/lib/Netdisco/Util/Connect.pm @@ -84,17 +84,12 @@ Given an IP address, returns an L instance configured for and connected to that device. The IP can be any on the device, and the management interface will be connected to. -The Netdisco configuration file must have first been loaded using -C otherwise the connection will fail (it is required for SNMP -settings). - Returns C if the connection fails. =cut sub snmp_connect { my $ip = shift; - my $nd_config = var('nd_config')->{_}; # get device details from db my $device = get_device($ip) @@ -103,16 +98,16 @@ sub snmp_connect { # TODO: really only supporing v2c at the moment my %snmp_args = ( DestHost => $device->ip, - Version => ($device->snmp_ver || $nd_config->{snmpver} || 2), - Retries => ($nd_config->{snmpretries} || 2), - Timeout => ($nd_config->{snmptimeout} || 1000000), - MibDirs => _build_mibdirs(), + 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 $comm = $nd_config->{community_rw}) =~ s/\s+//g; + (my $comm = setting('community_rw')) =~ s/\s+//g; my @communities = split /,/, $comm; my $info = undef; @@ -131,11 +126,9 @@ sub snmp_connect { } sub _build_mibdirs { - my $mibhome = var('nd_config')->{_}->{mibhome}; - (my $mibdirs = var('nd_config')->{_}->{mibdirs}) =~ s/\s+//g; - - $mibdirs =~ s/\$mibhome/$mibhome/g; - return [ split /,/, $mibdirs ]; + # FIXME: make this cross-platform (Path::Class?) + return map { setting('mibhome') .'/'. $_ } + @{ setting('mibdirs') || [] }; } 1; diff --git a/Netdisco/lib/Netdisco/Util/DeviceProperties.pm b/Netdisco/lib/Netdisco/Util/DeviceProperties.pm index 0f1df530..01d00583 100644 --- a/Netdisco/lib/Netdisco/Util/DeviceProperties.pm +++ b/Netdisco/lib/Netdisco/Util/DeviceProperties.pm @@ -28,7 +28,7 @@ subroutines. =head2 is_discoverable( $ip ) Given an IP address, returns C if Netdisco on this host is permitted to -discover its configuration by the local Netdisco configuration file. +discover its configuration by the local configuration. The configuration items C and C are checked against the given IP. @@ -41,21 +41,19 @@ sub is_discoverable { my $ip = shift; my $device = NetAddr::IP::Lite->new($ip) or return 0; - my $discover_no = var('nd_config')->{_}->{discover_no}; - my $discover_only = var('nd_config')->{_}->{discover_only}; + my $discover_no = setting('discover_no') || []; + my $discover_only = setting('discover_only') || []; - if (length $discover_no) { - my @d_no = split /,\s*/, $discover_no; - foreach my $item (@d_no) { + if (scalar @$discover_no) { + foreach my $item (@$discover_no) { my $ip = NetAddr::IP::Lite->new($item) or return 0; return 0 if $ip->contains($device); } } - if (length $discover_only) { + if (scalar @$discover_only) { my $okay = 0; - my @d_only = split /,\s*/, $discover_only; - foreach my $item (@d_only) { + foreach my $item (@$discover_only) { my $ip = NetAddr::IP::Lite->new($item) or return 0; ++$okay if $ip->contains($device); } diff --git a/Netdisco/lib/Netdisco/Util/Permissions.pm b/Netdisco/lib/Netdisco/Util/Permissions.pm index ad1c10e1..4d9c9089 100644 --- a/Netdisco/lib/Netdisco/Util/Permissions.pm +++ b/Netdisco/lib/Netdisco/Util/Permissions.pm @@ -31,7 +31,6 @@ sub vlan_reconfig_check { my $port = shift; my $ip = $port->ip; my $name = $port->port; - my $nd_config = var('nd_config')->{_}; my $is_vlan = is_vlan_interface($port); @@ -40,7 +39,7 @@ sub vlan_reconfig_check { if $is_vlan; return "forbidden: not permitted to change native vlan" - if not $nd_config->{vlanctl}; + if not setting('vlanctl'); return; } @@ -53,22 +52,21 @@ sub port_reconfig_check { my $port = shift; my $ip = $port->ip; my $name = $port->port; - my $nd_config = var('nd_config')->{_}; my $has_phone = has_phone($port); my $is_vlan = is_vlan_interface($port); # uplink check return "forbidden: port [$name] on [$ip] is an uplink" - if $port->remote_type and not $has_phone and not $nd_config->{allow_uplinks}; + if $port->remote_type and not $has_phone and not setting('allow_uplinks'); # phone check return "forbidden: port [$name] on [$ip] is a phone" - if $has_phone and $nd_config->{portctl_nophones}; + if $has_phone and setting('portctl_nophones'); # vlan (routed) interface check return "forbidden: [$name] is a vlan interface on [$ip]" - if $is_vlan and not $nd_config->{portctl_vlans}; + if $is_vlan and not setting('portctl_vlans'); return; }