changeset 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 be6a1aaec717
children f730dd0bcf85
files dash.conf dash.py modules/net_mon/net_mon.py modules/net_mon/timer_test.py views/bottledash_view.tpl
diffstat 5 files changed, 103 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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/<filepath:path>')
-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):
--- /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 <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)
--- /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
+
+""" <DECRIPTION>
+
+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 time, threading
+
+def foo():
+    print(time.ctime())
+    threading.Timer(10, foo).start()
+
+foo()
--- 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
 %>
-
+<meta http-equiv="refresh" content="5" />
 <script type="text/javascript">
 
     var global_width;
@@ -182,14 +182,16 @@
             type = ""
             tile_content = ""
             status = ""
+
             if tile["type"] == "mon" :
                 type = "statusmon"
                 tile_content = tile["source"]
                 if tile["status"] == "up" :
                     status = "active"
-                elif tile["status"] == "down" :
+                else :
                     status = "dead"
                 end
+
             elif tile["type"] == "d3js" :
                 type = "chart"
                 status = tile["div_name"]
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)