Allow num_oid to use OCTET STRING indexes (#10410)

* make index available as OCTET STRING converted to OID
* codeclimate
This commit is contained in:
PipoCanaja
2019-08-21 10:04:16 +02:00
committed by GitHub
parent 9d7edd879f
commit e7a86add93
2 changed files with 5 additions and 1 deletions

View File

@ -85,7 +85,8 @@ The only sensor we have defined here is airflow. The available options are as fo
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
-On can help figure out the number.
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`.
- `low_limit` (optional): This is the critical low threshold that

View File

@ -1047,6 +1047,9 @@ function discovery_process(&$valid, $device, $sensor_type, $pre_cache)
$skippedFromYaml = YamlDiscovery::canSkipItem($value, $index, $data, $sensor_options, $pre_cache);
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
// strlen($index) as first number, and each letter converted to a number, separated by dots
$oid = str_replace('{{ $index_string }}', strlen($index) . '.' . implode(".", unpack("c*", $index)), $oid);
// process the description
$descr = YamlDiscovery::replaceValues('descr', $index, null, $data, $pre_cache);