mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
lnms device:poll better feedback (#14130)
* lnms device:poll better feedback Feedback when 0 devices are found to poll or 0 devices are polled. Make devices polled summary string translatable. * additional note on what the wildcard is * Fix style
This commit is contained in:
@@ -154,6 +154,14 @@ class Poller
|
||||
return $polled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total number of devices to poll.
|
||||
*/
|
||||
public function totalDevices(): int
|
||||
{
|
||||
return $this->buildDeviceQuery()->count();
|
||||
}
|
||||
|
||||
private function pollModules(): void
|
||||
{
|
||||
$this->filterModules();
|
||||
|
@@ -39,6 +39,7 @@ class DevicePoll extends LnmsCommand
|
||||
}
|
||||
|
||||
try {
|
||||
/** @var \LibreNMS\Poller $poller */
|
||||
$poller = app(Poller::class, ['device_spec' => $this->argument('device spec'), 'module_override' => explode(',', $this->option('modules'))]);
|
||||
$polled = $poller->poll();
|
||||
|
||||
@@ -46,7 +47,8 @@ class DevicePoll extends LnmsCommand
|
||||
if (! $this->output->isQuiet()) {
|
||||
if ($polled > 1) {
|
||||
$this->output->newLine();
|
||||
$this->line(sprintf('Polled %d devices in %0.3fs', $polled, $measurements->getCategory('device')->getSummary('poll')->getDuration()));
|
||||
$time_spent = sprintf('%0.3fs', $measurements->getCategory('device')->getSummary('poll')->getDuration());
|
||||
$this->line(trans('commands.device:poll.polled', ['count' => $polled, 'time' => $time_spent]));
|
||||
}
|
||||
$this->output->newLine();
|
||||
$measurements->printStats();
|
||||
@@ -54,6 +56,13 @@ class DevicePoll extends LnmsCommand
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// polled 0 devices, maybe there were none to poll
|
||||
if ($poller->totalDevices() == 0) {
|
||||
$this->error(trans('commands.device:poll.errors.no_devices'));
|
||||
|
||||
return 1;
|
||||
}
|
||||
} catch (QueryException $e) {
|
||||
if ($e->getCode() == 2002) {
|
||||
$this->error(trans('commands.device:poll.errors.db_connect'));
|
||||
@@ -71,6 +80,8 @@ class DevicePoll extends LnmsCommand
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->error(trans('commands.device:poll.errors.none_polled'));
|
||||
|
||||
return 1; // failed to poll
|
||||
}
|
||||
}
|
||||
|
@@ -110,7 +110,7 @@ return [
|
||||
'device:poll' => [
|
||||
'description' => 'Poll data from device(s) as defined by discovery',
|
||||
'arguments' => [
|
||||
'device spec' => 'Device spec to poll: device_id, hostname, wildcard, odd, even, all',
|
||||
'device spec' => 'Device spec to poll: device_id, hostname, wildcard (*), odd, even, all',
|
||||
],
|
||||
'options' => [
|
||||
'modules' => 'Specify single module to be run. Comma separate modules, submodules may be added with /',
|
||||
@@ -119,7 +119,10 @@ return [
|
||||
'errors' => [
|
||||
'db_connect' => 'Failed to connect to database. Verify database service is running and connection settings.',
|
||||
'db_auth' => 'Failed to connect to database. Verify credentials: :error',
|
||||
'no_devices' => 'No devices found matching your given device specification.',
|
||||
'none_polled' => 'No devices were polled.',
|
||||
],
|
||||
'polled' => 'Polled :count devices in :time',
|
||||
],
|
||||
'key:rotate' => [
|
||||
'description' => 'Rotate APP_KEY, this decrypts all encrypted data with the given old key and stores it with the new key in APP_KEY.',
|
||||
|
Reference in New Issue
Block a user