Siptrack API (client) examples

Simon Ekstrand edited this page Mar 21, 2016 · 1 revision

A large goal of siptrack is to be easily scriptable. The 'siptracklib' python client library is included with the siptrack package and is intended to be usable to quickly and easily create python scripts that use data from a siptrack server. The siptrack server can also be communicated with directly via an xmlrpc interface, but that is slightly more complicated.

There are two ways to connect to a siptrack server with siptracklib, siptracklib.fconnect, which uses account/configuration information from the siptrack configuration files, and siptracklib.connect, which takes all connection information as parameters.

import siptracklib
st = siptracklib.connect('', 'username', 'password', use_ssl = True)

st = siptracklib.fconnect()

This will return a connection to a siptrack server that can be used for querying, adding/removing entities etc.

Examples of searching the siptrack server:

>>>'', include = ['device'])
[siptracklib.device.Device object at 0xb790ea2c]

[ipv4.Network(16:, ipv4.Network(17:,

Viewing entity attributes:

>>> d ='', include = ['device'])[0]
>>> [(, a.value) for a in d.attributes]
[('name', ''), ('class', 'server'), ('description', 'Test server.'), ('notes', 'This is a test device.\n\n*Textile* wiki markup can be used in this notes field.')]

Listing a devices networks:

>>> d ='', include = ['device'])[0]
>>> d.listNetworks()

All objects in the siptrack server are stored in a single tree, shaped something like:

        network trees
        device trees
            device categories
user managers

All object types can also have attributes as children. Attributes can be accessed via 'attributes', ie.:

>>> d ='', include = ['device'])[0]
>>> d.attributes['name']
>>> d.attributes['name'] = ''
>>> d.attributes['name']

Adding and removing objects is also simple, objects are always added directly onto a parent, ie.:

>>> d ='', include = ['device'])[0]
>>> d2 = d.add('device')
>>> d2.attributes['name'] = 'interface-1'
>>> d2.delete()

The exception to this is networks, which must be added to the network tree they belong in, and will be placed correctly in the network tree automatically.

>>> nt ='ipv4', include = ['network tree'])[0]
>>> nt
>>> nt.addNetwork('')

Objects can be associated with the 'associate' method, ie.:

>>> d ='', include = ['device'])[0]
>>> n ='', include = ['ipv4 network'])
>>> d.associate(n)
>>> list(d.associations)
>>> d.disassociate(n)

The .listChildren() method can be used to list an objects children:

>>> st.view_tree.listChildren()
[siptracklib.user.UserManagerLocal object at 0xb799370c, siptracklib.view.View object at 0xb796ca6c]
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.