Squashed commit of the following: commit39b438aa4bAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 16:40:11 2017 +0100 add release notes commitca4ea90d35Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 16:32:06 2017 +0100 update distmeta commit4e35b904b0Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 16:30:22 2017 +0100 rename files from Daemon to Backend commit86a605ba68Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 16:26:43 2017 +0100 rename daemon to backend in code commitffe8fc180fAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 16:15:57 2017 +0100 add daemon files which exec to backend equivalents commit53e041594eAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 15:32:49 2017 +0100 rename netdisco-daemon to netdisco-backend
51 lines
1.2 KiB
Perl
51 lines
1.2 KiB
Perl
package App::Netdisco::Backend::Worker::Interactive::DeviceActions;
|
|
|
|
use App::Netdisco::Util::SNMP 'snmp_connect_rw';
|
|
use App::Netdisco::Util::Device 'get_device';
|
|
use App::Netdisco::Backend::Util ':all';
|
|
|
|
use Role::Tiny;
|
|
use namespace::clean;
|
|
|
|
sub location {
|
|
my ($self, $job) = @_;
|
|
return _set_device_generic($job->device, 'location', $job->subaction);
|
|
}
|
|
|
|
sub contact {
|
|
my ($self, $job) = @_;
|
|
return _set_device_generic($job->device, 'contact', $job->subaction);
|
|
}
|
|
|
|
sub _set_device_generic {
|
|
my ($ip, $slot, $data) = @_;
|
|
$data ||= '';
|
|
|
|
# snmp connect using rw community
|
|
my $info = snmp_connect_rw($ip)
|
|
or return job_error("Failed to connect to device [$ip] to update $slot");
|
|
|
|
my $method = 'set_'. $slot;
|
|
my $rv = $info->$method($data);
|
|
|
|
if (!defined $rv) {
|
|
return job_error(sprintf 'Failed to set %s on [%s]: %s',
|
|
$slot, $ip, ($info->error || ''));
|
|
}
|
|
|
|
# confirm the set happened
|
|
$info->clear_cache;
|
|
my $new_data = ($info->$slot || '');
|
|
if ($new_data ne $data) {
|
|
return job_error("Verify of $slot update failed on [$ip]: $new_data");
|
|
}
|
|
|
|
# update netdisco DB
|
|
my $device = get_device($ip);
|
|
$device->update({$slot => $data});
|
|
|
|
return job_done("Updated $slot on [$ip] to [$data]");
|
|
}
|
|
|
|
1;
|