annotate dash.py @ 30:accefaf00c6a

changed the bg color
author sean
date Fri, 14 Aug 2015 15:37:52 +0200
parents 140c9023df7a
children a957a56bb694
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
19
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
9 import os.path, sys, configparser, functools, bottle
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
10 import logging
0
e1264e58154c initial commpit
sean
parents:
diff changeset
11
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
12 CONFIG_FILE = "dash.conf"
8
8fc4db85f2f5 fixed a path error
sean
parents: 7
diff changeset
13 PATH = os.path.abspath(os.path.dirname(sys.argv[0]))
8fc4db85f2f5 fixed a path error
sean
parents: 7
diff changeset
14 CONFIG_PATH = PATH + "/" + CONFIG_FILE
8fc4db85f2f5 fixed a path error
sean
parents: 7
diff changeset
15
9
b06cb7fbf7f8 updated template paths for daemon usage
sean
parents: 8
diff changeset
16 # Create a new list with absolute paths
b06cb7fbf7f8 updated template paths for daemon usage
sean
parents: 8
diff changeset
17 MY_TEMPLATE_PATH = [
10
d71f39618d6f used another workaround to locate the correct template
sean
parents: 9
diff changeset
18 os.path.abspath(os.path.join(os.path.dirname(__file__), './views')),
9
b06cb7fbf7f8 updated template paths for daemon usage
sean
parents: 8
diff changeset
19 ]
b06cb7fbf7f8 updated template paths for daemon usage
sean
parents: 8
diff changeset
20
b06cb7fbf7f8 updated template paths for daemon usage
sean
parents: 8
diff changeset
21 # Patch @view() so it uses the customized path list instead of the global one
b06cb7fbf7f8 updated template paths for daemon usage
sean
parents: 8
diff changeset
22 view = functools.partial(bottle.view, template_lookup=MY_TEMPLATE_PATH)
b06cb7fbf7f8 updated template paths for daemon usage
sean
parents: 8
diff changeset
23
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
24 tiles = []
7
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
25 settings = {}
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
26
7
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
27 default_settings = configparser.ConfigParser()
19
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
28 default_settings['settings'] = {'show_top_bar': False, 'rows': 2}
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
29
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
30 #logging:
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
31
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
32 logger = logging.getLogger('myapp')
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
33 hdlr = logging.FileHandler(PATH + '/bottledash.log')
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
34 formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
35 hdlr.setFormatter(formatter)
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
36 logger.addHandler(hdlr)
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
37 logger.setLevel(logging.INFO)
7
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
38
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
sean
parents: 19
diff changeset
39 ### debug function: prints the current status of the "tiles" in
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
sean
parents: 19
diff changeset
40 ### the log-file
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
sean
parents: 19
diff changeset
41 def log_tile_status():
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
sean
parents: 19
diff changeset
42 global tiles
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
sean
parents: 19
diff changeset
43
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
sean
parents: 19
diff changeset
44 try:
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
sean
parents: 19
diff changeset
45 for tile in tiles:
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
sean
parents: 19
diff changeset
46 logger.info("found tile : " + str(tile))
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
sean
parents: 19
diff changeset
47 for option in tiles[0]:
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
sean
parents: 19
diff changeset
48 logger.info(str(option) + ' : ' + str(tile[option]))
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
sean
parents: 19
diff changeset
49 except KeyError:
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
sean
parents: 19
diff changeset
50 pass
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
sean
parents: 19
diff changeset
51
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
sean
parents: 19
diff changeset
52 ###read the config file. usually "dash.conf"
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
53 def read_config():
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
sean
parents: 19
diff changeset
54 global settings
8
8fc4db85f2f5 fixed a path error
sean
parents: 7
diff changeset
55 # print(PATH)
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
56
8
8fc4db85f2f5 fixed a path error
sean
parents: 7
diff changeset
57 if os.path.isfile(CONFIG_PATH) == False:
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
58 write_default_config()
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
59
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
sean
parents: 19
diff changeset
60 # print("read existing config file...")
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
61 config = configparser.ConfigParser()
8
8fc4db85f2f5 fixed a path error
sean
parents: 7
diff changeset
62 config.read(CONFIG_PATH)
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
63
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
64 for section in config.items():
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
65 if "tile" in section[0]:
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
66 tiles.append(section[1])
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
67
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
sean
parents: 19
diff changeset
68 ###log read tiles
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
sean
parents: 19
diff changeset
69 logger.info("------- read tiles --------")
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
sean
parents: 19
diff changeset
70 log_tile_status()
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
sean
parents: 19
diff changeset
71
7
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
72 try:
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
73 if config["settings"]:
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
74 settings = config["settings"]
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
75 else:
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
76 settings = default_settings["settings"]
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
77 except KeyError:
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
78 settings = default_settings["settings"]
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
79
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
80 ###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
81 def write_default_config():
25
05e5441c5160 charts will now be displayed as they should!
sean
parents: 24
diff changeset
82 logger.info("No config-file found. create new config file")
8
8fc4db85f2f5 fixed a path error
sean
parents: 7
diff changeset
83 file = open(CONFIG_PATH, "w")
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
84 file.write("""
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
85 ### bottledash default configuration
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
86 ### created by sean engelhardt >sean.engelhardt@intevation.de
7
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
87 ### 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
88 ###
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
89 ### Usage:
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
90 ### define the tiles for the dashboard in sections
7
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
91
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
92 # Settings:
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
93 # example:
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
94 # --------------------
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
95 # [settings]
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
96 # show_top_bar=True
29
140c9023df7a added important default servers
sean
parents: 28
diff changeset
97 # rows=3
7
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
98 # --------------------
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
99 # options:
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
100 # show_top_bar (True / False) [optional]
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
101 # If True, the dashboard will show the current date and the time on the top
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
102 # if False, the dashboard will not show a top-bar
29
140c9023df7a added important default servers
sean
parents: 28
diff changeset
103 # default: False
7
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
104 # hint: the top-bar has got a height of 5%!
29
140c9023df7a added important default servers
sean
parents: 28
diff changeset
105 #
140c9023df7a added important default servers
sean
parents: 28
diff changeset
106 # rows (integer-number) [recommended]
140c9023df7a added important default servers
sean
parents: 28
diff changeset
107 # the number or rows for the tiles. Not every number makes sence since
140c9023df7a added important default servers
sean
parents: 28
diff changeset
108 # you usually cannot scroll on the screen. This only works on the default
140c9023df7a added important default servers
sean
parents: 28
diff changeset
109 # tile template - it is always possivle to write an own template!
140c9023df7a added important default servers
sean
parents: 28
diff changeset
110 # example:
140c9023df7a added important default servers
sean
parents: 28
diff changeset
111 # If there are 4 tiles in 2 rows the reult would be the following:
140c9023df7a added important default servers
sean
parents: 28
diff changeset
112 # ▢▢
140c9023df7a added important default servers
sean
parents: 28
diff changeset
113 # ▢▢
140c9023df7a added important default servers
sean
parents: 28
diff changeset
114 #
140c9023df7a added important default servers
sean
parents: 28
diff changeset
115 # if there are 3 tiles in 3 rows the result would be the following
140c9023df7a added important default servers
sean
parents: 28
diff changeset
116 # â–¢
140c9023df7a added important default servers
sean
parents: 28
diff changeset
117 # â–¢
140c9023df7a added important default servers
sean
parents: 28
diff changeset
118 # â–¢
140c9023df7a added important default servers
sean
parents: 28
diff changeset
119 #
140c9023df7a added important default servers
sean
parents: 28
diff changeset
120 # if there re 12 tiles in 3 rows the reult would be the following
140c9023df7a added important default servers
sean
parents: 28
diff changeset
121 # ▢▢▢▢
140c9023df7a added important default servers
sean
parents: 28
diff changeset
122 # ▢▢▢▢
140c9023df7a added important default servers
sean
parents: 28
diff changeset
123 # ▢▢▢▢
140c9023df7a added important default servers
sean
parents: 28
diff changeset
124 #
140c9023df7a added important default servers
sean
parents: 28
diff changeset
125
7
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
126
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
127 [settings]
14
3a9cb396905f made a template how to use the web_view module
sean
parents: 10
diff changeset
128 show_top_bar=False
29
140c9023df7a added important default servers
sean
parents: 28
diff changeset
129 rows=3
7
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
130
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
131 # Tiles:
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
132 # example:
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
133 # --------------------
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
134 # [tile1]
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
135 # type=mon
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
136 # source=192.168.0.2
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
137 # status=up
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
138 # --------------------
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
139 # options:
29
140c9023df7a added important default servers
sean
parents: 28
diff changeset
140 # type (mon / web_view) [required]
7
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
141 # tells the program what kind of tile you need.
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
142 # a "mon" tile can be used for IT infrastructure monitoring purposes
29
140c9023df7a added important default servers
sean
parents: 28
diff changeset
143 # a "web_view" tile can be used to display a chart
7
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
144 # default: -
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
145 #
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
146 # source (<IP> or <FQDN>) [required for mon-types]
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
147 # ONLY FOR MON-Type tiles!
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
148 # tells the tile which resource to watch
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
149 # ONLY FOR DEBUGGING PURPOSE - WILL BE REMOVED LATER
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
150 # simulates up and down events for mon-type-tiles
14
3a9cb396905f made a template how to use the web_view module
sean
parents: 10
diff changeset
151 #
3a9cb396905f made a template how to use the web_view module
sean
parents: 10
diff changeset
152 # div_name: (identifier) [required for d3js-types]
3a9cb396905f made a template how to use the web_view module
sean
parents: 10
diff changeset
153 #
3a9cb396905f made a template how to use the web_view module
sean
parents: 10
diff changeset
154 # script: (name of a script without extension) [required for d3js-types0]
3a9cb396905f made a template how to use the web_view module
sean
parents: 10
diff changeset
155 #
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
156 [tile1]
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
157 type=mon
29
140c9023df7a added important default servers
sean
parents: 28
diff changeset
158 source=red2-Bottle-App
28
af280057d5fa enhanced the design
sean
parents: 25
diff changeset
159 status=wait
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
160
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
161 [tile2]
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
162 type=mon
29
140c9023df7a added important default servers
sean
parents: 28
diff changeset
163 source=Intevation_Homepage
28
af280057d5fa enhanced the design
sean
parents: 25
diff changeset
164 status=wait
7
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
165
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
166 [tile3]
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
167 type=mon
29
140c9023df7a added important default servers
sean
parents: 28
diff changeset
168 source=mpuls-jmd-demo
28
af280057d5fa enhanced the design
sean
parents: 25
diff changeset
169 status=wait
7
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
170
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
171 [tile4]
29
140c9023df7a added important default servers
sean
parents: 28
diff changeset
172 type=mon
140c9023df7a added important default servers
sean
parents: 28
diff changeset
173 source=aise-icn
140c9023df7a added important default servers
sean
parents: 28
diff changeset
174 status=wait
140c9023df7a added important default servers
sean
parents: 28
diff changeset
175
140c9023df7a added important default servers
sean
parents: 28
diff changeset
176 [tile5]
140c9023df7a added important default servers
sean
parents: 28
diff changeset
177 type=mon
140c9023df7a added important default servers
sean
parents: 28
diff changeset
178 source=mpuls-s_bew_prev
140c9023df7a added important default servers
sean
parents: 28
diff changeset
179 status=wait
140c9023df7a added important default servers
sean
parents: 28
diff changeset
180
140c9023df7a added important default servers
sean
parents: 28
diff changeset
181 [tile6]
25
05e5441c5160 charts will now be displayed as they should!
sean
parents: 24
diff changeset
182 type=web_view
14
3a9cb396905f made a template how to use the web_view module
sean
parents: 10
diff changeset
183 div_name=techintern
3a9cb396905f made a template how to use the web_view module
sean
parents: 10
diff changeset
184 script=display_issues_techintern
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
185 """)
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
186 file.close()
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
187
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
188 ##Bottle
0
e1264e58154c initial commpit
sean
parents:
diff changeset
189 @route('/')
15
82d66f4488cd renaming of some files
sean
parents: 14
diff changeset
190 @view('bottledash_view')
0
e1264e58154c initial commpit
sean
parents:
diff changeset
191 def call_dashboard():
7
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
192 return dict(tiles=tiles, settings=settings)
0
e1264e58154c initial commpit
sean
parents:
diff changeset
193
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
sean
parents: 19
diff changeset
194 #wait for post-request which shall inform the system about running services
19
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
195 @post('/updown')
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
196 def updown():
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
sean
parents: 19
diff changeset
197 global tiles
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
sean
parents: 19
diff changeset
198
19
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
199 service = request.forms.get('service')
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
200 status = request.forms.get('status')
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
sean
parents: 19
diff changeset
201 try:
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
sean
parents: 19
diff changeset
202 for tile in tiles:
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
sean
parents: 19
diff changeset
203 if tile["source"] == str(service):
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
sean
parents: 19
diff changeset
204 tile["status"] = str(status)
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
sean
parents: 19
diff changeset
205 except KeyError:
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
206 logger.info("this tile got no source : " + str(tile))
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
sean
parents: 19
diff changeset
207
19
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
208
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
209 logger.info('------- new alert --------')
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
210 logger.info('Service : ' + str(service))
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
211 logger.info('Status : ' + str(status))
24
7d431b779512 working connection with MON
sean
parents: 21
diff changeset
212 # log_tile_status()
19
be6a1aaec717 added the post listener, write logs if someone sends a post
sean
parents: 15
diff changeset
213
25
05e5441c5160 charts will now be displayed as they should!
sean
parents: 24
diff changeset
214 return ":: " + str(service) + " is " + str(status) + " !"
0
e1264e58154c initial commpit
sean
parents:
diff changeset
215
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
216
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
217 @post('/ask-systemstate')
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
218 def get_systemstate():
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
219 global tiles
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
220 service = request.forms.get('service')
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
221
25
05e5441c5160 charts will now be displayed as they should!
sean
parents: 24
diff changeset
222 # print("service: " + service)
21
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
223
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
224 try:
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
225 for tile in tiles:
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
226 if tile["source"] == str(service):
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
227 # return "service : " + str(service) + " is " + str(tile["status"])
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
228 return tile["status"]
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
229 except KeyError:
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
230 return "cannot find the service: " + str(service)
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
231
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
232 return "did not found anything in my list for : " + service
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
233
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
234
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
235 @route('/static/<filename>')
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
236 def server_static(filename):
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
237 return static_file(filename, root=PATH + '/static/')
f730dd0bcf85 dynamic checking of the tile-status
sean
parents: 20
diff changeset
238
0
e1264e58154c initial commpit
sean
parents:
diff changeset
239 @error(404)
e1264e58154c initial commpit
sean
parents:
diff changeset
240 def error404(error):
e1264e58154c initial commpit
sean
parents:
diff changeset
241 return 'Nothing here, sorry <br /> 404'
e1264e58154c initial commpit
sean
parents:
diff changeset
242
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
243 read_config()
7
c8cb2aa0b72c fixed default condifuration
sean
parents: 5
diff changeset
244 # print(tiles)
25
05e5441c5160 charts will now be displayed as they should!
sean
parents: 24
diff changeset
245 run(host='localhost', port=8080, debug=False, quiet=True)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)