Hi good people,
I'm after a little bit of help if possible.
Currently running OPNSense 22.7 as my main router on a dual WAN (Failover Only)
I use a CRON script that runs every 5 minutes to detect if my main WAN connection is back up and forcefully push all connections back over to it. The script is below, but ideally what I would like to do is ping an email via SMTP ideally when it's about to kill the states. I down the interface after the state kills as OPNSense itself seems to want to hang onto using my backup connection, but downing it for 3 minutes cures that issue.
Is there an easy command line statement I can use to ping an email from inside the CRON job?
Thanks for any input.
#!/bin/sh
# *** Kills firewall states on failover Mobile Data when WAN is up ***
WAN_IF="igc1"
CURRENT_TIME="$(date +"%c")"
WAN_STATUS=`route -n show default | grep interface | awk '{print $2}'`
if [ "$WAN_STATUS" = "$WAN_IF" ]; then
# See if there are any active states on the mobile data apart from the ping monitor and possibly web gui
MOBILE_NSTATES=`pfctl -s state | grep "192\.168\.5" | grep -v "192\.168\.5\.1:80" | wc -l`
if [ "$MOBILE_NSTATES" -gt 1 ]; then
echo "$CURRENT_TIME: MAINWAN is online, but connections remain on Mobile Data. Killing states."
pfctl -F state
ifconfig igc2 down;sleep 180;ifconfig igc2 up
else
echo "$CURRENT_TIME: ALL GOOD."
fi
fi
NVM, I decided to use CURL to send an email like this:
curl --request POST \
--url https://api.sendgrid.com/v3/mail/send \