This commit is contained in:
Anna Sudnitsina 2017-09-01 17:42:27 +03:00
parent 3d057b8f9b
commit c091bc7ee2
4 changed files with 43 additions and 70 deletions

View File

@ -6,9 +6,8 @@ $(function() {
var status = JSON.parse(data);
var htmlSelect = '';
for (n in status["quorum"]) { htmlSelect += "<option value=" + n + ">" + n + "</option>";}
$('#selectNode').html(htmlSelect);
console.log(htmlSelect);}
}
})
})
@ -16,7 +15,7 @@ $(function() {
function resolve() {
$.ajax({
url:"/resolve",
url:"resolve",
data:{"node":deadNode},
success:function(data){$('#details').css("display", "none");}
})
@ -40,12 +39,6 @@ $(function() {
}
}
function displayData(a){
$("#status").html("<p>"+a.health+"</p>");
if (a.health == 'deadly.') {
@ -68,23 +61,23 @@ $(function() {
};
w3DisplayData("id01", node2);
$('.tablink').css('display', 'block');
if (n != undefined && n != 'dead'){
var t = new Date(a.quorum[n]["updated"] * 1000)
if (selected_node != undefined && selected_node != 'dead'){
var t = new Date(a.quorum[selected_node]["updated"] * 1000)
var up_formatted = t.getFullYear() + "/" +
(t.getMonth() + 1) + "/" +
t.getDate() + " " +
t.getHours() + ":" +
t.getMinutes() + ":" +
t.getSeconds();
$("#name").html(n);
$("#ipv4").html(a.quorum[n]["ip"]["v4"].join("<br>"));
$("#ipv6").html(a.quorum[n]["ip"]["v6"].join("<br>"));
$("#name").html(selected_node);
$("#ipv4").html(a.quorum[selected_node]["ip"]["v4"].join("<br>"));
$("#ipv6").html(a.quorum[selected_node]["ip"]["v6"].join("<br>"));
$("#updated").html(up_formatted);
if (a.quorum[n]["mounts"] != null) {
if (a.quorum[selected_node]["mounts"] != null) {
var mnt_block = "";
for (i in a.quorum[n].mounts) {
var mnt = a.quorum[n].mounts[i];
mnt_block += "<a href='javascript:void(0)' onClick='unmount(n, a.quorum[n].mounts[i].mountpoint, a.quorum[n].mounts[i].block)' >unmount</a><br>Mountpoint: "
for (i in a.quorum[selected_node].mounts) {
var mnt = a.quorum[selected_node].mounts[i];
mnt_block += "<a href='javascript:void(0)' onClick='unmount(n, a.quorum[selected_node].mounts[i].mountpoint, a.quorum[selected_node].mounts[i].block)' >unmount</a><br>Mountpoint: "
+ mnt.mountpoint + "<br>Mountopts: "
+ mnt.mountopts + "<br>Fstype: "
+ mnt.fstype +
@ -96,7 +89,7 @@ $(function() {
}
else { $("#mon").html("")}
}
if (n =='dead') {
if (selected_node =='dead') {
var t, up_formatted
if (a.deadlyreason["updated"] != 0) {
t = new Date(a.deadlyreason["updated"] * 1000)
@ -119,10 +112,10 @@ $(function() {
}
function openNode(evt, nodeName) {
var i, x, tablinks;
n = nodeName;
selected_node = nodeName;
x = document.getElementsByClassName("node");
tablinks = document.getElementsByClassName("tablink");
if (n == 'dead') {
if (selected_node == 'dead') {
$('#details').css("border", "2px solid #f44336");
if ($('#showDeadlyDetails').html() == "Show details") {
$('#details').css("display", "block");

View File

@ -24,9 +24,9 @@
<a w3-repeat="node in quorum" href="javascript:void(0)" class="tablink" onclick="openNode(event, '{{node}}')" style='display:none'>{{node}}</a>
{% endverbatim %}
<h4>Metrics: </h4>
{% for k,v in metrics.items %} {{k}} {{v}}<br> {% endfor %}
</div>
<div class="w3-col m9" >
<div class="w3-container" style="height:50px; position:relative" id="statusContainer">
<div class="w3-padding w3-display-left" id="status">Status... </div>
@ -55,7 +55,7 @@
<div id="mount" class="w3-modal">
<div class="w3-modal-content">
<header class="w3-container w3-light-grey">
<span onclick="document.getElementById('mount').style.display='none'" class="w3-closebtn">&times;</span>
<span onclick="$('#mount').css('display', 'none')" class="w3-closebtn">&times;</span>
<h2>Mount</h2>
</header>
<form method="post" action="/" role="form" class="w3-container form" id="mountForm"> {% csrf_token %}
@ -72,14 +72,12 @@
</footer>
</div>
</div>
<script>
//var res = '{{status|escapejs}}';
</script>
</div>
<script>
var s = '{{ws|escapejs}}';
var ws = new WebSocket(s);
var a, n, deadNode;
var a, selected_node, deadNode;
ws.onopen = function() {ws.send(""); };
ws.onmessage = function (evt) {
a = JSON.parse(evt.data);
@ -93,12 +91,10 @@
data:$(this).serialize(),
method:'POST',
success:function(data){
console.log(data);
$('#mount').css('display', 'none');
$('input').val('');
var res = JSON.parse(data);
message = "<h3>" + res["state"] + "</h3> <p>"+ res["message"] +"</p>";
var res = JSON.parse(data);
message = "<h3>" + res["state"] + "</h3> <p>"+ res["message"] +"</p>";
$("#rspContainer").css("display", "block");
$("#rsp").html(message)
if (res["state"] == 'OK'){$("#rspContainer").css("background-color", "#4CAF50" );}

View File

@ -24,5 +24,4 @@ urlpatterns = [
url(r'^mount$', views.mount),
url(r'^unmount$', views.unmount),
url(r'^resolve$', views.resolve),
url(r'^metrics$', views.get_metrics),
]

View File

@ -1,75 +1,60 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.http import HttpResponse, JsonResponse
from django.http import JsonResponse
from django.shortcuts import render
import json
import requests
def action(name, method):
def action(name, method, data=None):
with open('conf.json') as conf:
url = json.load(conf)["api"] + '/' + name
if method == 'get':
print 'start'
try: res = requests.get(url).content
except: res = 'connection can\'t be established'
print 'end'
elif method == 'post':
try: res = requests.post(url).content
print data
try: res = requests.post(url, data).content
except: res = 'connection can\'t be established'
return res
'''
def status():
with open('conf.json') as conf:
status = json.load(conf)["api"] + '/status'
try: res = requests.get(status).content
except: res = 'connection can\'t be established'
return res
'''
def get_status(request):
my_status = action('status', 'get')
return JsonResponse(my_status, safe=False)
def mount(request):
if request.method == 'POST':
data = request.POST.dict()
'''
with open('conf.json') as conf:
url = json.load(conf)["api"] + '/mount'
res = requests.post(url, json.dumps(data))
print res
'''
res = action('mount', 'post')
res = action('mount', 'post', json.dumps(data))
return JsonResponse(res, safe=False)
def unmount(request):
with open('conf.json') as conf:
url = json.load(conf)["api"] + '/umount'
data = request.GET.dict()
try: res = requests.post(url, json.dumps(data)).content
except: res = 'connection can\'t be established'
res = action('umount', 'post', json.dumps(data))
return JsonResponse(res, safe=False)
def resolve():
with open('conf.json') as conf:
url = json.load(conf)["api"] + '/resolve'
def resolve(request):
data = request.GET.dict()
res = requests.post(metrics, json.dumps(data))
return JsonResponse(res.content, safe=False)
def get_metrics():
with open('conf.json') as conf:
metrics = json.load(conf)["api"] + '/metrics'
try: res = requests.get(metrics).content
except: res = 'connection can\'t be established'
return res
res = action('resolve', 'post', json.dumps(data))
print 'res' + res
return JsonResponse(res, safe=False)
def panel(request):
with open('conf.json') as conf:
ws = json.load(conf)["ws"]
metrics = json.loads(get_metrics())
my_status = status()
print '1'
metrics = json.loads(action('metrics', 'get'))
print '2'
my_status = action('status', 'get')
print '3'
return render(request, 'rbmd/index.html', {'ws' : ws, 'metrics' : metrics, 'status' : my_status})