Last active
January 4, 2016 06:49
-
-
Save xudshen/8584300 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'xudshen' | |
import hashlib | |
cache = {} | |
def insertAlert(type, timestamp, desc, host, cluster): | |
global cache | |
id = hashlib.md5((type + timestamp + desc + host).encode("utf8")).hexdigest() | |
if not id in cache: | |
cache[id] = [] | |
cache[id].append({'cluster':cluster, 'type':type, 'timestamp':timestamp, 'desc':desc, 'host':host}) | |
def isOK(arr): | |
global cache | |
return len(set(map(lambda x:x['cluster'] ,arr))) == 2 | |
def checkAlert(): | |
global cache | |
print(dict((key,value) for key, value in cache.items() if not isOK(value))) | |
insertAlert("type1", "123", "desccccc", "hostname1", "titan") | |
insertAlert("type2", "123", "desccccc", "hostname1", "titan") | |
insertAlert("type2", "123", "desccccc", "hostname1", "titan") | |
insertAlert("type1", "123", "desccccc", "hostname1", "cluster4ut") | |
#print(cache) | |
checkAlert() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment