Commit 7aa3d5d2 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

mailing works, added timestamp & alert mail template

parent 1d40f9d8
......@@ -47,7 +47,7 @@ def create_function(cur, appkey, devid, nfid, expr):
INSERT INTO
notifications_queue
VALUES
('{}','{}',{});
('{}','{}',{}, now());
END IF;
""".format( expr[0], get_type(expr[2]), expr[1], expr[2],
nfid, appkey, devid)
......
<h4> Hello {{ username }}, </h4>
<p> The alert {{ alertname }} from your {{ appname }} application is has been fired at {{ timestamp }}. </p>
<p> Remember the condition of the alert was {{ condition }}. </p>
<p>Take care,</p>
<p>HPC&amp;A IoT Server </p>
......@@ -17,7 +17,8 @@
<table class="table">
<thead>
<th> Name </th>
<th> Description </th>
<th> Condition </th>
<th> Email </th>
<th> </th>
</thead>
<tbody>
......@@ -25,6 +26,7 @@
<tr>
<th> {{ a[3] }} </th>
<th> {{ a[4] }} </th>
<th> {{ a[6] }} </th>
<th> <a href="/alert-rm?id={{ a[0] }}&devid={{ a[2] }}"> <span class="glyphicon glyphicon-remove"</span> </a> </th>
</tr>
{% endfor %}
......@@ -32,7 +34,7 @@
</table>
</div>
{% else %}
<center> There are no alarms for given application. </center>
<center> There are no alerts for given application. </center>
{% endif %}
<br>
<center><a href="/new-alert"><button class="btn btn-primary" type="submit">Create New Alert</button></a></center>
......
......@@ -19,10 +19,6 @@
<label>Name:</label><br>
<input type="text" maxlength="30" class="form-control" id="alertname" name="alertname" required><br>
</div>
<div class="form-group">
<label>Description:</label><br>
<textarea id="alertdesc" maxlength="300" class="form-control" name="alertdesc" rows="5"></textarea>
</div>
<h3> Condition: </h3>
<h4> IF </h4>
<select class="form-control" id="devid" name="devid" onchange="ondev()" required>
......
......@@ -526,6 +526,7 @@ def dev_data(var, dest, page):
def alerts():
if 'name' in session:
alerts = nfs.get_list(session['appkey'])
print(alerts)
return render_template('public/alerts.html', alert_list=alerts[1])
else:
return redirect(url_for('index'))
......@@ -548,13 +549,9 @@ def alert():
dev = dd.get(session['appkey'], request.form['devid'])
avalue = ''
desc_ext = request.form['alertdesc'] + ' (Application '+session['appname']+' => '+dev[1][0]+'.'+request.form['varname']+' '+request.form['operation']
if request.form['operation'] == 'CHANGES':
desc_ext += ')'
else:
desc_ext += ' '+request.form['avalue']+')'
desc = dev[1][0]+'.'+request.form['varname']+' '+request.form['operation']+' '+request.form['avalue']
res = nfs.create(nid, session['appkey'], request.form['devid'], request.form['alertname'], desc_ext, 'alert', request.form['alertemail'])
res = nfs.create(nid, session['appkey'], request.form['devid'], request.form['alertname'], desc, 'alert', request.form['alertemail'])
if res[0]:
# create new function and trigger
tr.create_function(session['appkey'], request.form['devid'], nid, [request.form['varname'],request.form['operation'],avalue])
......
CREATE TABLE public.notifications (
id VARCHAR(10) UNIQUE NOT NULL,
app_key VARCHAR(30) UNIQUE NOT NULL,
id VARCHAR(10) NOT NULL,
app_key VARCHAR(30) NOT NULL,
dev_id NUMERIC(3) NOT NULL,
name VARCHAR(50) NOT NULL,
description VARCHAR(300),
......@@ -11,21 +11,20 @@ CREATE TABLE public.notifications (
CREATE TABLE public.notifications_queue (
nf_id VARCHAR(10) NOT NULL,
app_key VARCHAR(30) NOT NULL,
dev_id NUMERIC(3) NOT NULL
dev_id NUMERIC(3) NOT NULL,
fired_on TIMESTAMP(6) NOT NULL
);
ALTER TABLE ONLY public.notifications
ADD CONSTRAINT notifications_pkey PRIMARY KEY (id, app_key, dev_id);
ALTER TABLE ONLY public.notifications_queue
ADD CONSTRAINT notifications_queue_pkey PRIMARY KEY (nf_id, app_key, dev_id);
ALTER TABLE ONLY public.notifications
ADD CONSTRAINT notifications_app_key_fkey FOREIGN KEY (app_key) REFERENCES public.applications(app_key);
ALTER TABLE ONLY public.notifications_queue
ADD CONSTRAINT notifications_queue_app_key_fkey FOREIGN KEY (app_key) REFERENCES public.notifications(app_key);
ADD CONSTRAINT notifications_queue_pkey PRIMARY KEY (nf_id, app_key, dev_id);
ALTER TABLE ONLY public.notifications_queue
ADD CONSTRAINT notifications_queue_nf_id_fkey FOREIGN KEY (nf_id) REFERENCES public.notifications(id);
ADD CONSTRAINT notifications_queue_app_key_fkey FOREIGN KEY (app_key, nf_id, dev_id) REFERENCES public.notifications(app_key, id, dev_id);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment