OPNsense Forum

English Forums => General Discussion => Topic started by: patrick3000 on April 28, 2023, 07:52:47 pm

Title: Use monit to test for interface down?
Post 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?
Title: Re: Use monit to test for interface down?
Post by: FullyBorked on May 01, 2023, 05:25:22 pm
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.
Title: Re: Use monit to test for interface down?
Post by: kpiq on May 09, 2023, 04:06:02 am
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.
Title: Re: Use monit to test for interface down?
Post by: kpiq on May 27, 2023, 12:07:10 am
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:

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.