Updated the script with an alternatuve method
====
#!/bin/bash
#Alternative
shopt -s extglob
# Test the wg0 connection state using monit ZeroStatus test
# RC =1 is the connection state which defaults the wg0 as being connected -> exit 1
# reports as 'status =1'
RC=1
# If no wg0 packets are received, it needs to be restarted with RC =0 -> exit 0
# Important: need to report 'status =0' to the opnsense monit ZeroStatus test
# which will re-start the wg0 connection
# in-line command
#[[ $(netstat -i | grep -F -- " 0 - " | grep "100.80.224.94" | wc -l) -eq "1" ]] \
#&& RC=0 && echo "!connected" $(date +"%Y-%m-%d %H:%M:%S") && exit $RC \
#|| echo "connected" $(date +"%Y-%m-%d %H:%M:%S") && exit $RC
RC=`netstat -i | grep -F -- " 0 - " | grep "100.80.224.94" | wc -l`
#echo $RC
[$RC -eq 1 ] && RC="0" || RC="1"
case $RC in
0) printf "wg0 !connected $(date +"%Y-%m-%d %H:%M:%S") \n" && exit 0;;
1) printf "wg0 connected $(date +"%Y-%m-%d %H:%M:%S") \n" && exit 1;;
*) printf "Issue with wg0_monit_start.sh \n";;
esac
====
====
#!/bin/bash
#Alternative
shopt -s extglob
# Test the wg0 connection state using monit ZeroStatus test
# RC =1 is the connection state which defaults the wg0 as being connected -> exit 1
# reports as 'status =1'
RC=1
# If no wg0 packets are received, it needs to be restarted with RC =0 -> exit 0
# Important: need to report 'status =0' to the opnsense monit ZeroStatus test
# which will re-start the wg0 connection
# in-line command
#[[ $(netstat -i | grep -F -- " 0 - " | grep "100.80.224.94" | wc -l) -eq "1" ]] \
#&& RC=0 && echo "!connected" $(date +"%Y-%m-%d %H:%M:%S") && exit $RC \
#|| echo "connected" $(date +"%Y-%m-%d %H:%M:%S") && exit $RC
RC=`netstat -i | grep -F -- " 0 - " | grep "100.80.224.94" | wc -l`
#echo $RC
[$RC -eq 1 ] && RC="0" || RC="1"
case $RC in
0) printf "wg0 !connected $(date +"%Y-%m-%d %H:%M:%S") \n" && exit 0;;
1) printf "wg0 connected $(date +"%Y-%m-%d %H:%M:%S") \n" && exit 1;;
*) printf "Issue with wg0_monit_start.sh \n";;
esac
====
"