When querying my internal API I get a bunch of responses. Those responses will tell me if a specific service is up/down.
Curl command:
curl https://myinternalapi.example.com/Ping/1.1
Output:
<?xml version="1.0" encoding="UTF-8"?><ping><service name="FBcheckOnline" status="down"/><service name="APICheckOn" status="up"/></ping>
I would like to parse the output data using Python/Bash. With the data parsed, I can then create if statements to check if a specific service is up or down.
The desired output would be something like:
FBcheckOnline down
APICheckOn up
How can I do that using Python (2.7) or Bash?
EDIT 1: I managed to get it working with Python 2.7
from xml.dom import minidom
xmldoc = minidom.parse('test.xml')
items = xmldoc.getElementsByTagName('service')
for item in items:
print item.attributes['name'].value,
print item.attributes['status'].value
However, I am trying to make it parse the data from a curl command instead of a file... or make the curl command to send the output to a file and then read it.