Mercurial > bottledash
comparison dash.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 | be6a1aaec717 |
children | f730dd0bcf85 |
comparison
equal
deleted
inserted
replaced
19:be6a1aaec717 | 20:1a13a4ecf931 |
---|---|
34 formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') | 34 formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') |
35 hdlr.setFormatter(formatter) | 35 hdlr.setFormatter(formatter) |
36 logger.addHandler(hdlr) | 36 logger.addHandler(hdlr) |
37 logger.setLevel(logging.INFO) | 37 logger.setLevel(logging.INFO) |
38 | 38 |
39 ##read the config file. usually "dash.conf" | 39 ### debug function: prints the current status of the "tiles" in |
40 ### the log-file | |
41 def log_tile_status(): | |
42 global tiles | |
43 | |
44 try: | |
45 for tile in tiles: | |
46 logger.info("found tile : " + str(tile)) | |
47 for option in tiles[0]: | |
48 logger.info(str(option) + ' : ' + str(tile[option])) | |
49 except KeyError: | |
50 pass | |
51 | |
52 ###read the config file. usually "dash.conf" | |
40 def read_config(): | 53 def read_config(): |
41 | 54 global settings |
42 # print(PATH) | 55 # print(PATH) |
43 global settings | |
44 | 56 |
45 if os.path.isfile(CONFIG_PATH) == False: | 57 if os.path.isfile(CONFIG_PATH) == False: |
46 write_default_config() | 58 write_default_config() |
47 | 59 |
48 print("read existing config file...") | 60 # print("read existing config file...") |
49 config = configparser.ConfigParser() | 61 config = configparser.ConfigParser() |
50 config.read(CONFIG_PATH) | 62 config.read(CONFIG_PATH) |
51 | 63 |
52 for section in config.items(): | 64 for section in config.items(): |
53 if "tile" in section[0]: | 65 if "tile" in section[0]: |
54 tiles.append(section[1]) | 66 tiles.append(section[1]) |
67 | |
68 ###log read tiles | |
69 logger.info("------- read tiles --------") | |
70 log_tile_status() | |
55 | 71 |
56 try: | 72 try: |
57 if config["settings"]: | 73 if config["settings"]: |
58 settings = config["settings"] | 74 settings = config["settings"] |
59 else: | 75 else: |
115 # | 131 # |
116 # div_name: (identifier) [required for d3js-types] | 132 # div_name: (identifier) [required for d3js-types] |
117 # | 133 # |
118 # script: (name of a script without extension) [required for d3js-types0] | 134 # script: (name of a script without extension) [required for d3js-types0] |
119 # | 135 # |
120 | |
121 | |
122 [tile1] | 136 [tile1] |
123 type=mon | 137 type=mon |
124 source=192.168.0.2 | 138 source=192.168.0.2 |
125 status=down | 139 status=down |
126 | 140 |
136 | 150 |
137 [tile4] | 151 [tile4] |
138 type=d3js | 152 type=d3js |
139 div_name=techintern | 153 div_name=techintern |
140 script=display_issues_techintern | 154 script=display_issues_techintern |
141 | |
142 """) | 155 """) |
143 file.close() | 156 file.close() |
144 | 157 |
145 ##Bottle | 158 ##Bottle |
146 @route('/') | 159 @route('/') |
147 @view('bottledash_view') | 160 @view('bottledash_view') |
148 def call_dashboard(): | 161 def call_dashboard(): |
149 return dict(tiles=tiles, settings=settings) | 162 return dict(tiles=tiles, settings=settings) |
150 | 163 |
164 #wait for post-request which shall inform the system about running services | |
151 @post('/updown') | 165 @post('/updown') |
152 def updown(): | 166 def updown(): |
167 global tiles | |
168 | |
153 service = request.forms.get('service') | 169 service = request.forms.get('service') |
154 status = request.forms.get('status') | 170 status = request.forms.get('status') |
171 try: | |
172 for tile in tiles: | |
173 if tile["source"] == str(service): | |
174 tile["status"] = str(status) | |
175 except KeyError: | |
176 logger.info("this tile got no source : " + str(tile)) | |
177 | |
155 | 178 |
156 logger.info('------- new alert --------') | 179 logger.info('------- new alert --------') |
157 logger.info('Service : ' + str(service)) | 180 logger.info('Service : ' + str(service)) |
158 logger.info('Status : ' + str(status)) | 181 logger.info('Status : ' + str(status)) |
159 logger.info('--------------------------') | 182 log_tile_status() |
160 return "thx! :: " + str(service) + " is " + str(status) + " !" | |
161 | 183 |
162 @route('/config') | 184 return "thanks for informing bottledash! :: " + str(service) + " is " + str(status) + " !" |
163 def call_config(): | |
164 return 'Not implemented yet' | |
165 | |
166 | |
167 @route('/static/<filepath:path>') | |
168 def server_static(filepath): | |
169 return static_file(filepath, root='./static_files/') | |
170 | 185 |
171 @error(404) | 186 @error(404) |
172 def error404(error): | 187 def error404(error): |
173 return 'Nothing here, sorry <br /> 404' | 188 return 'Nothing here, sorry <br /> 404' |
174 | 189 |