OPNsense Forum

English Forums => General Discussion => Topic started by: Stuzoo72 on February 06, 2022, 01:10:59 AM

Title: How to initiate an opnsense action when WAN goes down
Post by: Stuzoo72 on February 06, 2022, 01:10:59 AM
Hi,
I have WAN connection, broadband and a 4G router.
dpinger monitors the gateway on the broadband WAN very well and shows online/offline.

I have separate inbound and outbound connections from Opnsense to the 4G router.
For technical Telco reasons, when the broadband is down I need to disable DHCP on the Opnsnese inbound interface connected to the 4G router. I can't get around this.

I need to setup a job/task that is basically

If Gateway Monitor (broadband) is down then disable DHCP on opnssnese [Net_4G_inbound]
If Gateway Monitor (broadband) is up then enable DHCP on opnssnese [Net_4G_inbound]

Any ideas?
Title: Re: How to initiate an opnsense action when WAN goes down
Post by: franco on February 07, 2022, 11:53:33 AM
Hi,

https://github.com/opnsense/core/blob/master/src/etc/rc.syshook.d/monitor/10-dpinger is a script that hooks into the monitor events. The rc.syshook.d/monitor directory will take any script, maybe you want to add one as 20-dhcp so it triggers after initial dpinger functionality, or maybe you need it ealier as 05-dhcp.

Depending on what "disable DHCP" means the script could end up being relatively complex. I'm happy to provide more hints if needed.


Cheers,
Franco
Title: Re: How to initiate an opnsense action when WAN goes down
Post by: Greelan on February 07, 2022, 12:16:52 PM
Monit could probably also do this job
Title: Re: How to initiate an opnsense action when WAN goes down
Post by: franco on February 07, 2022, 12:27:57 PM
True, good idea.


Cheers,
Franco
Title: Re: How to initiate an opnsense action when WAN goes down
Post by: Stuzoo72 on February 13, 2022, 02:14:07 AM
Thanks for the replies. I do like Monit as a solution.

I have enabled Monit and the inbuilt "gateway_alert" service setting. For the moment this does what I need - reporting if one of the gateways is down.
From that I can action start/stop etc.

What I now need is a command to stop (disable) and one to start (enable) DHCP on a specific interface.
From GUI it would be
Services: DHCPv4: [WAN2_Incoming]
Toggle enable/disbale "Enable DHCP server on the WAN2_Incoming interface"

I don't want to turn off DHCP for for all interfaces, just this one.

Can some one help with scripts for the above enable/disable?



Where is the best place to store scripts used by Monit? Somewhere that won't be overwritten during an upgrade.