Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladislav Rykov
THSO.server
Commits
7aa3d5d2
Commit
7aa3d5d2
authored
May 14, 2020
by
Vladislav Rykov
Browse files
mailing works, added timestamp & alert mail template
parent
1d40f9d8
Changes
8
Hide whitespace changes
Inline
Side-by-side
app/app/__pycache__/views.cpython-37.pyc
View file @
7aa3d5d2
No preview for this file type
app/app/dao/trigger/__pycache__/trigger.cpython-37.pyc
View file @
7aa3d5d2
No preview for this file type
app/app/dao/trigger/trigger.py
View file @
7aa3d5d2
...
...
@@ -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
)
...
...
app/app/templates/mailing/alert.html
0 → 100644
View file @
7aa3d5d2
<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
&
A IoT Server
</p>
app/app/templates/public/alerts.html
View file @
7aa3d5d2
...
...
@@ -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 al
arm
s for given application.
</center>
<center>
There are no al
ert
s for given application.
</center>
{% endif %}
<br>
<center><a
href=
"/new-alert"
><button
class=
"btn btn-primary"
type=
"submit"
>
Create New Alert
</button></a></center>
...
...
app/app/templates/public/new-alert.html
View file @
7aa3d5d2
...
...
@@ -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
>
...
...
app/app/views.py
View file @
7aa3d5d2
...
...
@@ -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
])
...
...
db-e.sql
View file @
7aa3d5d2
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
);
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment