Squashed commit of the following: commit3284b62509Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 21:17:06 2014 +0100 config defaults tidying commitade7bcd880Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 20:00:01 2014 +0100 high priority jobs are picked first and inserted to prio queue commitd450dfd2bdAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 19:25:21 2014 +0100 better status commitb8a742e5deAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 16:54:03 2014 +0100 update proctitle when worker not running commit0c3675a8f4Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 16:48:58 2014 +0100 remove all trace of SQLite - new lightweight Job object commita13ed25f6aAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 14:45:22 2014 +0100 rename pollers to tasks commit44b50f413fAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 14:13:00 2014 +0100 update docs commit517b1ae4c1Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 13:55:31 2014 +0100 merge interactive and poller worker types commite9043b90e8Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 13:47:41 2014 +0100 only take one job at a time per worker commit2366738d54Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 13:43:31 2014 +0100 auto job priorities commit1fd473fd50Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 13:18:59 2014 +0100 preload all worker modules into shared memory commit9ceb43c0f7Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 13:13:07 2014 +0100 daemon clean commitc817a35537Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 12:36:24 2014 +0100 first refactor for MCE::Flow and MCE::Queue
51 lines
1.2 KiB
Perl
51 lines
1.2 KiB
Perl
package App::Netdisco::Daemon::Worker::Interactive::DeviceActions;
|
|
|
|
use App::Netdisco::Util::SNMP 'snmp_connect_rw';
|
|
use App::Netdisco::Util::Device 'get_device';
|
|
use App::Netdisco::Daemon::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;
|