Ubuntu – Is it possible to add a notification message when a VPN gets connected

10.04notificationvpn

I'm using Ubuntu 10.04 and I use to connect to a pptp VPN, everything works perfectly, when i start my VPN connection I can see that the connection is in progress from the NetworkManager icon, and I can see that the connection is on when the Network icon gets the small lock.

notification area with network connection and vpn lock icon

Is it possible to add a notification ballon, like the one I see when the network connection is estabilished?

eth0 connection estabilished notification baloon

P.s if the connection fail or is dropped, the notification cames out like this:
vpn failed

Best Answer

This is more like a hack but should work (works for me).

vpn-notify.py:

import gtk
import pynotify
import dbus
from dbus.mainloop.glib import DBusGMainLoop

def vpn_connection_handler(*args, **keywords):
    state = args[0].get('State',0)
    if state == 2:
        n = pynotify.Notification ("VPN", "Connection established")
        n.show()


pynotify.init ("icon-summary-body")


dbus_loop = DBusGMainLoop()

system_bus = dbus.SystemBus(mainloop=dbus_loop)
system_bus.add_signal_receiver(vpn_connection_handler,
    dbus_interface="org.freedesktop.NetworkManager.VPN.Connection",
    signal_name="PropertiesChanged")

gtk.gdk.threads_init()
gtk.main()

Run it with:

python vpn-notify.py

Establish the VPN connection.