fix: Use correct entity columns for sensors (#7775)

* fix: Use correct entity columns for sensors

* updated schema

* Update custom rules too
This commit is contained in:
Neil Lathwood
2017-11-22 04:41:22 +00:00
committed by Tony Murray
parent a56267e5ba
commit ccbe3ea2e3
4 changed files with 13 additions and 14 deletions

View File

@@ -206,7 +206,7 @@ function discover_device(&$device, $options = null)
//end discover_device()
// Discover sensors
function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, $divisor = 1, $multiplier = 1, $low_limit = null, $low_warn_limit = null, $warn_limit = null, $high_limit = null, $current = null, $poller_type = 'snmp', $entPhysicalIndex = null, $entPhysicalIndex_measured = null, $user_func = null, $entity_link_type = null, $entity_link_index = 0)
function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, $divisor = 1, $multiplier = 1, $low_limit = null, $low_warn_limit = null, $warn_limit = null, $high_limit = null, $current = null, $poller_type = 'snmp', $entPhysicalIndex = null, $entPhysicalIndex_measured = null, $user_func = null)
{
$low_limit = set_null($low_limit);
$low_warn_limit = set_null($low_warn_limit);
@@ -260,8 +260,6 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
'entPhysicalIndex' => $entPhysicalIndex,
'entPhysicalIndex_measured' => $entPhysicalIndex_measured,
'user_func' => $user_func,
'entity_link_type' => $entity_link_type,
'entity_link_index' => $entity_link_index,
);
foreach ($insert as $key => $val_check) {
@@ -346,9 +344,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
$divisor == $sensor_entry['sensor_divisor'] &&
$entPhysicalIndex_measured == $sensor_entry['entPhysicalIndex_measured'] &&
$entPhysicalIndex == $sensor_entry['entPhysicalIndex'] &&
$user_func == $sensor_entry['user_func'] &&
$entity_link_type == $sensor_entry['entity_link_type'] &&
$entity_link_index == $sensor_entry['entity_link_index']
$user_func == $sensor_entry['user_func']
) {
echo '.';
@@ -361,8 +357,6 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
'entPhysicalIndex' => $entPhysicalIndex,
'entPhysicalIndex_measured' => $entPhysicalIndex_measured,
'user_func' => $user_func,
'entity_link_type' => $entity_link_type,
'entity_link_index' => $entity_link_index,
);
$updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', array($sensor_entry['sensor_id']));
echo 'U';

View File

@@ -168,8 +168,8 @@ if ($device['os_group'] == 'cisco') {
list(, $tmp_ifindex) = explode(".", $entity_array[$phys_index][0]['entAliasMappingIdentifier']);
$tmp_port = get_port_by_index_cache($device['device_id'], $tmp_ifindex);
if (is_array($tmp_port)) {
$entity_link_type = 'port';
$entity_link_index = $tmp_ifindex;
$entPhysicalIndex = $tmp_ifindex;
$entry['entSensorMeasuredEntity'] = 'ports';
}
}
break;
@@ -177,7 +177,7 @@ if ($device['os_group'] == 'cisco') {
$phys_index = $entity_array[$phys_index]['entPhysicalContainedIn'];
}
}
discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'cisco-entity-sensor', ucwords($descr), $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current, 'snmp', $entPhysicalIndex, $entry['entSensorMeasuredEntity'], null, $entity_link_type, $entity_link_index);
discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'cisco-entity-sensor', ucwords($descr), $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current, 'snmp', $entPhysicalIndex, $entry['entSensorMeasuredEntity'], null);
#Cisco IOS-XR : add a fake sensor to graph as dbm
if ($type == "power" and $device['os'] == "iosxr" and (preg_match("/power (R|T)x/i", $descr) or preg_match("/(R|T)x Power/i", $descr))) {
// convert Watts to dbm
@@ -190,7 +190,7 @@ if ($device['os_group'] == 'cisco') {
$multiplier = 1;
$divisor = 1;
//echo("\n".$valid['sensor'].", $type, $device, $oid, $index, 'cisco-entity-sensor', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current");
discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'cisco-entity-sensor', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current, 'snmp', $entPhysicalIndex, $entry['entSensorMeasuredEntity'], null, $entity_link_type, $entity_link_index);
discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'cisco-entity-sensor', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current, 'snmp', $entPhysicalIndex, $entry['entSensorMeasuredEntity'], null);
}
}

View File

@@ -1337,8 +1337,6 @@ sensors:
- { Field: lastupdate, Type: timestamp, 'Null': false, Extra: 'on update CURRENT_TIMESTAMP', Default: CURRENT_TIMESTAMP }
- { Field: sensor_prev, Type: float, 'Null': true, Extra: '' }
- { Field: user_func, Type: varchar(100), 'Null': true, Extra: '' }
- { Field: entity_link_type, Type: varchar(32), 'Null': true, Extra: '' }
- { Field: entity_link_index, Type: 'int(11) unsigned', 'Null': false, Extra: '', Default: '0' }
Indexes:
PRIMARY: { Name: PRIMARY, Columns: [sensor_id], Unique: true, Type: BTREE }
sensor_host: { Name: sensor_host, Columns: [device_id], Unique: false, Type: BTREE }

7
sql-schema/216.sql Normal file
View File

@@ -0,0 +1,7 @@
UPDATE `sensors` SET `entPhysicalIndex_measured` = 'ports', `entPhysicalIndex` = entity_link_index WHERE entity_link_type='port';
UPDATE `config` SET `config_value` = "(%sensors.entPhysicalIndex_measured = 'ports' && %sensors.entPhysicalIndex = %ports.ifIndex && %macros.port_up)", `config_default` = "(%sensors.entPhysicalIndex_measured = 'ports' && %sensors.entPhysicalIndex = %ports.ifIndex && %macros.port_up)" WHERE `config_name` = 'alert.macros.rule.sensor_port_link';
UPDATE `alert_rules` SET `query` = REPLACE(query, 'entity_link_type', 'entPhysicalIndex_measured');
UPDATE `alert_rules` SET `query` = REPLACE(query, 'entity_link_index', 'entPhysicalIndex');
UPDATE `alert_rules` SET `rule` = REPLACE(rule, 'entity_link_type', 'entPhysicalIndex_measured');
UPDATE `alert_rules` SET `rule` = REPLACE(rule, 'entity_link_index', 'entPhysicalIndex');
ALTER TABLE `sensors` DROP `entity_link_type` , DROP `entity_link_index`;