-
Notifications
You must be signed in to change notification settings - Fork 390
/
main.py
68 lines (56 loc) · 2.39 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
from opserver.plugins.alarm_base import *
from opserver.sandesh.alarmgen_ctrl.sandesh_alarm_base.ttypes import *
import json
class PhyifBandwidth(AlarmBase):
"""Physical Bandwidth usage anomaly
Physical Bandwidth usage anomaly as per VrouterStatsAgent.out_bps_ewm or VrouterStatsAgent.in_bps_ewm"""
def __init__(self):
AlarmBase.__init__(self, AlarmBase.ALARM_MINOR)
def checkbw(self, stat, sname, vname, thresh):
alm = []
match_list_u = []
match_list_o = []
for k,val in stat.iteritems():
if val["sigma"] >= thresh:
match_list_o.append(AlarmMatch(json_operand1_value=json.dumps(
val["sigma"]), json_variables={
vname:json.dumps(k)}))
if val["sigma"] <= (-thresh):
match_list_u.append(AlarmMatch(json_operand1_value=json.dumps(
val["sigma"]), json_variables={
vname:json.dumps(k)}))
if len(match_list_o):
alm.append(AlarmAndList(and_list=[AlarmConditionMatch(
condition=AlarmCondition(operation=">=",
operand1=sname, operand2=AlarmOperand2(
json_value=json.dumps(thresh)),
variables=[vname]),
match=match_list_o)]))
if len(match_list_u):
alm.append(AlarmAndList(and_list=[AlarmConditionMatch(
condition=AlarmCondition(operation="<=",
operand1=sname, operand2=AlarmOperand2(
json_value=json.dumps(-thresh)),
variables=[vname]),
match=match_list_u)]))
return alm
def __call__(self, uve_key, uve_data):
or_list = []
v0 = uve_data.get("VrouterStatsAgent")
if v0 is None:
return None
v1 = v0.get("out_bps_ewm",None)
if not v1:
v1 = {}
outlist = self.checkbw(v1, "VrouterStatsAgent.out_bps_ewm.*.sigma",
"VrouterStatsAgent.out_bps_ewm.__key", 2)
v2 = v0.get("in_bps_ewm",None)
if not v2:
v2 = {}
inlist = self.checkbw(v2, "VrouterStatsAgent.in_bps_ewm.*.sigma",
"VrouterStatsAgent.in_bps_ewm.__key", 2)
total_list = outlist + inlist
if len(total_list):
return total_list
else:
return None