Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to "sub" index (when OID has multiple indexes) #9893

Merged
merged 10 commits into from Mar 5, 2019
@@ -111,7 +111,13 @@ public static function replaceValues($name, $index, $count, $data, $pre_cache)
$value = dynamic_discovery_get_value($name, $index, $data, $pre_cache);
if (is_null($value)) {
// built in replacements
// prepare the $subindexX match variable replacement
$subindexes = explode('.', $index);
foreach (array_keys($subindexes) as $pos) {
This conversation was marked as resolved by PipoCanaja

This comment has been minimized.

Copy link
@murrant

murrant Mar 4, 2019

Member

You didn't initialize $subindexStr, you could probably make this a little more readable.

This comment has been minimized.

Copy link
@PipoCanaja

PipoCanaja Mar 4, 2019

Author Contributor

done

$subindexStr[$pos] = '{{ $subindex' . $pos . ' }}';
}
$value = str_replace(array('{{ $index }}', '{{ $count }}'), array($index, $count), $data[$name]);
$value = str_replace($subindexStr, $subindexes, $value);

Check notice on line 120 in LibreNMS/Device/YamlDiscovery.php

Scrutinizer / Inspection

LibreNMS/Device/YamlDiscovery.php#L120

The variable ``$subindexStr`` seems to be defined by a ``foreach`` iteration on line ``116``. Are you sure the iterator is never empty, otherwise this variable is not defined?
// search discovery data for values
$value = preg_replace_callback('/{{ \$([a-zA-Z0-9.]+) }}/', function ($matches) use ($index, $data, $pre_cache) {
@@ -62,7 +62,7 @@ modules:
value: airFlowSensorValue
divisor: 10
num_oid: '.1.3.6.1.4.1.5528.100.4.1.5.1.2.{{ $index }}'
descr: airFlowSensorLabel
descr: '{{ $airFlowSensorLabel }}'
index: 'airFlowSensorValue.{{ $index }}'
```

@@ -83,7 +83,7 @@ The only sensor we have defined here is airflow. The available options are as fo
- `low_warn_limit` (optional): This is the warning low threshold that `value` should be (used in alerting). If an OID is specified then divisor / multiplier are used.
- `warn_limit` (optional): This is the warning high threshold that `value` should be (used in alerting). If an OID is specified then divisor / multiplier are used.
- `high_limit` (optional): This is the critical high threshold that `value` should be (used in alerting). If an OID is specified then divisor / multiplier are used.
- `descr` (required): The visible label for this sensor. It can be a key with in the table or a static string, optionally using `{{ index }}`
- `descr` (required): The visible label for this sensor. It can be a key with in the table or a static string, optionally using `{{ index }}`.
- `group` (optional): Groups sensors together under in the webui, displaying this text. Not specifying this will put the sensors in the default group.
- `index` (optional): This is the index value we use to uniquely identify this sensor. `{{ $index }}` will be replaced by the `index` from the snmp walk.
- `skip_values` (optional): This is an array of values we should skip over (see note below).
@@ -101,6 +101,11 @@ For `options:` you have the following available:
- `skip_value_lt`: If sensor value is less than this, skip the discovery.
- `skip_value_gt`: If sensor value is greater than this, skip the discovery.

Multiple variables can be used in the sensors definition. The syntax is `{{ $variable }}`. Any oid in the current
table can be used, as well as pre_cached data. The index ($index) and the sub_indexes
(in case the oid is indexed multiple times) are also available: if $index="1.20", then
$subindex0="1" and $subindex1="20".

> `skip_values` can also compare items within the OID table against values. One example of this is:
```yaml
@@ -139,7 +139,7 @@ modules:
oid: hwFanStatusTable
value: hwEntityFanState
num_oid: '.1.3.6.1.4.1.2011.5.25.31.1.1.10.1.7.{{ $index }}'
descr: 'Fan {{ $hwEntityFanDesc }} Status'
descr: 'Slot {{ $subindex0 }} Fan {{ $subindex1 }} Status'
group: Fans
state_name: hwEntityFanState
states:
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.