What's new

Diversion Emitting service_event for Diversion status for use in user scripts

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Phantomski

Regular Contributor
Hi,

first of all thanks for the amtm / Diversion and the latest update!

This one is more of a request, or an idea.

At the moment, the only way (I know of) how to remotely monitor the status of Diversion ad-blocking running on the router is to ssh into it and check the pixelserv is running by using ps | grep [p]ixelserv-tls. This is a bit resource heavy (and thus not best to be invoked too often) and pollutes the log a bit too with dropbear logging.

I would like to write a script, that would monitor the status of Diversion and report that status to the remote monitoring client (curl to Home Assistant for example). Ideally, that would be event-triggered and not periodically polled. So at first my idea was to use service-event user script, but unfortunately no Diversion specific service events are emitted for Diversion status, apart from the generic dnsmasq restart. There's also no specific user script like wan-event or openvpn-event

Is there anything along these lines available (or planned for the future) and I just couldn't find it, or the only way at the moment would be a script daemon periodically checking the router's log or Diversion status and emitting changes?

Thanks
 
Diversion provides a commandline status output for the iOS Shortcut for Diversion but it only reports what the config file says.
This command can also be run in the terminal:
Code:
diversion sh-state
A better way to check if ad-blocking is running and pixelserv-tls is up would be with these two pings from anywhere within your LAN, including the router itself:
Code:
ping diversion-adblocking-ip.address
This would be answered by Dnsmasq that has the blocking list loaded, therefore Diversion runs as expected. diversion-adblocking-ip.address (this literal string) is always at the top of the blocking list and points to the blocking IP.
Code:
curl http://<pixelsert-tls IP>/servstats.txt
This would return the stats in textformat by pixelserv-tls. Use http, not https. This confirms the binary is running.

A bit of grep or awk and one could automate all this and run it by a cron job.
 
Code:
ping diversion-adblocking-ip.address
This would be answered by Dnsmasq that has the blocking list loaded, therefore Diversion runs as expected. diversion-adblocking-ip.address (this literal string) is always at the top of the blocking list and points to the blocking IP.
Code:
curl http://<pixelsert-tls IP>/servstats.txt
This would return the stats in textformat by pixelserv-tls. Use http, not https. This confirms the binary is running.
Brilliant, I can work with these two. Thanks!
 
Just to circle back to this in case someone else is interested or working out how to do this in the Home Assistant.

Eventually settled down on dig to test DNS dnsmasq records directly, rather than relying on ping, which due to how HA handles DNS caching and upstream fallback can be a little finicky. Also, simple A query to the router seems much quicker way of doing it than even a single ICMP. Long story short.

YAML:
switch:
  - platform: command_line
    switches:
      router_diversion:
        friendly_name: Router Diversion
        command_on: 'ssh <user>@<host> -i <key> -o ''StrictHostKeyChecking=no'' -p <port> ''diversion enable'''
        command_off: 'ssh <user>@<host> -i <key> -o ''StrictHostKeyChecking=no'' -p <port> ''diversion disable'''
        command_state: "dig diversion-adblocking-ip.address @<router/DNS IP> | grep NOERROR && exit 0 || exit 1"

Of course both of these would work just as well, it just wasn't as reliable for me due to DNS caching and not as easy/clean to handle due to ping timeouts when pixelserv is unreachable:
YAML:
command_state: "ping -c 2 <pixelserv IP> &> /dev/null && exit 0 || exit 1"
command_state: "ping -c 2 diversion-adblocking-ip.address &> /dev/null && exit 0 || exit 1"
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top