mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
DynamicDiscovery - Guess num_oid if not provided in YAML file (#12570)
* Guess num_oid if not provided in YAML file * Discover Processor num_oid if necessary * num_oid is now optional * documentation upgrade
This commit is contained in:
@@ -41,6 +41,7 @@ class YamlDiscovery
|
||||
public static function discover(OS $os, $class, $yaml_data)
|
||||
{
|
||||
$pre_cache = $os->preCache();
|
||||
$device = $os->getDeviceArray();
|
||||
$items = [];
|
||||
|
||||
// convert to class name for static call below
|
||||
@@ -80,6 +81,24 @@ class YamlDiscovery
|
||||
$data['value'] = $data['oid'];
|
||||
}
|
||||
|
||||
if (! isset($data['num_oid'])) {
|
||||
try {
|
||||
d_echo('Info: Trying to find a numerical OID for ' . $data['value'] . '.');
|
||||
$search_mib = $device['dynamic_discovery']['mib'];
|
||||
if (Str::contains($data['oid'], '::') && ! (Str::contains($data['value'], '::'))) {
|
||||
// We should search this mib first
|
||||
$exp_oid = explode('::', $data['oid']);
|
||||
$search_mib = $exp_oid[0] . ':' . $search_mib;
|
||||
}
|
||||
$num_oid = static::oidToNumeric($data['value'], $device, $search_mib, $device['mib_dir']);
|
||||
$data['num_oid'] = $num_oid . '.{{ $index }}';
|
||||
d_echo('Info: We found numerical oid for ' . $data['value'] . ': ' . $data['num_oid']);
|
||||
} catch (\Exception $e) {
|
||||
d_echo('Error: We cannot find a numerical OID for ' . $data['value'] . '. Skipping this one...');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data as $name => $value) {
|
||||
if ($name == '$oid' || $name == 'skip_values') {
|
||||
$current_data[$name] = $value;
|
||||
|
@@ -88,9 +88,9 @@ are as follows:
|
||||
- `oid` (required): This is the name of the table you want to do the snmp walk on.
|
||||
- `value` (optional): This is the key within the table that contains
|
||||
the value. If not provided willuse `oid`
|
||||
- `num_oid` (required): This is the numerical OID that contains
|
||||
`value`. This should always include `{{ $index }}`. snmptranslate
|
||||
-On can help figure out the number.
|
||||
- `num_oid` (optional): If not provided, this parameter should be computed
|
||||
automatically by discovery process. This is the numerical OID that contains
|
||||
`value`. This should usually include `{{ $index }}`.
|
||||
In case the index is a string, `{{ $index_string }}` can be used instead.
|
||||
- `divisor` (optional): This is the divisor to use against the returned `value`.
|
||||
- `multiplier` (optional): This is the multiplier to use against the returned `value`.
|
||||
|
@@ -115,7 +115,7 @@ Available yaml data keys:
|
||||
Key | Default | Description
|
||||
----- | --- | -----
|
||||
oid | required | The string based oid to fetch data, could be a table or a single value
|
||||
num_oid | required | the numerical oid to fetch data from when polling, usually should be appended by {{ $index }}
|
||||
num_oid | optional | The numerical oid to fetch data from when polling, usually should be appended by {{ $index }}. Computed by discovery process if not provided.
|
||||
value | optional | Oid to retrieve data from, primarily used for tables
|
||||
precision | 1 | The multiplier to multiply the data by. If this is negative, the data will be multiplied then subtracted from 100.
|
||||
descr | Processor | Description of this processor, may be an oid or plain string. Helpful values {{ $index }} and {{$count}}
|
||||
|
@@ -951,6 +951,27 @@ function discovery_process(&$valid, $device, $sensor_class, $pre_cache)
|
||||
d_echo("Final sensor value: $value\n");
|
||||
|
||||
$skippedFromYaml = YamlDiscovery::canSkipItem($value, $index, $data, $sensor_options, $pre_cache);
|
||||
|
||||
// Check if we have a "num_oid" value. If not, we'll try to compute it from textual OIDs with snmptranslate.
|
||||
if (empty($data['num_oid'])) {
|
||||
try {
|
||||
d_echo('Info: Trying to find a numerical OID for ' . $data_name . '.');
|
||||
$search_mib = $device['dynamic_discovery']['mib'];
|
||||
if (Str::contains($data['oid'], '::') && ! (Str::contains($data_name, '::'))) {
|
||||
// We should search this mib first
|
||||
$exp_oid = explode('::', $data['oid']);
|
||||
$search_mib = $exp_oid[0] . ':' . $search_mib;
|
||||
}
|
||||
$num_oid = YamlDiscovery::oidToNumeric($data_name, $device, $search_mib, $device['mib_dir']);
|
||||
$data['num_oid'] = $num_oid . '.{{ $index }}';
|
||||
d_echo('Info: We found numerical oid for ' . $data_name . ': ' . $data['num_oid']);
|
||||
} catch (\Exception $e) {
|
||||
d_echo('Error: We cannot find a numerical OID for ' . $data_name . '. Skipping this one...');
|
||||
$skippedFromYaml = true;
|
||||
// Cause we still don't have a num_oid
|
||||
}
|
||||
}
|
||||
|
||||
if ($skippedFromYaml === false && is_numeric($value)) {
|
||||
$oid = str_replace('{{ $index }}', $index, $data['num_oid']);
|
||||
// if index is a string, we need to convert it to OID
|
||||
|
@@ -781,12 +781,12 @@ function snmp_translate($oid, $mib = 'ALL', $mibdir = null, $options = null, $de
|
||||
$cmd = [Config::get('snmptranslate', 'snmptranslate'), '-M', mibdir($mibdir, $device), '-m', $mib];
|
||||
|
||||
if (oid_is_numeric($oid)) {
|
||||
$default_options = '-Os';
|
||||
$default_options = ['-Os', '-Pu'];
|
||||
} else {
|
||||
if ($mib != 'ALL' && ! Str::contains($oid, '::')) {
|
||||
$oid = "$mib::$oid";
|
||||
}
|
||||
$default_options = '-On';
|
||||
$default_options = ['-On', '-Pu'];
|
||||
}
|
||||
$options = is_null($options) ? $default_options : $options;
|
||||
$cmd = array_merge($cmd, (array) $options);
|
||||
|
@@ -170,7 +170,6 @@
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"num_oid",
|
||||
"oid"
|
||||
]
|
||||
}
|
||||
@@ -279,7 +278,6 @@
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"descr",
|
||||
"num_oid",
|
||||
"oid",
|
||||
"states"
|
||||
]
|
||||
@@ -446,7 +444,6 @@
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"descr",
|
||||
"num_oid",
|
||||
"oid"
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user