refactor: Improve yaml state discovery (#7221)

* feature: Improve yaml state discovery
Handle state values that are returned as strings instead of int
Synchronize state values for existing state translations so we can change them without creating a new translation and losing historical data
More extensive/verbose yaml discovery phpunit tests
dbBulkInsert, use the first entry instead of requiring the first entry to be at index 0

* Update sensor state documentation
re-order values for better readability
remove os check
Use snmpwalk_group since it is more flexible

* Add some more debug output in dynamic discovery
This commit is contained in:
Tony Murray
2017-09-03 13:58:39 -05:00
committed by Neil Lathwood
parent 5441bafc81
commit 7b262a6851
5 changed files with 180 additions and 96 deletions

View File

@@ -97,12 +97,12 @@ modules:
index: '{{ $index }}'
state_name: otherStateSensorErrorStatus
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 }
- { value: 0, generic: 0, graph: 0, descr: normal }
- { value: 1, generic: 1, graph: 0, descr: info }
- { value: 2, generic: 1, graph: 0, descr: warning }
- { value: 3, generic: 2, graph: 0, descr: error }
- { value: 4, generic: 2, graph: 0, descr: critical }
- { value: 5, generic: 2, graph: 0, descr: failure }
```
@@ -114,45 +114,28 @@ The file should be located in /includes/discovery/sensors/state/cisco.inc.php.
```php
<?php
if ($device['os_group'] == 'cisco') {
$oids = snmpwalk_cache_multi_oid($device, 'ciscoEnvMonSupplyStatusTable', array(), 'CISCO-ENVMON-MIB');
$cur_oid = '.1.3.6.1.4.1.9.9.13.1.5.1.3.';
$oids = snmpwalk_group($device, 'ciscoEnvMonSupplyStatusTable', 'CISCO-ENVMON-MIB');
if (is_array($oids)) {
if (!empty($oids)) {
//Create State Index
$state_name = 'ciscoEnvMonSupplyState';
$states = array(
array('value' => 1, 'generic' => 0, 'graph' => 0, 'descr' => 'normal'),
array('value' => 2, 'generic' => 1, 'graph' => 0, 'descr' => 'warning'),
array('value' => 3, 'generic' => 2, 'graph' => 0, 'descr' => 'critical'),
array('value' => 4, 'generic' => 3, 'graph' => 0, 'descr' => 'shutdown'),
array('value' => 5, 'generic' => 3, 'graph' => 0, 'descr' => 'notPresent'),
array('value' => 6, 'generic' => 2, 'graph' => 0, 'descr' => 'notFunctioning'),
);
create_state_index($state_name, $states);
//Create State Index
$state_name = 'ciscoEnvMonSupplyState';
$state_index_id = create_state_index($state_name);
$num_oid = '.1.3.6.1.4.1.9.9.13.1.5.1.3.';
foreach ($oids as $index => $entry) {
//Discover Sensors
discover_sensor($valid['sensor'], 'state', $device, $num_oid.$index, $index, $state_name, $entry['ciscoEnvMonSupplyStatusDescr'], '1', '1', null, null, null, null, $entry['ciscoEnvMonSupplyState'], 'snmp', $index);
//Create State Translation
if ($state_index_id) {
$states = array(
array($state_index_id,'normal',0,1,0) ,
array($state_index_id,'warning',0,2,1) ,
array($state_index_id,'critical',0,3,2) ,
array($state_index_id,'shutdown',0,4,3) ,
array($state_index_id,'notPresent',0,5,3) ,
array($state_index_id,'notFunctioning',0,6,2)
);
foreach($states as $value){
$insert = array(
'state_index_id' => $value[0],
'state_descr' => $value[1],
'state_draw_graph' => $value[2],
'state_value' => $value[3],
'state_generic_value' => $value[4]
);
dbInsert($insert, 'state_translations');
}
}
foreach ($oids as $index => $entry) {
//Discover Sensors
discover_sensor($valid['sensor'], 'state', $device, $cur_oid.$index, $index, $state_name, $entry['ciscoEnvMonSupplyStatusDescr'], '1', '1', null, null, null, null, $entry['ciscoEnvMonSupplyState'], 'snmp', $index);
//Create Sensor To State Index
create_sensor_to_state_index($device, $state_name, $index);
}
//Create Sensor To State Index
create_sensor_to_state_index($device, $state_name, $index);
}
}
```