chg: [server UI v0.1] add UI v0.1

pull/8/head
Terrtia 2019-01-21 16:53:40 +01:00
parent c37250f869
commit 7ff0f9ccdb
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
6 changed files with 205 additions and 17 deletions

View File

@ -253,14 +253,20 @@ class Echo(Protocol, TimeoutMixin):
if not self.data_saved:
redis_server_stream.sadd('session_uuid:{}'.format(data_header['type']), self.session_uuid.encode())
redis_server_stream.hset('map-type:session_uuid-uuid:{}'.format(data_header['type']), self.session_uuid, data_header['uuid_header'])
redis_server_metadata.hdel('metadata_uuid:{}'.format(data_header['uuid_header']), 'Error')
self.data_saved = True
else:
logger.warning("stream exceed max entries limit, uuid={}, session_uuid={}, type={}".format(data_header['uuid_header'], self.session_uuid, data_header['type']))
## TODO: FIXME
redis_server_metadata.hset('metadata_uuid:{}'.format(data_header['uuid_header']), 'Error', 'Error: stream exceed max entries limit')
self.transport.abortConnection()
else:
print('hmac do not match')
print(data)
logger.debug("HMAC don't match, uuid={}, session_uuid={}".format(data_header['uuid_header'], self.session_uuid))
## TODO: FIXME
redis_server_metadata.hset('metadata_uuid:{}'.format(data_header['uuid_header']), 'Error', 'Error: HMAC don\'t match')

View File

