Skip to content

Commit f2b24d0

Browse files
committed
Configure output for all commands
1 parent 8a199e4 commit f2b24d0

File tree

10 files changed

+30
-37
lines changed

10 files changed

+30
-37
lines changed

app/Console/Commands/ConfigListCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public function __construct()
2525
*/
2626
public function handle(): int
2727
{
28-
$this->configureOutputOptions();
2928
$search = $this->argument('search') ?? '';
3029

3130
$settings = (new DynamicConfig)->all()

app/Console/Commands/DeviceAdd.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ public function __construct()
7979
*/
8080
public function handle(): int
8181
{
82-
$this->configureOutputOptions();
83-
8482
$this->validate([
8583
'port' => 'numeric|between:1,65535',
8684
'poller-group' => ['numeric', Rule::in(PollerGroup::pluck('id')->prepend(0))],

app/Console/Commands/DeviceDiscover.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ public function __construct()
5555

5656
public function handle(MeasurementManager $measurements): int
5757
{
58-
$this->configureOutputOptions();
59-
6058
try {
6159
$this->handleDebug();
6260

app/Console/Commands/DevicePing.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public function __construct()
3434
*/
3535
public function handle(DeviceIsPingable $deviceIsPingable): int
3636
{
37-
$this->configureOutputOptions();
3837
$spec = $this->argument('device spec');
3938

4039
if ($spec == 'fast') {

app/Console/Commands/DevicePoll.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ public function handle(MeasurementManager $measurements): int
4343
return $this->dispatchWork();
4444
}
4545

46-
$this->configureOutputOptions();
47-
4846
if ($this->option('no-data')) {
4947
LibrenmsConfig::set('rrd.enable', false);
5048
LibrenmsConfig::set('influxdb.enable', false);

app/Console/Commands/MaintenanceRrdStep.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public function __construct()
2828

2929
public function handle(RrdProcess $rrdProcess): int
3030
{
31-
$this->configureOutputOptions();
32-
3331
$this->systemStep = (int) LibrenmsConfig::get('rrd.step', 300);
3432
$this->icmpStep = (int) LibrenmsConfig::get('ping_rrd_step', $this->systemStep);
3533
$this->systemHeartbeat = (int) LibrenmsConfig::get('rrd.heartbeat', $this->systemStep * 2);

app/Console/Commands/PortTune.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public function __construct()
2525
*/
2626
public function handle(): int
2727
{
28-
$this->configureOutputOptions();
29-
3028
$port_spec = $this->getPortSpec();
3129

3230
$devices = Device::whereDeviceSpec($this->argument('device spec'))->get();

app/Console/Commands/SnmpFetch.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ public function __construct()
4141
*/
4242
public function handle(): int
4343
{
44-
$this->configureOutputOptions();
45-
4644
$this->validate([
4745
'output' => ['nullable', Rule::in(['value', 'values', 'table', 'index-table'])],
4846
]);

app/Console/LnmsCommand.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
use Illuminate\Console\Command;
3030
use Illuminate\Validation\Rule;
3131
use Illuminate\Validation\ValidationException;
32-
use LibreNMS\Util\Debug;
3332
use Symfony\Component\Console\Exception\InvalidArgumentException;
34-
use Symfony\Component\Console\Output\OutputInterface;
3533
use Validator;
3634

3735
abstract class LnmsCommand extends Command
@@ -164,27 +162,6 @@ protected function validate(array $rules, array $messages = []): array
164162
}
165163
}
166164

167-
protected function configureOutputOptions(): void
168-
{
169-
$verbosity = $this->getOutput()->getVerbosity();
170-
171-
if ($verbosity === OutputInterface::VERBOSITY_QUIET) {
172-
\Log::setDefaultDriver('stack'); // this omits stdout
173-
Debug::setCliQuietOutput();
174-
175-
return;
176-
}
177-
178-
\Log::setDefaultDriver('console');
179-
180-
if ($verbosity >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
181-
Debug::set();
182-
if ($verbosity >= OutputInterface::VERBOSITY_DEBUG) {
183-
Debug::setVerbose();
184-
}
185-
}
186-
}
187-
188165
protected function validatePromptInput(string $attributeName, string|array $rules): callable
189166
{
190167
return function (string|array $value) use ($attributeName, $rules): ?string {

app/Listeners/CommandStartingListener.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
use App\Exceptions\RunningAsIncorrectUserException;
3030
use Illuminate\Console\Events\CommandStarting;
31+
use Illuminate\Support\Facades\Log;
32+
use LibreNMS\Util\Debug;
33+
use Symfony\Component\Console\Output\OutputInterface;
3134

3235
class CommandStartingListener
3336
{
@@ -39,6 +42,33 @@ class CommandStartingListener
3942
* @throws RunningAsIncorrectUserException
4043
*/
4144
public function handle(CommandStarting $event): void
45+
{
46+
$this->configureOutput($event);
47+
$this->checkRunningUser($event);
48+
}
49+
50+
private function configureOutput(CommandStarting $event): void
51+
{
52+
$verbosity = $event->output->getVerbosity();
53+
54+
if ($verbosity === OutputInterface::VERBOSITY_QUIET) {
55+
Log::setDefaultDriver('stack'); // this omits stdout
56+
Debug::setCliQuietOutput();
57+
58+
return;
59+
}
60+
61+
Log::setDefaultDriver('console');
62+
63+
if ($verbosity >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
64+
Debug::set();
65+
if ($verbosity >= OutputInterface::VERBOSITY_DEBUG) {
66+
Debug::setVerbose();
67+
}
68+
}
69+
}
70+
71+
private function checkRunningUser(CommandStarting $event): void
4272
{
4373
// Check that we don't run this as the wrong user and break the install
4474
if (in_array($event->command, $this->skip_user_check)) {

0 commit comments

Comments
 (0)