error out on discover failing to get good interfaces from SNMP
This commit is contained in:
@@ -63,8 +63,8 @@ register_worker({ phase => 'early', driver => 'snmp' }, sub {
|
|||||||
my $protect = setting('snmp_field_protection')->{'device'} || {};
|
my $protect = setting('snmp_field_protection')->{'device'} || {};
|
||||||
my %dirty = $device->get_dirty_columns;
|
my %dirty = $device->get_dirty_columns;
|
||||||
foreach my $field (keys %dirty) {
|
foreach my $field (keys %dirty) {
|
||||||
next unless check_acl_only($ip, ($protect->{$field} || []));
|
next unless check_acl_only($ip, $protect->{$field});
|
||||||
if (exists $dirty{$field} and not $dirty{$field}) {
|
if (!defined $dirty{$field} or $dirty{$field} eq '') {
|
||||||
return $job->cancel("discover cancelled: $ip failed to return valid $field");
|
return $job->cancel("discover cancelled: $ip failed to return valid $field");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,6 +94,39 @@ register_worker({ phase => 'early', driver => 'snmp' }, sub {
|
|||||||
return Status->info(" [$device] device - OK to continue discover");
|
return Status->info(" [$device] device - OK to continue discover");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
register_worker({ phase => 'early', driver => 'snmp' }, sub {
|
||||||
|
my ($job, $workerconf) = @_;
|
||||||
|
|
||||||
|
my $device = $job->device;
|
||||||
|
return unless $device->in_storage;
|
||||||
|
|
||||||
|
my $snmp = App::Netdisco::Transport::SNMP->reader_for($device)
|
||||||
|
or return Status->defer("discover failed: could not SNMP connect to $device");
|
||||||
|
|
||||||
|
my $pass = Status->info(" [$device] device - OK to continue discover");
|
||||||
|
my $interfaces = $snmp->interfaces;
|
||||||
|
|
||||||
|
# OK if no interfaces
|
||||||
|
return $pass if 0 == scalar keys %$interfaces;
|
||||||
|
# OK if any value is not the same as key
|
||||||
|
return $pass if scalar grep {$_ ne $interfaces->{$_}} keys %$interfaces;
|
||||||
|
# OK if any non-digit in values
|
||||||
|
return $pass if scalar grep {$_ !~ m/^[0-9]+$/} values %$interfaces;
|
||||||
|
|
||||||
|
# gather ports
|
||||||
|
my $device_ports = {map {($_->port => $_)}
|
||||||
|
$device->ports(undef, {prefetch => 'properties'})->all};
|
||||||
|
# OK if no ports
|
||||||
|
return $pass if 0 == scalar keys %$device_ports;
|
||||||
|
# OK if any interface value is a port name
|
||||||
|
foreach my $port (keys %$device_ports) {
|
||||||
|
return $pass if scalar grep {$port eq $_} values %$interfaces;
|
||||||
|
}
|
||||||
|
|
||||||
|
# else cancel
|
||||||
|
return $job->cancel("discover cancelled: $device failed to return valid interfaces");
|
||||||
|
});
|
||||||
|
|
||||||
register_worker({ phase => 'early', driver => 'snmp' }, sub {
|
register_worker({ phase => 'early', driver => 'snmp' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user