Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dbus signal handler for e NetworkManager VPN connection

Tags:

python

linux

dbus

I need to develop some python code to be executed when a VPN connection is established, the VPN is controlled from NetworkManager, I am trying to figure how to use an NM DBUS event for this.

Using "dbus-monitor --system" I was able to identify the connect signal:

signal sender=:1.1 -> dest=(null destination) serial=464 path=/org/freedesktop/NetworkManager/ActiveConnection/3; interface=org.freedesktop.NetworkManager.VPN.Connection; member=PropertiesChanged
   array [
      dict entry(
         string "VpnState"
         variant             uint32 5
      )
      dict entry(
         string "State"
         variant             uint32 2
      )
   ]

Now I need to identify the corresponding signal handler calling signature:

bus.add_signal_receiver(
   handler_name_in_your_program,
   "signal_name",
   "interface_name",
   "connection_name",
   "object_name"

)

Can someone help me translating the dbus-monitor trace output into the corresponding function values for the bus sginal handler ?

like image 216
João Pinto Avatar asked Dec 09 '10 18:12

João Pinto


1 Answers

I was able to figure it out:

def vpn_connection_handler(*args, **keywords):
    state = args[0].get('State',0)
    if state == 2:
        # On connect code goes here

system_bus.add_signal_receiver(vpn_connection_handler,
    dbus_interface="org.freedesktop.NetworkManager.VPN.Connection",
        signal_name="PropertiesChanged")
like image 189
João Pinto Avatar answered Sep 19 '22 06:09

João Pinto