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

NNMi API - using Python and WS-I filters

Hello,

 

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:

 

http://24x7x0.wordpress.com/2011/07/07/use-python-to-talk-to-nnmi/

 

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:

 

"name=HOST01"

"EXISTS {name=HOST01"}"

"node.name=HOST01"

"{customAttribute.name=name}{customAttribute.value=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();

condition1.setName("customAttribute.name");

condition1.setOperator(Operator.EQ);

condition1.setValue("test");

Condition condition2 = new Condition();

condition2.setName("customAttribute.value");

condition2.setOperator(Operator.EQ);

condition2.setValue("0");

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

Filter existFilter = new Expression();

existFilter.setOperator(BooleanOperator.AND);

existFilter.setSubFilters(subFilters);

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

Expression exist = new Expression();

exist.setOperator(BooleanOperator.EXISTS);

exist.setSubFilters(existSubFilters);

 

 

Kind regards

 

 

 

Please use plain text.
Occasional Collector
thiezn
Posts: 3
Registered: ‎06-30-2011
Message 2 of 2 (121 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 = 'http://nms.yourdomain.com/NodeBeanService/NodeBean?wsdl'

 

def getNode(hostname):

  client = Client(url_node, transport=t)

 

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

  filter.name="name"

  filter.operator="EQ"

  filter.value=hostname

 

  # print filter

  node = client.service.getNodes(filter)

 

  if node:

    for i in node.item[:]:

      print str(i)

  else:

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

 

 

Cheers,..

Please use plain text.
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