feature: Added support to cisco sensors to link them to ports + macro/docs for alerting (#6959)

* feature: Added support to cisco sensors to link them to ports + macro/docs for alerting

* renamed sql
This commit is contained in:
Neil Lathwood
2017-08-04 19:37:50 +01:00
committed by GitHub
parent 0d36244eda
commit 707b6c6954
6 changed files with 54 additions and 8 deletions

View File

@@ -119,6 +119,12 @@ Description: Only select sensors that aren't ignored.
Source: `(%sensors.sensor_alert = 1)`
Entity: `%macros.sensor_port_link`
Description: Only selects sensors that have a port linked to them, the port is up and the device is up.
Source: `(%sensors.entity_link_type = 'port' && %sensors.entity_link_index = %ports.ifIndex && %macros.port_up && %macros.device_up))`
## <a name="macros-misc">Misc</a> (Boolean)
### Packet Loss

View File

@@ -198,7 +198,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)
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)
{
$low_limit = set_null($low_limit);
$low_warn_limit = set_null($low_warn_limit);
@@ -252,6 +252,8 @@ 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) {
@@ -336,7 +338,9 @@ 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']
$user_func == $sensor_entry['user_func'] &&
$entity_link_type == $sensor_entry['entity_link_type'] &&
$entity_link_index == $sensor_entry['entity_link_index']
) {
echo '.';
} else {
@@ -348,6 +352,8 @@ 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

@@ -7,11 +7,14 @@ if ($device['os_group'] == 'cisco') {
echo 'Caching OIDs:';
if (!is_array($entity_array)) {
$tmp_oids = array('entPhysicalDescr', 'entPhysicalName', 'entPhysicalClass', 'entPhysicalContainedIn', 'entPhysicalParentRelPos');
$entity_array = array();
echo ' entPhysicalDescr';
$entity_array = snmpwalk_cache_multi_oid($device, 'entPhysicalDescr', $entity_array, 'CISCO-ENTITY-SENSOR-MIB');
echo ' entPhysicalName';
$entity_array = snmpwalk_cache_multi_oid($device, 'entPhysicalName', $entity_array, 'CISCO-ENTITY-SENSOR-MIB');
foreach ($tmp_oids as $tmp_oid) {
echo " $tmp_oid";
$entity_array = snmpwalk_cache_multi_oid($device, $tmp_oid, $entity_array, 'ENTITY-MIB:CISCO-ENTITY-SENSOR-MIB');
}
echo ' entAliasMappingIdentifier';
$entity_array = snmpwalk_cache_twopart_oid($device, 'entAliasMappingIdentifier', $entity_array, 'ENTITY-MIB:IF-MIB');
}
echo ' entSensorType';
@@ -159,7 +162,26 @@ if ($device['os_group'] == 'cisco') {
} //end if
if ($ok) {
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']);
$phys_index = $entity_array[$index]['entPhysicalContainedIn'];
while ($phys_index != 0) {
if ($index === $phys_index) {
break;
}
if ($entity_array[$phys_index]['entPhysicalClass'] === 'port') {
if (str_contains($entity_array[$phys_index][0]['entAliasMappingIdentifier'], 'ifIndex.')) {
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;
}
}
break;
} else {
$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);
#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
@@ -172,7 +194,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']);
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);
}
}

View File

@@ -115,5 +115,13 @@
{
"rule": "%services.service_status = \"2\"",
"name": "Service critical"
},
{
"rule": "%sensors.sensor_current > %sensors.sensor_limit && %sensors.sensor_alert = \"1\" && %macros.device_up = \"1\" && %macros.sensor_port_link = \"1\"",
"name": "Sensor over limit with linked port"
},
{
"rule": "%sensors.sensor_current < %sensors.sensor_limit_low && %sensors.sensor_alert = \"1\" && %macros.device_up = \"1\" && %macros.sensor_port_link = \"1\"",
"name": "Sensor under limit with linked port"
}
]

View File

@@ -1310,6 +1310,8 @@ route:
sensors:
Columns:
device_id: { Field: device_id, Type: 'int(11) unsigned', 'Null': false, Default: '0', Extra: '' }
entity_link_index: { Field: entity_link_index, Type: 'int(11) unsigned', 'Null': false, Default: '0', Extra: '' }
entity_link_type: { Field: entity_link_type, Type: varchar(32), 'Null': true, Default: null, Extra: '' }
entPhysicalIndex: { Field: entPhysicalIndex, Type: varchar(16), 'Null': true, Default: null, Extra: '' }
entPhysicalIndex_measured: { Field: entPhysicalIndex_measured, Type: varchar(16), 'Null': true, Default: null, Extra: '' }
lastupdate: { Field: lastupdate, Type: timestamp, 'Null': false, Default: CURRENT_TIMESTAMP, Extra: 'on update CURRENT_TIMESTAMP' }

2
sql-schema/201.sql Normal file
View File

@@ -0,0 +1,2 @@
ALTER TABLE `sensors` ADD `entity_link_type` VARCHAR(32) NULL, ADD `entity_link_index` INT(11) UNSIGNED NOT NULL DEFAULT 0;
INSERT INTO `config` (`config_name`,`config_value`,`config_default`,`config_descr`,`config_group`,`config_group_order`,`config_sub_group`,`config_sub_group_order`,`config_hidden`,`config_disabled`) VALUES ('alert.macros.rule.sensor_port_link',"(%sensors.entity_link_type = 'port' && %sensors.entity_link_index = %ports.ifIndex && %macros.port_up)","(%sensors.entity_link_type = 'port' && %sensors.entity_link_index = %ports.ifIndex && %macros.port_up)",'Sensors linked to port','alerting',0,'macros',0,'1','0');