WIP: sysutils/nut: Add diagnostics (#657)

This commit is contained in:
Michael
2018-04-25 11:24:38 +02:00
committed by Franco Fichtner
parent ea48c118af
commit aa5760ae84
5 changed files with 32 additions and 8 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
PLUGIN_NAME= nut
PLUGIN_VERSION= 0.4
PLUGIN_VERSION= 0.5
PLUGIN_COMMENT= Network UPS Tools
PLUGIN_DEPENDS= nut
PLUGIN_MAINTAINER= m.muenz@gmail.com
@@ -1,7 +1,7 @@
<?php
/*
* Copyright (C) 2017 Michael Muenz
* Copyright (C) 2017-2018 Michael Muenz
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,6 +29,7 @@
namespace OPNsense\Nut\Api;
use OPNsense\Base\ApiMutableServiceControllerBase;
use OPNsense\Core\Backend;
class ServiceController extends ApiMutableServiceControllerBase
{
@@ -39,8 +40,19 @@ class ServiceController extends ApiMutableServiceControllerBase
public function upsstatusAction()
{
$model = new Nut();
$cnf = Config::getInstance()->object();
$host = "127.0.0.1";
if (!empty((string)$cnf->netclient->address)) {
$host = (string)$cnf->netclient->address;
}
$upsname = "UPSName";
if (!empty((string)$cnf->general->name)) {
$upsname = (string)$cnf->general->name;
}
$ups = $upsname . '@' . $host;
$backend = new Backend();
$response = $backend->configdRun("nut upsstatus");
$response = $backend->configdpRun("nut upsstatus", array($ups));
return array("response" => $response);
}
}
@@ -1,8 +1,5 @@
<menu>
<Services>
<Nut cssClass="fa fa-battery-full fa-fw">
<Configuration order="10" url="/ui/nut/"/>
<Diagnostics order="20" url="/ui/nut/diagnostics"/>
</Nut>
<Nut cssClass="fa fa-battery-full fa-fw" url="/ui/nut/"/>
</Services>
</menu>
@@ -26,6 +26,14 @@
#}
<script>
// Put API call into a function, needed for auto-refresh
function update_diagnostics() {
ajaxCall(url="/api/nut/service/upsstatus", sendData={}, callback=function(data,status) {
$("#listdiagnostics").text(data['response']);
});
}
$( document ).ready(function() {
var data_get_map = {'frm_nut':'/api/nut/settings/get'};
@@ -38,6 +46,9 @@
updateServiceControlUI('nut');
// call function update_diagnostics with a auto-refresh of 3 seconds
setInterval(update_diagnostics, 10000);
// update history on tab state and implement navigation
if(window.location.hash != "") {
$('a[href="' + window.location.hash + '"]').click()
@@ -71,8 +82,12 @@
<ul class="nav nav-tabs" role="tablist" id="maintabs">
{{ partial("layout_partials/base_tabs_header",['formData':settings]) }}
<li><a data-toggle="tab" href="#diagnostics">{{ lang._('Diagnostics') }}</a></li>
</ul>
<div class="content-box tab-content">
{{ partial("layout_partials/base_tabs_content",['formData':settings]) }}
<div id="diagnostics" class="tab-pane fade in">
<pre id="listdiagnostics"></pre>
</div>
</div>
@@ -23,7 +23,7 @@ type:script_output
message:request nut status
[upsstatus]
command:/usr/local/bin/upsc -l
command:/usr/local/bin/upsc
parameters: %s
type:script_output
message:retrieve ups status