Fun with dhcpd hooks
Today, I found out one of my switches had a hiccup and caused a packet loss of about 80%. This triggered me to build meshping, a distributed ping service that I'm going to integrate with FluxMon in order to notice such stuff more quickly in the future. Of course, I could just use any monitoring tool, but I just can't be arsed to configure one. I need something that configures itself.
So now that I have meshping, I want to integrate it with the ISC DHCPd that is
running on my router so it automatically pings new clients via meshping. Turns out this is surprisingly easy because
isc-dhcpd actually supports hooks in its config — and
people even know how to use 'em!
So I just had to clone meshping onto my router and add these lines to dhcpd.conf:
on commit {
set clip = binary-to-ascii(10, 8, ".", leased-address);
execute("/opt/meshping/cli.py", "-qa", "-T", clip, "-t", option host-name);
}
on release {
set clip = binary-to-ascii(10, 8, ".", leased-address);
execute("/opt/meshping/cli.py", "-qd", "-T", clip);
}
on expiry {
set clip = binary-to-ascii(10, 8, ".", leased-address);
execute("/opt/meshping/cli.py", "-qd", "-T", clip);
}
I then triggered my client to renew its lease, and sure enough, it showed up in meshping (those avg/min/max/last values are milliseconds, btw):
Target Sent Recv Errs Outd Loss Err Outd Avg Min Max Last 192.168.0.165 6 6 0 0 0.00% 0.00% 0.00% 3.71 0.00 12.46 1.38
Here's the output of meshping's CLI:
root@hive:/opt/meshping# ./cli.py
{
...
"43625": {
"last": 0.0013849735260009766,
"name": "damien",
"min": 0,
"max": 0.012456893920898438,
"due": 1441532131.453555,
"errs": 0,
"outd": 0,
"itv": 30,
"sum": 0.022266864776611328,
"recv": 6,
"id": 43625,
"sent": 6,
"addr": "192.168.0.165"
},
...
}
This is awesome. Now I just need a little Flux sensor to query meshping and I'll have all the data I can dream of.
Of course, getting FluxMon to actually make sense of that is going to be a whole new story...