Mercurial > bottledash
comparison dash.py @ 7:c8cb2aa0b72c
fixed default condifuration
author | sean |
---|---|
date | Wed, 22 Jul 2015 13:31:25 +0200 |
parents | c49f7fe82743 |
children | 8fc4db85f2f5 |
comparison
equal
deleted
inserted
replaced
6:3acc5164369e | 7:c8cb2aa0b72c |
---|---|
9 import configparser | 9 import configparser |
10 import os.path | 10 import os.path |
11 | 11 |
12 CONFIG_FILE = "dash.conf" | 12 CONFIG_FILE = "dash.conf" |
13 tiles = [] | 13 tiles = [] |
14 settings = {} | |
14 | 15 |
16 default_settings = configparser.ConfigParser() | |
17 default_settings['settings'] = {'show_top_bar': True} | |
18 | |
19 ##read the config file. usually "dash.conf" | |
15 def read_config(): | 20 def read_config(): |
21 global settings | |
16 | 22 |
17 if os.path.isfile(CONFIG_FILE) == False: | 23 if os.path.isfile(CONFIG_FILE) == False: |
18 write_default_config() | 24 write_default_config() |
19 | 25 |
20 config = configparser.ConfigParser() | 26 config = configparser.ConfigParser() |
21 config.read(CONFIG_FILE) | 27 config.read(CONFIG_FILE) |
22 | 28 |
23 | |
24 | |
25 #read the tiles | |
26 read_tiles_config(config) | |
27 | |
28 def read_tiles_config(config): | |
29 for section in config.items(): | 29 for section in config.items(): |
30 if "tile" in section[0]: | 30 if "tile" in section[0]: |
31 tiles.append(section[1]) | 31 tiles.append(section[1]) |
32 # print(tiles[0]["type"]) | |
33 | 32 |
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 | |
34 def write_default_config(): | 42 def write_default_config(): |
35 file = open("dash.conf", "w") | 43 file = open("dash.conf", "w") |
36 file.write(""" | 44 file.write(""" |
37 | |
38 ### bottledash default configuration | 45 ### bottledash default configuration |
39 ### created by sean engelhardt >sean.engelhardt@intevation.de | 46 ### created by sean engelhardt >sean.engelhardt@intevation.de |
40 ### license: GNU GPL >= v2 | 47 ### license: GNU GPL >= v2. See LICENSE for details |
41 ### | 48 ### |
42 ### Usage: | 49 ### Usage: |
43 ### define the tiles for the dashboard in sections | 50 ### define the tiles for the dashboard in sections |
44 ### | 51 |
45 ### options for tiles: | 52 # Settings: |
46 ### | 53 # example: |
47 ### type | 54 # -------------------- |
48 ### values: mon, d3.js | 55 # [settings] |
49 ### | 56 # show_top_bar=True |
50 ### source (only if type = mon) | 57 # -------------------- |
51 ### value: IP or FQDN | 58 # options: |
52 ### status | 59 # show_top_bar (True / False) [optional] |
53 ### | 60 # If True, the dashboard will show the current date and the time on the top |
54 ### status (for debug purpose only | only if type = mon) | 61 # if False, the dashboard will not show a top-bar |
55 ### values: up, down | 62 # default: True |
56 ### | 63 # hint: the top-bar has got a height of 5%! |
57 ### example: | 64 |
58 ### [tile1] | 65 [settings] |
59 ### type=mon | 66 show_top_bar=True |
60 ### source=192.168.0.2 | 67 |
61 ### status=up | 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 | |
62 | 91 |
63 [tile1] | 92 [tile1] |
64 type=mon | 93 type=mon |
65 source=192.168.0.2 | 94 source=192.168.0.2 |
66 status=down | 95 status=up |
67 | 96 |
68 [tile2] | 97 [tile2] |
69 type=mon | 98 type=mon |
70 source=192.168.2.1 | 99 source=192.168.2.3 |
100 status=down | |
101 | |
102 [tile3] | |
103 type=mon | |
104 source=192.168.4.3 | |
71 status=up | 105 status=up |
106 | |
107 [tile4] | |
108 type=mon | |
109 source=192.168.4.3 | |
110 status=down | |
111 | |
72 """) | 112 """) |
73 file.close() | 113 file.close() |
74 | 114 |
75 ##Bottle | 115 ##Bottle |
76 @route('/') | 116 @route('/') |
77 @view('hello_template') | 117 @view('hello_template') |
78 def call_dashboard(): | 118 def call_dashboard(): |
79 return dict(tiles=tiles) | 119 return dict(tiles=tiles, settings=settings) |
80 | 120 |
81 @route('/config') | 121 @route('/config') |
82 def call_config(): | 122 def call_config(): |
83 return 'Not implemented yet' | 123 return 'Not implemented yet' |
84 | 124 |
90 @error(404) | 130 @error(404) |
91 def error404(error): | 131 def error404(error): |
92 return 'Nothing here, sorry <br /> 404' | 132 return 'Nothing here, sorry <br /> 404' |
93 | 133 |
94 read_config() | 134 read_config() |
95 print(tiles) | 135 # print(tiles) |
96 run(host='localhost', port=8080, debug=True) | 136 run(host='localhost', port=8080, debug=True) |