From ccbe3ea2e3e596c864e9428024944e5023b27e95 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Wed, 22 Nov 2017 04:41:22 +0000 Subject: [PATCH] fix: Use correct entity columns for sensors (#7775) * fix: Use correct entity columns for sensors * updated schema * Update custom rules too --- includes/discovery/functions.inc.php | 10 ++-------- includes/discovery/sensors/cisco-entity-sensor.inc.php | 8 ++++---- misc/db_schema.yaml | 2 -- sql-schema/216.sql | 7 +++++++ 4 files changed, 13 insertions(+), 14 deletions(-) create mode 100644 sql-schema/216.sql diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index f785d8c4bd..100e7852bc 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -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'; diff --git a/includes/discovery/sensors/cisco-entity-sensor.inc.php b/includes/discovery/sensors/cisco-entity-sensor.inc.php index 2591b77837..f7ef1be5f3 100644 --- a/includes/discovery/sensors/cisco-entity-sensor.inc.php +++ b/includes/discovery/sensors/cisco-entity-sensor.inc.php @@ -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); } } diff --git a/misc/db_schema.yaml b/misc/db_schema.yaml index 228be46f63..a5457c24d1 100644 --- a/misc/db_schema.yaml +++ b/misc/db_schema.yaml @@ -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 } diff --git a/sql-schema/216.sql b/sql-schema/216.sql new file mode 100644 index 0000000000..50fdd6c182 --- /dev/null +++ b/sql-schema/216.sql @@ -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`;