-
Notifications
You must be signed in to change notification settings - Fork 390
/
main.py
114 lines (95 loc) · 3.86 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from opserver.plugins.alarm_base import *
from opserver.sandesh.alarmgen_ctrl.sandesh_alarm_base.ttypes import *
import json
class AddressMismatchCompute(AlarmBase):
"""Compute Node IP Address mismatch.
Compute Node has IP Address mismatch between ContrailConfig.virtual_router_ip_address
and Operational State in VrouterAgent"""
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"]
except KeyError:
return None
else:
try:
lval = json.loads(uattr["virtual_router_ip_address"])
except KeyError:
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
class AddressMismatchControl(AlarmBase):
"""Control Node IP Address mismatch.
Control Node has IP Address mismatch between ContrailConfig.bgp_router_parameters.address
and Operational State in BgpRouterState"""
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"]
bgp_router_param = uattr["bgp_router_parameters"]
except KeyError:
return None
else:
try:
lval = json.loads(bgp_router_param)["address"]
except KeyError:
lval = None
if "BgpRouterState" not in uve_data:
return None
try:
rval = uve_data["BgpRouterState"]["bgp_router_ip_list"]
except KeyError:
rval = None
if not isinstance(rval,list) or lval not in rval:
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