try: inputFile = open("/var/www/iot/checkAlive/data.json",'r') except Exception as e: logFile.write(str(e)+"\n")
try: data = json.load(inputFile) except Exception as e: logFile.write(str(e)+"\n")
try: inputFile.close() except Exception as e: logFile.write(str(e)+"\n")
for host in data: if (int(time.time()) - int(data[host]) >= 300) and (int(time.time()) - int(data[host]) <= 360): # 超过5分钟没有心跳包就发短信 try: sendSMS(host) logFile.write("Problem found in "+host+". SMS has been sent.\n") except Exception as e: logFile.write(str(e)+"\n")
logFile.close()
slave中的crontab配置,其他定时任务同理
1
*/1 * * * * curl -X GET 'https://monitor.example.com/?name=hostname&token=example_token'