drop netdisco.conf and use environment YAML only
This commit is contained in:
@@ -15,21 +15,15 @@ with "Netdisco::Daemon::Actions::$_"
|
|||||||
newdaemon(
|
newdaemon(
|
||||||
progname => 'netdisco-daemon',
|
progname => 'netdisco-daemon',
|
||||||
($> != 0 ? (pidbase => './') : ()),
|
($> != 0 ? (pidbase => './') : ()),
|
||||||
configfile => '/etc/netdisco/netdisco.conf',
|
|
||||||
logpriority => 'daemon.info',
|
logpriority => 'daemon.info',
|
||||||
);
|
);
|
||||||
|
|
||||||
sub gd_preconfig {
|
sub gd_preconfig {
|
||||||
my $self = shift;
|
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.")
|
$self->gd_error("No read-write community string has been set.")
|
||||||
unless length $config->{_}->{community_rw};
|
unless length setting('community_rw');
|
||||||
|
|
||||||
# add local settings
|
|
||||||
$config->{loc} = {
|
|
||||||
sleep_time => 5,
|
|
||||||
};
|
|
||||||
|
|
||||||
return (); # important
|
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 {
|
sub revert_job {
|
||||||
|
|||||||
@@ -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
|
connected to that device. The IP can be any on the device, and the management
|
||||||
interface will be connected to.
|
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.
|
Returns C<undef> if the connection fails.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub snmp_connect {
|
sub snmp_connect {
|
||||||
my $ip = shift;
|
my $ip = shift;
|
||||||
my $nd_config = var('nd_config')->{_};
|
|
||||||
|
|
||||||
# get device details from db
|
# get device details from db
|
||||||
my $device = get_device($ip)
|
my $device = get_device($ip)
|
||||||
@@ -103,16 +98,16 @@ sub snmp_connect {
|
|||||||
# TODO: really only supporing v2c at the moment
|
# TODO: really only supporing v2c at the moment
|
||||||
my %snmp_args = (
|
my %snmp_args = (
|
||||||
DestHost => $device->ip,
|
DestHost => $device->ip,
|
||||||
Version => ($device->snmp_ver || $nd_config->{snmpver} || 2),
|
Version => ($device->snmp_ver || setting('snmpver') || 2),
|
||||||
Retries => ($nd_config->{snmpretries} || 2),
|
Retries => (setting('snmpretries') || 2),
|
||||||
Timeout => ($nd_config->{snmptimeout} || 1000000),
|
Timeout => (setting('snmptimeout') || 1000000),
|
||||||
MibDirs => _build_mibdirs(),
|
MibDirs => [ _build_mibdirs() ],
|
||||||
AutoSpecify => 1,
|
AutoSpecify => 1,
|
||||||
IgnoreNetSNMPConf => 1,
|
IgnoreNetSNMPConf => 1,
|
||||||
Debug => ($ENV{INFO_TRACE} || 0),
|
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 @communities = split /,/, $comm;
|
||||||
|
|
||||||
my $info = undef;
|
my $info = undef;
|
||||||
@@ -131,11 +126,9 @@ sub snmp_connect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub _build_mibdirs {
|
sub _build_mibdirs {
|
||||||
my $mibhome = var('nd_config')->{_}->{mibhome};
|
# FIXME: make this cross-platform (Path::Class?)
|
||||||
(my $mibdirs = var('nd_config')->{_}->{mibdirs}) =~ s/\s+//g;
|
return map { setting('mibhome') .'/'. $_ }
|
||||||
|
@{ setting('mibdirs') || [] };
|
||||||
$mibdirs =~ s/\$mibhome/$mibhome/g;
|
|
||||||
return [ split /,/, $mibdirs ];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ subroutines.
|
|||||||
=head2 is_discoverable( $ip )
|
=head2 is_discoverable( $ip )
|
||||||
|
|
||||||
Given an IP address, returns C<true> if Netdisco on this host is permitted to
|
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
|
The configuration items C<discover_no> and C<discover_only> are checked
|
||||||
against the given IP.
|
against the given IP.
|
||||||
@@ -41,21 +41,19 @@ sub is_discoverable {
|
|||||||
my $ip = shift;
|
my $ip = shift;
|
||||||
|
|
||||||
my $device = NetAddr::IP::Lite->new($ip) or return 0;
|
my $device = NetAddr::IP::Lite->new($ip) or return 0;
|
||||||
my $discover_no = var('nd_config')->{_}->{discover_no};
|
my $discover_no = setting('discover_no') || [];
|
||||||
my $discover_only = var('nd_config')->{_}->{discover_only};
|
my $discover_only = setting('discover_only') || [];
|
||||||
|
|
||||||
if (length $discover_no) {
|
if (scalar @$discover_no) {
|
||||||
my @d_no = split /,\s*/, $discover_no;
|
foreach my $item (@$discover_no) {
|
||||||
foreach my $item (@d_no) {
|
|
||||||
my $ip = NetAddr::IP::Lite->new($item) or return 0;
|
my $ip = NetAddr::IP::Lite->new($item) or return 0;
|
||||||
return 0 if $ip->contains($device);
|
return 0 if $ip->contains($device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length $discover_only) {
|
if (scalar @$discover_only) {
|
||||||
my $okay = 0;
|
my $okay = 0;
|
||||||
my @d_only = split /,\s*/, $discover_only;
|
foreach my $item (@$discover_only) {
|
||||||
foreach my $item (@d_only) {
|
|
||||||
my $ip = NetAddr::IP::Lite->new($item) or return 0;
|
my $ip = NetAddr::IP::Lite->new($item) or return 0;
|
||||||
++$okay if $ip->contains($device);
|
++$okay if $ip->contains($device);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ sub vlan_reconfig_check {
|
|||||||
my $port = shift;
|
my $port = shift;
|
||||||
my $ip = $port->ip;
|
my $ip = $port->ip;
|
||||||
my $name = $port->port;
|
my $name = $port->port;
|
||||||
my $nd_config = var('nd_config')->{_};
|
|
||||||
|
|
||||||
my $is_vlan = is_vlan_interface($port);
|
my $is_vlan = is_vlan_interface($port);
|
||||||
|
|
||||||
@@ -40,7 +39,7 @@ sub vlan_reconfig_check {
|
|||||||
if $is_vlan;
|
if $is_vlan;
|
||||||
|
|
||||||
return "forbidden: not permitted to change native vlan"
|
return "forbidden: not permitted to change native vlan"
|
||||||
if not $nd_config->{vlanctl};
|
if not setting('vlanctl');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -53,22 +52,21 @@ sub port_reconfig_check {
|
|||||||
my $port = shift;
|
my $port = shift;
|
||||||
my $ip = $port->ip;
|
my $ip = $port->ip;
|
||||||
my $name = $port->port;
|
my $name = $port->port;
|
||||||
my $nd_config = var('nd_config')->{_};
|
|
||||||
|
|
||||||
my $has_phone = has_phone($port);
|
my $has_phone = has_phone($port);
|
||||||
my $is_vlan = is_vlan_interface($port);
|
my $is_vlan = is_vlan_interface($port);
|
||||||
|
|
||||||
# uplink check
|
# uplink check
|
||||||
return "forbidden: port [$name] on [$ip] is an uplink"
|
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
|
# phone check
|
||||||
return "forbidden: port [$name] on [$ip] is a phone"
|
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
|
# vlan (routed) interface check
|
||||||
return "forbidden: [$name] is a vlan interface on [$ip]"
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user