Merge branch 'master' of github.com:netdisco/netdisco

This commit is contained in:
Oliver Gorwits
2017-05-30 20:42:25 +01:00
10 changed files with 40 additions and 32 deletions

View File

@@ -5,6 +5,7 @@ use Dancer::Plugin::DBIC 'schema';
use App::Netdisco::Util::Device
qw/get_device match_devicetype is_discoverable/;
use App::Netdisco::Util::Permission 'check_acl_only';
use App::Netdisco::Util::DNS ':all';
use App::Netdisco::JobQueue qw/jq_queued jq_insert/;
use NetAddr::IP::Lite ':lower';
@@ -76,8 +77,8 @@ sub set_canonical_ip {
foreach my $key (sort keys %$map) {
# lhs matches device, rhs matches device_ip
if (check_acl($device, $key)
and check_acl($alias, $map->{$key})) {
if (check_acl_only($device, $key)
and check_acl_only($alias, $map->{$key})) {
if ($snmp->snmp_connect_ip( $alias->alias )) {
$new_ip = $alias->alias;

View File

@@ -101,6 +101,7 @@ sub jq_queued {
sub _get_denied_actions {
my $device = shift;
my @badactions = ();
return @badactions unless $device;
push @badactions, ('discover', @{ setting('job_prio')->{high} })
if not is_discoverable($device);
@@ -142,17 +143,19 @@ sub jq_lock {
$fqdn ||= (hostfqdn || 'localhost');
my $happy = false;
# need to handle device discovered since backend daemon started
# and the skiplist was primed. these should be checked against
# the various acls and have device_skip entry added if needed,
# and return false if it should have been skipped.
my @badactions = _get_denied_actions($job->device);
if (scalar @badactions) {
schema('netdisco')->resultset('DeviceSkip')->find_or_create({
backend => $fqdn, device => $job->device,
},{ key => 'device_skip_pkey' })->add_to_actionset(@badactions);
if ($job->device) {
# need to handle device discovered since backend daemon started
# and the skiplist was primed. these should be checked against
# the various acls and have device_skip entry added if needed,
# and return false if it should have been skipped.
my @badactions = _get_denied_actions($job->device);
if (scalar @badactions) {
schema('netdisco')->resultset('DeviceSkip')->find_or_create({
backend => $fqdn, device => $job->device,
},{ key => 'device_skip_pkey' })->add_to_actionset(@badactions);
return false if scalar grep {$_ eq $job->action} @badactions;
return false if scalar grep {$_ eq $job->action} @badactions;
}
}
# lock db row and update to show job has been picked
@@ -200,9 +203,11 @@ sub jq_defer {
try {
schema('netdisco')->txn_do(sub {
schema('netdisco')->resultset('DeviceSkip')->find_or_create({
backend => $fqdn, device => $job->device,
},{ key => 'device_skip_pkey' })->increment_deferrals;
if ($job->device) {
schema('netdisco')->resultset('DeviceSkip')->find_or_create({
backend => $fqdn, device => $job->device,
},{ key => 'device_skip_pkey' })->increment_deferrals;
}
# lock db row and update to show job is available
schema('netdisco')->resultset('Admin')

View File

@@ -8,7 +8,7 @@ use Net::DNS;
use AnyEvent::DNS;
use NetAddr::IP::Lite ':lower';
use App::Netdisco::Util::Permission 'check_acl';
use App::Netdisco::Util::Permission;
use base 'Exporter';
our @EXPORT = ();
@@ -129,7 +129,7 @@ sub hostnames_resolve_async {
IP: foreach my $hash_ref (@$ips) {
my $ip = $hash_ref->{'ip'} || $hash_ref->{'alias'};
next IP if check_acl($ip, $skip);
next IP if App::Netdisco::Util::Permission::check_acl_no($ip, $skip);
# check /etc/hosts file and short-circuit if found
foreach my $name (reverse sort keys %HOSTS) {

View File

@@ -239,7 +239,7 @@ Returns false if the host is not permitted to arpnip the target device.
=cut
sub is_arpnipable_now {
my $ip = shift;
my ($ip) = @_;
my $device = get_device($ip) or return 0;
return _bail_msg("is_arpnipable: cannot arpnip an undiscovered device")
@@ -290,7 +290,7 @@ Returns false if the host is not permitted to macsuck the target device.
=cut
sub is_macsuckable_now {
my $ip = shift;
my ($ip) = @_;
my $device = get_device($ip) or return 0;
return _bail_msg("is_macsuckable: cannot macsuck an undiscovered device")

View File

@@ -2,7 +2,7 @@ package App::Netdisco::Util::SNMP;
use Dancer qw/:syntax :script/;
use App::Netdisco::Util::Device 'get_device';
use App::Netdisco::Util::Permission qw/check_acl_no check_acl/;
use App::Netdisco::Util::Permission ':all';
use SNMP::Info;
use Try::Tiny;
@@ -300,7 +300,7 @@ sub _build_communities {
if not $stanza->{tag}
and !exists $stanza->{community};
if ($stanza->{$mode} and check_acl($device, $stanza->{only})) {
if ($stanza->{$mode} and check_acl_only($device, $stanza->{only})) {
if ($device->in_storage and
$stored_tag and $stored_tag eq $stanza->{tag}) {
# last known-good by tag