Skip to content

Commit

Permalink
Support for configuring alarm for a specific object
Browse files Browse the repository at this point in the history
Presently, the uve_keys field in the alarm schema takes only list of
uve-types. This patch adds support for specifying uve objects in
addition to uve-types in the uve-keys. uve object can be specified in
the format <uve-type>:<uve-name>

Change-Id: I7e25d49a206c289dd5ada1d6145cbc7255878afe
Closes-Bug: #1606187
(cherry picked from commit b59b7be)
  • Loading branch information
Sundaresan Rajangam committed Aug 18, 2016
1 parent 3701277 commit c2a75d3
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 26 deletions.
41 changes: 25 additions & 16 deletions src/opserver/alarmgen.py
Expand Up @@ -1368,15 +1368,18 @@ def run_uve_processing(self):
def examine_uve_for_alarms(self, uve_key, uve):
table = uve_key.split(':', 1)[0]
alarm_cfg = self._config_handler.alarm_config_db()
if not alarm_cfg.has_key(table):
new_uve_alarms = {}
else:
prevt = UTCTimestampUsec()
aproc = AlarmProcessor(self._logger)
for alarm_fqname, alarm_obj in alarm_cfg[table].iteritems():
aproc.process_alarms(alarm_fqname, alarm_obj, uve_key, uve)
new_uve_alarms = aproc.uve_alarms
self.tab_perf[table].record_call(UTCTimestampUsec() - prevt)
prevt = UTCTimestampUsec()
aproc = AlarmProcessor(self._logger)
# Process all alarms configured for this uve-type
for alarm_fqname, alarm_obj in \
alarm_cfg.get(table, {}).iteritems():
aproc.process_alarms(alarm_fqname, alarm_obj, uve_key, uve)
# Process all alarms configured for this uve-key
for alarm_fqname, alarm_obj in \
alarm_cfg.get(uve_key, {}).iteritems():
aproc.process_alarms(alarm_fqname, alarm_obj, uve_key, uve)
new_uve_alarms = aproc.uve_alarms
self.tab_perf[table].record_call(UTCTimestampUsec() - prevt)

