Skip to content

Instantly share code, notes, and snippets.

@xudshen
Last active January 4, 2016 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xudshen/8584300 to your computer and use it in GitHub Desktop.
Save xudshen/8584300 to your computer and use it in GitHub Desktop.
__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