Commit afc703fd authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

telegram alerts incorporated into user views

parent 6f9b910b
...@@ -34,3 +34,340 @@ LINE 5: ('dev1 test', '1', 'dsds', '\x7b226d6f64656c223a2022... ...@@ -34,3 +34,340 @@ LINE 5: ('dev1 test', '1', 'dsds', '\x7b226d6f64656c223a2022...
[2020-06-11 09:54:28,518] WARNING in views_admin: Administrator admin deleted application 5e4932cc for user-user [2020-06-11 09:54:28,518] WARNING in views_admin: Administrator admin deleted application 5e4932cc for user-user
[2020-06-11 09:55:16,026] INFO in views: User admin created new application - test [2020-06-11 09:55:16,026] INFO in views: User admin created new application - test
[2020-06-11 10:01:02,029] INFO in views: User admin deleted application - 649fd3ab [2020-06-11 10:01:02,029] INFO in views: User admin deleted application - 649fd3ab
[2020-06-30 10:56:32,460] INFO in views: Logged in superuser admin
[2020-06-30 10:57:05,008] INFO in views: Logged in superuser admin
[2020-06-30 12:36:13,017] ERROR in views: superuser admin failed to create alert for application 3b56f3d8 - 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
[2020-06-30 12:38:40,214] ERROR in views: superuser admin failed to create alert for application 3b56f3d8 - 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
[2020-06-30 12:40:31,061] ERROR in views: superuser admin failed to create alert for application 3b56f3d8 - 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
[2020-06-30 12:41:36,826] ERROR in views: superuser admin failed to create alert for application 3b56f3d8 - 'alert'
[2020-06-30 13:05:01,368] ERROR in views: superuser admin failed to create alert for application 3b56f3d8 - Exception: 'alert'
[2020-06-30 13:06:54,240] INFO in views: superuser admin created alert 884e51 - ddmjson.temperature > 0 for application 3b56f3d8
[2020-06-30 14:27:24,473] ERROR in app: Exception on /application/3b56f3d8/alerts [GET]
Traceback (most recent call last):
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./app/helpers/decorators.py", line 23, in restricted_function
return f(*args, **kwargs)
File "./app/helpers/decorators.py", line 35, in protected_function
return f(*args, **kwargs)
File "./app/views.py", line 495, in application_alerts
return render_template('new/public/alerts.html', alert_list=alerts[1], app=ap[1])
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/templating.py", line 140, in render_template
ctx.app,
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/templating.py", line 120, in _render
rv = template.render(context)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 1090, in render
self.environment.handle_exception()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "/home/pi/thso.server/app/app/templates/new/public/alerts.html", line 1, in top-level template code
{% extends 'logged_layout.html' %}
File "/home/pi/thso.server/app/app/templates/logged_layout.html", line 1, in top-level template code
{% extends 'general_layout.html' %}
File "/home/pi/thso.server/app/app/templates/general_layout.html", line 35, in top-level template code
{% block content %} {% endblock %}
File "/home/pi/thso.server/app/app/templates/logged_layout.html", line 196, in block "content"
{% block body %} {% endblock %}
File "/home/pi/thso.server/app/app/templates/new/public/alerts.html", line 36, in block "body"
{% for a in alert_list %}
TypeError: 'IndexError' object is not iterable
[2020-06-30 14:27:58,458] ERROR in app: Exception on /application/3b56f3d8/alerts [GET]
Traceback (most recent call last):
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./app/helpers/decorators.py", line 23, in restricted_function
return f(*args, **kwargs)
File "./app/helpers/decorators.py", line 35, in protected_function
return f(*args, **kwargs)
File "./app/views.py", line 495, in application_alerts
return render_template('new/public/alerts.html', alert_list=alerts[1], app=ap[1])
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/templating.py", line 140, in render_template
ctx.app,
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/templating.py", line 120, in _render
rv = template.render(context)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 1090, in render
self.environment.handle_exception()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "/home/pi/thso.server/app/app/templates/new/public/alerts.html", line 1, in top-level template code
{% extends 'logged_layout.html' %}
File "/home/pi/thso.server/app/app/templates/logged_layout.html", line 1, in top-level template code
{% extends 'general_layout.html' %}
File "/home/pi/thso.server/app/app/templates/general_layout.html", line 35, in top-level template code
{% block content %} {% endblock %}
File "/home/pi/thso.server/app/app/templates/logged_layout.html", line 196, in block "content"
{% block body %} {% endblock %}
File "/home/pi/thso.server/app/app/templates/new/public/alerts.html", line 36, in block "body"
{% for a in alert_list %}
TypeError: 'IndexError' object is not iterable
[2020-06-30 14:29:43,392] ERROR in app: Exception on /application/3b56f3d8/alerts [GET]
Traceback (most recent call last):
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./app/helpers/decorators.py", line 23, in restricted_function
return f(*args, **kwargs)
File "./app/helpers/decorators.py", line 35, in protected_function
return f(*args, **kwargs)
File "./app/views.py", line 495, in application_alerts
return render_template('new/public/alerts.html', alert_list=alerts[1], app=ap[1])
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/templating.py", line 140, in render_template
ctx.app,
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/templating.py", line 120, in _render
rv = template.render(context)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 1090, in render
self.environment.handle_exception()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "/home/pi/thso.server/app/app/templates/new/public/alerts.html", line 1, in top-level template code
{% extends 'logged_layout.html' %}
File "/home/pi/thso.server/app/app/templates/logged_layout.html", line 1, in top-level template code
{% extends 'general_layout.html' %}
File "/home/pi/thso.server/app/app/templates/general_layout.html", line 35, in top-level template code
{% block content %} {% endblock %}
File "/home/pi/thso.server/app/app/templates/logged_layout.html", line 196, in block "content"
{% block body %} {% endblock %}
File "/home/pi/thso.server/app/app/templates/new/public/alerts.html", line 36, in block "body"
{% for a in alert_list %}
TypeError: 'IndexError' object is not iterable
[2020-06-30 14:36:01,025] ERROR in app: Exception on /application/3b56f3d8/alerts [GET]
Traceback (most recent call last):
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./app/helpers/decorators.py", line 23, in restricted_function
return f(*args, **kwargs)
File "./app/helpers/decorators.py", line 35, in protected_function
return f(*args, **kwargs)
File "./app/views.py", line 495, in application_alerts
return render_template('new/public/alerts.html', alert_list=alerts[1], app=ap[1])
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/templating.py", line 140, in render_template
ctx.app,
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/templating.py", line 120, in _render
rv = template.render(context)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 1090, in render
self.environment.handle_exception()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "/home/pi/thso.server/app/app/templates/new/public/alerts.html", line 1, in top-level template code
{% extends 'logged_layout.html' %}
File "/home/pi/thso.server/app/app/templates/logged_layout.html", line 1, in top-level template code
{% extends 'general_layout.html' %}
File "/home/pi/thso.server/app/app/templates/general_layout.html", line 35, in top-level template code
{% block content %} {% endblock %}
File "/home/pi/thso.server/app/app/templates/logged_layout.html", line 196, in block "content"
{% block body %} {% endblock %}
File "/home/pi/thso.server/app/app/templates/new/public/alerts.html", line 36, in block "body"
{% for a in alert_list %}
TypeError: 'IndexError' object is not iterable
[2020-06-30 14:36:08,046] ERROR in app: Exception on /application/3b56f3d8/alerts [GET]
Traceback (most recent call last):
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./app/helpers/decorators.py", line 23, in restricted_function
return f(*args, **kwargs)
File "./app/helpers/decorators.py", line 35, in protected_function
return f(*args, **kwargs)
File "./app/views.py", line 495, in application_alerts
return render_template('new/public/alerts.html', alert_list=alerts[1], app=ap[1])
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/templating.py", line 140, in render_template
ctx.app,
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/templating.py", line 120, in _render
rv = template.render(context)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 1090, in render
self.environment.handle_exception()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "/home/pi/thso.server/app/app/templates/new/public/alerts.html", line 1, in top-level template code
{% extends 'logged_layout.html' %}
File "/home/pi/thso.server/app/app/templates/logged_layout.html", line 1, in top-level template code
{% extends 'general_layout.html' %}
File "/home/pi/thso.server/app/app/templates/general_layout.html", line 35, in top-level template code
{% block content %} {% endblock %}
File "/home/pi/thso.server/app/app/templates/logged_layout.html", line 196, in block "content"
{% block body %} {% endblock %}
File "/home/pi/thso.server/app/app/templates/new/public/alerts.html", line 36, in block "body"
{% for a in alert_list %}
TypeError: 'IndexError' object is not iterable
[2020-06-30 16:52:38,747] INFO in views: superuser admin deleted alert 884e51 for application 3b56f3d8
[2020-06-30 16:52:41,086] INFO in views: superuser admin deleted alert 7201c2 for application 3b56f3d8
[2020-06-30 17:02:58,029] ERROR in app: Exception on /application/3b56f3d8/device/1/download-csv [GET]
Traceback (most recent call last):
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./app/helpers/decorators.py", line 23, in restricted_function
return f(*args, **kwargs)
File "./app/helpers/decorators.py", line 35, in protected_function
return f(*args, **kwargs)
File "./app/views.py", line 332, in application_device_download_csv
f.write(str(row[2][v]))
TypeError: memoryview: invalid slice key
[2020-06-30 17:10:07,673] ERROR in app: Exception on /recent-activity [GET]
Traceback (most recent call last):
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./app/helpers/decorators.py", line 23, in restricted_function
return f(*args, **kwargs)
File "./app/views.py", line 366, in recent_activity
ra += '<tr><th scope="row">'+r[1]+'</th><th>'+r[2]+'</th><th>'+r[0]+'</th><th>'+str(ddm.read_data(r[3], dev[3]))+'</th></tr>'
File "./app/helpers/device_data_model.py", line 147, in read_data
return json.loads(data.decode('utf-8'))
AttributeError: 'memoryview' object has no attribute 'decode'
[2020-06-30 17:17:18,567] ERROR in app: Exception on /application/3b56f3d8/alerts [GET]
Traceback (most recent call last):
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./app/helpers/decorators.py", line 23, in restricted_function
return f(*args, **kwargs)
File "./app/helpers/decorators.py", line 35, in protected_function
return f(*args, **kwargs)
File "./app/views.py", line 495, in application_alerts
return render_template('new/public/alerts.html', alert_list=alerts[1], app=ap[1])
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/templating.py", line 138, in render_template
ctx.app.jinja_env.get_or_select_template(template_name_or_list),
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 930, in get_or_select_template
return self.get_template(template_name_or_list, parent, globals)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 883, in get_template
return self._load_template(name, self.make_globals(globals))
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 857, in _load_template
template = self.loader.load(self, name, globals)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/loaders.py", line 127, in load
code = environment.compile(source, name, filename)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 638, in compile
self.handle_exception(source=source_hint)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "/home/pi/thso.server/app/app/templates/new/public/alerts.html", line 41, in template
<th> {{ a[5]|split('_')[1] }} </th>
jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got '['
[2020-06-30 17:17:44,630] ERROR in app: Exception on /application/3b56f3d8/alerts [GET]
Traceback (most recent call last):
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./app/helpers/decorators.py", line 23, in restricted_function
return f(*args, **kwargs)
File "./app/helpers/decorators.py", line 35, in protected_function
return f(*args, **kwargs)
File "./app/views.py", line 495, in application_alerts
return render_template('new/public/alerts.html', alert_list=alerts[1], app=ap[1])
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/templating.py", line 138, in render_template
ctx.app.jinja_env.get_or_select_template(template_name_or_list),
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 930, in get_or_select_template
return self.get_template(template_name_or_list, parent, globals)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 883, in get_template
return self._load_template(name, self.make_globals(globals))
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 857, in _load_template
template = self.loader.load(self, name, globals)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/loaders.py", line 127, in load
code = environment.compile(source, name, filename)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 638, in compile
self.handle_exception(source=source_hint)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/home/pi/thso.server/env/lib/python3.7/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "/home/pi/thso.server/app/app/templates/new/public/alerts.html", line 41, in template
<th> {{ a[5]|split('_')[1] }} </th>
jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got '['
[2020-06-30 17:18:31,111] INFO in views: superuser admin created alert 8bbd83 - devmpack.lever == 1 for application 3b56f3d8
[2020-06-30 17:19:11,846] INFO in views: superuser admin created alert ddb142 - ddmjson.lever == 0 for application 3b56f3d8
...@@ -83,10 +83,10 @@ def get_alerts_list(cur, appkey): ...@@ -83,10 +83,10 @@ def get_alerts_list(cur, appkey):
WHERE WHERE
app_key = %s app_key = %s
AND AND
action_type = 'alert' action_type LIKE 'alert_%%'
""" """
cur.execute(query, (appkey,)) cur.execute(query, (appkey,))
return (True, cur.fetchall()) return (True, cur.fetchall())
......
...@@ -9,6 +9,8 @@ import app.helpers.misc as misc ...@@ -9,6 +9,8 @@ import app.helpers.misc as misc
import app.dao.device.device as dd import app.dao.device.device as dd
import app.helpers.device_data_model as ddm import app.helpers.device_data_model as ddm
import app.helpers.telegram_sender as ts
from binascii import unhexlify from binascii import unhexlify
@thread @thread
...@@ -28,10 +30,14 @@ def listening(): ...@@ -28,10 +30,14 @@ def listening():
dev = dd.get(d['appkey'], d['devid'])[1] dev = dd.get(d['appkey'], d['devid'])[1]
d['message']['data'] = ddm.read_data(unhexlify(d['message']['data'][2:]), dev[3]) d['message']['data'] = ddm.read_data(unhexlify(d['message']['data'][2:]), dev[3])
if d['lvalue'] in d['message']['data'] and (d['op'][0] == 'O' or eval(str(d['message']['data'][d['lvalue']]) + d['op'] + d['rvalue'])): if d['lvalue'] in d['message']['data'] and (d['op'][0] == 'O' or eval(str(d['message']['data'][d['lvalue']]) + d['op'] + d['rvalue'])):
if d['action_type'] == 'alert': if d['action_type'] == 'alert_email':
# send mail # send mail
n = nf.get(d['appkey'], d['devid'], d['nfid'])[1] n = nf.get(d['appkey'], d['devid'], d['nfid'])[1]
mailer.send_mail(app, n, d) mailer.send_mail(app, n, d)
elif d['action_type'] == 'alert_telegram':
# send telegram message
n = nf.get(d['appkey'], d['devid'], d['nfid'])[1]
ts.send_message(app, n, d)
elif d['action_type'] == 'automation': elif d['action_type'] == 'automation':
# enqueue confid # enqueue confid
# action format: '<devid>#<confid>#<arg>' # action format: '<devid>#<confid>#<arg>'
......
from flask import render_template
import app.dao.application.application as ad
import telegram
def send(msg, chat_id, token):
bot = telegram.Bot(token=token)
bot.sendMessage(chat_id, text=msg, parse_mode=telegram.ParseMode.HTML)
def send_message(app, alert, fired):
with app.app_context():
ap = ad.get(fired['appkey'])
context = {'alert':alert, 'username':ap[1][2], 'appname':ap[1][0], 'message':fired['message']}
msg = render_template('mailing/telegram_alert.html', **context)
send(msg, alert[6], app.config['TELEGRAM_BOT_TOKEN'])
Hello {{ username }},
The alert {{ alert[3] }} from your {{ appname }} application has been fired at {{ message['timedate'] }} with the next message: {{ message['data'] }}.
Remember the condition of the alert was {{ alert[4] }}.
Take care,
HPC&A IoT Server
...@@ -29,7 +29,8 @@ ...@@ -29,7 +29,8 @@
<thead> <thead>
<th> Name </th> <th> Name </th>
<th> Condition </th> <th> Condition </th>
<th> Email </th> <th> Alert Type </th>
<th> Receiver </th>
<th> </th> <th> </th>
</thead> </thead>
<tbody> <tbody>
...@@ -37,6 +38,7 @@ ...@@ -37,6 +38,7 @@
<tr> <tr>
<th> {{ a[3] }} </th> <th> {{ a[3] }} </th>
<th> {{ a[4] }} </th> <th> {{ a[4] }} </th>
<th> {{ a[5].split('_')[1] }} </th>
<th> {{ a[6] }} </th> <th> {{ a[6] }} </th>
<th> <a href="javascript:void(0)" onclick="return remove_alert('{{ a[0] }}', '{{ a[2] }}');"> <span class="fa fa-remove"</span> </a> </th> <th> <a href="javascript:void(0)" onclick="return remove_alert('{{ a[0] }}', '{{ a[2] }}');"> <span class="fa fa-remove"</span> </a> </th>
</tr> </tr>
......
...@@ -51,17 +51,25 @@ ...@@ -51,17 +51,25 @@
<p> Use n (e.g. 5) for integer notation, n.n (e.g. 5.0) for float, and true or false for boolean. <br> <p> Use n (e.g. 5) for integer notation, n.n (e.g. 5.0) for float, and true or false for boolean. <br>
Keep types consistently for each variable for both, alerts and automations. </p> Keep types consistently for each variable for both, alerts and automations. </p>
--> -->
</form>
<br> <br>
<h4> THEN </h4> <h4> THEN </h4>
<h5> Send email to: </h5> <h5> Select alert type: </h5>
<input class="form-control" type="email" form="alertform" id="alertemail" name="alertemail" placeholder="Type email..." required> <select class='form-control notifelem' name='alerttype' id='alerttype' onchange="return onalerttype();" required>
<option selected="selected" value="email">Email</option>
<option value="telegram">Telegram Message</option>
<option value="sms">SMS Message</option>
</select>
<br>
<input class="form-control" type="text" id="alertemail" name="alertemail" placeholder="Type email..." required>
<p id="hint"></p>
<br><br> <br><br>
<div class="form-group"> <div class="form-group">
<button type="submit" id="submit" form="alertform" class="btn btn-primary">Create Alert</button> <button type="submit" id="submit" class="btn btn-primary">Create Alert</button>
</div> </div>
</form>
</div> </div>
</div> </div>
...@@ -110,5 +118,21 @@ ...@@ -110,5 +118,21 @@
input.setAttribute("required", "true"); input.setAttribute("required", "true");
} }
} }
function onalerttype() {
var dev_sel = document.getElementById("alerttype");
var sel_op = dev_sel.options[dev_sel.selectedIndex].text;
var input = document.getElementById("alertemail");
$("#hint").text("");
if (sel_op[0] == "E") {
input.setAttribute("placeholder", "Type email...");
} else if (sel_op[0] == "T") {
input.setAttribute("placeholder", "Type chat id...");
$("#hint").text("Hint: send /start to @userinfobot bot.");
} else if (sel_op[0] == "S") {
input.setAttribute("placeholder", "Type telephone number...");
}
}
</script> </script>
{% endblock %} {% endblock %}
...@@ -511,20 +511,20 @@ def application_new_alert(appkey): ...@@ -511,20 +511,20 @@ def application_new_alert(appkey):
try: try:
desc = dev[1][0]+'.'+request.form['varname']+' '+request.form['operation']+' '+request.form['avalue'] desc = dev[1][0]+'.'+request.form['varname']+' '+request.form['operation']+' '+request.form['avalue']
res = nfs.create(nid, appkey, request.form['devid'], request.form['alertname'], desc, 'alert', request.form['alertemail']) res = nfs.create(nid, appkey, request.form['devid'], request.form['alertname'], desc, 'alert_'+request.form['alerttype'], request.form['alertemail'])
if res[0]: if res[0]:
# create new function and trigger # create new function and trigger
t = tr.create_function_rt(appkey, request.form['devid'], nid, [request.form['varname'],request.form['operation'],request.form['avalue']],'alert',request.form['alertemail']) t = tr.create_function_rt(appkey, request.form['devid'], nid, [request.form['varname'],request.form['operation'],request.form['avalue']],'alert_'+request.form['alerttype'], request.form['alertemail'])
t = tr.create(appkey, request.form['devid'], nid) t = tr.create(appkey, request.form['devid'], nid)
flash('Alert created', 'success') flash('Alert created', 'success')
app.logger.info('%s %s created alert %s - %s for application %s', session['alert'], session['name'], nid, desc, appkey) app.logger.info('%s %s created alert %s - %s for application %s', session['role'], session['name'], nid, desc, appkey)
return redirect(url_for('application_alerts', appkey=appkey)) return redirect(url_for('application_alerts', appkey=appkey))
else: else:
app.logger.error('%s %s failed to create alert for application %s - %s', session['role'], session['name'], appkey, res[1]) app.logger.error('%s %s failed to create alert for application %s - %s', session['role'], session['name'], appkey, res[1])
flash('Error creating new alert: {}'.format(res[1]), 'danger') flash('Error creating new alert: {}'.format(res[1]), 'danger')
return redirect(request.url) return redirect(request.url)
except Exception as e: except Exception as e:
app.logger.error('%s %s failed to create alert for application %s - %s', session['role'], session['name'], appkey, e) app.logger.error('%s %s failed to create alert for application %s - Exception: %s', session['role'], session['name'], appkey, e)
flash('Error creating new alert: {}. Make sure you have filled all form fields.'.format(e), 'danger') flash('Error creating new alert: {}. Make sure you have filled all form fields.'.format(e), 'danger')
return redirect(request.url) return redirect(request.url)
......
...@@ -32,6 +32,8 @@ class Config(object): ...@@ -32,6 +32,8 @@ class Config(object):
MAIL_PASSWORD = 'HPC&A10T.' MAIL_PASSWORD = 'HPC&A10T.'
MAIL_DEFAULT_SENDER = 'hpcaiotserver@gmail.com' MAIL_DEFAULT_SENDER = 'hpcaiotserver@gmail.com'
TELEGRAM_BOT_TOKEN = '1240239295:AAE-RLGTRmUxds_yzk5l5mtl-hLhOaC_-50'
# in minutes # in minutes
FIRE_NOTIFICATIONS_INTERVAL = 1 FIRE_NOTIFICATIONS_INTERVAL = 1
......
APScheduler==3.6.3 APScheduler==3.6.3
bcrypt==3.1.7 bcrypt==3.1.7
blinker==1.4 blinker==1.4
certifi==2020.6.20
cffi==1.14.0 cffi==1.14.0
click==7.1.1 click==7.1.1
cryptography==2.9.2
decorator==4.4.2
Flask==1.1.2 Flask==1.1.2
Flask-Mail==0.9.1 Flask-Mail==0.9.1
itsdangerous==1.1.0 itsdangerous==1.1.0
...@@ -12,8 +15,10 @@ msgpack==1.0.0 ...@@ -12,8 +15,10 @@ msgpack==1.0.0
pgpubsub==0.0.5 pgpubsub==0.0.5
psycopg2==2.8.5 psycopg2==2.8.5
pycparser==2.20 pycparser==2.20
python-telegram-bot==12.8
pytz==2019.3 pytz==2019.3
six==1.14.0 six==1.14.0
tornado==6.0.4
tzlocal==2.0.0 tzlocal==2.0.0
uWSGI==2.0.18 uWSGI==2.0.18
Werkzeug==1.0.1 Werkzeug==1.0.1
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