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:
@@ -24,25 +24,28 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
||||
my ($job, $workerconf) = @_;
|
||||
my ($device, $pn, $data) = map {$job->$_} qw/device port 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 alias");
|
||||
# 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 alias");
|
||||
|
||||
my $iid = get_iid($snmp, vars->{'port'})
|
||||
or return Status->error("Failed to get port ID for [$pn] from $device");
|
||||
my $iid = get_iid($snmp, vars->{'port'})
|
||||
or return Status->error("Failed to get port ID for [$pn] from $device");
|
||||
|
||||
my $rv = $snmp->set_i_alias($data, $iid);
|
||||
my $rv = $snmp->set_i_alias($data, $iid);
|
||||
|
||||
if (!defined $rv) {
|
||||
return Status->error(sprintf 'Failed to set [%s] alias to [%s] on $device: %s',
|
||||
$pn, $data, ($snmp->error || ''));
|
||||
}
|
||||
if (!defined $rv) {
|
||||
return Status->error(sprintf 'Failed to set [%s] alias to [%s] on $device: %s',
|
||||
$pn, $data, ($snmp->error || ''));
|
||||
}
|
||||
|
||||
# confirm the set happened
|
||||
$snmp->clear_cache;
|
||||
my $state = ($snmp->i_alias($iid) || '');
|
||||
if (ref {} ne ref $state or $state->{$iid} ne $data) {
|
||||
return Status->error("Verify of [$pn] alias failed on $device");
|
||||
# confirm the set happened
|
||||
$snmp->clear_cache;
|
||||
my $state = ($snmp->i_alias($iid) || '');
|
||||
if (ref {} ne ref $state or $state->{$iid} ne $data) {
|
||||
return Status->error("Verify of [$pn] alias failed on $device");
|
||||
}
|
||||
}
|
||||
|
||||
# update netdisco DB
|
||||
|
||||
Reference in New Issue
Block a user