Mercurial > bottledash
annotate dash.py @ 7:c8cb2aa0b72c
fixed default condifuration
author | sean |
---|---|
date | Wed, 22 Jul 2015 13:31:25 +0200 |
parents | c49f7fe82743 |
children | 8fc4db85f2f5 |
rev | line source |
---|---|
4
3e66e2f92770
added LICENSE and license headers in the sourcecode. Added readme
sean
parents:
3
diff
changeset
|
1 """ |
3e66e2f92770
added LICENSE and license headers in the sourcecode. Added readme
sean
parents:
3
diff
changeset
|
2 This software is part of "Bottledash" |
3e66e2f92770
added LICENSE and license headers in the sourcecode. Added readme
sean
parents:
3
diff
changeset
|
3 author: sean engelhardt > sean.engelhardt@intevation.de |
3e66e2f92770
added LICENSE and license headers in the sourcecode. Added readme
sean
parents:
3
diff
changeset
|
4 license: GNU >= V2. See LICENSE for details |
3e66e2f92770
added LICENSE and license headers in the sourcecode. Added readme
sean
parents:
3
diff
changeset
|
5 """ |
3e66e2f92770
added LICENSE and license headers in the sourcecode. Added readme
sean
parents:
3
diff
changeset
|
6 |
3
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
7 from bottle import get, post, request, view, response, route |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
8 from bottle import template, run, static_file, error |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
9 import configparser |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
10 import os.path |
0 | 11 |
3
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
12 CONFIG_FILE = "dash.conf" |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
13 tiles = [] |
7 | 14 settings = {} |
3
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
15 |
7 | 16 default_settings = configparser.ConfigParser() |
17 default_settings['settings'] = {'show_top_bar': True} | |
18 | |
19 ##read the config file. usually "dash.conf" | |
3
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
20 def read_config(): |
7 | 21 global settings |
3
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
22 |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
23 if os.path.isfile(CONFIG_FILE) == False: |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
24 write_default_config() |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
25 |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
26 config = configparser.ConfigParser() |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
27 config.read(CONFIG_FILE) |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
28 |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
29 for section in config.items(): |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
30 if "tile" in section[0]: |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
31 tiles.append(section[1]) |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
32 |
7 | 33 try: |
34 if config["settings"]: | |
35 settings = config["settings"] | |
36 else: | |
37 settings = default_settings["settings"] | |
38 except KeyError: | |
39 settings = default_settings["settings"] | |
40 | |
41 ###write the default condfig file if there is none | |
3
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
42 def write_default_config(): |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
43 file = open("dash.conf", "w") |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
44 file.write(""" |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
45 ### bottledash default configuration |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
46 ### created by sean engelhardt >sean.engelhardt@intevation.de |
7 | 47 ### license: GNU GPL >= v2. See LICENSE for details |
3
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
48 ### |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
49 ### Usage: |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
50 ### define the tiles for the dashboard in sections |
7 | 51 |
52 # Settings: | |
53 # example: | |
54 # -------------------- | |
55 # [settings] | |
56 # show_top_bar=True | |
57 # -------------------- | |
58 # options: | |
59 # show_top_bar (True / False) [optional] | |
60 # If True, the dashboard will show the current date and the time on the top | |
61 # if False, the dashboard will not show a top-bar | |
62 # default: True | |
63 # hint: the top-bar has got a height of 5%! | |
64 | |
65 [settings] | |
66 show_top_bar=True | |
67 | |
68 # Tiles: | |
69 # example: | |
70 # -------------------- | |
71 # [tile1] | |
72 # type=mon | |
73 # source=192.168.0.2 | |
74 # status=up | |
75 # -------------------- | |
76 # options: | |
77 # type (mon / d3js) [required] | |
78 # tells the program what kind of tile you need. | |
79 # a "mon" tile can be used for IT infrastructure monitoring purposes | |
80 # a d3js tile can be used to display a chart | |
81 # default: - | |
82 # | |
83 # source (<IP> or <FQDN>) [required for mon-types] | |
84 # ONLY FOR MON-Type tiles! | |
85 # tells the tile which resource to watch | |
86 # default: none | |
87 # | |
88 # status: (up / down) [required] | |
89 # ONLY FOR DEBUGGING PURPOSE - WILL BE REMOVED LATER | |
90 # simulates up and down events for mon-type-tiles | |
3
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
91 |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
92 [tile1] |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
93 type=mon |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
94 source=192.168.0.2 |
7 | 95 status=up |
3
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
96 |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
97 [tile2] |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
98 type=mon |
7 | 99 source=192.168.2.3 |
100 status=down | |
101 | |
102 [tile3] | |
103 type=mon | |
104 source=192.168.4.3 | |
3
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
105 status=up |
7 | 106 |
107 [tile4] | |
108 type=mon | |
109 source=192.168.4.3 | |
110 status=down | |
111 | |
3
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
112 """) |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
113 file.close() |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
114 |
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
115 ##Bottle |
0 | 116 @route('/') |
117 @view('hello_template') | |
118 def call_dashboard(): | |
7 | 119 return dict(tiles=tiles, settings=settings) |
0 | 120 |
121 @route('/config') | |
122 def call_config(): | |
123 return 'Not implemented yet' | |
124 | |
125 | |
126 @route('/static/<filepath:path>') | |
127 def server_static(filepath): | |
128 return static_file(filepath, root='./static_files/') | |
129 | |
130 @error(404) | |
131 def error404(error): | |
132 return 'Nothing here, sorry <br /> 404' | |
133 | |
3
3f5bcad45756
pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents:
0
diff
changeset
|
134 read_config() |
7 | 135 # print(tiles) |
0 | 136 run(host='localhost', port=8080, debug=True) |