Saturday, January 21, 2012

Extracting data from CA Wily APM via web service API


Found an interesting gotcha with the CA Wily API web services that bit me in the buttocks this week and thought anybody else that might want to access the CA Wily APM via web services might like to know about.

I wrote some sample web service client code in python using the suds library to pull a list of agents against some LPARs and then list out the available metrics for the agents.

8<------------
from suds.client import Client


userName = 'someAccount'
passWord = 'supersupersekrit'


serverName = 'someserver'
serverPort = 1234


metricsDataServiceURL = 'http://%s:%d/introscope-web-services/services/…' % (serverName, serverPort)
agentListURL = 'http://%s:%d/introscope-web-services/services/…' % (serverName, serverPort)


agentListClient = Client(agentListURL, username=userName, password=passWord)
agentList = agentListClient.service.listAgents('.*servername.*')


for agentName in agentList:
  print "Working on Agent %s" % (agentName,)
  metricList = agentListClient.service.listMetrics(agentName, '.*')
  for metricName in metricList:
    print "\t%s" % (metricName,)
------------->8

What I failed to take into account is that the list of agents that is returned from the system have special regex meta characters and when passed back with the call to the listMetrics and these meta characters need to be escaped with a back-whack.

I was able to fix the problem by importing the re regular expression library and using a call to re.escape with the agent name by changing the line

8<--------
metricList = agentListClient.service.listMetrics(agentName, '.*')
--------->8

to

8<--------
metricList = agentListClient.service.listMetrics(re.escape(agentName), '.*')
--------->8

After that, I was able to retrieve a list of all the available metrics for the captured Agents. Any of the API calls that require a resolved Agent name from a regex just need to be escaped and all is well.