From 8048c535c4a740aa5f3024464d0547e757ec53bf Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Sat, 2 Apr 2016 03:28:09 +0200 Subject: [PATCH] Initial UPS status implementation --- lib/sigar-amd64-winnt.dll | Bin src/wa/server/plugin/hwstatus/HDDStatus.tmpl | 4 +- src/wa/server/plugin/hwstatus/NetStatus.tmpl | 56 ++++++++++--------- src/wa/server/plugin/nutups/UPSStatus.java | 55 ++++++++++++++++++ src/wa/server/plugin/nutups/UPSStatus.tmpl | 55 ++++++++++++++++++ src/wa/server/plugin/nutups/plugin.json | 7 +++ 6 files changed, 148 insertions(+), 29 deletions(-) mode change 100644 => 100755 lib/sigar-amd64-winnt.dll create mode 100755 src/wa/server/plugin/nutups/UPSStatus.java create mode 100755 src/wa/server/plugin/nutups/UPSStatus.tmpl create mode 100755 src/wa/server/plugin/nutups/plugin.json diff --git a/lib/sigar-amd64-winnt.dll b/lib/sigar-amd64-winnt.dll old mode 100644 new mode 100755 diff --git a/src/wa/server/plugin/hwstatus/HDDStatus.tmpl b/src/wa/server/plugin/hwstatus/HDDStatus.tmpl index 0ebcb37..6032c91 100755 --- a/src/wa/server/plugin/hwstatus/HDDStatus.tmpl +++ b/src/wa/server/plugin/hwstatus/HDDStatus.tmpl @@ -57,12 +57,12 @@ function byteToString(value){ - - + + + \ No newline at end of file diff --git a/src/wa/server/plugin/nutups/UPSStatus.java b/src/wa/server/plugin/nutups/UPSStatus.java new file mode 100755 index 0000000..cac9f70 --- /dev/null +++ b/src/wa/server/plugin/nutups/UPSStatus.java @@ -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 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); + } + } +} diff --git a/src/wa/server/plugin/nutups/UPSStatus.tmpl b/src/wa/server/plugin/nutups/UPSStatus.tmpl new file mode 100755 index 0000000..ad7dc56 --- /dev/null +++ b/src/wa/server/plugin/nutups/UPSStatus.tmpl @@ -0,0 +1,55 @@ +
+ + + + + + \ No newline at end of file diff --git a/src/wa/server/plugin/nutups/plugin.json b/src/wa/server/plugin/nutups/plugin.json new file mode 100755 index 0000000..b4b91dd --- /dev/null +++ b/src/wa/server/plugin/nutups/plugin.json @@ -0,0 +1,7 @@ +{ + "version": "1.0", + "name": "NUT UPS", + "interfaces": [ + {"wa.server.plugin.WAStatus": "wa.server.plugin.nutups.UPSStatus"} + ] +} \ No newline at end of file