File: web.py

package info (click to toggle)
zeekctl 2.2.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,544 kB
  • sloc: python: 5,639; sh: 1,374; makefile: 71; awk: 24
file content (59 lines) | stat: -rw-r--r-- 1,239 bytes parent folder | download
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
from ZeekControl import version
from ZeekControl.ser import dumps
import os
import bottle
import json

app = bottle.Bottle(autojson=False)
app.install(bottle.JSONPlugin(json_dumps=lambda s: json.dumps(s, default=dumps)))

@app.route('/start')
def start():
    i = app.daemon.call("start")
    return {"id": i} 

@app.route('/stop')
def start():
    i = app.daemon.call("stop")
    return {"id": i} 

@app.route('/restart')
def restart():
    i = app.daemon.call("restart")
    return {"id": i} 


@app.route('/nodes')
def nodes():
    s = app.daemon.sync_call("nodes")
    print "\n\n\nReturning", s, "\n\n"
    return {"result": s}

@app.route('/exec/:cmd')
def start(cmd):
    i = app.daemon.call("execute", cmd)
    return {"id": i} 

@app.route('/result/:id')
def result(id):
    id = int(id)
    return {"result": app.daemon.getresult(id)}

@app.route('/log/:id')
@app.route('/log/:id/:since')
def result(id, since=0):
    id = int(id)
    since = int(since)
    return {"log": app.daemon.getlog(id, since) or []}

@app.route('/:cmd')
def cmd(cmd):
    i = app.daemon.call(cmd)
    return {"id": i} 

def run_app(client):
    app.daemon = client
    bottle.run(app, host='localhost', port=8082)

if __name__ == "__main__":
    main()