view 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
line wrap: on
line source
#!/usr/bin/env python3

""" very simple network_monitoring. Derterminats if a remote machine
is available or not

author: Sean Engelhardt <sean.engelhardt@intevation.de>

This is Free Software unter the terms of the
GNU GENERAL PUBLIC LICENSE Version 2 or later.
See http://www.gnu.org/licenses/gpl-3.0.txt for details
"""

import socket, time, threading

interval = 5
ip = "212.95.122.133"
port = 80

def is_service_available(ip, port):
    server_available = False
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        s.connect((ip, port))
        server_available = True
    except socket.error:
        server_available = False
    s.close()
    return server_available

def check_service_regularly(interval, ip, port):
    is_available = is_service_available(ip, port)

    # return is_available
    print("Server " + ip + " ::: "+ str(is_available))
    threading.Timer(interval, check_service_regularly, [interval, ip, port]).start()

# print("server : " + str(check_service_regularly(5, "212.95.122.133", 80)))

check_service_regularly(interval, "212.95.122.133", 80)
check_service_regularly(interval, "127.0.0.1", 80)
check_service_regularly(interval, "127.0.0.1", 81)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)