Skip to content

Commit f2ac6d7

Browse files
murrantStyleCIBot
andauthored
Move definitions in to resources/definitions (librenms#17341)
* Move definitions in to resources/definitions OS detection : resources/definitions/os_detection OS discovery : resources/definitions/os_discovery More consistent location that should be future-proof. Better folder names (feedback on names welcomed) Move schema definitions into resources/definitions/schema this will break users with local os definitions we could help them out and add some code to move those files to the new location in daily update. Thoughts? * Fix more broken paths * move local os definitions * Move misc definitions * style fixes * Migration handle missing directories * Move os yaml files * I guess I'm moving db_schema.yaml too :) * Apply fixes from StyleCI * Exclude os_defs from resources * Schema files were supposed to be in resources/definitions/schema --------- Co-authored-by: StyleCI Bot <[email protected]>
1 parent 0e97ad2 commit f2ac6d7

File tree

1,422 files changed

+377
-311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,422 files changed

+377
-311
lines changed

LibreNMS/DB/Schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function getPrimaryKey($table)
106106
public function getSchema()
107107
{
108108
if (! isset($this->schema)) {
109-
$file = Config::get('install_dir') . '/misc/db_schema.yaml';
109+
$file = resource_path('definitions/schema/db_schema.yaml');
110110
$this->schema = Yaml::parse(file_get_contents($file));
111111
}
112112

LibreNMS/OS.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public function discoverStorage(): Collection
374374
public function getDiscovery($module = null)
375375
{
376376
if (! array_key_exists('dynamic_discovery', $this->device)) {
377-
$file = base_path('/includes/definitions/discovery/' . $this->getName() . '.yaml');
377+
$file = resource_path('definitions/os_discovery/' . $this->getName() . '.yaml');
378378
if (file_exists($file)) {
379379
$this->device['dynamic_discovery'] = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($file));
380380
}

LibreNMS/Util/FileCategorizer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function __construct($items = [])
6565
return Str::endsWith($item, '.svg') ? $item : false;
6666
});
6767
$this->addCategory('resources', function ($item) {
68-
return Str::startsWith($item, 'resources/') ? $item : false;
68+
return (str_starts_with($item, 'resources/') && ! str_starts_with($item, 'resources/definitions/os_')) ? $item : false;
6969
});
7070
$this->addCategory('full-checks', function ($item) {
7171
return in_array($item, ['composer.lock', '.github/workflows/test.yml']) ? $item : false;
@@ -100,7 +100,7 @@ public function categorize()
100100

101101
private function validateOs($os)
102102
{
103-
return file_exists("includes/definitions/$os.yaml") ? $os : null;
103+
return file_exists("resources/definitions/os_detection/$os.yaml") ? $os : null;
104104
}
105105

106106
private function osFromMibs(): void
@@ -125,7 +125,7 @@ private function osFromMibs(): void
125125
'--files-with-matches',
126126
'--file=-',
127127
'--',
128-
'includes/definitions/',
128+
'resources/definitions/os_',
129129
'includes/discovery/',
130130
'includes/polling/',
131131
'LibreNMS/OS/',
@@ -146,7 +146,7 @@ private function osFromMibs(): void
146146

147147
private function osFromFile($file)
148148
{
149-
if (Str::startsWith($file, 'includes/definitions/')) {
149+
if (Str::startsWith($file, 'resources/definitions/os_')) {
150150
return basename($file, '.yaml');
151151
} elseif (Str::startsWith($file, ['includes/polling', 'includes/discovery'])) {
152152
return $this->validateOs(basename($file, '.inc.php'));

LibreNMS/Util/ModuleTestHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public static function extractVariant($os_file)
298298

299299
if (! Str::contains($full_name, '_')) {
300300
return [$full_name, ''];
301-
} elseif (is_file(Config::get('install_dir') . "/includes/definitions/$full_name.yaml")) {
301+
} elseif (is_file(resource_path("definitions/os_detection/$full_name.yaml"))) {
302302
return [$full_name, ''];
303303
} else {
304304
[$rvar, $ros] = explode('_', strrev($full_name), 2);

LibreNMS/Validations/Database/CheckSchemaStructure.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
use Illuminate\Database\QueryException;
3030
use Illuminate\Support\Facades\DB;
31-
use LibreNMS\Config;
3231
use LibreNMS\DB\Eloquent;
3332
use LibreNMS\DB\Schema;
3433
use LibreNMS\Interfaces\Validation;
@@ -47,7 +46,7 @@ class CheckSchemaStructure implements Validation, ValidationFixer
4746

4847
public function __construct()
4948
{
50-
$this->schema_file = Config::get('install_dir') . '/misc/db_schema.yaml';
49+
$this->schema_file = resource_path('definitions/schema/db_schema.yaml');
5150
}
5251

5352
/**

app/ConfigRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __construct()
7575
*/
7676
public function getDefinitions(): array
7777
{
78-
return json_decode(file_get_contents($this->get('install_dir') . '/misc/config_definitions.json'), true)['config'];
78+
return json_decode(file_get_contents($this->get('install_dir') . '/resources/definitions/config_definitions.json'), true)['config'];
7979
}
8080

8181
/**
@@ -382,7 +382,7 @@ private function loadPreUserConfigDefaults(): void
382382
}
383383

384384
// load macros from json
385-
$macros = json_decode(file_get_contents($this->get('install_dir') . '/misc/macros.json'), true);
385+
$macros = json_decode(file_get_contents($this->get('install_dir') . '/resources/definitions/macros.json'), true);
386386
Arr::set($this->config, 'alert.macros.rule', $macros);
387387

388388
Arr::set($this->config, 'log_dir', $this->get('install_dir') . '/logs');
@@ -583,7 +583,7 @@ public function populateLegacyDbCredentials(): void
583583
*/
584584
private function loadAllOsDefinitions(): void
585585
{
586-
$os_list = glob($this->get('install_dir') . '/includes/definitions/*.yaml');
586+
$os_list = glob($this->get('install_dir') . '/resources/definitions/os_detection/*.yaml');
587587

588588
foreach ($os_list as $yaml_file) {
589589
$os = basename($yaml_file, '.yaml');

app/Console/Commands/SchemaDumpCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function handle(ConnectionResolverInterface $connections, Dispatcher $dis
5757

5858
\Artisan::call('migrate', $parameters, $stdout);
5959

60-
$file = $this->option('path') ?: base_path('/misc/db_schema.yaml');
60+
$file = $this->option('path') ?: resource_path('definitions/schema/db_schema.yaml');
6161
$yaml = Yaml::dump(Schema::dump($database), 3, 2);
6262

6363
if (file_put_contents($file, $yaml)) {

app/Console/Commands/SetConfigCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private function validateOsSetting(string $os, string $setting, $value)
229229
$validator = new Validator;
230230
$validator->validate(
231231
$os_data,
232-
(object) ['$ref' => 'file://' . base_path('/misc/os_schema.json')],
232+
(object) ['$ref' => 'file://' . resource_path('definitions/schema/os_schema.json')],
233233
Constraint::CHECK_MODE_TYPE_CAST
234234
);
235235

composer.lock

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

config.php.default

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
## Have a look in misc/config_definitions.json for examples of settings you can set here. DO NOT EDIT misc/config_definitions.json!
3+
## Have a look in resources/definitions/config_definitions.json for examples of settings you can set here. DO NOT EDIT config_definitions.json!
44

55
// This is the user LibreNMS will run as
66
//Please ensure this user is created and has the correct permissions to your install

0 commit comments

Comments
 (0)