# HG changeset patch # User sean # Date 1439461066 -7200 # Node ID f730dd0bcf85d2ae2dd11fd47aab18ea1fa973c4 # Parent 1a13a4ecf931df4e199ce467cb1a4c68eb96b5df dynamic checking of the tile-status diff -r 1a13a4ecf931 -r f730dd0bcf85 README.txt --- a/README.txt Wed Aug 12 13:45:58 2015 +0200 +++ b/README.txt Thu Aug 13 12:17:46 2015 +0200 @@ -12,3 +12,9 @@ For further details see the insctructions inside the dash.conf. + +#todo +POST-Request to update the tiles: + +curl -d service=192.168.2.3 -d status=up localhost:8080/updown +curl -d service=192.168.2.3 -d status=down localhost:8080/updown \ No newline at end of file diff -r 1a13a4ecf931 -r f730dd0bcf85 dash.py --- a/dash.py Wed Aug 12 13:45:58 2015 +0200 +++ b/dash.py Thu Aug 13 12:17:46 2015 +0200 @@ -173,7 +173,7 @@ if tile["source"] == str(service): tile["status"] = str(status) except KeyError: - logger.info("this tile got no source : " + str(tile)) + logger.info("this tile got no source : " + str(tile)) logger.info('------- new alert --------') @@ -183,6 +183,29 @@ return "thanks for informing bottledash! :: " + str(service) + " is " + str(status) + " !" + +@post('/ask-systemstate') +def get_systemstate(): + global tiles + service = request.forms.get('service') + + print("service: " + service) + + try: + for tile in tiles: + if tile["source"] == str(service): + # return "service : " + str(service) + " is " + str(tile["status"]) + return tile["status"] + except KeyError: + return "cannot find the service: " + str(service) + + return "did not found anything in my list for : " + service + + +@route('/static/') +def server_static(filename): + return static_file(filename, root=PATH + '/static/') + @error(404) def error404(error): return 'Nothing here, sorry
404' diff -r 1a13a4ecf931 -r f730dd0bcf85 modules/web_view/graph.html --- a/modules/web_view/graph.html Wed Aug 12 13:45:58 2015 +0200 +++ b/modules/web_view/graph.html Thu Aug 13 12:17:46 2015 +0200 @@ -87,7 +87,10 @@ - + + + + - - - -
- % if show_top_bar == "True" : -
- {{weekday}} {{today.day}}. {{month_name}} -
- % end - -
- <% - for tile in tiles : - type = "" - tile_content = "" - status = "" + var tiles = document.getElementsByClassName("tile"); + var border_width = 1; + var space_between_tiles = 8; - if tile["type"] == "mon" : - type = "statusmon" - tile_content = tile["source"] - if tile["status"] == "up" : - status = "active" - else : - status = "dead" - end + var mon_tile_ips = []; - elif tile["type"] == "d3js" : - type = "chart" - status = tile["div_name"] - tile_content = web_view.make_chart(tile["script"], tile["div_name"]) - end - %> -
- {{!tile_content}} + //save the IPs if the mon-tiles + % for tile in tiles: + % if tile["type"] == "mon": + mon_tile_ips.push('{{tile["source"]}}'); + % end + % end + + var space_lr_borders; + var space_lr_margin; + + function calc_tile_with(){ + var tiles_per_row = Math.floor(tiles.length / {{number_of_rows}}); + var distance = (space_between_tiles*2) + (border_width*2); + var tile_width = ((global_width / tiles_per_row ) - distance); + return tile_width; + } + + function calc_tile_height(){ + var distance = (space_between_tiles*2) + (border_width*2); + var tile_height = ((global_height / {{number_of_rows}} ) - distance); + return tile_height; + } + + function resize_content(){ + global_width = document.getElementById("content").clientWidth; + global_height = document.getElementById("content").clientHeight; + + + tile_width = calc_tile_with(); + tile_height = calc_tile_height(); + + for(var tile = 0; tile < tiles.length; tile++){ + tiles[tile].style.width= tile_width + 'px'; + tiles[tile].style.height= tile_height + 'px'; + } + } + + function set_mon_tile_status(ip, status){ + document.getElementById(ip).className = "tile statusmon " + status; + } + + //check current state of I + function check_server_state(ip){ + var request = new XMLHttpRequest(); + var params = "service=" + ip; + request.open('POST', "http://localhost:8080/ask-systemstate", false); + request.send(params); + + // console.log(request.responseText); + return request.responseText + + } + + function check_server_state_loop() { + for (var i = 0; i < mon_tile_ips.length; i++) { + var state = check_server_state(mon_tile_ips[i]) + if (state == "up") { + set_mon_tile_status(mon_tile_ips[i], "active") + } else { + set_mon_tile_status(mon_tile_ips[i], "dead") + } + } + } + setInterval(check_server_state_loop, 10000); // Time in milliseconds + + window.onresize = function(){ + resize_content(); + } + + document.addEventListener("DOMContentLoaded", function(event) { + resize_content(); + }); + + + +
+ % if show_top_bar == "True": +
+ {{weekday}} {{today.day}}. {{month_name}}
- % end +
+ <% + for tile in tiles : + type = "" + tile_content = "" + status = "" + uid = "" + + if tile["type"] == "mon" : + type = "statusmon" + tile_content = tile["source"] + uid = tile["source"] + if tile["status"] == "up" : + status = "active" + else : + status = "dead" + end + + elif tile["type"] == "d3js" : + type = "chart" + uid = tile["div_name"] + tile_content = web_view.make_chart(tile["script"], tile["div_name"]) + end + %> + +
+ {{!tile_content}} +
+ + % end +
-
+ +