So, if you want to script this from the ground up, why not just drop a script into /etc/hotplug.d/iface/
with content like this:
/usr/bin/env > /tmp/envs_${INTERFACE}_${DEVICE}_${ACTION}.log
Then you see, which variables you get, and can write a script to react accordingly