mirror of
https://github.com/opnsense/plugins.git
synced 2026-05-28 04:34:15 -04:00
sysutils/nut: restructure diagnostics (#885)
This commit is contained in:
parent
0e98919622
commit
c2f178c730
7 changed files with 156 additions and 35 deletions
|
|
@ -1,5 +1,5 @@
|
|||
PLUGIN_NAME= nut
|
||||
PLUGIN_VERSION= 1.1
|
||||
PLUGIN_VERSION= 1.2
|
||||
PLUGIN_COMMENT= Network UPS Tools
|
||||
PLUGIN_DEPENDS= nut
|
||||
PLUGIN_MAINTAINER= m.muenz@gmail.com
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace OPNsense\Nut\Api;
|
||||
|
||||
use OPNsense\Base\ApiControllerBase;
|
||||
use OPNsense\Core\Backend;
|
||||
use OPNsense\Nut\Nut;
|
||||
|
||||
class DiagnosticsController extends ApiControllerBase
|
||||
{
|
||||
public function upsstatusAction()
|
||||
{
|
||||
$this->sessionClose();
|
||||
$mdl = new Nut();
|
||||
$host = '127.0.0.1';
|
||||
if (!empty((string)$mdl->netclient->address)) {
|
||||
$host = (string)$mdl->netclient->address;
|
||||
}
|
||||
$upsname = 'UPSName';
|
||||
if (!empty((string)$mdl->general->name)) {
|
||||
$upsname = (string)$mdl->general->name;
|
||||
}
|
||||
$backend = new Backend();
|
||||
$response = $backend->configdpRun('nut upsstatus', array("{$upsname}@{$host}"));
|
||||
return array("response" => $response);
|
||||
}
|
||||
}
|
||||
|
|
@ -29,7 +29,6 @@
|
|||
namespace OPNsense\Nut\Api;
|
||||
|
||||
use OPNsense\Base\ApiMutableServiceControllerBase;
|
||||
use OPNsense\Core\Backend;
|
||||
use OPNsense\Nut\Nut;
|
||||
|
||||
class ServiceController extends ApiMutableServiceControllerBase
|
||||
|
|
@ -38,21 +37,4 @@ class ServiceController extends ApiMutableServiceControllerBase
|
|||
static protected $internalServiceTemplate = 'OPNsense/Nut';
|
||||
static protected $internalServiceEnabled = 'general.enable';
|
||||
static protected $internalServiceName = 'nut';
|
||||
|
||||
public function upsstatusAction()
|
||||
{
|
||||
$this->sessionClose();
|
||||
$mdl = new Nut();
|
||||
$host = '127.0.0.1';
|
||||
if (!empty((string)$mdl->netclient->address)) {
|
||||
$host = (string)$mdl->netclient->address;
|
||||
}
|
||||
$upsname = 'UPSName';
|
||||
if (!empty((string)$mdl->general->name)) {
|
||||
$upsname = (string)$mdl->general->name;
|
||||
}
|
||||
$backend = new Backend();
|
||||
$response = $backend->configdpRun('nut upsstatus', array("{$upsname}@{$host}"));
|
||||
return array("response" => $response);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OPNsense\Nut;
|
||||
|
||||
use \OPNsense\Nut;
|
||||
|
||||
/**
|
||||
* Class DiagnosticsController
|
||||
* @package OPNsense/Nut
|
||||
*/
|
||||
class DiagnosticsController extends \OPNsense\Base\IndexController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$this->view->pick('OPNsense/Nut/diagnostics');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
<menu>
|
||||
<Services>
|
||||
<Nut cssClass="fa fa-battery-full fa-fw" url="/ui/nut"/>
|
||||
<Nut cssClass="fa fa-battery-full fa-fw">
|
||||
<Configuration order="10" url="/ui/nut/index"/>
|
||||
<Diagnostics order="20" url="/ui/nut/diagnostics"/>
|
||||
</Nut>
|
||||
</Services>
|
||||
</menu>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
{#
|
||||
# Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#}
|
||||
|
||||
<ul class="nav nav-tabs" role="tablist" id="maintabs">
|
||||
<li class="active"><a data-toggle="tab" href="#diagnostics">{{ lang._('UPS Status') }}</a></li>
|
||||
</ul>
|
||||
|
||||
<div class="content-box tab-content">
|
||||
<div id="diagnostics" class="tab-pane fade in active">
|
||||
<pre id="listdiagnostics"></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
// Put API call into a function, needed for auto-refresh
|
||||
function update_diagnostics() {
|
||||
ajaxCall(url="/api/nut/diagnostics/upsstatus", sendData={}, callback=function(data,status) {
|
||||
$("#listdiagnostics").text(data['response']);
|
||||
});
|
||||
}
|
||||
|
||||
$( document ).ready(function() {
|
||||
|
||||
// call function update_diagnostics with a auto-refresh of 2 seconds
|
||||
setInterval(update_diagnostics, 2000);
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
{#
|
||||
# Copyright (C) 2017 Michael Muenz <m.muenz@gmail.com>
|
||||
# Copyright (C) 2017-2018 Michael Muenz <m.muenz@gmail.com>
|
||||
# Copyright (C) 2014-2017 Deciso B.V.
|
||||
# All rights reserved.
|
||||
#
|
||||
|
|
@ -27,13 +27,6 @@
|
|||
|
||||
<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'};
|
||||
|
|
@ -46,9 +39,6 @@
|
|||
|
||||
updateServiceControlUI('nut');
|
||||
|
||||
// call function update_diagnostics with a auto-refresh of 2 seconds
|
||||
setInterval(update_diagnostics, 2000);
|
||||
|
||||
// update history on tab state and implement navigation
|
||||
if(window.location.hash != "") {
|
||||
$('a[href="' + window.location.hash + '"]').click()
|
||||
|
|
@ -82,12 +72,8 @@
|
|||
|
||||
<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>
|
||||
|
|
|
|||
Loading…
Reference in a new issue