def on_message(ws, message): msg_as_JSON = json.loads(message) type = msg_as_JSON.get("type") if type: if type == "auth": print("Auth completed") elif type == "container": if CONTAINER_MSG: generic_hipchat(message) elif type == "service": parents = msg_as_JSON.get("parents") service = get_resource(msg_as_JSON.get("resource_uri")) service_as_JSON = json.loads(service) if parents: stack = get_resource(parents[0]) stack_as_JSON = json.loads(stack) stack_name = stack_as_JSON.get('name') if STACK_NAME and stack_name != STACK_NAME: # do nothing print("Doing nothing, STACK_NAME({}) set and notification is related to different stack({})".format(STACK_NAME,stack_name)) else: text = ("A Service {} was {}d. The current state is {}. \nIt belonged to the " "{} Stack.\nThe Stack state is: {}".format(service_as_JSON.get('name'), msg_as_JSON.get('action'), service_as_JSON.get('state'), stack_name, stack_as_JSON.get('state'))) post_hipchat(text=text) elif type != "user-notifications": print("{}:{}:{}:{}:{}".format(type, msg_as_JSON.get("action"), msg_as_JSON.get("state"), msg_as_JSON.get("resource_uri"), msg_as_JSON.get("parents")))
def on_message(ws, message): msg_as_JSON = json.loads(message) type = msg_as_JSON.get("type") if type: if type == "auth": print("Auth completed") elif type == "container": generic_slack(message) elif type == "service": parents = msg_as_JSON.get("parents") if parents: stack = get_resource(parents[0]) stack_as_JSON = json.loads(stack) text = ("A Service on Tutum was {}d.\nIt belonged to the " "{} Stack.\nThe Stack state is: {}".format(msg_as_JSON.get('action'), stack_as_JSON.get('name'), stack_as_JSON.get('state'))) post_slack(text=text) elif type != "user-notifications": print("{}:{}:{}:{}:{}".format(type, msg_as_JSON.get("action"), msg_as_JSON.get("state"), msg_as_JSON.get("resource_uri"), msg_as_JSON.get("parents")))
def on_message(ws, message): msg_as_JSON = json.loads(message) type = msg_as_JSON.get("type") if type: if type == "auth": print("Auth completed") elif type == "container": generic_slack(message) elif type == "service": parents = msg_as_JSON.get("parents") if parents: stack = get_resource(parents[0]) stack_as_JSON = json.loads(stack) text = ("A Service on Tutum was {}d.\nIt belonged to the " "{} Stack.\nThe Stack state is: {}".format( msg_as_JSON.get('action'), stack_as_JSON.get('name'), stack_as_JSON.get('state'))) post_slack(text=text) elif type != "user-notifications": print("{}:{}:{}:{}:{}".format(type, msg_as_JSON.get("action"), msg_as_JSON.get("state"), msg_as_JSON.get("resource_uri"), msg_as_JSON.get("parents")))