Skip to content

Commit aaa54eb

Browse files
authored
Validation page improvements (librenms#18515)
* Per-group validation * Manual running of a group's validation * Fix webserver validation url * stagger initial fetch calls to prevent ui blocking * better error
1 parent cc1a11e commit aaa54eb

File tree

8 files changed

+347
-42
lines changed

8 files changed

+347
-42
lines changed

LibreNMS/Validations/WebServer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public function validate(Validator $validator): void
4747
if (! app()->runningInConsole()) {
4848
$url = $this->removeStandardPorts(request()->url());
4949
$base_url = LibrenmsConfig::get('base_url');
50-
$expected = $this->removeStandardPorts(Str::finish($base_url, '/') . 'validate/results');
51-
$correct_base = str_replace('/validate/results', '', $url);
50+
$expected = $this->removeStandardPorts(Str::finish($base_url, '/') . 'validate/results/webserver');
51+
$correct_base = str_replace('/validate/results/webserver', '', $url);
5252

5353
if ($url !== $expected) {
5454
preg_match($this->host_regex, $url, $actual_host_match);

LibreNMS/Validator.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535

3636
class Validator
3737
{
38-
/** @var array */
39-
private $validation_groups = [];
40-
/** @var array */
41-
private $results = [];
42-
/** @var string|null */
43-
private $username;
38+
/** @var array<string, ValidationGroup> */
39+
private array $validation_groups = [];
40+
/** @var array<string, ValidationResult[]> */
41+
private array $results = [];
42+
43+
private ?string $username = null;
4444

4545
/**
4646
* Validator constructor.
@@ -67,6 +67,14 @@ public function __construct()
6767
}
6868
}
6969

70+
/**
71+
* @return array<string, bool>
72+
*/
73+
public function getValidationGroups(): array
74+
{
75+
return array_map(fn (ValidationGroup $validator) => $validator->isDefault(), $this->validation_groups);
76+
}
77+
7078
/**
7179
* Run validations. An empty array will run all default validations.
7280
*
@@ -159,8 +167,6 @@ public function getAllResults(): array
159167

160168
/**
161169
* Print all ValidationResults or a group of them.
162-
*
163-
* @param string|null $validation_group
164170
*/
165171
public function printResults(?string $validation_group = null): void
166172
{

app/Http/Controllers/ValidateController.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,26 @@ class ValidateController extends Controller
1212
{
1313
public function index(): View
1414
{
15-
return view('validate.index');
15+
$validationGroups = (new Validator())->getValidationGroups();
16+
17+
$groups = collect($validationGroups)
18+
->map(fn (bool $enabled, string $group) => [
19+
'group' => $group,
20+
'enabled' => $enabled,
21+
'name' => trans("validation.validations.groups.{$group}"),
22+
])
23+
->values()
24+
->all();
25+
26+
return view('validate.index', [
27+
'groups' => $groups,
28+
]);
1629
}
1730

18-
public function runValidation(): JsonResponse
31+
public function runValidation(?string $group = null): JsonResponse
1932
{
2033
$validator = new Validator();
21-
$validator->validate();
34+
$validator->validate($group ? [$group] : []);
2235

2336
return response()->json($validator->toArray());
2437
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"fakerphp/faker": "^1.23",
6666
"friendsofphp/php-cs-fixer": "^3.66",
6767
"larastan/larastan": "^3.1",
68+
"laravel/boost": "^1.8",
6869
"laravel/dusk": "^8.2.2",
6970
"mockery/mockery": "^1.6",
7071
"nunomaduro/collision": "^8.6",

composer.lock

Lines changed: 201 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lang/en/validation.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,36 @@
5454
'fix' => 'Fix',
5555
'fixed' => 'Fix has completed, refresh to re-run validations.',
5656
'fetch_failed' => 'Failed to fetch validation results',
57-
'backend_failed' => 'Failed to load data from backend, check console for error.',
57+
'backend_failed' => 'Failed to load data from backend, run ./validate.php on the console to check.',
5858
'invalid_fixer' => 'Invalid Fixer',
5959
'show_all' => 'Show all',
6060
'show_less' => 'Show less',
6161
'validate' => 'Validate',
6262
'validating' => 'Validating',
63+
'skipped' => 'Skipped',
64+
'run' => 'Run',
6365
],
6466
'validations' => [
67+
// Display names for validation groups
68+
'groups' => [
69+
'configuration' => 'Configuration',
70+
'database' => 'Database',
71+
'dependencies' => 'Dependencies',
72+
'disk' => 'Disk',
73+
'distributedpoller' => 'Distributed Poller',
74+
'mail' => 'Mail',
75+
'php' => 'PHP',
76+
'poller' => 'Poller',
77+
'programs' => 'Programs',
78+
'python' => 'Python',
79+
'rrd' => 'RRD',
80+
'rrdcheck' => 'RRD Check',
81+
'scheduler' => 'Scheduler',
82+
'system' => 'System',
83+
'updates' => 'Updates',
84+
'user' => 'User',
85+
'webserver' => 'Web Server',
86+
],
6587
'rrd' => [
6688
'CheckRrdVersion' => [
6789
'fail' => 'The rrdtool version you have specified is newer than what is installed. Config: :config_version Installed :installed_version',

0 commit comments

Comments
 (0)