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:
Tony Murray
2022-07-22 16:31:27 -05:00
committed by GitHub
parent b13ba8c574
commit 799c03df29
3 changed files with 24 additions and 2 deletions

View File

@@ -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();

View File

@@ -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
}
}

View File

@@ -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.',