-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive.py
More file actions
94 lines (82 loc) · 3.11 KB
/
interactive.py
File metadata and controls
94 lines (82 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import argparse
import workerbee
import json
from bottle import route, run, template, get, post, request, static_file
parser = argparse.ArgumentParser(description='Manage HoneyComb')
parser.add_argument('--username', required=False, help='Username')
parser.add_argument('--debug', required=False, help='Debug', action='store_true')
options = parser.parse_args()
hc = workerbee.workerbee(options.debug, options.username)
@route('/')
def root():
return '''
<form action="/login" method="post">
Username: <input name="username" type="text" value="%s" />
Password: <input name="password" type="password" value="%s" />
<input value="Login" type="submit" />
</form>
''' % (hc.getUsername(), hc.getPassword())
@route('/node/:nodename/attribute/:attribute/graph')
def graph(nodename, attribute):
filename='node-%s-attribute-%s.png' % (nodename, attribute)
print 'Creating file ' + filename
hc.graphNodeAttribute([nodename], attribute, filename)
return static_file(filename, root='.')
@route('/node/:nodename/attribute/:attribute')
def node(nodename, attribute):
return 'Data: <code>' + json.dumps(hc.nodes()['nodesDict'][nodename]['attributes'][attribute], indent=2) + '</code><br/><a href="/node/' + nodename + '/attribute/' + attribute + '/graph">graph</a>'
@route('/node/:nodename')
def node(nodename):
output='<ul>'
attributes = hc.nodes()['nodesDict'][nodename]['attributes'].keys()
attributes.sort()
for attribute in attributes:
output = output + '<li>' + '<a href="/node/' + nodename + '/attribute/' + attribute + '">' + attribute + '</a>' + '</li>'
output = output + '</ul>'
return output
@route('/channels')
def channels():
output='<ul>'
channels = hc.channels()['channelsDict'].keys()
channels.sort()
for channel in channels:
output = output + '<li>' + '<a href="channel/' + channel + '">' + channel + '</a>' + '</li>'
output = output + '</ul>'
return output
@route('/events')
def events():
output='<ul>'
events = hc.events()['eventsDict'].keys()
events.sort()
for event in events:
output = output + '<li>' + '<a href="event/' + event + '">' + event + '</a>' + '</li>'
output = output + '</ul>'
return output
@route('/nodes')
def nodes():
output='<ul>'
nodes = hc.nodes()['nodesDict'].keys()
nodes.sort()
for node in nodes:
output = output + '<li>' + '<a href="node/' + node + '">' + node + '</a>' + '</li>'
output = output + '</ul>'
return output
@route('/login', method='POST')
def do_login():
username = request.forms.get('username')
password = request.forms.get('password')
if hc.login(username, password):
return '''
<p>Your login information was correct.</p>
<ul>
<li><a href="/nodes">nodes</li>
<li><a href="/channels">channels</li>
<li><a href="/events">events</li>
<li><a href="/logout">logout</li></ul>
'''
else:
return '<p>Login failed.</p>'
@route('/logout')
def logout():
hc.logout()
run(host='localhost', port=8080)