v1.0
This commit is contained in:
parent
3d057b8f9b
commit
c091bc7ee2
@ -6,9 +6,8 @@ $(function() {
|
|||||||
var status = JSON.parse(data);
|
var status = JSON.parse(data);
|
||||||
var htmlSelect = '';
|
var htmlSelect = '';
|
||||||
for (n in status["quorum"]) { htmlSelect += "<option value=" + n + ">" + n + "</option>";}
|
for (n in status["quorum"]) { htmlSelect += "<option value=" + n + ">" + n + "</option>";}
|
||||||
|
|
||||||
$('#selectNode').html(htmlSelect);
|
$('#selectNode').html(htmlSelect);
|
||||||
console.log(htmlSelect);}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -16,7 +15,7 @@ $(function() {
|
|||||||
|
|
||||||
function resolve() {
|
function resolve() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url:"/resolve",
|
url:"resolve",
|
||||||
data:{"node":deadNode},
|
data:{"node":deadNode},
|
||||||
success:function(data){$('#details').css("display", "none");}
|
success:function(data){$('#details').css("display", "none");}
|
||||||
})
|
})
|
||||||
@ -40,12 +39,6 @@ $(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function displayData(a){
|
function displayData(a){
|
||||||
$("#status").html("<p>"+a.health+"</p>");
|
$("#status").html("<p>"+a.health+"</p>");
|
||||||
if (a.health == 'deadly.') {
|
if (a.health == 'deadly.') {
|
||||||
@ -68,23 +61,23 @@ $(function() {
|
|||||||
};
|
};
|
||||||
w3DisplayData("id01", node2);
|
w3DisplayData("id01", node2);
|
||||||
$('.tablink').css('display', 'block');
|
$('.tablink').css('display', 'block');
|
||||||
if (n != undefined && n != 'dead'){
|
if (selected_node != undefined && selected_node != 'dead'){
|
||||||
var t = new Date(a.quorum[n]["updated"] * 1000)
|
var t = new Date(a.quorum[selected_node]["updated"] * 1000)
|
||||||
var up_formatted = t.getFullYear() + "/" +
|
var up_formatted = t.getFullYear() + "/" +
|
||||||
(t.getMonth() + 1) + "/" +
|
(t.getMonth() + 1) + "/" +
|
||||||
t.getDate() + " " +
|
t.getDate() + " " +
|
||||||
t.getHours() + ":" +
|
t.getHours() + ":" +
|
||||||
t.getMinutes() + ":" +
|
t.getMinutes() + ":" +
|
||||||
t.getSeconds();
|
t.getSeconds();
|
||||||
$("#name").html(n);
|
$("#name").html(selected_node);
|
||||||
$("#ipv4").html(a.quorum[n]["ip"]["v4"].join("<br>"));
|
$("#ipv4").html(a.quorum[selected_node]["ip"]["v4"].join("<br>"));
|
||||||
$("#ipv6").html(a.quorum[n]["ip"]["v6"].join("<br>"));
|
$("#ipv6").html(a.quorum[selected_node]["ip"]["v6"].join("<br>"));
|
||||||
$("#updated").html(up_formatted);
|
$("#updated").html(up_formatted);
|
||||||
if (a.quorum[n]["mounts"] != null) {
|
if (a.quorum[selected_node]["mounts"] != null) {
|
||||||
var mnt_block = "";
|
var mnt_block = "";
|
||||||
for (i in a.quorum[n].mounts) {
|
for (i in a.quorum[selected_node].mounts) {
|
||||||
var mnt = a.quorum[n].mounts[i];
|
var mnt = a.quorum[selected_node].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: "
|
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.mountpoint + "<br>Mountopts: "
|
||||||
+ mnt.mountopts + "<br>Fstype: "
|
+ mnt.mountopts + "<br>Fstype: "
|
||||||
+ mnt.fstype +
|
+ mnt.fstype +
|
||||||
@ -96,7 +89,7 @@ $(function() {
|
|||||||
}
|
}
|
||||||
else { $("#mon").html("")}
|
else { $("#mon").html("")}
|
||||||
}
|
}
|
||||||
if (n =='dead') {
|
if (selected_node =='dead') {
|
||||||
var t, up_formatted
|
var t, up_formatted
|
||||||
if (a.deadlyreason["updated"] != 0) {
|
if (a.deadlyreason["updated"] != 0) {
|
||||||
t = new Date(a.deadlyreason["updated"] * 1000)
|
t = new Date(a.deadlyreason["updated"] * 1000)
|
||||||
@ -119,10 +112,10 @@ $(function() {
|
|||||||
}
|
}
|
||||||
function openNode(evt, nodeName) {
|
function openNode(evt, nodeName) {
|
||||||
var i, x, tablinks;
|
var i, x, tablinks;
|
||||||
n = nodeName;
|
selected_node = nodeName;
|
||||||
x = document.getElementsByClassName("node");
|
x = document.getElementsByClassName("node");
|
||||||
tablinks = document.getElementsByClassName("tablink");
|
tablinks = document.getElementsByClassName("tablink");
|
||||||
if (n == 'dead') {
|
if (selected_node == 'dead') {
|
||||||
$('#details').css("border", "2px solid #f44336");
|
$('#details').css("border", "2px solid #f44336");
|
||||||
if ($('#showDeadlyDetails').html() == "Show details") {
|
if ($('#showDeadlyDetails').html() == "Show details") {
|
||||||
$('#details').css("display", "block");
|
$('#details').css("display", "block");
|
||||||
|
@ -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>
|
<a w3-repeat="node in quorum" href="javascript:void(0)" class="tablink" onclick="openNode(event, '{{node}}')" style='display:none'>{{node}}</a>
|
||||||
{% endverbatim %}
|
{% endverbatim %}
|
||||||
<h4>Metrics: </h4>
|
<h4>Metrics: </h4>
|
||||||
|
|
||||||
{% for k,v in metrics.items %} {{k}} {{v}}<br> {% endfor %}
|
{% for k,v in metrics.items %} {{k}} {{v}}<br> {% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="w3-col m9" >
|
<div class="w3-col m9" >
|
||||||
<div class="w3-container" style="height:50px; position:relative" id="statusContainer">
|
<div class="w3-container" style="height:50px; position:relative" id="statusContainer">
|
||||||
<div class="w3-padding w3-display-left" id="status">Status... </div>
|
<div class="w3-padding w3-display-left" id="status">Status... </div>
|
||||||
@ -55,7 +55,7 @@
|
|||||||
<div id="mount" class="w3-modal">
|
<div id="mount" class="w3-modal">
|
||||||
<div class="w3-modal-content">
|
<div class="w3-modal-content">
|
||||||
<header class="w3-container w3-light-grey">
|
<header class="w3-container w3-light-grey">
|
||||||
<span onclick="document.getElementById('mount').style.display='none'" class="w3-closebtn">×</span>
|
<span onclick="$('#mount').css('display', 'none')" class="w3-closebtn">×</span>
|
||||||
<h2>Mount</h2>
|
<h2>Mount</h2>
|
||||||
</header>
|
</header>
|
||||||
<form method="post" action="/" role="form" class="w3-container form" id="mountForm"> {% csrf_token %}
|
<form method="post" action="/" role="form" class="w3-container form" id="mountForm"> {% csrf_token %}
|
||||||
@ -72,14 +72,12 @@
|
|||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
</div>
|
||||||
//var res = '{{status|escapejs}}';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var s = '{{ws|escapejs}}';
|
var s = '{{ws|escapejs}}';
|
||||||
var ws = new WebSocket(s);
|
var ws = new WebSocket(s);
|
||||||
var a, n, deadNode;
|
var a, selected_node, deadNode;
|
||||||
ws.onopen = function() {ws.send(""); };
|
ws.onopen = function() {ws.send(""); };
|
||||||
ws.onmessage = function (evt) {
|
ws.onmessage = function (evt) {
|
||||||
a = JSON.parse(evt.data);
|
a = JSON.parse(evt.data);
|
||||||
@ -93,12 +91,10 @@
|
|||||||
data:$(this).serialize(),
|
data:$(this).serialize(),
|
||||||
method:'POST',
|
method:'POST',
|
||||||
success:function(data){
|
success:function(data){
|
||||||
console.log(data);
|
|
||||||
$('#mount').css('display', 'none');
|
$('#mount').css('display', 'none');
|
||||||
$('input').val('');
|
$('input').val('');
|
||||||
var res = JSON.parse(data);
|
var res = JSON.parse(data);
|
||||||
|
message = "<h3>" + res["state"] + "</h3> <p>"+ res["message"] +"</p>";
|
||||||
message = "<h3>" + res["state"] + "</h3> <p>"+ res["message"] +"</p>";
|
|
||||||
$("#rspContainer").css("display", "block");
|
$("#rspContainer").css("display", "block");
|
||||||
$("#rsp").html(message)
|
$("#rsp").html(message)
|
||||||
if (res["state"] == 'OK'){$("#rspContainer").css("background-color", "#4CAF50" );}
|
if (res["state"] == 'OK'){$("#rspContainer").css("background-color", "#4CAF50" );}
|
||||||
|
@ -24,5 +24,4 @@ urlpatterns = [
|
|||||||
url(r'^mount$', views.mount),
|
url(r'^mount$', views.mount),
|
||||||
url(r'^unmount$', views.unmount),
|
url(r'^unmount$', views.unmount),
|
||||||
url(r'^resolve$', views.resolve),
|
url(r'^resolve$', views.resolve),
|
||||||
url(r'^metrics$', views.get_metrics),
|
|
||||||
]
|
]
|
||||||
|
@ -1,75 +1,60 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.http import HttpResponse, JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
def action(name, method):
|
def action(name, method, data=None):
|
||||||
|
|
||||||
with open('conf.json') as conf:
|
with open('conf.json') as conf:
|
||||||
url = json.load(conf)["api"] + '/' + name
|
url = json.load(conf)["api"] + '/' + name
|
||||||
if method == 'get':
|
if method == 'get':
|
||||||
|
print 'start'
|
||||||
try: res = requests.get(url).content
|
try: res = requests.get(url).content
|
||||||
except: res = 'connection can\'t be established'
|
except: res = 'connection can\'t be established'
|
||||||
|
print 'end'
|
||||||
elif method == 'post':
|
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'
|
except: res = 'connection can\'t be established'
|
||||||
return res
|
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):
|
def get_status(request):
|
||||||
|
|
||||||
my_status = action('status', 'get')
|
my_status = action('status', 'get')
|
||||||
return JsonResponse(my_status, safe=False)
|
return JsonResponse(my_status, safe=False)
|
||||||
|
|
||||||
def mount(request):
|
def mount(request):
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
data = request.POST.dict()
|
data = request.POST.dict()
|
||||||
'''
|
res = action('mount', 'post', json.dumps(data))
|
||||||
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')
|
|
||||||
return JsonResponse(res, safe=False)
|
return JsonResponse(res, safe=False)
|
||||||
|
|
||||||
def unmount(request):
|
def unmount(request):
|
||||||
|
|
||||||
with open('conf.json') as conf:
|
|
||||||
url = json.load(conf)["api"] + '/umount'
|
|
||||||
data = request.GET.dict()
|
data = request.GET.dict()
|
||||||
try: res = requests.post(url, json.dumps(data)).content
|
res = action('umount', 'post', json.dumps(data))
|
||||||
except: res = 'connection can\'t be established'
|
|
||||||
return JsonResponse(res, safe=False)
|
return JsonResponse(res, safe=False)
|
||||||
|
|
||||||
def resolve():
|
def resolve(request):
|
||||||
with open('conf.json') as conf:
|
|
||||||
url = json.load(conf)["api"] + '/resolve'
|
|
||||||
data = request.GET.dict()
|
|
||||||
res = requests.post(metrics, json.dumps(data))
|
|
||||||
return JsonResponse(res.content, safe=False)
|
|
||||||
|
|
||||||
def get_metrics():
|
data = request.GET.dict()
|
||||||
with open('conf.json') as conf:
|
res = action('resolve', 'post', json.dumps(data))
|
||||||
metrics = json.load(conf)["api"] + '/metrics'
|
print 'res' + res
|
||||||
try: res = requests.get(metrics).content
|
return JsonResponse(res, safe=False)
|
||||||
except: res = 'connection can\'t be established'
|
|
||||||
return res
|
|
||||||
|
|
||||||
def panel(request):
|
def panel(request):
|
||||||
with open('conf.json') as conf:
|
with open('conf.json') as conf:
|
||||||
ws = json.load(conf)["ws"]
|
ws = json.load(conf)["ws"]
|
||||||
metrics = json.loads(get_metrics())
|
print '1'
|
||||||
my_status = status()
|
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})
|
return render(request, 'rbmd/index.html', {'ws' : ws, 'metrics' : metrics, 'status' : my_status})
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user