forked from ciarams87/VMAXAlexa
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patharray_alerts.py
More file actions
80 lines (63 loc) · 2.46 KB
/
array_alerts.py
File metadata and controls
80 lines (63 loc) · 2.46 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
import logging
from flask import Flask, render_template
from flask_ask import Ask, statement, question, session
import vmax_requests as vmax
app = Flask(__name__)
ask = Ask(app, "/")
LOG = logging.getLogger("flask_ask").setLevel(logging.DEBUG)
@ask.launch
def new_game():
welcome_msg = render_template('welcome')
return question(welcome_msg)
@ask.intent("VmaxIntroIntent")
def vmax_intro():
vmax_message = render_template('vmax_intro')
return statement(vmax_message)
@ask.intent("YesIntent")
def list_arrays():
arrays = vmax.get_array_list()
len_array_list = len(arrays)
arrays_msg = render_template('array', amount=len_array_list,
array_list=list(enumerate(arrays)))
session.attributes['arrays'] = arrays
return question(arrays_msg)
@ask.intent("ChooseArrayIntent", convert={'index': int})
def choose_array(index):
array_list = session.attributes['arrays']
try:
array = array_list[index]
except IndexError:
msg = render_template('indexerror')
else:
session.attributes['array'] = array
(perf_unacknowledged, array_unacknowledged,
server_unacknowledged) = vmax.get_alert_summary(array)
total_unacknowledged = perf_unacknowledged + array_unacknowledged + server_unacknowledged
if total_unacknowledged:
msg = render_template('alerts', array_alert_num=total_unacknowledged,
server_unacknowledged=server_unacknowledged)
else:
msg = render_template('no_alerts')
return question(msg)
@ask.intent("ListAlertsIntent")
def list_and_acknowledge_alerts():
return_alerts = []
array = session.attributes['array']
alert_list = vmax.get_all_array_alerts(
array, filters={'acknowledged': 'false'})
if alert_list and len(alert_list) > 0:
for alert_id in alert_list:
alert_details = vmax.get_alert(array, alert_id)
return_alerts.append(alert_details)
vmax.acknowledge_array_alert(array, alert_id)
msg = render_template('alert_details',
alert_list=list(enumerate(return_alerts)))
return question(msg)
@ask.on_session_started
def new_session():
LOG.info('new session started')
@ask.intent("GoodbyeIntent")
def goodbye():
return statement(render_template('goodbye'))
if __name__ == '__main__':
app.run(debug=True)