allow setting some speudo device info (#572)

* allow port name to be changed on pseudo devices, was once added in commit 1f020e07ee

* also allow this for location and contact
This commit is contained in:
nick n
2019-05-02 14:19:46 +02:00
committed by Oliver Gorwits
parent 3d5525ca77
commit 3ec136aea3
3 changed files with 50 additions and 41 deletions

View File

@@ -16,22 +16,25 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
my ($job, $workerconf) = @_;
my ($device, $data) = map {$job->$_} qw/device extra/;
# snmp connect using rw community
my $snmp = App::Netdisco::Transport::SNMP->writer_for($device)
or return Status->defer("failed to connect to $device to update contact");
# update pseudo devices directly in database
unless ($device->is_pseudo()) {
# snmp connect using rw community
my $snmp = App::Netdisco::Transport::SNMP->writer_for($device)
or return Status->defer("failed to connect to $device to update contact");
my $rv = $snmp->set_contact($data);
my $rv = $snmp->set_contact($data);
if (!defined $rv) {
return Status->error(
"failed to set contact on $device: ". ($snmp->error || ''));
}
if (!defined $rv) {
return Status->error(
"failed to set contact on $device: ". ($snmp->error || ''));
}
# confirm the set happened
$snmp->clear_cache;
my $new_data = ($snmp->contact || '');
if ($new_data ne $data) {
return Status->error("verify of contact failed on $device: $new_data");
# confirm the set happened
$snmp->clear_cache;
my $new_data = ($snmp->contact || '');
if ($new_data ne $data) {
return Status->error("verify of contact failed on $device: $new_data");
}
}
# update netdisco DB