OPNsense Forum
English Forums => General Discussion => Topic started by: patrick3000 on April 28, 2023, 07:52:47 pm
-
I have two WANS, a primary WAN and a secondary WAN, and a gateway group with failover from primary WAN to secondary WAN when primary WAN goes down.
I would like to use Monit, available under "services," to send an email notifying me when either WAN goes down. I looked in the OPNsense documentation for Monit and didn't see anything about notification when an interface goes down.
So I'm wondering: before I spend the time setting up Monit and configuring it with my email, is this something that Monit can do? Does anyone have some tips on the setup?
-
Yes it's possible there is even a built in script for this, I've been using this for years.
Go to Services/Monit/Settings.
Alert Settings - assume you have other alerts setup and working
Under Service Settings create a new service call it - gateway_alert.
Type - Custom
Path - /usr/local/opnsense/scripts/OPNsense/Monit/gateway_alert
Tests - NonZeroStatus
Description - Monitors for gateway status changes and failover.
-
Well, there is a problem with that. It had been some time since I noticed that Monit was not alerting me of loss of internet connectivity. Today I disconnected my cable modem and ran /usr/local/opnsense/scripts/OPNsense/Monit/gateway_alert. It keeps getting an exit code of 0, no matter what.
-
In order for these steps to work there is one missing piece that I was unaware of. That script monitores gateway groups, not single gateways. In addition to the steps provide by FullyBorked (great job!) you need to:
- Create a Gateway Group (System > Gateway > Group).
- Include in that group only the WAN interface. Don't worry about any others. If you have others and want to monitor them too you'll need separate Gateway Groups.
- Choose the Trigger. I like Packet Loss and High Latency. It just works!
- Save and Apply.
Now the script will alert you for sure. See https://github.com/opnsense/core/issues/6562.
Thanks to AdSchellevis (https://github.com/AdSchellevis) for the information.