Monit setup to notify on connectivity change

Started by cpw, May 23, 2019, 06:52:26 AM

Previous topic - Next topic
Hi. Last one, promise!

So, I'd like to know if anyone has successfully setup monit to monitor network interface state changes, and used them to generate some kind of event? My old setup used a pinger similar to dpinger, but when it detected a state change, I could call an arbitrary script, which I used to post a message to an MQTT topic, where other things could act on the "downed" interface.

In OPNSense, it looks like monit is supposed to be how you do this kind of activity, but quite frankly, it's a complete headscratcher how you'd actually accomplish doing it. I'm guessing I need to monitor the connection, but which connection, how? What do I put in the query expression? Are there placeholders for re0 or whatever?

If monit is not the solution to this problem, how do I do it? I want to dispatch something when connectivity changes, either through DHCP address change, or ISP having a bad day and making a mess of their routing tables, or thunder striking the telco node outside my house and frying the local telephony infrastructure (all have happened in the past 15 years living here).

Many thanks for any help!

Hi cpw,

There's a system facility called rc.syshook which offers a couple of endpoints for  core pr plugin functionality to be called in a serialised, ordered fashion:

https://docs.opnsense.org/development/backend/autorun.html

What's probably most interesting here is the "monitor" event which corresponds with a dpinger event. "carp" is in there too to detect state changes. The caveat with monitor is that it's a new event which is only available on 19.7 development version for the time being.

https://github.com/opnsense/core/tree/master/src/etc/rc.syshook.d (all the core events and scripts)

https://github.com/opnsense/core/blob/master/src/etc/rc.syshook (the shell script called for an event)

Hope that helps.


Cheers,
Franco

Interesting. This definitely looks like a possible way forward. Is there any documentation on what is available in the script (env vars)?

It looks like it might be a way to do external notification on connectivity change, for sure.