def all(ips, actions): states = [] for ip in ips: print ip initial_state = ping(str(ip)) state = {} state["ip"] = ip state["state"] = initial_state state["flapping"] = 0 states.append(state) State.checkComputers(ip, actions, initial_state) # print states return states
Socket.Start(socket_port) print "Socket Started" ips, actions = State.getIP() ip_states = Ping.all(ips, actions) try: while True: time.sleep(sleep_between_ping) for i, ip_state in enumerate(ip_states): state, result = Ping.checkState(ip_state) ip_states[i] = state if(result): data = state["ip"] if state["state"]: State.checkComputers(state["ip"], actions, 1) state = "on" else: State.checkComputers(state["ip"], actions, 0) state = "off" print "SENDING-----" print "IP:" + data + " " + state PhpRequest.send(path, "/computers/"+data, state) Socket.Send(data+";"+state) print "SENDING-----" except KeyboardInterrupt: Socket.Close() os._exit(13)