Mercurial > bottledash
comparison dash.py @ 19:be6a1aaec717
added the post listener, write logs if someone sends a post
author | sean |
---|---|
date | Tue, 11 Aug 2015 14:18:09 +0200 |
parents | 82d66f4488cd |
children | 1a13a4ecf931 |
comparison
equal
deleted
inserted
replaced
18:3da0d624bec0 | 19:be6a1aaec717 |
---|---|
4 license: GNU >= V2. See LICENSE for details | 4 license: GNU >= V2. See LICENSE for details |
5 """ | 5 """ |
6 | 6 |
7 from bottle import get, post, request, view, response, route | 7 from bottle import get, post, request, view, response, route |
8 from bottle import template, run, static_file, error | 8 from bottle import template, run, static_file, error |
9 import os.path,sys,configparser,functools,bottle | 9 import os.path, sys, configparser, functools, bottle |
10 import logging | |
10 | 11 |
11 CONFIG_FILE = "dash.conf" | 12 CONFIG_FILE = "dash.conf" |
12 PATH = os.path.abspath(os.path.dirname(sys.argv[0])) | 13 PATH = os.path.abspath(os.path.dirname(sys.argv[0])) |
13 CONFIG_PATH = PATH + "/" + CONFIG_FILE | 14 CONFIG_PATH = PATH + "/" + CONFIG_FILE |
14 | 15 |
22 | 23 |
23 tiles = [] | 24 tiles = [] |
24 settings = {} | 25 settings = {} |
25 | 26 |
26 default_settings = configparser.ConfigParser() | 27 default_settings = configparser.ConfigParser() |
27 default_settings['settings'] = {'show_top_bar': False} | 28 default_settings['settings'] = {'show_top_bar': False, 'rows': 2} |
29 | |
30 #logging: | |
31 | |
32 logger = logging.getLogger('myapp') | |
33 hdlr = logging.FileHandler(PATH + '/bottledash.log') | |
34 formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') | |
35 hdlr.setFormatter(formatter) | |
36 logger.addHandler(hdlr) | |
37 logger.setLevel(logging.INFO) | |
28 | 38 |
29 ##read the config file. usually "dash.conf" | 39 ##read the config file. usually "dash.conf" |
30 | |
31 def read_config(): | 40 def read_config(): |
32 | 41 |
33 # print(PATH) | 42 # print(PATH) |
34 global settings | 43 global settings |
35 | 44 |
137 @route('/') | 146 @route('/') |
138 @view('bottledash_view') | 147 @view('bottledash_view') |
139 def call_dashboard(): | 148 def call_dashboard(): |
140 return dict(tiles=tiles, settings=settings) | 149 return dict(tiles=tiles, settings=settings) |
141 | 150 |
151 @post('/updown') | |
152 def updown(): | |
153 service = request.forms.get('service') | |
154 status = request.forms.get('status') | |
155 | |
156 logger.info('------- new alert --------') | |
157 logger.info('Service : ' + str(service)) | |
158 logger.info('Status : ' + str(status)) | |
159 logger.info('--------------------------') | |
160 return "thx! :: " + str(service) + " is " + str(status) + " !" | |
161 | |
142 @route('/config') | 162 @route('/config') |
143 def call_config(): | 163 def call_config(): |
144 return 'Not implemented yet' | 164 return 'Not implemented yet' |
145 | 165 |
146 | 166 |