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
feature: Added support for sensors to be discovered from yaml #6859
Changes from 5 commits
cece4d8
202b3fa
5c24c7a
0434377
438c724
67dfde3
aac6e8e
74f5928
3553015
08f2c8e
2b8ff70
5401bfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,66 @@ We also map these values to the actual state sensor(state_index) where these val | |
*Is as you might have guessed, where the sensor_id is mapped to a state_index_id.* | ||
|
||
### Example | ||
|
||
For YAML based state discovery: | ||
|
||
```yaml | ||
mib: NETBOTZV2-MIB | ||
modules: | ||
sensors: | ||
state: | ||
- | ||
oid: dryContactSensorTable | ||
value: dryContactSensorValue | ||
num_oid: .1.3.6.1.4.1.5528.100.4.2.1.1.2. | ||
descr: dryContactSensorLabel | ||
index: 'dryContactSensor.{{ $index }}' | ||
state_name: dryContactSensor | ||
states: | ||
- { descr: 'null', graph: 0, value: -1, generic: 3 } | ||
- { descr: open, graph: 0, value: 0, generic: 0 } | ||
- { descr: closed, graph: 0, value: 1, generic: 2 } | ||
- | ||
oid: doorSwitchSensorTable | ||
value: doorSwitchSensorValue | ||
num_oid: .1.3.6.1.4.1.5528.100.4.2.2.1.2. | ||
descr: doorSwitchSensorLabel | ||
index: 'doorSwitchSensor.{{ $index }}' | ||
state_name: doorSwitchSensor | ||
states: | ||
- { descr: 'null', graph: 0, value: -1, generic: 3 } | ||
- { descr: open, graph: 0, value: 0, generic: 0 } | ||
- { descr: closed, graph: 0, value: 1, generic: 2 } | ||
- | ||
oid: cameraMotionSensorTable | ||
value: cameraMotionSensorValue | ||
num_oid: .1.3.6.1.4.1.5528.100.4.2.3.1.2. | ||
descr: cameraMotionSensorLabel | ||
index: 'cameraMotionSensor.{{ $index }}' | ||
state_name: cameraMotionSensor | ||
states: | ||
- { descr: 'null', graph: 0, value: -1, generic: 3 } | ||
- { descr: noMotion, graph: 0, value: 0, generic: 0 } | ||
- { descr: motionDetected, graph: 0, value: 1, generic: 2 } | ||
- | ||
oid: otherStateSensorTable | ||
value: otherStateSensorValue | ||
num_oid: .1.3.6.1.4.1.5528.100.4.2.10.1.3. | ||
descr: otherStateSensorLabel | ||
index: '{{ $index }}' | ||
state_name: otherStateSensorErrorStatus | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about otherStateSensor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's how it is in the old code so replicating that. |
||
states: | ||
- { descr: normal, graph: 0, value: 0, generic: 0 } | ||
- { descr: info, graph: 0, value: 1, generic: 1 } | ||
- { descr: warning, graph: 0, value: 2, generic: 1 } | ||
- { descr: error, graph: 0, value: 3, generic: 2 } | ||
- { descr: critical, graph: 0, value: 4, generic: 2 } | ||
- { descr: failure, graph: 0, value: 5, generic: 2 } | ||
|
||
``` | ||
|
||
For advanced state discovery: | ||
|
||
This example will be based on a Cisco power supply sensor and is all it takes to have sensor state support for Cisco power supplys in Cisco switches. | ||
The file should be located in /includes/discovery/sensors/state/cisco.inc.php. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
mib: NETBOTZV2-MIB | ||
modules: | ||
sensors: | ||
airflow: | ||
- | ||
oid: airFlowSensorTable | ||
value: airFlowSensorValue | ||
divisor: 10 | ||
num_oid: .1.3.6.1.4.1.5528.100.4.1.5.1.2. | ||
descr: airFlowSensorLabel | ||
index: 'airFlowSensorValue.{{ $index }}' | ||
temperature: | ||
- | ||
oid: dewPointSensorTable | ||
value: dewPointSensorValue | ||
divisor: 10 | ||
num_oid: .1.3.6.1.4.1.5528.100.4.1.3.1.2. | ||
descr: dewPointSensorLabel | ||
index: 'dewPointSensorValue.{{ $index }}' | ||
- | ||
oid: tempSensorTable | ||
value: tempSensorValue | ||
num_oid: .1.3.6.1.4.1.5528.100.4.1.1.1.8. | ||
descr: tempSensorLabel | ||
index: '{{ $index }}' | ||
humidity: | ||
- | ||
oid: humiSensorTable | ||
value: humiSensorValue | ||
num_oid: .1.3.6.1.4.1.5528.100.4.1.2.1.8. | ||
descr: humiSensorLabel | ||
index: '{{ $index }}' | ||
state: | ||
- | ||
oid: dryContactSensorTable | ||
value: dryContactSensorValue | ||
num_oid: .1.3.6.1.4.1.5528.100.4.2.1.1.2. | ||
descr: dryContactSensorLabel | ||
index: 'dryContactSensor.{{ $index }}' | ||
state_name: dryContactSensor | ||
states: | ||
- { descr: 'null', graph: 0, value: -1, generic: 3 } | ||
- { descr: open, graph: 0, value: 0, generic: 0 } | ||
- { descr: closed, graph: 0, value: 1, generic: 2 } | ||
- | ||
oid: doorSwitchSensorTable | ||
value: doorSwitchSensorValue | ||
num_oid: .1.3.6.1.4.1.5528.100.4.2.2.1.2. | ||
descr: doorSwitchSensorLabel | ||
index: 'doorSwitchSensor.{{ $index }}' | ||
state_name: doorSwitchSensor | ||
states: | ||
- { descr: 'null', graph: 0, value: -1, generic: 3 } | ||
- { descr: open, graph: 0, value: 0, generic: 0 } | ||
- { descr: closed, graph: 0, value: 1, generic: 2 } | ||
- | ||
oid: cameraMotionSensorTable | ||
value: cameraMotionSensorValue | ||
num_oid: .1.3.6.1.4.1.5528.100.4.2.3.1.2. | ||
descr: cameraMotionSensorLabel | ||
index: 'cameraMotionSensor.{{ $index }}' | ||
state_name: cameraMotionSensor | ||
states: | ||
- { descr: 'null', graph: 0, value: -1, generic: 3 } | ||
- { descr: noMotion, graph: 0, value: 0, generic: 0 } | ||
- { descr: motionDetected, graph: 0, value: 1, generic: 2 } | ||
- | ||
oid: otherStateSensorTable | ||
value: otherStateSensorValue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the correct name is: |
||
num_oid: .1.3.6.1.4.1.5528.100.4.2.10.1.3. | ||
descr: otherStateSensorLabel | ||
index: '{{ $index }}' | ||
state_name: otherStateSensorErrorStatus | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about otherStateSensor? |
||
states: | ||
- { descr: normal, graph: 0, value: 0, generic: 0 } | ||
- { descr: info, graph: 0, value: 1, generic: 1 } | ||
- { descr: warning, graph: 0, value: 2, generic: 1 } | ||
- { descr: error, graph: 0, value: 3, generic: 2 } | ||
- { descr: critical, graph: 0, value: 4, generic: 2 } | ||
- { descr: failure, graph: 0, value: 5, generic: 2 } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,17 @@ | |
d_echo($pre_cache); | ||
} | ||
|
||
if (isset($device['dynamic_discovery']['modules']['sensors'])) { | ||
foreach ($device['dynamic_discovery']['modules']['sensors'] as $key => $data_array) { | ||
foreach ($data_array as $data) { | ||
foreach ((array)$data['oid'] as $oid) { | ||
$tmp_name = $data['oid']; | ||
$pre_cache[$tmp_name] = snmpwalk_cache_oid($device, $oid, $pre_cache[$tmp_name], $device['dynamic_discovery']['mib'], null, '-OeQUs'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should check if the oid has already been fetched here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And send an empty array to the walk function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Walking a single entry is ok but I'm not sure how well the code will work against that yet. I've added support for passing a description as a string as well as saying which key in the array contains the description so it's possibly ok with single OIDs. |
||
} | ||
} | ||
} | ||
} | ||
|
||
// Run custom sensors | ||
require 'includes/discovery/sensors/cisco-entity-sensor.inc.php'; | ||
require 'includes/discovery/sensors/entity-sensor.inc.php'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the correct name is:
otherStateSensorErrorStatus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, don't think it matters though.