Hello
I'm trying to use the Cisco PI API to get data into InfluxDB with a Python script.
Howewer i can't make it work using the default XML output from the API
For instance, lets say i want to get the "reachability" field of a device. Here is the API output:
<?xml version="1.0" ?> <queryResponse last="6" first="0" count="7" type="Devices" responseType="listEntityInstances" requestUrl="https://ciscopi/webacs/api/v4/data/Devices?.full=true" rootUrl="https://ciscopi/webacs/api/v4/data" domain="ROOT-DOMAIN"> <entity dtoType="devicesDTO" type="Devices" url="https://ciscopi/webacs/api/v4/data/Devices/1409408"> <devicesDTO displayName="1409408" id="1409408"> <collectionDetail><status><general code="SUCCESS"/></status></collectionDetail> <collectionTime>2020-01-04T21:02:15.696+01:00</collectionTime> <creationTime>2020-01-02T13:55:41.103+01:00</creationTime> <deviceId>1413413</deviceId> <deviceName>somehostname.domain</deviceName> <deviceType>Cisco Catalyst 4510R plus E Switch</deviceType> <ipAddress>1.1.1.1</ipAddress> <managementStatus>MANAGED_AND_SYNCHRONIZED</managementStatus> <productFamily>Switches and Hubs</productFamily> <reachability>REACHABLE</reachability> <softwareType>IOS-XE</softwareType> <softwareVersion>03.08.06.E</softwareVersion> <adminStatus>MANAGED</adminStatus> <collectionStatus>COMPLETED</collectionStatus> <manufacturerPartNrs> <manufacturerPartNr> <name>Switch System</name> <partNumber>WS-C4510R+E</partNumber> <serialNumber>mySN0000000</serialNumber> </manufacturerPartNr> </manufacturerPartNrs> </devicesDTO> </entity> <entity dtoType="devicesDTO" type="Devices" url="https://ciscopi/webacs/api/v4/data/Devices/1409409"> <devicesDTO displayName="1409409" id="1409409"> <collectionDetail><status><general code="SUCCESS"/></status></collectionDetail> <collectionTime>2020-01-04T21:00:20.885+01:00</collectionTime> <creationTime>2020-01-02T13:57:29.302+01:00</creationTime> <deviceId>1413412</deviceId> <deviceName>someotherhostname.domain</deviceName> <deviceType>Cisco 2504 Wireless LAN Controller</deviceType> <ipAddress>2.2.2.2</ipAddress> <location>SO</location> <managementStatus>MANAGED_AND_SYNCHRONIZED</managementStatus> <productFamily>Wireless Controller</productFamily> <reachability>REACHABLE</reachability> <softwareType>Cisco Controller</softwareType> <softwareVersion>8.5.151.0</softwareVersion> <adminStatus>MANAGED</adminStatus> <collectionStatus>COMPLETED</collectionStatus> <manufacturerPartNrs> <manufacturerPartNr> <name>Chassis</name> <partNumber>AIR-CT2504-K9</partNumber> <serialNumber>mySN000000</serialNumber> </manufacturerPartNr> </manufacturerPartNrs> </devicesDTO> </entity> </queryResponse>
And here is my simple script:
from lxml import etree tree = etree.parse("source.xml") for reachable in tree.xpath("/queryResponse/entity/reachability"): print(reachable.text)
The script give me nothing... Do -you have an idea why? Or maybe i'm using the API the wrong way?
Thanks :)
No comments:
Post a Comment