drop netdisco.conf and use environment YAML only
This commit is contained in:
@@ -84,17 +84,12 @@ Given an IP address, returns an L<SNMP::Info> 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<load_nd_config> otherwise the connection will fail (it is required for SNMP
|
||||
settings).
|
||||
|
||||
Returns C<undef> 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;
|
||||
|
||||
@@ -28,7 +28,7 @@ subroutines.
|
||||
=head2 is_discoverable( $ip )
|
||||
|
||||
Given an IP address, returns C<true> 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<discover_no> and C<discover_only> 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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user