Skip to content

Commit

Permalink
Remove duplicate mib directories from snmp queries (#9148)
Browse files Browse the repository at this point in the history
General cleanup of that function

DO NOT DELETE THIS TEXT

#### Please note

> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.

- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)

#### Testers

If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
  • Loading branch information
murrant authored and laf committed Sep 4, 2018
1 parent 2978e52 commit 5c4a298
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions includes/snmp.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,24 @@ function get_mib_dir($device)
* If $mibdir is empty '', return an empty string
*
* @param string $mibdir should be the name of the directory within $config['mib_dir']
* @param string $device
* @param array $device
* @return string The option string starting with -M
*/
function mibdir($mibdir = null, $device = array())
function mibdir($mibdir = null, $device = [])
{
global $config;

$extra_dir = implode(':', get_mib_dir($device));
if (!empty($extra_dir)) {
$extra_dir = ":".$extra_dir;
}
$base = Config::get('mib_dir');
$dirs = get_mib_dir($device);
$dirs[] = "$base/$mibdir";

if (is_null($mibdir)) {
return " -M ${config['mib_dir']}$extra_dir";
}
// make sure base directory is included first
array_unshift($dirs, $base);

if (empty($mibdir)) {
// use system mibs
return '';
}
// remove trailing /, remove empty dirs, and remove duplicates
$dirs = array_unique(array_filter(array_map(function ($dir) {
return rtrim($dir, '/');
}, $dirs)));

return " -M ${config['mib_dir']}$extra_dir:${config['mib_dir']}/$mibdir";
return " -M " . implode(':', $dirs);
}//end mibdir()

/**
Expand Down

0 comments on commit 5c4a298

Please sign in to comment.