From 2d0c6ac44327a929e6505b1a34f5e1b7873a181c Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Fri, 3 Jan 2020 12:29:07 +0100 Subject: [PATCH] sysutils/apuled: manually merge update PR: https://github.com/opnsense/plugins/pull/1413 --- sysutils/apuled/Makefile | 2 +- .../src/opnsense/scripts/apuled/apuledctl | 35 ++++++++++++------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/sysutils/apuled/Makefile b/sysutils/apuled/Makefile index f6821168b..4ecabf721 100644 --- a/sysutils/apuled/Makefile +++ b/sysutils/apuled/Makefile @@ -1,5 +1,5 @@ PLUGIN_NAME= apuled -PLUGIN_VERSION= 0.1 +PLUGIN_VERSION= 0.2 PLUGIN_DEVEL= yes PLUGIN_COMMENT= PC Engine APU LED control PLUGIN_MAINTAINER= julio@cloudfence.com.br diff --git a/sysutils/apuled/src/opnsense/scripts/apuled/apuledctl b/sysutils/apuled/src/opnsense/scripts/apuled/apuledctl index 522a52e84..9ca443e86 100755 --- a/sysutils/apuled/src/opnsense/scripts/apuled/apuledctl +++ b/sysutils/apuled/src/opnsense/scripts/apuled/apuledctl @@ -35,20 +35,29 @@ if [ ! -e "$LED1" ];then fi check_wan(){ -# check internet connection -# ping f.root-servers.net # LED2 - network notifications -# XXX fix this IP? -PING_CHECK=$(ping -t 3 -c 3 192.5.5.241 | grep "packet loss" | awk '{print $7}' | cut -d. -f1) -# ok -if [ "$PING_CHECK" -eq 0 ];then - echo "1" > $LED2 -# latency -elif [ "$PING_CHECK" -gt 30 ] && [ "$PING_CHECK" -lt 100 ];then +# Fetch from dpinger the list of gateways and the status of each one +GWLIST=$(ls /var/run/dpinger* | grep sock) + +for GW in $GWLIST; do + GWSTATUS=$(nc -U $GW | awk '{print $4}') + # We're ONLINE + if [ "$GWSTATUS" -eq 0 ];then + echo "1" > $LED2 + # Some losses - LATENCY + elif [ "$GWSTATUS" -gt 30 ] && [ "$GWSTATUS" -lt 100 ];then + LATENCY=1 + # One of our Gateways is DOWN - ALARM + # Test if the GWs are OK. If just one of the GWs failed the test, the LED will show DOWN status + elif [ "$GWSTATUS" -eq 100 ];then + echo "f1" > $LED2 + exit 0 + fi +done + +# In case of packets loss, I'll warn! +if [ ! -z "$LATENCY" ];then echo "f3" > $LED2 -# link down -elif [ "$PING_CHECK" -eq 100 ];then - echo "f1" > $LED2 fi } @@ -77,6 +86,6 @@ fi } # Main routine -check_wan check_load check_disk +check_wan