Skip to content

Commit

Permalink
Merge "Update alarm plugins to use modified Alarm structure"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed May 17, 2016
2 parents a1bea0e + b03f85f commit 12325b9
Show file tree
Hide file tree
Showing 18 changed files with 1,655 additions and 289 deletions.
1 change: 1 addition & 0 deletions src/base/sandesh/process_info.sandesh
Expand Up @@ -95,6 +95,7 @@ struct DiskPartitionUsageStats {
2: string partition_name
3: u64 partition_space_used_1k
4: u64 partition_space_available_1k
5: u16 percentage_partition_space_used
}

// Sent by the node manager
Expand Down
6 changes: 6 additions & 0 deletions src/nodemgr/common/event_manager.py
Expand Up @@ -377,6 +377,12 @@ def send_disk_usage_info_base(self, NodeStatusUVE, NodeStatus,
int(partition_space_used_1k)
disk_usage_stat.partition_space_available_1k = \
int(partition_space_available_1k)
total_disk_space = \
disk_usage_stat.partition_space_used_1k + \
disk_usage_stat.partition_space_available_1k
disk_usage_stat.percentage_partition_space_used = \
int(round((float(disk_usage_stat.partition_space_used_1k)/ \
float(total_disk_space))*100))
except ValueError:
sys.stderr.write("Failed to get local disk space usage" + "\n")
else:
Expand Down
11 changes: 5 additions & 6 deletions src/opserver/alarmgen.py
Expand Up @@ -216,17 +216,16 @@ def process_alarms(self, ext, uv, local_uve):
or_list = ext.obj.__call__(uv, local_uve)
self._logger.debug("Alarm[%s] %s: %s" % (uv, nm, str(or_list)))
if or_list:
self.uve_alarms[nm] = UVEAlarmInfo(type = nm, severity = sev,
timestamp = 0, token = "",
any_of = or_list, ack = False)
self.uve_alarms[nm] = UVEAlarmInfo(type=nm, severity=sev,
timestamp=0, token="",
rules=or_list, ack=False)
except Exception as ex:
template = "Exception {0} in Alarm Processing. Arguments:\n{1!r}"
messag = template.format(type(ex).__name__, ex.args)
self._logger.error("%s : traceback %s" % \
(messag, traceback.format_exc()))
self.uve_alarms[nm] = UVEAlarmInfo(type = nm, severity = sev,
timestamp = 0, token = "",
any_of = [AllOf(all_of=[])], ack = False)
self.uve_alarms[nm] = UVEAlarmInfo(type=nm, severity=sev,
timestamp=0, token="", rules=[], ack=False)

class AlarmStateMachine:
tab_alarms_timer = {}
Expand Down
151 changes: 68 additions & 83 deletions src/opserver/plugins/alarm_address_mismatch/main.py
Expand Up @@ -11,76 +11,56 @@ def __init__(self):

def __call__(self, uve_key, uve_data):
or_list = []
and_list = []
trigger = True

if trigger:
if "ContrailConfig" not in uve_data:
trigger = False
else:
and_list.append(AlarmElement(\
rule=AlarmTemplate(oper="!=",
operand1=Operand1(keys=["ContrailConfig"]),
operand2=Operand2(json_value="null")),
json_operand1_value=json.dumps({})))

try:
uattr = uve_data["ContrailConfig"]["elements"]
if isinstance(uattr,list):
uattr = uattr[0][0]
lval = json.loads(uattr["virtual_router_ip_address"])
except KeyError:
lval = None

if trigger:
if "VrouterAgent" not in uve_data:
trigger = False
else:
and_list.append(AlarmElement(\
rule=AlarmTemplate(oper="!=",
operand1=Operand1(keys=["VrouterAgent"]),
operand2=Operand2(json_value="null")),
json_operand1_value=json.dumps({})))

if trigger:
try:
rval1 = uve_data["VrouterAgent"]["self_ip_list"]
except KeyError:
rval1 = None

if not isinstance(rval1,list) or lval not in rval1:
and_list.append(AlarmElement(\
rule=AlarmTemplate(oper="not in",
operand1=Operand1(keys=\
["ContrailConfig","elements","virtual_router_ip_address"],
json=2),
operand2=Operand2(keys=["VrouterAgent","self_ip_list"])),
json_operand1_value=json.dumps(lval),
json_operand2_value=json.dumps(rval1)))
else:
trigger = False

if trigger:

if "ContrailConfig" not in uve_data:
return None

try:
uattr = uve_data["ContrailConfig"]["elements"]
except KeyError:
return None
else:
try:
rval2 = uve_data["VrouterAgent"]["control_ip"]
lval = json.loads(uattr["virtual_router_ip_address"])
except KeyError:
rval2 = None

if lval != rval2:
and_list.append(AlarmElement(\
rule=AlarmTemplate(oper="!=",
operand1=Operand1(keys=\
["ContrailConfig","elements",
"virtual_router_ip_address"],
json=2),
operand2=Operand2(keys=["VrouterAgent","control_ip"])),
json_operand1_value=json.dumps(lval),
json_operand2_value=json.dumps(rval2)))
else:
trigger = False

if trigger:
or_list.append(AllOf(all_of=and_list))
lval = None

if "VrouterAgent" not in uve_data:
return None

try:
rval1 = uve_data["VrouterAgent"]["self_ip_list"]
except KeyError:
rval1 = None

if not isinstance(rval1,list) or lval not in rval1:
and_list = []
and_list.append(AlarmConditionMatch(
condition=AlarmCondition(operation="not in",
operand1="ContrailConfig.elements." + \
"virtual_router_ip_address",
operand2="VrouterAgent.self_ip_list"),
match=[AlarmMatch(json_operand1_value=json.dumps(lval),
json_operand2_value=json.dumps(rval1))]))
or_list.append(AlarmRuleMatch(rule=and_list))

try:
rval2 = uve_data["VrouterAgent"]["control_ip"]
except KeyError:
rval2 = None

if lval != rval2:
and_list = []
and_list.append(AlarmConditionMatch(
condition=AlarmCondition(operation="!=",
operand1="ContrailConfig.elements." + \
"virtual_router_ip_address",
operand2="VrouterAgent.control_ip"),
match=[AlarmMatch(json_operand1_value=json.dumps(lval),
json_operand2_value=json.dumps(rval2))]))
or_list.append(AlarmRuleMatch(rule=and_list))

if len(or_list):
return or_list
else:
return None
Expand All @@ -93,17 +73,21 @@ def __init__(self):
AlarmBase.__init__(self, AlarmBase.SYS_ERR)

def __call__(self, uve_key, uve_data):
or_list = []

if "ContrailConfig" not in uve_data:
return None

try:
uattr = uve_data["ContrailConfig"]["elements"]
if isinstance(uattr,list):
uattr = uattr[0][0]
lval = json.loads(uattr["bgp_router_parameters"])["address"]
bgp_router_param = uattr["bgp_router_parameters"]
except KeyError:
lval = None
return None
else:
try:
lval = json.loads(bgp_router_param)["address"]
except KeyError:
lval = None

if "BgpRouterState" not in uve_data:
return None
Expand All @@ -113,17 +97,18 @@ def __call__(self, uve_key, uve_data):
except KeyError:
rval = None

and_list = []
if not isinstance(rval,list) or lval not in rval:
and_list.append(AnyOf(any_of=[AlarmElement(\
rule=AlarmTemplate(oper="not in",
operand1=Operand1(keys=["ContrailConfig",\
"elements","bgp_router_parameters","address"],
json=2),
operand2=Operand2(keys=\
["BgpRouterState","bgp_router_ip_list"])),
json_operand1_value=json.dumps(lval),
json_operand2_value=json.dumps(rval))]))
return and_list
and_list = []
and_list.append(AlarmConditionMatch(
condition=AlarmCondition(operation="not in",
operand1="ContrailConfig.elements." + \
"bgp_router_parameters.address",
operand2="BgpRouterState.bgp_router_ip_list"),
match=[AlarmMatch(json_operand1_value=json.dumps(lval),
json_operand2_value=json.dumps(rval))]))
or_list.append(AlarmRuleMatch(rule=and_list))

if len(or_list):
return or_list

return None
41 changes: 18 additions & 23 deletions src/opserver/plugins/alarm_bgp_connectivity/main.py
Expand Up @@ -15,37 +15,32 @@ def __call__(self, uve_key, uve_data):
v1 = uve_data.get("BgpRouterState", None)
if v1 is not None:
and_list = []
and_list.append(AlarmElement(\
rule=AlarmTemplate(oper="!=",
operand1=Operand1(keys=["BgpRouterState"]),
operand2=Operand2(json_value="null")),
json_operand1_value=json.dumps({})))
v2 = v1.get("num_up_bgp_peer", None)
if v2 is None:
and_list.append(AlarmElement(\
rule=AlarmTemplate(oper="==",
operand1=Operand1(keys=["BgpRouterState","num_up_bgp_peer"]),
operand2=Operand2(json_value="null")),
json_operand1_value=json.dumps(None)))
or_list.append(AllOf(all_of=and_list))
and_list.append(AlarmConditionMatch(
condition=AlarmCondition(operation="==",
operand1="BgpRouterState.num_up_bgp_peer",
operand2="null"),
match=[AlarmMatch(json_operand1_value="null")]))
or_list.append(AlarmRuleMatch(rule=and_list))

if v1 is not None:
lval = v1.get("num_up_bgp_peer",None)
rval = v1.get("num_bgp_peer",None)
lval = v1.get("num_up_bgp_peer", None)
rval = v1.get("num_bgp_peer", None)
else:
lval = None
rval = None

if lval != rval:
and_list = []
and_list.append(AlarmElement(\
rule=AlarmTemplate(oper="!=",
operand1=Operand1(keys=["BgpRouterState","num_up_bgp_peer"]),
operand2=Operand2(keys=["BgpRouterState","num_bgp_peer"])),
json_operand1_value=json.dumps(lval),
json_operand2_value=json.dumps(rval)))
or_list.append(AllOf(all_of=and_list))
if lval != rval:
and_list = []
and_list.append(AlarmConditionMatch(
condition=AlarmCondition(operation="!=",
operand1="BgpRouterState.num_up_bgp_peer",
operand2="BgpRouterState.num_bgp_peer"),
match=[AlarmMatch(json_operand1_value=json.dumps(lval),
json_operand2_value=json.dumps(rval))]))
or_list.append(AlarmRuleMatch(rule=and_list))
if len(or_list):
return or_list
else:
return None
return None
13 changes: 6 additions & 7 deletions src/opserver/plugins/alarm_config_incorrect/main.py
Expand Up @@ -10,17 +10,16 @@ def __call__(self, uve_key, uve_data):
or_list = []
if not uve_data.has_key("ContrailConfig"):
and_list = []
and_list.append(AlarmElement(\
rule=AlarmTemplate(oper="==",
operand1=Operand1(keys=["ContrailConfig"]),
operand2=Operand2(json_value="null")),
json_operand1_value=json.dumps(None)))
or_list.append(AllOf(all_of=and_list))
and_list.append(AlarmConditionMatch(
condition=AlarmCondition(operation="==",
operand1="ContrailConfig", operand2="null"),
match=[AlarmMatch(json_operand1_value="null")]))
or_list.append(AlarmRuleMatch(rule=and_list))

if len(or_list):
return or_list
else:
return None
return None

class ConfIncorrectCompute(ConfIncorrect):
"""Compute Node config missing or incorrect.
Expand Down
45 changes: 22 additions & 23 deletions src/opserver/plugins/alarm_disk_usage/main.py
Expand Up @@ -4,39 +4,38 @@

class DiskUsage(AlarmBase):
"""Disk Usage crosses a threshold.
NodeMgr reports disk usage in DatabaseUsageInfo.database_usage"""
NodeMgr reports disk usage in NodeStatus.disk_usage_info"""

def __init__(self):
AlarmBase.__init__(self, AlarmBase.SYS_ERR)
self._threshold = 0.90
self._threshold = 50

def __call__(self, uve_key, uve_data):
or_list = []
db_usage_info = uve_data.get("DatabaseUsageInfo", None)
if db_usage_info is None:
node_status = uve_data.get("NodeStatus", None)
if node_status is None:
return None
db_usage_list = db_usage_info.get("database_usage", None)
if db_usage_list is None:
disk_usage_list = node_status.get("disk_usage_info", None)
if disk_usage_list is None:
return None

for db_usage in db_usage_list:
used_space = db_usage["disk_space_used_1k"]
available_space = db_usage["disk_space_available_1k"]
use_space_threshold = available_space * self._threshold
if used_space > use_space_threshold:
or_list.append(AllOf(all_of=[AlarmElement(\
rule=AlarmTemplate(oper=">",
operand1=Operand1(\
keys=["DatabaseUsageInfo","database_usage","disk_space_used_1k"]),
operand2=Operand2(json_value=str(use_space_threshold))),
json_operand1_value=str(used_space),
json_vars={\
"DatabaseUsageInfo.database_usage.disk_space_used_1k":\
str(used_space),
"DatabaseUsageInfo.database_usage.disk_space_available_1k":\
str(available_space)})]))
match_list = []
for disk_usage in disk_usage_list:
if disk_usage["percentage_partition_space_used"] > self._threshold:
match_list.append(AlarmMatch(json_operand1_value=json.dumps(
disk_usage["percentage_partition_space_used"]), json_vars={
"NodeStatus.disk_usage_info.partition_name":\
json.dumps(disk_usage["partition_name"])}))
if len(match_list):
and_list = [AlarmConditionMatch(
condition=AlarmCondition(operation=">",
operand1="NodeStatus.disk_usage_info." +\
"percentage_partition_space_used",
operand2=json.dumps(self._threshold),
vars=["NodeStatus.disk_usage_info.partition_name"]),
match=match_list)]
or_list.append(AlarmRuleMatch(rule=and_list))
if len(or_list):
return or_list
else:
return None

0 comments on commit 12325b9

Please sign in to comment.