Implement optional x in y matching for attributes in the monitor system
This commit is contained in:
@@ -19,12 +19,34 @@ def testNetTarget(name, target):
|
||||
if not called:
|
||||
return False
|
||||
|
||||
def contained_in(x, y):
|
||||
if x is None or y is None:
|
||||
return False
|
||||
elif x == y:
|
||||
return True
|
||||
else:
|
||||
return y in x
|
||||
|
||||
def is_in(k, vs, A):
|
||||
return any(contained_in(A.get(k), vp) for vp in vs)
|
||||
|
||||
def matches(A, B):
|
||||
return all(is_in(k, vs, A) for (k, vs) in B.items())
|
||||
|
||||
def magicFunction(A, B):
|
||||
isInside = False
|
||||
if "send" in B.keys():
|
||||
del B["send"]
|
||||
if "sources" in B.keys():
|
||||
del B["sources"]
|
||||
return all(A[k] in B[k] for k in set(A) & set(B)) and set(B) <= set(A)
|
||||
if "inside" in B.keys():
|
||||
if B["inside"] == True:
|
||||
isInside = True
|
||||
del B["inside"]
|
||||
if isInside:
|
||||
return matches(A, B)
|
||||
else:
|
||||
return all(A[k] in B[k] for k in set(A) & set(B)) and set(B) <= set(A)
|
||||
|
||||
def event(name, target, cast):
|
||||
monitorGroups = testNetTarget(name, target)
|
||||
|
||||
Reference in New Issue
Block a user