# HG changeset patch # User sean # Date 1439379958 -7200 # Node ID 1a13a4ecf931df4e199ce467cb1a4c68eb96b5df # Parent be6a1aaec717233d60df12bb45c467b4e129f13a 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 diff -r be6a1aaec717 -r 1a13a4ecf931 dash.conf --- a/dash.conf Tue Aug 11 14:18:09 2015 +0200 +++ b/dash.conf Wed Aug 12 13:45:58 2015 +0200 @@ -56,17 +56,22 @@ [tile1] type=mon source=192.168.0.2 -status=down +status="dynamic" [tile2] type=mon source=192.168.2.3 -status=up +status="dynamic" [tile3] type=mon source=192.168.4.3 -status=up +status="dynamic" + +#[tile4] +#type=mon +#source=192.168.4.56 +#status="dynamic" [tile4] type=d3js diff -r be6a1aaec717 -r 1a13a4ecf931 dash.py --- a/dash.py Tue Aug 11 14:18:09 2015 +0200 +++ b/dash.py Wed Aug 12 13:45:58 2015 +0200 @@ -36,16 +36,28 @@ logger.addHandler(hdlr) logger.setLevel(logging.INFO) -##read the config file. usually "dash.conf" +### debug function: prints the current status of the "tiles" in +### the log-file +def log_tile_status(): + global tiles + + try: + for tile in tiles: + logger.info("found tile : " + str(tile)) + for option in tiles[0]: + logger.info(str(option) + ' : ' + str(tile[option])) + except KeyError: + pass + +###read the config file. usually "dash.conf" def read_config(): - + global settings # print(PATH) - global settings if os.path.isfile(CONFIG_PATH) == False: write_default_config() - print("read existing config file...") + # print("read existing config file...") config = configparser.ConfigParser() config.read(CONFIG_PATH) @@ -53,6 +65,10 @@ if "tile" in section[0]: tiles.append(section[1]) + ###log read tiles + logger.info("------- read tiles --------") + log_tile_status() + try: if config["settings"]: settings = config["settings"] @@ -117,8 +133,6 @@ # # script: (name of a script without extension) [required for d3js-types0] # - - [tile1] type=mon source=192.168.0.2 @@ -138,7 +152,6 @@ type=d3js div_name=techintern script=display_issues_techintern - """) file.close() @@ -148,25 +161,27 @@ def call_dashboard(): return dict(tiles=tiles, settings=settings) +#wait for post-request which shall inform the system about running services @post('/updown') def updown(): + global tiles + service = request.forms.get('service') status = request.forms.get('status') + try: + for tile in tiles: + if tile["source"] == str(service): + tile["status"] = str(status) + except KeyError: + logger.info("this tile got no source : " + str(tile)) + logger.info('------- new alert --------') logger.info('Service : ' + str(service)) logger.info('Status : ' + str(status)) - logger.info('--------------------------') - return "thx! :: " + str(service) + " is " + str(status) + " !" + log_tile_status() -@route('/config') -def call_config(): - return 'Not implemented yet' - - -@route('/static/') -def server_static(filepath): - return static_file(filepath, root='./static_files/') + return "thanks for informing bottledash! :: " + str(service) + " is " + str(status) + " !" @error(404) def error404(error): diff -r be6a1aaec717 -r 1a13a4ecf931 modules/net_mon/net_mon.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/net_mon/net_mon.py Wed Aug 12 13:45:58 2015 +0200 @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +""" very simple network_monitoring. Derterminats if a remote machine +is available or not + +author: Sean Engelhardt + +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) diff -r be6a1aaec717 -r 1a13a4ecf931 modules/net_mon/timer_test.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/net_mon/timer_test.py Wed Aug 12 13:45:58 2015 +0200 @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +""" + +author: Sean Engelhardt + +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 time, threading + +def foo(): + print(time.ctime()) + threading.Timer(10, foo).start() + +foo() diff -r be6a1aaec717 -r 1a13a4ecf931 views/bottledash_view.tpl --- a/views/bottledash_view.tpl Tue Aug 11 14:18:09 2015 +0200 +++ b/views/bottledash_view.tpl Wed Aug 12 13:45:58 2015 +0200 @@ -43,7 +43,7 @@ # vp_size = "3vw" #end %> - +