def recheckIfUnreachable(host, ops): time.sleep(5) status = ip_dict_read(host) str = '..............'+'Second try'+'..............\n' noofpackets = 2 timeout = 500 #in milliseconds command = 'ping {0} {1} -w {2} {3}'.format(ops,noofpackets,timeout,host) Stdout,Stderr = systemCommandCheckIP(command) if Stdout: str += ("Host [{}] is now reachable.\n".format(host)) str += '......................................\n' LogFile.newLog(host, "Reachable") if status[0] == 1: ip_dict_write(host, [0, 0]) else: ip_dict_write(host, [1, 0]) constructions = get_constructions() bot = constructions["bot"] for chat_id in constructions["update"]: bot.sendMessage(chat_id, text='{0} is online'.format(constructions[host])) print str else: str += ("Host [{}] is unreachable.\n".format(host)) LogFile.newLog(host, "Unreachable") Report.sendEmail("ip:" + host + " is still unreachable") str += 'Report sent!\n' str += '......................................\n' ip_dict_write(host, [3, 0]) constructions = get_constructions() bot = constructions["bot"] for chat_id in constructions["update"]: bot.sendMessage(chat_id, text='{0} is offline'.format(constructions[host])) print str