From 0b70e35c8c1e07c0b04ad9a1719b0c7e13131564 Mon Sep 17 00:00:00 2001 From: Stephan de Wit Date: Wed, 29 Nov 2023 09:54:20 +0100 Subject: [PATCH] dec-hw: dual power supply status for Deciso appliances (#3687) - API endpoint to query the current power supply status - small dashboard widget --- sysutils/dec-hw/+POST_INSTALL | 1 + sysutils/dec-hw/Makefile | 8 ++ sysutils/dec-hw/pkg-descr | 4 + .../src/etc/rc.syshook.d/early/30-powerstat | 13 +++ .../OPNsense/dechw/Api/InfoController.php | 57 +++++++++++ .../src/opnsense/scripts/dec-hw/powerstat | 15 +++ .../service/conf/actions.d/actions_dechw.conf | 5 + .../dec-hw/src/www/widgets/include/dechw.inc | 3 + .../src/www/widgets/widgets/dechw.widget.php | 94 +++++++++++++++++++ 9 files changed, 200 insertions(+) create mode 100644 sysutils/dec-hw/+POST_INSTALL create mode 100644 sysutils/dec-hw/Makefile create mode 100644 sysutils/dec-hw/pkg-descr create mode 100755 sysutils/dec-hw/src/etc/rc.syshook.d/early/30-powerstat create mode 100644 sysutils/dec-hw/src/opnsense/mvc/app/controllers/OPNsense/dechw/Api/InfoController.php create mode 100755 sysutils/dec-hw/src/opnsense/scripts/dec-hw/powerstat create mode 100644 sysutils/dec-hw/src/opnsense/service/conf/actions.d/actions_dechw.conf create mode 100644 sysutils/dec-hw/src/www/widgets/include/dechw.inc create mode 100644 sysutils/dec-hw/src/www/widgets/widgets/dechw.widget.php diff --git a/sysutils/dec-hw/+POST_INSTALL b/sysutils/dec-hw/+POST_INSTALL new file mode 100644 index 000000000..a9ba08024 --- /dev/null +++ b/sysutils/dec-hw/+POST_INSTALL @@ -0,0 +1 @@ +/usr/local/etc/rc.syshook.d/early/30-powerstat diff --git a/sysutils/dec-hw/Makefile b/sysutils/dec-hw/Makefile new file mode 100644 index 000000000..326b54895 --- /dev/null +++ b/sysutils/dec-hw/Makefile @@ -0,0 +1,8 @@ +PLUGIN_NAME= dec-hw +PLUGIN_VERSION= 1.0 +PLUGIN_COMMENT= Deciso Hardware specific information +PLUGIN_MAINTAINER= stephan.de.wit@deciso.com +PLUGIN_TIER= 2 + +.include "../../Mk/plugins.mk" + diff --git a/sysutils/dec-hw/pkg-descr b/sysutils/dec-hw/pkg-descr new file mode 100644 index 000000000..c8f40a55e --- /dev/null +++ b/sysutils/dec-hw/pkg-descr @@ -0,0 +1,4 @@ +This package allows fetching the current power status for Deciso +appliances with dual power supplies via an API call and includes a simple +dashboard widget. + diff --git a/sysutils/dec-hw/src/etc/rc.syshook.d/early/30-powerstat b/sysutils/dec-hw/src/etc/rc.syshook.d/early/30-powerstat new file mode 100755 index 000000000..df63a9fc3 --- /dev/null +++ b/sysutils/dec-hw/src/etc/rc.syshook.d/early/30-powerstat @@ -0,0 +1,13 @@ +#!/bin/sh + +AMDGPIO="/boot/kernel/amdgpio.ko" + +if [ ! -e "$AMDGPIO" ]; then + echo "Error: amdpgio kernel module missing" + logger -t "dec-hw" "Error: amdpgio kernel module missing" + exit 1 +fi + +kldload "$AMDGPIO" 2>&1 + +exit 0 diff --git a/sysutils/dec-hw/src/opnsense/mvc/app/controllers/OPNsense/dechw/Api/InfoController.php b/sysutils/dec-hw/src/opnsense/mvc/app/controllers/OPNsense/dechw/Api/InfoController.php new file mode 100644 index 000000000..9581cc101 --- /dev/null +++ b/sysutils/dec-hw/src/opnsense/mvc/app/controllers/OPNsense/dechw/Api/InfoController.php @@ -0,0 +1,57 @@ + "failed", + "status_translated" => gettext("Power status could not be fetched. + This widget is only applicable to Deciso hardware with dual power supplies.") + ]; + $status = parse_ini_string((new Backend())->configdRun('dechw power')); + + if (!empty($status)) { + $result["status"] = "OK"; + unset($result["status_translated"]); + + foreach (['pwr1', 'pwr2'] as $key) { + $result[$key . '_translated'] = $status[$key] === '1' ? gettext('On') : gettext('Off'); + } + $result = array_merge($result, $status); + } + + return $result; + } +} diff --git a/sysutils/dec-hw/src/opnsense/scripts/dec-hw/powerstat b/sysutils/dec-hw/src/opnsense/scripts/dec-hw/powerstat new file mode 100755 index 000000000..08773e451 --- /dev/null +++ b/sysutils/dec-hw/src/opnsense/scripts/dec-hw/powerstat @@ -0,0 +1,15 @@ +#!/bin/sh + +GPIOC="/dev/gpioc0" + +if [ ! -e "$GPIOC" ]; then + logger -t "dec-hw" "Error: GPIO device does not exist, exiting." + exit 0 +fi + +i=1 +for PIN in 4 5; do + STATUS=$(gpioctl -f "$GPIOC" "$PIN") + printf "pwr%d=%d\n" "$i" "$STATUS" + i=$((i + 1)) +done diff --git a/sysutils/dec-hw/src/opnsense/service/conf/actions.d/actions_dechw.conf b/sysutils/dec-hw/src/opnsense/service/conf/actions.d/actions_dechw.conf new file mode 100644 index 000000000..7483a404d --- /dev/null +++ b/sysutils/dec-hw/src/opnsense/service/conf/actions.d/actions_dechw.conf @@ -0,0 +1,5 @@ +[power] +command:/usr/local/opnsense/scripts/dec-hw/powerstat +parameters: +type:script_output +message:Deciso PWR LED state diff --git a/sysutils/dec-hw/src/www/widgets/include/dechw.inc b/sysutils/dec-hw/src/www/widgets/include/dechw.inc new file mode 100644 index 000000000..64b611402 --- /dev/null +++ b/sysutils/dec-hw/src/www/widgets/include/dechw.inc @@ -0,0 +1,3 @@ + + + + + + +
+
+
+ +
+
+ +
+