Initial UPS status implementation
This commit is contained in:
parent
6ad7c2ed58
commit
8048c535c4
6 changed files with 148 additions and 29 deletions
0
lib/sigar-amd64-winnt.dll
Normal file → Executable file
0
lib/sigar-amd64-winnt.dll
Normal file → Executable file
|
|
@ -57,12 +57,12 @@ function byteToString(value){
|
||||||
|
|
||||||
<div id="template" class="hidden">
|
<div id="template" class="hidden">
|
||||||
<div id="" class="col-md-4"><div class="panel panel-default">
|
<div id="" class="col-md-4"><div class="panel panel-default">
|
||||||
<div class="panel-heading hdd-title">HDD: {{.mount}} ({{.size_total}})</div>
|
<div class="panel-heading hdd-title"></div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<center><img src="img/hdd_ok.png" /></center><br>
|
<center><img src="img/hdd_ok.png" /></center><br>
|
||||||
<div class="progress">
|
<div class="progress">
|
||||||
<div class="progress-bar hdd-used" role="progressbar"></div>
|
<div class="progress-bar hdd-used" role="progressbar"></div>
|
||||||
<center class="hdd-free">{{.size_free}}</center>
|
<center class="hdd-free"></center>
|
||||||
</div>
|
</div>
|
||||||
<table class="table small hdd-detail">
|
<table class="table small hdd-detail">
|
||||||
<thead><tr>
|
<thead><tr>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
<div id="net-container"></div>
|
<div id="net-container"></div>
|
||||||
|
|
||||||
<div class="col-md-9"><div class="panel panel-default">
|
<div class="col-md-9"><div class="panel panel-default">
|
||||||
|
|
@ -19,33 +20,6 @@
|
||||||
</div></div>
|
</div></div>
|
||||||
|
|
||||||
|
|
||||||
<div id="template" class="hidden">
|
|
||||||
<div id="" class="col-md-6"><div class="panel panel-default">
|
|
||||||
<div class="panel-heading net-title"></div>
|
|
||||||
<div class="panel-body">
|
|
||||||
<div class="col-md-8">
|
|
||||||
<div><canvas class="net-graph" height="370"></canvas></div>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-4">
|
|
||||||
<table class="table small net-detail">
|
|
||||||
<tr><th>Name</th><td class="net-name"></td></tr>
|
|
||||||
<tr><th>Status</th><td class="net-up"></td></tr>
|
|
||||||
<tr><th>IP</th><td class="net-ip"></td></tr>
|
|
||||||
<tr><th>Netmask</th><td class="net-netmask"></td></tr>
|
|
||||||
<tr><th>Total Rx</th><td class="net-total-rx"></td></tr>
|
|
||||||
<tr><th>Total Tx</th><td class="net-total-tx"></td></tr>
|
|
||||||
<tr><th>Dropped</th><td class="net-dropped"></td></tr>
|
|
||||||
<tr><th>Errors</th><td class="net-error"></td></tr>
|
|
||||||
<tr><th>Mac</th><td class="net-mac"></td></tr>
|
|
||||||
<tr><th>Type</th><td class="net-type"></td></tr>
|
|
||||||
<tr><th>Flags</th><td class="net-flags"></td></tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!--<div><canvas id="hdd-io" height="400"></canvas></div>-->
|
|
||||||
</div>
|
|
||||||
</div></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<script language="javascript" type="text/javascript">
|
<script language="javascript" type="text/javascript">
|
||||||
|
|
@ -141,3 +115,31 @@ function updateRoutingTable(){
|
||||||
setTimeout(updateNet, 30000);
|
setTimeout(updateNet, 30000);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<div id="template" class="hidden">
|
||||||
|
<div id="" class="col-md-6"><div class="panel panel-default">
|
||||||
|
<div class="panel-heading net-title"></div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="col-md-8">
|
||||||
|
<div><canvas class="net-graph" height="370"></canvas></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<table class="table small net-detail">
|
||||||
|
<tr><th>Name</th><td class="net-name"></td></tr>
|
||||||
|
<tr><th>Status</th><td class="net-up"></td></tr>
|
||||||
|
<tr><th>IP</th><td class="net-ip"></td></tr>
|
||||||
|
<tr><th>Netmask</th><td class="net-netmask"></td></tr>
|
||||||
|
<tr><th>Total Rx</th><td class="net-total-rx"></td></tr>
|
||||||
|
<tr><th>Total Tx</th><td class="net-total-tx"></td></tr>
|
||||||
|
<tr><th>Dropped</th><td class="net-dropped"></td></tr>
|
||||||
|
<tr><th>Errors</th><td class="net-error"></td></tr>
|
||||||
|
<tr><th>Mac</th><td class="net-mac"></td></tr>
|
||||||
|
<tr><th>Type</th><td class="net-type"></td></tr>
|
||||||
|
<tr><th>Flags</th><td class="net-flags"></td></tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<!--<div><canvas id="hdd-io" height="400"></canvas></div>-->
|
||||||
|
</div>
|
||||||
|
</div></div>
|
||||||
|
</div>
|
||||||
55
src/wa/server/plugin/nutups/UPSStatus.java
Executable file
55
src/wa/server/plugin/nutups/UPSStatus.java
Executable file
|
|
@ -0,0 +1,55 @@
|
||||||
|
package wa.server.plugin.nutups;
|
||||||
|
|
||||||
|
import wa.server.plugin.WAStatus;
|
||||||
|
import zutil.io.file.FileUtil;
|
||||||
|
import zutil.osal.app.linux.NutUPSClient;
|
||||||
|
import zutil.parser.DataNode;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Ziver on 2016-04-02.
|
||||||
|
*/
|
||||||
|
public class UPSStatus implements WAStatus {
|
||||||
|
|
||||||
|
private NutUPSClient nutClient;
|
||||||
|
|
||||||
|
|
||||||
|
public UPSStatus(){
|
||||||
|
nutClient = new NutUPSClient("192.168.1.110", NutUPSClient.DEFAULT_PORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "UPS Status";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String html() {
|
||||||
|
try {
|
||||||
|
return FileUtil.getContent(FileUtil.findURL("wa/server/plugin/nutups/UPSStatus.tmpl"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
return e.getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void jsonUpdate(Map<String, String> request, DataNode root) {
|
||||||
|
if(request.containsKey("ups")) {
|
||||||
|
DataNode upsRoot = new DataNode(DataNode.DataType.List);
|
||||||
|
for (NutUPSClient.UPSDevice ups : nutClient.getUPSList()){
|
||||||
|
DataNode upsNode = new DataNode(DataNode.DataType.Map);
|
||||||
|
root.set("id", ups.getId());
|
||||||
|
root.set("model", ups.getModelName());
|
||||||
|
root.set("desc", ups.getDescription());
|
||||||
|
root.set("charge", ups.getBatteryCharge());
|
||||||
|
root.set("load", ups.getPowerLoad());
|
||||||
|
root.set("power_usage", ups.getPowerUsage());
|
||||||
|
root.add(upsNode);
|
||||||
|
}
|
||||||
|
root.set("ups", upsRoot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
55
src/wa/server/plugin/nutups/UPSStatus.tmpl
Executable file
55
src/wa/server/plugin/nutups/UPSStatus.tmpl
Executable file
|
|
@ -0,0 +1,55 @@
|
||||||
|
<div id="ups-container"></div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script language="javascript" type="text/javascript">
|
||||||
|
$(function() {
|
||||||
|
updateUps();
|
||||||
|
});
|
||||||
|
|
||||||
|
function updateUps(){
|
||||||
|
$.getJSON("{{nav.getUrl()}}&json&ups", function( data ) {
|
||||||
|
$.each(data['ups'], function( index, hdd ){
|
||||||
|
var element = null;
|
||||||
|
var html_id = "ups-id-" + hdd.id;
|
||||||
|
if($("#"+html_id).length)
|
||||||
|
element = $("#" + html_id);
|
||||||
|
else{ // Create new element
|
||||||
|
element = $("#template").children().clone();
|
||||||
|
$(element).attr("id", html_id);
|
||||||
|
$(element).appendTo("#ups-container");
|
||||||
|
}
|
||||||
|
|
||||||
|
$(element).find(".ups-id").html();
|
||||||
|
$(element).find(".ups-model").html();
|
||||||
|
$(element).find(".ups-description").html();
|
||||||
|
$(element).find(".ups-charge").html(+"%");
|
||||||
|
$(element).find(".ups-load").html(+"%");
|
||||||
|
$(element).find(".ups-usage").html(+"W");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
setTimeout(updateUps, 2000);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="template" class="hidden">
|
||||||
|
<div id="" class="col-md-6"><div class="panel panel-default">
|
||||||
|
<div class="panel-heading ups-title"></div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="battery"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8">
|
||||||
|
<table class="table small net-detail">
|
||||||
|
<tr><th>ID</th><td class="ups-id"></td></tr>
|
||||||
|
<tr><th>Model</th><td class="ups-model"></td></tr>
|
||||||
|
<tr><th>Description</th><td class="ups-description"></td></tr>
|
||||||
|
<tr><th>Battery Charge</th><td class="ups-charge"></td></tr>
|
||||||
|
<tr><th>Device Load</th><td class="ups-load"></td></tr>
|
||||||
|
<tr><th>Power Usage</th><td class="ups-usage"></td></tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<!--<div><canvas id="hdd-io" height="400"></canvas></div>-->
|
||||||
|
</div>
|
||||||
|
</div></div>
|
||||||
|
</div>
|
||||||
7
src/wa/server/plugin/nutups/plugin.json
Executable file
7
src/wa/server/plugin/nutups/plugin.json
Executable file
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"version": "1.0",
|
||||||
|
"name": "NUT UPS",
|
||||||
|
"interfaces": [
|
||||||
|
{"wa.server.plugin.WAStatus": "wa.server.plugin.nutups.UPSStatus"}
|
||||||
|
]
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue