chg: [UI-dashboard] convert time to local

This commit is contained in:
Terrtia 2018-07-26 10:34:43 +02:00
parent 5ad5939bd5
commit 0a82482db4
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
3 changed files with 27 additions and 8 deletions

View file

@ -7,11 +7,12 @@
import json import json
import os import os
import datetime import datetime
import time
import flask import flask
from Date import Date from Date import Date
from flask import Flask, render_template, jsonify, request, Blueprint from flask import Flask, render_template, jsonify, request, Blueprint, url_for
# ============ VARIABLES ============ # ============ VARIABLES ============
import Flask_config import Flask_config
@ -38,8 +39,6 @@ def event_stream():
msg = {'channel': channel, 'type': type, 'pattern': pattern, 'data': data} msg = {'channel': channel, 'type': type, 'pattern': pattern, 'data': data}
level = (msg['channel']).split('.')[1] level = (msg['channel']).split('.')[1]
#if msg['type'] == 'pmessage' and (level == "WARNING" or level == "CRITICAL"):
#print(msg)
if msg['type'] == 'pmessage' and level != "DEBUG": if msg['type'] == 'pmessage' and level != "DEBUG":
yield 'data: %s\n\n' % json.dumps(msg) yield 'data: %s\n\n' % json.dumps(msg)
@ -81,16 +80,26 @@ def dashboard_alert(log):
# check if we need to display this log # check if we need to display this log
if len(log)>50: if len(log)>50:
date = log[1:5]+log[6:8]+log[9:11] date = log[1:5]+log[6:8]+log[9:11]
time = log[12:20] utc_str = log[1:20]
log = log[46:].split(';') log = log[46:].split(';')
if len(log) == 6: if len(log) == 6:
res = {'date': date, 'time': time, 'script': log[0], 'domain': log[1], 'date_paste': log[2], 'paste': log[3], 'message': log[4]} time = datetime_from_utc_to_local(utc_str)
path = url_for('showsavedpastes.showsavedpaste',paste=log[5])
res = {'date': date, 'time': time, 'script': log[0], 'domain': log[1], 'date_paste': log[2],
'paste': log[3], 'message': log[4], 'path': path}
return res return res
else: else:
return False return False
else: else:
return False return False
def datetime_from_utc_to_local(utc_str):
utc_datetime = datetime.datetime.strptime(utc_str, '%Y-%m-%d %H:%M:%S')
now_timestamp = time.time()
offset = datetime.datetime.fromtimestamp(now_timestamp) - datetime.datetime.utcfromtimestamp(now_timestamp)
local_time_str = (utc_datetime + offset).strftime('%H:%M:%S')
return local_time_str
# ============ ROUTES ============ # ============ ROUTES ============
@ -110,7 +119,7 @@ def get_last_logs_json():
last_logs = [] last_logs = []
date_range = get_date_range(date, max_day_search) date_range = get_date_range(date, max_day_search)
while max_day_search != day_search | warning_found != warning_to_found: while max_day_search != day_search and warning_found != warning_to_found:
filename_warning_log = 'logs/Script_warn-'+ date_range[day_search] +'.log' filename_warning_log = 'logs/Script_warn-'+ date_range[day_search] +'.log'
filename_log = os.path.join(os.environ['AIL_HOME'], filename_warning_log) filename_log = os.path.join(os.environ['AIL_HOME'], filename_warning_log)
@ -136,7 +145,7 @@ def get_last_logs_json():
# check previous warning log file # check previous warning log file
day_search = day_search + 1 day_search = day_search + 1
return jsonify(last_logs) return jsonify(list(reversed(last_logs)))
@dashboard.route("/_stuff", methods=['GET']) @dashboard.route("/_stuff", methods=['GET'])

View file

@ -206,6 +206,7 @@
var msage = document.createElement('TD') var msage = document.createElement('TD')
var inspect = document.createElement('TD') var inspect = document.createElement('TD')
tr.className = "warning";
time.appendChild(document.createTextNode(d.time)) time.appendChild(document.createTextNode(d.time))
chan.appendChild(document.createTextNode('Script')) chan.appendChild(document.createTextNode('Script'))
level.appendChild(document.createTextNode('WARNING')) level.appendChild(document.createTextNode('WARNING'))
@ -226,7 +227,15 @@
msage.appendChild(iconspan); msage.appendChild(iconspan);
msage.appendChild(document.createTextNode(message.join(" "))); msage.appendChild(document.createTextNode(message.join(" ")));
inspect.appendChild(document.createTextNode(' ')) var action_icon_a = document.createElement("A");
action_icon_a.setAttribute("TARGET", "_blank");
action_icon_a.setAttribute("HREF", d.path);
var action_icon_span = document.createElement('SPAN');
action_icon_span.className = "fa fa-search-plus";
action_icon_a.appendChild(action_icon_span);
inspect.appendChild(action_icon_a)
inspect.setAttribute("style", "text-align:center;");
tr.appendChild(time) tr.appendChild(time)
tr.appendChild(chan); tr.appendChild(chan);

View file

@ -249,6 +249,7 @@ function create_log_table(obj_json) {
action_icon_a.appendChild(action_icon_span); action_icon_a.appendChild(action_icon_span);
inspect.appendChild(action_icon_a); inspect.appendChild(action_icon_a);
inspect.setAttribute("style", "text-align:center;");
tr.appendChild(time) tr.appendChild(time)
tr.appendChild(chan); tr.appendChild(chan);