How to initiate an opnsense action when WAN goes down

Started by Stuzoo72, February 06, 2022, 01:10:59 AM

Previous topic - Next topic
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?

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
"AI has absolutely reduced the cost of creating technical debt." -- ChatGPT


True, good idea.


Cheers,
Franco
"AI has absolutely reduced the cost of creating technical debt." -- ChatGPT

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.