def send_status_ping(): if GlobalVars.metasmoke_host is None: log( 'info', 'Attempted to send status ping but metasmoke_host is undefined. Not sent.' ) return elif GlobalVars.metasmoke_down: payload = { "location": GlobalVars.location, "timestamp": time.time() } SocketScience.send(payload) metasmoke_key = GlobalVars.metasmoke_key try: payload = { 'location': GlobalVars.location, 'key': metasmoke_key, 'standby': GlobalVars.standby_mode } headers = {'content-type': 'application/json'} response = Metasmoke.post("/status-update.json", data=json.dumps(payload), headers=headers) try: response = response.json() GlobalVars.metasmoke_last_ping_time = datetime.now( ) # Otherwise the ping watcher will exit(10) if 'failover' in response and GlobalVars.standby_mode: if response['failover']: GlobalVars.standby_mode = False chatcommunicate.tell_rooms_with( "debug", GlobalVars.location + " received failover signal.", notify_site="/failover") if response['standby']: chatcommunicate.tell_rooms_with( "debug", GlobalVars.location + " entering metasmoke-forced standby.") time.sleep(2) os._exit(7) if 'shutdown' in response: if response['shutdown']: os._exit(6) except Exception: # TODO: What could happen here? pass except Exception as e: log('error', e)
def send_status_ping(): if GlobalVars.metasmoke_host is None: log('info', 'Attempted to send status ping but metasmoke_host is undefined. Not sent.') return elif GlobalVars.metasmoke_down: payload = { "location": GlobalVars.location, "timestamp": time.time() } SocketScience.send(payload) metasmoke_key = GlobalVars.metasmoke_key try: payload = { 'location': GlobalVars.location, 'key': metasmoke_key, 'standby': GlobalVars.standby_mode } headers = {'content-type': 'application/json'} response = Metasmoke.post("/status-update.json", data=json.dumps(payload), headers=headers, ignore_down=True) try: response = response.json() GlobalVars.metasmoke_last_ping_time = datetime.now() # Otherwise the ping watcher will exit(10) if response.get('pull_update', False): log('info', "Received pull command from MS ping response") exit_mode("pull_update") if 'failover' in response and GlobalVars.standby_mode: if response['failover']: GlobalVars.standby_mode = False chatcommunicate.tell_rooms_with("debug", GlobalVars.location + " received failover signal.", notify_site="/failover") if response.get('standby', False): chatcommunicate.tell_rooms_with("debug", GlobalVars.location + " entering metasmoke-forced standby.") time.sleep(2) exit_mode("standby") if response.get('shutdown', False): exit_mode("shutdown") except Exception: # TODO: What could happen here? pass except Exception as e: log('error', e)
def send_status_ping(): if GlobalVars.metasmoke_host is None: log( 'info', 'Attempted to send status ping but metasmoke_host is undefined. Not sent.' ) return elif GlobalVars.metasmoke_down: payload = { "location": GlobalVars.location, "timestamp": time.time() } SocketScience.send(payload) metasmoke_key = GlobalVars.metasmoke_key try: payload = { 'location': GlobalVars.location, 'key': metasmoke_key, 'standby': GlobalVars.standby_mode or GlobalVars.no_se_activity_scan } headers = {'content-type': 'application/json'} response = Metasmoke.post("/status-update.json", data=json.dumps(payload), headers=headers, ignore_down=True) try: response = response.json() GlobalVars.metasmoke_last_ping_time = datetime.utcnow( ) # Otherwise the ping watcher will exit(10) if response.get('pull_update', False): log('info', "Received pull command from MS ping response") exit_mode("pull_update") if ('failover' in response and GlobalVars.standby_mode and not GlobalVars.no_se_activity_scan): # If we're not scanning, then we don't want to become officially active due to failover. if response['failover']: GlobalVars.standby_mode = False chatcommunicate.tell_rooms_with( "debug", GlobalVars.location + " received failover signal.", notify_site="/failover") if response.get('standby', False): chatcommunicate.tell_rooms_with( "debug", GlobalVars.location + " entering metasmoke-forced standby.") time.sleep(2) exit_mode("standby") if response.get('shutdown', False): exit_mode("shutdown") except Exception: # TODO: What could happen here? pass except Exception as e: log('error', e)