From 7a6ef2491ea9f075ccfe503c37411fcd3f44b86a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Bouynot?= Date: Tue, 31 Oct 2023 14:38:51 +0100 Subject: [PATCH] Smokeping menu and title use device displayname (#15387) * Menu and title use displayname * Fix empty strings * Fix array creation * Use groupby instead of loop * Change one forgotten var * Revert to working simple changes * Change test data to include displayname * Fix bad copy paste in test data --- app/Console/Commands/SmokepingGenerateCommand.php | 9 ++++++--- tests/SmokepingCliTest.php | 12 ++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/SmokepingGenerateCommand.php b/app/Console/Commands/SmokepingGenerateCommand.php index 0b00b05553..9c9a10501a 100644 --- a/app/Console/Commands/SmokepingGenerateCommand.php +++ b/app/Console/Commands/SmokepingGenerateCommand.php @@ -127,7 +127,10 @@ class SmokepingGenerateCommand extends LnmsCommand // Take the devices array and build it into a hierarchical list $smokelist = []; foreach ($devices as $device) { - $smokelist[$device->type][$device->hostname] = ['transport' => $device->transport]; + $smokelist[$device->type][$device->hostname] = [ + 'transport' => $device->transport, + 'displayname' => $device->displayName(), + ]; } $targets = $this->buildTargets($smokelist, Config::get('smokeping.probes'), $this->option('single-process')); @@ -315,8 +318,8 @@ class SmokepingGenerateCommand extends LnmsCommand foreach ($devices as $hostname => $config) { if (! $this->dnsLookup || $this->deviceIsResolvable($hostname)) { $lines[] = sprintf('++ %s', $this->buildMenuEntry($hostname)); - $lines[] = sprintf(' menu = %s', $hostname); - $lines[] = sprintf(' title = %s', $hostname); + $lines[] = sprintf(' menu = %s', $config['displayname']); + $lines[] = sprintf(' title = %s', $config['displayname']); if (! $singleProcess) { $lines[] = sprintf(' probe = %s', $this->balanceProbes($config['transport'], $probeCount)); diff --git a/tests/SmokepingCliTest.php b/tests/SmokepingCliTest.php index 3d064bb836..590880b406 100644 --- a/tests/SmokepingCliTest.php +++ b/tests/SmokepingCliTest.php @@ -39,43 +39,55 @@ class SmokepingCliTest extends DBTestCase 'Le23HKVMvN' => [ 'Cl09bZU4sn' => [ 'transport' => 'udp', + 'displayname' => 'Cl09bZU4sn', ], 'c559TvthzY' => [ 'transport' => 'udp6', + 'displayname' => 'c559TvthzY', ], 'sNtzSdxdw8' => [ 'transport' => 'udp6', + 'displayname' => 'sNtzSdxdw8', ], '10.0.0.3' => [ 'transport' => 'udp', + 'displayname' => '10.0.0.3', ], '2600::' => [ 'transport' => 'udp', + 'displayname' => '2600::', ], ], 'Psv9oZcxdC' => [ 'oHiPfLzrmU' => [ 'transport' => 'udp', + 'displayname' => 'oHiPfLzrmU', ], 'kEn7hZ7N37' => [ 'transport' => 'udp6', + 'displayname' => 'kEn7hZ7N37', ], 'PcbZ5FKtS3' => [ 'transport' => 'udp6', + 'displayname' => 'PcbZ5FKtS3', ], '192.168.1.1' => [ 'transport' => 'udp', + 'displayname' => '192.168.1.1', ], 'fe80::' => [ 'transport' => 'udp', + 'displayname' => 'fe80::', ], ], '4diY0pWFik' => [ 'example.org' => [ 'transport' => 'udp', + 'displayname' => 'example.org', ], 'host_with_under_score.example.org' => [ 'transport' => 'udp6', + 'displayname' => 'host_with_under_score.example.org', ], ], ];