sysutils/nut: multiple fixes (#648)

This commit is contained in:
Michael
2018-04-17 08:29:45 +02:00
committed by Franco Fichtner
parent 7649c15201
commit 609f9b0e97
11 changed files with 39 additions and 45 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
PLUGIN_NAME= nut
PLUGIN_VERSION= 0.3
PLUGIN_VERSION= 0.4
PLUGIN_COMMENT= Network UPS Tools
PLUGIN_DEPENDS= nut
PLUGIN_MAINTAINER= m.muenz@gmail.com
@@ -59,7 +59,7 @@ function nut_services()
'stop' => array('nut stop'),
),
'name' => 'nut',
'pidfile' => '/var/run/nut.pid'
'pidfile' => '/var/db/nut/upsd.pid'
);
}
if (nut_netclient()) {
@@ -70,7 +70,8 @@ function nut_services()
'start' => array('nut start'),
'stop' => array('nut stop'),
),
'name' => 'upsmon'
'name' => 'upsmon',
'pidfile' => '/var/db/nut/upsmon.pid'
);
}
@@ -140,4 +140,10 @@ class ServiceController extends ApiControllerBase
return array('response' => array());
}
}
public function upsstatusAction()
{
$backend = new Backend();
$response = $backend->configdRun("nut upsstatus");
return array("response" => $response);
}
}
@@ -13,6 +13,12 @@
<type>dropdown</type>
<help>Set the service mode. Currently only standalone and netclient are available.</help>
</field>
<field>
<id>nut.general.name</id>
<label>Name</label>
<type>text</type>
<help>Set a name for your UPS.</help>
</field>
</subtab>
<subtab id="nut-general-account" description="Nut Account Settings">
<field>
@@ -37,12 +43,6 @@
<type>checkbox</type>
<help>Enable the USBHID driver.</help>
</field>
<field>
<id>nut.usbhid.name</id>
<label>Name</label>
<type>text</type>
<help>Set a name for your UPS.</help>
</field>
<field>
<id>nut.usbhid.args</id>
<label>Extra Arguments</label>
@@ -57,12 +57,6 @@
<type>checkbox</type>
<help>Enable the Netclient driver.</help>
</field>
<field>
<id>nut.netclient.name</id>
<label>Name</label>
<type>text</type>
<help>Set a name for your UPS.</help>
</field>
<field>
<id>nut.netclient.address</id>
<label>IP Address</label>
@@ -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/"/>
<Diagnostics order="20" url="/ui/nut/diagnostics"/>
</Nut>
</Services>
</menu>
@@ -1,6 +1,7 @@
<model>
<mount>//OPNsense/Nut</mount>
<description>Network UPS Tools</description>
<version>0.1.0</version>
<items>
<general>
<enable type="BooleanField">
@@ -15,6 +16,10 @@
<netclient>netclient</netclient>
</OptionValues>
</mode>
<name type="TextField">
<default>UPSName</default>
<Required>Y</Required>
</name>
</general>
<account>
@@ -33,10 +38,6 @@
<Required>Y</Required>
<default>0</default>
</enable>
<name type="TextField">
<default>UPS-Name</default>
<Required>Y</Required>
</name>
<args type="TextField">
<default>port=auto</default>
<Required>N</Required>
@@ -47,10 +48,6 @@
<Required>Y</Required>
<default>0</default>
</enable>
<name type="TextField">
<default>UPS-Name</default>
<Required>Y</Required>
</name>
<address type="HostnameField">
<default></default>
<Required>N</Required>
@@ -55,26 +55,15 @@
var frm_title = $(this).closest("form").attr("data-title");
// save data for General TAB
saveFormToEndpoint(url="/api/nut/settings/set", formid=frm_id, callback_ok=function(){
// on correct save, perform reconfigure. set progress animation when reloading
// on correct save, perform restart, set progress animation when reloading
$("#"+frm_id+"_progress").addClass("fa fa-spinner fa-pulse");
ajaxCall(url="/api/nut/service/reconfigure", sendData={}, callback=function(data,status){
ajaxCall(url="/api/nut/service/restart", sendData={}, callback=function(data,status){
// when done, disable progress animation.
$("#"+frm_id+"_progress").removeClass("fa fa-spinner fa-pulse");
if (status != "success" || data['status'] != 'ok' ) {
// fix error handling
BootstrapDialog.show({
type:BootstrapDialog.TYPE_WARNING,
title: frm_title,
message: JSON.stringify(data),
draggable: true
});
} else {
ajaxCall(url="/api/nut/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
}
});
});
});
@@ -21,3 +21,9 @@ command:/usr/local/etc/rc.d/nut status;exit 0
parameters:
type:script_output
message:request nut status
[upsstatus]
command:/usr/local/bin/upsc -l
parameters: %s
type:script_output
message:retrieve ups status
@@ -1,7 +1,5 @@
{% if helpers.exists('OPNsense.Nut.general.enable') and OPNsense.Nut.general.enable == '1' %}
{% if helpers.exists('OPNsense.Nut.general.mode') and OPNsense.Nut.general.mode == 'netclient' %}
nut_upsmon_enable="YES"
{% else %}
{% else %}
nut_upsmon_enable="NO"
{% endif %}
{% endif %}
@@ -3,7 +3,7 @@
#
{% if helpers.exists('OPNsense.Nut.general.enable') and OPNsense.Nut.general.enable == '1' %}
{% if helpers.exists('OPNsense.Nut.usbhid.enable') and OPNsense.Nut.usbhid.enable == '1' %}
[{{ OPNsense.Nut.usbhid.name }}]
[{{ OPNsense.Nut.general.name }}]
driver=usbhid-ups
{% if helpers.exists('OPNsense.Nut.usbhid.args') and OPNsense.Nut.usbhid.args != '' %}
{{ OPNsense.Nut.usbhid.args }}
@@ -2,12 +2,12 @@
# the next update.
#
{% if helpers.exists('OPNsense.Nut.usbhid.enable') and OPNsense.Nut.usbhid.enable == '1' %}
MONITOR {{ OPNsense.Nut.usbhid.name }} 1 monuser {{ OPNsense.Nut.account.mon_password }} master
SHUTDOWNCMD "/sbin/shutdown -p +0"
MONITOR {{ OPNsense.Nut.general.name }} 1 monuser {{ OPNsense.Nut.account.mon_password }} master
SHUTDOWNCMD "/usr/local/etc/rc.halt"
POWERDOWNFLAG /etc/killpower
{% endif %}
{% if helpers.exists('OPNsense.Nut.netclient.enable') and OPNsense.Nut.netclient.enable == '1' %}
MONITOR {{ OPNsense.Nut.netclient.name }}@{{ OPNsense.Nut.netclient.address }} 1 {{ OPNsense.Nut.netclient.user }} {{ OPNsense.Nut.netclient.password }} slave
SHUTDOWNCMD "/sbin/shutdown -p +0"
MONITOR {{ OPNsense.Nut.general.name }}@{{ OPNsense.Nut.netclient.address }} 1 {{ OPNsense.Nut.netclient.user }} {{ OPNsense.Nut.netclient.password }} slave
SHUTDOWNCMD "/usr/local/etc/rc.halt"
POWERDOWNFLAG /etc/killpower
{% endif %}