Re: NNMi API - using Python and WS-I filters (365 Views)
Occasional Collector
Posts: 3
Registered: ‎06-30-2011
Message 1 of 2 (387 Views)

NNMi API - using Python and WS-I filters



We are using python frequently in our compagny to automate certain processes and came  across the following article describing a way to interface with the NNMi 9 WS-I API:


The example works great only I'm struggling with using filters. I would like to for example query the API to return a node with a certain name. I read up on the WS-I Filter Definition chapter in the Developers Toolkit guide but couldn't figure out the proper syntax for the filter.


I've tried several things e.g:



"EXISTS {name=HOST01"}"




but unfortunately it seems anything I use just dumps the full node table (actually only 1000 records as maxObjects='1000' by default which i also don't know how to change :) )


The developers guide does show a few examples in Java but I'm not sure how to translate it.


(Java example)

// EXIST clause

Condition condition1 = new Condition();




Condition condition2 = new Condition();




Filter[] subFilters = new Filter[]{condition1, condition2};

Filter existFilter = new Expression();



Filter[] existSubFilters = new Filter[]{existFilter};

Expression exist = new Expression();





Kind regards




Occasional Collector
Posts: 3
Registered: ‎06-30-2011
Message 2 of 2 (365 Views)

Re: NNMi API - using Python and WS-I filters

Hi Guys,


After some browsing and fiddling around I finally managed to create a proper filter. It came down to my lack of understanding of using SOAP i guess.. Anyway here's a quick python function to get a specific host from NNMi using python and suds:



from suds.client import Client

from suds.transport.http import HttpAuthenticated


user = "myNNMiUser"

pw = "myNNMipw"


= HttpAuthenticated(username=user, password=pw)

url_node = ''


def getNode(hostname):

  client = Client(url_node, transport=t)


  filter = client.factory.create('ns3:condition')"name"




  # print filter

  node = client.service.getNodes(filter)


  if node:

    for i in node.item[:]:

      print str(i)


    print "No node with hostname " + hostname + " found.."




The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.