view modules/net_mon/net_mon.py @ 45:8449509b7f6f

Limit time frame of graph Requires roundup_cc ≥ 99e2e0e17103.
author Gernot Schulz <gernot@intevation.de>
date Sun, 31 Jan 2016 15:32:35 +0100
parents 1a13a4ecf931
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)