Commit 0be78ca3 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

log messages added to public views

parent 3a9cf4a4
...@@ -66,6 +66,8 @@ def register(): ...@@ -66,6 +66,8 @@ def register():
session['name'] = username session['name'] = username
session['role'] = 'user' session['role'] = 'user'
app.logger.info('New registered user %s', username)
return redirect(url_for('index')) return redirect(url_for('index'))
else: else:
return redirect(url_for('login')) return redirect(url_for('login'))
...@@ -91,11 +93,15 @@ def login(): ...@@ -91,11 +93,15 @@ def login():
session['name'] = username session['name'] = username
session['role'] = res[1][2] session['role'] = res[1][2]
app.logger.info('Logged in user %s', username)
return redirect(url_for('index')) return redirect(url_for('index'))
@app.route('/logout') @app.route('/logout')
def logout(): def logout():
app.logger.info('Logged out user %s', session['name'])
session.clear() session.clear()
return redirect(url_for('login')) return redirect(url_for('login'))
...@@ -147,7 +153,11 @@ def application_create(): ...@@ -147,7 +153,11 @@ def application_create():
if not res[0]: if not res[0]:
ad.delete(appkey) ad.delete(appkey)
flash('Error: {}'.format(res[1]), 'danger') flash('Error: {}'.format(res[1]), 'danger')
app.logger.error('User %s failed to create new application - %s', session['name'], res[1])
return redirect(request.url) return redirect(request.url)
else:
app.logger.info('User %s created new application - %s', session['name'], request.form['appname'])
return redirect(url_for('applications')) return redirect(url_for('applications'))
...@@ -174,8 +184,10 @@ def application_delete(appkey): ...@@ -174,8 +184,10 @@ def application_delete(appkey):
if not res[0]: if not res[0]:
flash('Error deleting application: {}'.format(res[1]), 'danger') flash('Error deleting application: {}'.format(res[1]), 'danger')
app.logger.error('User %s failed to delete application - %s', session['name'], res[1])
return redirect(url_for('application', appkey=appkey)) return redirect(url_for('application', appkey=appkey))
else: else:
app.logger.info('User %s deleted application - %s', session['name'], appkey)
flash('Application deleted.', 'success') flash('Application deleted.', 'success')
return redirect(url_for('applications')) return redirect(url_for('applications'))
...@@ -212,15 +224,19 @@ def application_add_device(appkey): ...@@ -212,15 +224,19 @@ def application_add_device(appkey):
res = dd.create_ddm(request.form['devname'], request.form['devid'], appkey, request.form['devdesc'], ddmin) res = dd.create_ddm(request.form['devname'], request.form['devid'], appkey, request.form['devdesc'], ddmin)
if not res[0]: if not res[0]:
app.logger.error('User %s failed to add device for application %s - %s', session['name'], appkey, res[1])
flash('Error: {}'.format(res[1]), 'danger') flash('Error: {}'.format(res[1]), 'danger')
return redirect(request.url) return redirect(request.url)
else: else:
res = data.create_table_ddm(appkey, request.form['devid']) res = data.create_table_ddm(appkey, request.form['devid'])
if not res[0]: if not res[0]:
app.logger.error('User %s failed to add device for application %s - %s', session['name'], appkey, res[1])
dd.delete(session['appkey'], request.form['devid']) dd.delete(session['appkey'], request.form['devid'])
flash('Error: {}'.format(res[1]), 'danger') flash('Error: {}'.format(res[1]), 'danger')
return redirect(request.url) return redirect(request.url)
else: else:
app.logger.info('User %s added new device %s for application %s', session['name'], request.form['devname'], appkey)
flash('Device added', 'success')
return redirect(url_for('application', appkey=appkey)) return redirect(url_for('application', appkey=appkey))
...@@ -238,6 +254,12 @@ def application_device_delete(appkey, devid): ...@@ -238,6 +254,12 @@ def application_device_delete(appkey, devid):
data.delete_table(appkey, devid) data.delete_table(appkey, devid)
res = dd.delete(appkey, devid) res = dd.delete(appkey, devid)
if not res[0]:
app.logger.error('User %s failed to delete device %s for application %s - %s', session['name'], devid, appkey, res[1])
flash('Failed to delete device: {}'.format(res[1]), 'danger')
redirect(url_for('application_device_settings', appkey=appkey, devid=devid))
else:
app.logger.info('User %s deleted for application %s device %s', session['name'], appkey, devid)
flash('Device removed.', 'success') flash('Device removed.', 'success')
return redirect(url_for('application', appkey=appkey)) return redirect(url_for('application', appkey=appkey))
...@@ -263,12 +285,20 @@ def application_device_configuration(appkey, devid): ...@@ -263,12 +285,20 @@ def application_device_configuration(appkey, devid):
return render_template('new/public/device-configuration.html', dev=dev, app=ap, config_list=config_list) return render_template('new/public/device-configuration.html', dev=dev, app=ap, config_list=config_list)
elif request.method == 'POST': elif request.method == 'POST':
base64_args = misc.pend_base64_encode(request.form['arg'], request.form['confid']) base64_args = misc.pend_base64_encode(request.form['arg'], request.form['confid'])
pend.create(appkey, devid, base64_args) res = pend.create(appkey, devid, base64_args)
if not res[0]:
app.logger.error('User %s failed to queue config message %s for the app %s device %s - %s', session['name'], base64_args, appkey, devid, res[1])
flash('Failed to enqueue message: {}'.format(res[1]), 'danger')
redirect(url_for('application_device_settings', appkey=appkey, devid=devid))
else:
app.logger.info('User %s deleted device %s for application %s', session['name'], devid, appkey)
flash('Message enqueued', 'success') flash('Message enqueued', 'success')
return '', 201 return '', 201
@app.route('/application/<appkey>/device/<devid>/download-csv') @app.route('/application/<appkey>/device/<devid>/download-csv')
@decorators.restricted('interface') @decorators.restricted('interface')
@decorators.application_protected @decorators.application_protected
...@@ -303,6 +333,8 @@ def application_device_download_csv(appkey, devid): ...@@ -303,6 +333,8 @@ def application_device_download_csv(appkey, devid):
f.write(',') f.write(',')
f.write('\n') f.write('\n')
app.logger.info('User %s downloaded data for application %s device %s', session['name'], appkey, devid)
return send_from_directory(app.config['DATA_DOWNLOAD_DIR'], fn, as_attachment=True) return send_from_directory(app.config['DATA_DOWNLOAD_DIR'], fn, as_attachment=True)
...@@ -343,8 +375,10 @@ def application_device_configuration_remove(appkey, devid): ...@@ -343,8 +375,10 @@ def application_device_configuration_remove(appkey, devid):
res = pend.delete(appkey, devid, request.args.get('conf')+'_') res = pend.delete(appkey, devid, request.args.get('conf')+'_')
if res[0]: if res[0]:
app.logger.info('User %s deleted config messsage %s for application %s device %s', session['name'], request.args.get('conf'), appkey, devid)
flash('Configuration message successfully removed.','success') flash('Configuration message successfully removed.','success')
else: else:
app.logger.error('User %s failed to delet config messsage %s for application %s device %s - %s', session['name'], request.args.get('conf'), appkey, devid, res[1])
flash('Error removing configuration message: {}'.format(res[1]), 'danger') flash('Error removing configuration message: {}'.format(res[1]), 'danger')
return '', 200 return '', 200
...@@ -392,9 +426,11 @@ def delete_account(): ...@@ -392,9 +426,11 @@ def delete_account():
res = ud.delete(user[1][0]) res = ud.delete(user[1][0])
if not res[0]: if not res[0]:
app.logger.error('User %s failed to delete the account - %s', session['name'], res[1])
flash('Error: {}'.format(res[1]), 'danger') flash('Error: {}'.format(res[1]), 'danger')
return render_template('new/public/settings.html', user=session['name']) return render_template('new/public/settings.html', user=session['name'])
else: else:
app.logger.warning('User %s deleted the account', session['name'])
flash('User {} was successfully deleted'.format(request.args.get('name')), 'success') flash('User {} was successfully deleted'.format(request.args.get('name')), 'success')
return redirect(url_for('login')) return redirect(url_for('login'))
...@@ -481,11 +517,14 @@ def application_new_alert(appkey): ...@@ -481,11 +517,14 @@ def application_new_alert(appkey):
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['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('User %s created alert %s - %s for application %s', 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('User %s failed to create alert for application %s - %s', 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('User %s failed to create alert for application %s - %s', 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)
...@@ -500,9 +539,11 @@ def application_notification_remove(appkey, ntype): ...@@ -500,9 +539,11 @@ def application_notification_remove(appkey, ntype):
res = nfs.delete(appkey, request.args.get('devid'), request.args.get('id')) res = nfs.delete(appkey, request.args.get('devid'), request.args.get('id'))
if res[0]: if res[0]:
app.logger.info('User %s deleted %s %s for application %s', session['name'], ntype, request.args.get('id'), appkey)
flash('{} removed'.format(ntype.capitalize()), 'success') flash('{} removed'.format(ntype.capitalize()), 'success')
return '', 200 return '', 200
else: else:
app.logger.error('User %s failed to delete %s %s for application %s - %s', session['name'], ntype, request.args.get('id'), appkey, res[1])
flash('{} cannot be removed : {}'.format(ntype.capitalize(), res[1]), 'danger') flash('{} cannot be removed : {}'.format(ntype.capitalize(), res[1]), 'danger')
return '', 500 return '', 500
...@@ -541,12 +582,15 @@ def application_new_automation(appkey): ...@@ -541,12 +582,15 @@ def application_new_automation(appkey):
# 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']],'automation', action) t = tr.create_function_rt(appkey, request.form['devid'], nid, [request.form['varname'],request.form['operation'],request.form['avalue']],'automation', action)
tr.create(appkey, request.form['devid'], nid) tr.create(appkey, request.form['devid'], nid)
app.logger.info('User %s created automation %s - %s for application %s', session['name'], nid, desc, appkey)
flash('Automation created', 'success') flash('Automation created', 'success')
return redirect(url_for('application_automation', appkey=appkey)) return redirect(url_for('application_automation', appkey=appkey))
else: else:
app.logger.error('User %s failed to create automation for application %s - %s', 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('User %s failed to create automation for application %s - %s', 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)
......
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