mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 10:28:13 +00:00
Add MIB to OS helper to tests (#13795)
This commit is contained in:
parent
0c08670acc
commit
513fbf06e2
@ -26,6 +26,7 @@
|
||||
namespace LibreNMS\Util;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class FileCategorizer extends Categorizer
|
||||
{
|
||||
@ -79,6 +80,8 @@ class FileCategorizer extends Categorizer
|
||||
|
||||
public function categorize()
|
||||
{
|
||||
// This can't be a normal addCategory() function since it returns multiple results
|
||||
$this->osFromMibs();
|
||||
parent::categorize();
|
||||
|
||||
// split out os
|
||||
@ -99,6 +102,47 @@ class FileCategorizer extends Categorizer
|
||||
return file_exists("includes/definitions/$os.yaml") ? $os : null;
|
||||
}
|
||||
|
||||
private function osFromMibs(): void
|
||||
{
|
||||
$mibs = [];
|
||||
|
||||
foreach ($this->items as $file) {
|
||||
if (Str::startsWith($file, 'mibs/')) {
|
||||
$mibs[] = basename($file, '.mib');
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($mibs)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$grep = new Process(
|
||||
[
|
||||
'grep',
|
||||
'--fixed-strings',
|
||||
'--recursive',
|
||||
'--files-with-matches',
|
||||
'--file=-',
|
||||
'--',
|
||||
'includes/definitions/',
|
||||
'includes/discovery/',
|
||||
'includes/polling/',
|
||||
'LibreNMS/OS/',
|
||||
],
|
||||
null,
|
||||
null,
|
||||
implode("\n", $mibs)
|
||||
);
|
||||
|
||||
$grep->run();
|
||||
|
||||
foreach (explode("\n", trim($grep->getOutput())) as $item) {
|
||||
if (($os_name = $this->osFromFile($item)) !== null) {
|
||||
$this->categorized['os-files'][] = ['os' => $os_name, 'file' => $item];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function osFromFile($file)
|
||||
{
|
||||
if (Str::startsWith($file, 'includes/definitions/')) {
|
||||
|
Loading…
Reference in New Issue
Block a user