Mercurial > bottledash
comparison modules/net_mon/net_mon.py @ 20:1a13a4ecf931
can not recive post-requests wich should deliver if a server is up or down. Updated after a refresh of the webpage, wich will automatically done after 5 seconds
author | sean |
---|---|
date | Wed, 12 Aug 2015 13:45:58 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
19:be6a1aaec717 | 20:1a13a4ecf931 |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 """ very simple network_monitoring. Derterminats if a remote machine | |
4 is available or not | |
5 | |
6 author: Sean Engelhardt <sean.engelhardt@intevation.de> | |
7 | |
8 This is Free Software unter the terms of the | |
9 GNU GENERAL PUBLIC LICENSE Version 2 or later. | |
10 See http://www.gnu.org/licenses/gpl-3.0.txt for details | |
11 """ | |
12 | |
13 import socket, time, threading | |
14 | |
15 interval = 5 | |
16 ip = "212.95.122.133" | |
17 port = 80 | |
18 | |
19 def is_service_available(ip, port): | |
20 server_available = False | |
21 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
22 try: | |
23 s.connect((ip, port)) | |
24 server_available = True | |
25 except socket.error: | |
26 server_available = False | |
27 s.close() | |
28 return server_available | |
29 | |
30 def check_service_regularly(interval, ip, port): | |
31 is_available = is_service_available(ip, port) | |
32 | |
33 # return is_available | |
34 print("Server " + ip + " ::: "+ str(is_available)) | |
35 threading.Timer(interval, check_service_regularly, [interval, ip, port]).start() | |
36 | |
37 # print("server : " + str(check_service_regularly(5, "212.95.122.133", 80))) | |
38 | |
39 check_service_regularly(interval, "212.95.122.133", 80) | |
40 check_service_regularly(interval, "127.0.0.1", 80) | |
41 check_service_regularly(interval, "127.0.0.1", 81) |