del_types = []
if not self.tab_alarms.has_key(table):
Expand Down Expand Up @@ -1431,18 +1434,24 @@ def alarm_config_change_worker(self, partition, alarm_config_change_map):
self._logger.debug('Alarm config change worker for partition %d'
% (partition))
try:
for table, alarm_map in alarm_config_change_map.iteritems():
for uve_key, alarm_map in alarm_config_change_map.iteritems():
self._logger.debug('Handle alarm config change for '
'[partition:table:{alarms}] -> [%d:%s:%s]' %
(partition, table, str(alarm_map)))
'[partition:uve_key:{alarms}] -> [%d:%s:%s]' %
(partition, uve_key, str(alarm_map)))
uve_type_name = uve_key.split(':', 1)
try:
uves = self.ptab_info[partition][table]
if len(uve_type_name) == 1:
uves = self.ptab_info[partition][uve_type_name[0]]
else:
uve = self.ptab_info[partition][uve_type_name[0]]\
[uve_type_name[1]]
uves = {uve_type_name[1]: uve}
except KeyError:
continue
else:
for uve, data in uves.iteritems():
self._logger.debug('process alarm for uve %s' % (uve))
self.examine_uve_for_alarms(table+':'+uve,
for name, data in uves.iteritems():
self._logger.debug('process alarm for uve %s' % (name))
self.examine_uve_for_alarms(uve_type_name[0]+':'+name,
data.values())
gevent.sleep(0)
except Exception as e:
Expand Down
19 changes: 12 additions & 7 deletions src/opserver/alarmgen_config_handler.py
Expand Up @@ -49,18 +49,23 @@ def _update_alarm_config_table(self, alarm_fqname, alarm_obj, uve_keys,
operation):
alarm_config_change_map = {}
for key in uve_keys:
uve_type_name = key.split(':', 1)
try:
table = UVE_MAP[key]
table = UVE_MAP[uve_type_name[0]]
except KeyError:
self._logger('Invalid table name "%s" specified in '
self._logger('Invalid uve_key "%s" specified in '
'alarm config "%s"' % (key, alarm_fqname),
SandeshLevel.SYS_ERR)
else:
if len(uve_type_name) == 2:
uve_key = table+':'+uve_type_name[1]
else:
uve_key = table
try:
alarm_table = self._alarm_config_db[table]
alarm_table = self._alarm_config_db[uve_key]
except KeyError:
self._alarm_config_db[table] = {}
alarm_table = self._alarm_config_db[table]
self._alarm_config_db[uve_key] = {}
alarm_table = self._alarm_config_db[uve_key]
finally:
if operation == 'CREATE' or operation == 'UPDATE':
if not isinstance(alarm_obj, AlarmBase):
Expand All @@ -75,10 +80,10 @@ def _update_alarm_config_table(self, alarm_fqname, alarm_obj, uve_keys,
if alarm_table.has_key(alarm_fqname):
del alarm_table[alarm_fqname]
if not len(alarm_table):
del self._alarm_config_db[table]
del self._alarm_config_db[uve_key]
else:
assert(0)
alarm_config_change_map[table] = {alarm_fqname:operation}
alarm_config_change_map[uve_key] = {alarm_fqname:operation}
return alarm_config_change_map
# end _update_alarm_config_table

Expand Down
38 changes: 36 additions & 2 deletions src/opserver/test/test_alarmgen_config_handler.py
Expand Up @@ -78,7 +78,8 @@ def test_handle_config_update(self):
alarm_config1 = self._get_config_object('alarm',
{
'name': 'alarm1',
'uve_keys': ['analytics-node', 'control-node'],
'uve_keys': ['analytics-node', 'control-node',
'vrouter:host1'],
'alarm_severity': AlarmBase.ALARM_CRITICAL,
'alarm_rules': {
'or_list': [
Expand All @@ -102,7 +103,8 @@ def test_handle_config_update(self):
alarm_config1_1 = self._get_config_object('alarm',
{
'name': 'alarm1',
'uve_keys': ['invalid', 'control-node', 'config-node'],
'uve_keys': ['invalid', 'control-node', 'config-node',
'vrouter:host2'],
'alarm_severity': AlarmBase.ALARM_CRITICAL,
'alarm_rules': {
'or_list': [
Expand Down Expand Up @@ -240,6 +242,10 @@ def test_handle_config_update(self):
'ObjectBgpRouter': {
'global-syscfg-default:alarm1':
AlarmBase(config=alarm_config1)
},
'ObjectVRouter:host1': {
'global-syscfg-default:alarm1':
AlarmBase(config=alarm_config1)
}
},
alarm_config_change_map={
Expand All @@ -248,6 +254,9 @@ def test_handle_config_update(self):
},
'ObjectBgpRouter': {
'global-syscfg-default:alarm1': 'CREATE'
},
'ObjectVRouter:host1': {
'global-syscfg-default:alarm1': 'CREATE'
}
}
)
Expand Down Expand Up @@ -278,6 +287,10 @@ def test_handle_config_update(self):
'ObjectConfigNode': {
'global-syscfg-default:alarm1':
AlarmBase(config=alarm_config1_1)
},
'ObjectVRouter:host2': {
'global-syscfg-default:alarm1':
AlarmBase(config=alarm_config1_1)
}
},
alarm_config_change_map={
Expand All @@ -289,6 +302,12 @@ def test_handle_config_update(self):
},
'ObjectConfigNode': {
'global-syscfg-default:alarm1': 'CREATE'
},
'ObjectVRouter:host1': {
'global-syscfg-default:alarm1': 'DELETE'
},
'ObjectVRouter:host2': {
'global-syscfg-default:alarm1': 'CREATE'
}
}
)
Expand Down Expand Up @@ -324,6 +343,10 @@ def test_handle_config_update(self):
'ObjectVNTable': {
'default-domain:admin:alarm1':
AlarmBase(config=alarm_config2)
},
'ObjectVRouter:host2': {
'global-syscfg-default:alarm1':
AlarmBase(config=alarm_config1_1)
}
},
alarm_config_change_map={
Expand Down Expand Up @@ -367,6 +390,10 @@ def test_handle_config_update(self):
AlarmBase(config=alarm_config2),
'default-domain:demo:alarm1':
AlarmBase(config=alarm_config3)
},
'ObjectVRouter:host2': {
'global-syscfg-default:alarm1':
AlarmBase(config=alarm_config1_1)
}
},
alarm_config_change_map={
Expand Down Expand Up @@ -409,6 +436,10 @@ def test_handle_config_update(self):
AlarmBase(config=alarm_config2_1),
'default-domain:demo:alarm1':
AlarmBase(config=alarm_config3)
},
'ObjectVRouter:host2': {
'global-syscfg-default:alarm1':
AlarmBase(config=alarm_config1_1)
}
},
alarm_config_change_map={
Expand Down Expand Up @@ -450,6 +481,9 @@ def test_handle_config_update(self):
},
'ObjectConfigNode': {
'global-syscfg-default:alarm1': 'DELETE'
},
'ObjectVRouter:host2': {
'global-syscfg-default:alarm1': 'DELETE'
}
}
)
Expand Down
2 changes: 1 addition & 1 deletion src/schema/alarm.xsd
Expand Up @@ -78,7 +78,7 @@
<xsd:element name="uve-keys" type="UveKeysType"/>
<!--#IFMAP-SEMANTICS-IDL
Property('uve-keys', 'alarm', 'required', 'CRUD',
'List of UVE tables where this alarm config should be applied. For example, rules based on NodeStatus UVE can be applied to multiple object types such as analytics-node, config-node, control-node, etc.,') -->
'List of UVE tables or UVE objects where this alarm config should be applied. For example, rules based on NodeStatus UVE can be applied to multiple object types or specific uve objects such as analytics-node, config-node, control-node:<hostname>, etc.,') -->
<xsd:element name="alarm-severity" type="AlarmSeverity"/>
<!--#IFMAP-SEMANTICS-IDL
Property('alarm-severity', 'alarm', 'required', 'CRUD',
Expand Down

0 comments on commit c2a75d3

Please sign in to comment.