@ -14,6 +14,14 @@ baseUrl = ''
if baseUrl != '':
baseUrl = '/'+baseUrl
host_redis_stream = "localhost"
port_redis_stream = 6379
redis_server_stream = redis.StrictRedis(
host=host_redis_stream,
port=port_redis_stream,
db=0)
host_redis_metadata = "localhost"
port_redis_metadata= 6380
@ -29,7 +37,8 @@ app.config['MAX_CONTENT_LENGTH'] = 900 * 1024 * 1024
# ========== ROUTES ============
@app.route('/')
def index():
return render_template("index.html")
date = datetime.datetime.now().strftime("%Y/%m/%d")
return render_template("index.html", date=date)
@app.route('/_json_daily_uuid_stats')
def _json_daily_uuid_stats():
@ -42,5 +51,42 @@ def _json_daily_uuid_stats():
return jsonify(data_daily_uuid)
@app.route('/_json_daily_type_stats')
def _json_daily_type_stats():
date = datetime.datetime.now().strftime("%Y%m%d")
daily_uuid = redis_server_metadata.zrange('daily_type:{}'.format(date), 0, -1, withscores=True)
data_daily_uuid = []
for result in daily_uuid:
data_daily_uuid.append({"key": result[0], "value": int(result[1])})
return jsonify(data_daily_uuid)
@app.route('/sensors_status')
def sensors_status():
date = datetime.datetime.now().strftime("%Y%m%d")
daily_uuid = redis_server_metadata.zrange('daily_uuid:{}'.format(date), 0, -1)
status_daily_uuid = []
for result in daily_uuid:
first_seen = redis_server_metadata.hget('metadata_uuid:{}'.format(result), 'first_seen')
first_seen_gmt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(first_seen)))
last_seen = redis_server_metadata.hget('metadata_uuid:{}'.format(result), 'last_seen')
last_seen_gmt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(last_seen)))
Error = redis_server_metadata.hget('metadata_uuid:{}'.format(result), 'Error')
if first_seen is not None and last_seen is not None:
status_daily_uuid.append({"uuid": result,"first_seen": first_seen, "last_seen": last_seen,
"first_seen_gmt": first_seen_gmt, "last_seen_gmt": last_seen_gmt, "Error": Error})
return render_template("sensors_status.html", status_daily_uuid=status_daily_uuid)
# demo function
@app.route('/delete_data')
def delete_data():
date = datetime.datetime.now().strftime("%Y%m%d")
redis_server_metadata.delete('daily_type:{}'.format(date))
redis_server_metadata.delete('daily_uuid:{}'.format(date))
return render_template("index.html")
if __name__ == "__main__":
app.run(host='0.0.0.0', port=7000, threaded=True)

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -2,10 +2,13 @@
<html>
<head>
<title>D4-Project</title>
<link rel="icon" href="{{ url_for('static', filename='img/d4-logo.png')}}">
<!-- Core CSS -->
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
<!-- JS -->
<script src="{{ url_for('static', filename='js/bootstrap.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/d3.min.js')}}"></script>
<style>
@ -36,7 +39,7 @@
}
text.category{
fill: #666666;
font-size: 14px;
font-size: 18px;
}
</style>
@ -45,19 +48,61 @@
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-dark">
<a class="navbar-brand" href="{{ url_for('index') }}">
<img src="{{ url_for('static', filename='img/d4-logo.png')}}" alt="D4 Project" style="width:80px;">
</a>
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link mr-3" href="{{ url_for('index') }}">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item" mr-3>
<a class="nav-link mr-3" href="{{ url_for('sensors_status') }}">Sensors Status</a>
</li>
<li class="nav-item mr-3">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Server Management</a>
</li>
</ul>
</nav>
<div class="row">
<div class="row mr-0">
<div class="col">
<div id="everything">
<div id="chart"></div>
</div>
<div class="card text-center mt-2 ml-2">
<div class="card-header bg-dark text-white">
UUID
</div>
<div class="card-body">
<div id="chart_uuid"></div>
</div>
<div class="card-footer text-muted">
{{date}}
</div>
</div>
</div>
<div class="col">
<div id="everything">
<div id="charter"></div>
<div class="card text-center mt-2 ml-2">
<div class="card-header bg-dark text-white">
Types
</div>
<div class="card-body">
<div id="chart_type"></div>
</div>
<div class="card-footer text-muted">
{{date}}
</div>
</div>
</div>
</div>
<div class="d-flex justify-content-center mt-4">
<img src="{{ url_for('static', filename='img/circl.png')}}" alt="circl" class="h-75 mt-4">
<img src="{{ url_for('static', filename='img/cef.png')}}" alt="cef">
</div>
<div class="d-flex justify-content-center">
<a href="{{ url_for('delete_data') }}">
<button type="button" class="btn btn-primary mt-3">Delete All Data (Demo)</button>
</a>
</div>
</body>
@ -99,8 +144,8 @@ var setup = function(targetID){
var redrawChart = function(targetID, newdata) {
//Import settings
var margin=settings.margin, width=settings.width, height=settings.height, categoryIndent=settings.categoryIndent,
svg=settings.svg, x=settings.x, y=settings.y;
var margin=targetID.margin, width=targetID.width, height=targetID.height, categoryIndent=targetID.categoryIndent,
svg=targetID.svg, x=targetID.x, y=targetID.y;
//Reset domains
y.domain(newdata.sort(function(a,b){
@ -205,8 +250,8 @@ var redrawChart = function(targetID, newdata) {
.attr("transform", function(d){ return "translate(0," + y(d.key) + ")"; });
};
var pullData = function(settings,callback){
d3.json("{{ url_for('_json_daily_uuid_stats') }}", function (err, data){
var pullData = function(json_url,settings,callback){
d3.json(json_url, function (err, data){
if (err) return console.warn(err);
callback(settings,data);
})
@ -220,17 +265,24 @@ var formatData = function(data){
.slice(0, 15); // linit to 15 items
}
var redraw = function(settings){
pullData(settings,redrawChart)
var redraw = function(json_url,settings){
pullData(json_url,settings,redrawChart)
}
json_url_uuid = "{{ url_for('_json_daily_uuid_stats') }}"
json_url_type = "{{ url_for('_json_daily_type_stats') }}"
//setup
var settings = setup('#chart');
redraw(settings)
var settings = setup('#chart_uuid');
redraw(json_url_uuid,settings)
var settings_type = setup('#chart_type');
redraw(json_url_type,settings_type)
//Interval
setInterval(function(){
redraw(settings)
redraw(json_url_uuid,settings)
redraw(json_url_type,settings_type)
}, 4000);
////

View File

@ -0,0 +1,84 @@
<!DOCTYPE html>
<html>
<head>
<title>D4-Project</title>
<link rel="icon" href="{{ url_for('static', filename='img/d4-logo.png')}}">
<!-- Core CSS -->
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
<!-- JS -->
<script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
<script src="{{ url_for('static', filename='js/bootstrap.min.js')}}"></script>
<style>
</style>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-dark">
<a class="navbar-brand" href="{{ url_for('index') }}">
<img src="{{ url_for('static', filename='img/d4-logo.png')}}" alt="D4 Project" style="width:80px;">
</a>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link mr-3" href="{{ url_for('index') }}">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item" mr-3>
<a class="nav-link active mr-3" href="{{ url_for('sensors_status') }}">Sensors Status</a>
</li>
<li class="nav-item mr-3">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Server Management</a>
</li>
</ul>
</nav>
{% for row_uuid in status_daily_uuid %}
<div class="card text-center mt-3 ml-2 mr-2">
<div class="card-header bg-dark text-white">
UUID: {{row_uuid['uuid']}}
</div>
<div class="card-body">
<div class="card-group">
<div class="card">
<div class="card-header bg-info text-white">
First Seen
</div>
<div class="card-body">
<p class="card-text">{{row_uuid['first_seen_gmt']}} - ({{row_uuid['first_seen']}})</p>
</div>
</div>
<div class="card">
<div class="card-header bg-info text-white">
Last Seen
</div>
<div class="card-body">
<p class="card-text">{{row_uuid['last_seen_gmt']}} - ({{row_uuid['last_seen']}})</p>
</div>
</div>
<div class="card">
{% if not row_uuid['Error'] %}
<div class="card-header bg-success text-white">
Status
</div>
<div class="card-body text-success">
<p class="card-text">OK</p>
{% else %}
<div class="card-header bg-danger text-white">
Status
</div>
<div class="card-body text-danger">
<p class="card-text">{{row_uuid['Error']}}</p>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endfor %}
</body>