On an intermediate trap catching server, which receives traps from switches, it is possible to forward the traps to a desktop PC. In /etc/snmp/snmptrapd.conf write something like:
forward default udp6:[2001:db8::]:162
If /etc/hosts.allow and /etc/hosts.deny control access, then disableAuthorization can be set as well.
On the desktop pc, write:
authCommunity log,execute,net public traphandle IF-MIB::linkDown /etc/snmp/traps down traphandle IF-MIB::linkUp /etc/snmp/traps up # snmptrap -v 1 -c public 192.0.2.1 IF-MIB::linkDown localhost 2 1 "" # snmptrap -v 1 -c public 192.0.2.1 IF-MIB::linkUp localhost 3 1 "" traphandle default /etc/snmp/traps
A trap handler can present the link up down messages to the logged in user via GNOME.
#!/bin/sh
read host
read ip
interface="unknown"
while read oid val
do
case "${oid}" in
.1.3.6.1.6.3.1.1.4.1.0)
case "${val}" in
.1.3.6.1.6.3.1.1.5.3)
link="down"
;;
.1.3.6.1.6.3.1.1.5.4)
link="up"
;;
esac
;;
.1.3.6.1.2.1.2.2.1.1.1)
interface="${val}"
;;
esac
done
dbus=($(ps -C dbus-launch -o user=))
pulse=($(ps -C pulseaudio -o user=))
if test "${link}" = "up"
then
if test "${#dbus[*]}" -ne 0
then
eval "$(<$(eval echo ~"${dbus[0]}")/.dbus/session-bus/$(</var/lib/dbus/machine-id)-0)"
export DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID DBUS_SESSION_BUS_WINDOWID
/bin/su --command=$'/usr/bin/notify-send -t 1000 up $\'interface '"${interface}"$'\'' "${dbus[0]}"
fi
if test "${#pulse[*]}" -ne 0
then
# configure samples in ~/.pulse/default.pa and ~/.pulse/daemon.conf
/bin/su --command=$'pactl play-sample bark' "${pulse[0]}"
fi
fi
if test "${link}" = "down"
then
if test "${#dbus[*]}" -ne 0
then
eval "$(<$(eval echo ~"${dbus[0]}")/.dbus/session-bus/$(</var/lib/dbus/machine-id)-0)"
export DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID DBUS_SESSION_BUS_WINDOWID
/bin/su --command=$'/usr/bin/notify-send -t 1000 down $\'interface '"${interface}"$'\'' "${dbus[0]}"
fi
if test "${#pulse[*]}" -ne 0
then
/bin/su --command=$'pactl play-sample sonar' "${pulse[0]}"
fi
fi