How to parse relevance query xml file

Hi,

Does anyone have a method or suggestion on how to parse a relevance query xml? Not sure how It can be done with an xml fille that has ‘Answer’ for all the tags and no unique fields for each property.

Thanks

Are you looking to get a specific answer from clientqueryresult?

Hi jgo,

Im trying to print the results from a query xml that has each value between Answer > <.
I would like to print each value something like this:

Computer: ServerName
IP Address: 10.10.10.11
Root Server: bfRootServer
OS: Windows Server 2012
Last Report Time: Fri, 22 Jun 2018 10:26:53 -0500
BES Agent Version: 9.2.1.48
Support Group: SupportGroup1

Maybe a way with sed or awk to grab the value sequentially from each line?

Can you post one of the ClientQueryresult?

And… what OS are you using when you parse the XML?

Will there be a BigFix agent on the Endpoint you parse the XML with?

I’m using bash on a solaris box.

Yes the endpoints have BES agents.

<?xml version="1.0" encoding="UTF-8"?> <BESAPI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BESAPI.xsd"> <Query Resource="(names of it, ip addresses of it, root server of it, operating systems of it, last report time of it, agent versions of it, values of results from (BES Property &quot;SupportGroup&quot;) of it) of bes computers whose ( name of it as lowercase starts with &quot;ServerName&quot;)"> <Result> <Tuple> <Answer type="string">ServerName</Answer> <Answer type="string">10.10.10.1</Answer> <Answer type="string">bfRootServer (0)</Answer> <Answer type="string">Linux Red Hat Enterprise Server 6.9 (2.6.32-696.23.1.el6.x86_64)</Answer> <Answer type="time">Fri, 22 Jun 2018 10:26:53 -0500</Answer> <Answer type="string">9.2.1.48</Answer> <Answer type="string">SupportGroup1</Answer> </Tuple> </Result> <Evaluation> <Time>34.402ms</Time> <Plurality>Plural</Plurality> </Evaluation> </Query> </BESAPI>

That looks funky. Can you upload the file?

<a class="attachment" href="/uploads/default/original/2X/5/57aac48cdabb812fd23ce6734cbd888e15ef8c7d.bes">results.bes</a> (1.3 KB)

you’ll have to change the file extension to xml or txt.

I think this will give you the values:

if (xpath "/BESAPI/Query/Evaluation/Plurality" of xml documents of file "%FILEPATH%" as text="Plural") then (xpaths "/BESAPI/Query/Result/Tuple/Answer" of xml documents of file "%FILEPATH%" as text) else (xpaths "/BESAPI/Query/Result/Answer" of xml documents of file "%FILEPATH%" as text)

`
-Jgo

Thanks. Is this relevance query language and where do I make reference to the xml file, here? xpath = ‘file.xml’

That would be the “%FILEPATH%”. You would replace it with the path to the file.

OK, I’ll give it a try. Thanks again.

Couple of options for making it look prettier:

q:(("Computer: " & tuple string item 0 of it) & "%0D%0A" of ("IP Address: " & tuple string item 1 of it) & "%0D%0A" &("Root Server: " & tuple string item 2 of it) & "%0D%0A" &("OS: " & tuple string item 3 of it) & "%0D%0A" &("Last Report Time: " & tuple string item 4 of it & ", " & tuple string item 5 of it) & "%0D%0A" &("BES Agent Version:" & tuple string item 6 of it) & "%0D%0A" &("Support Group: " & tuple string item 7 of it)) of concatenation ", " of (it as text) of (if (xpath "/BESAPI/Query/Evaluation/Plurality" of xml documents of file "c:\users\bigfix\desktop\results.xml" as text="Plural") then (xpaths "/BESAPI/Query/Result/Tuple/Answer" of xml documents of file "c:\users\bigfix\desktop\results.xml") else (xpaths "/BESAPI/Query/Result/Answer" of xml documents of file "c:\users\bigfix\desktop\results.xml"))
A: Computer: ServerName%0d%0a%0d%0aRoot Server: bfRootServer (0)%0d%0aOS: Linux Red Hat Enterprise Server 6.9 (2.6.32-696.23.1.el6.x86_64)%0d%0aLast Report Time: Fri, 22 Jun 2018 10:26:53 -0500%0d%0aBES Agent Version:9.2.1.48%0d%0aSupport Group: SupportGroup1
T: 1.069 ms

OR

q:(tr of td of ("Computer: " & tuple string item 0 of it) & tr of td of ("IP Address: " & tuple string item 1 of it) & tr of td of ("Root Server: " & tuple string item 2 of it) & tr of td of ("OS: " & tuple string item 3 of it) & tr of td of ("Last Report Time: " & tuple string item 4 of it & ", " & tuple string item 5 of it) & tr of td of ("BES Agent Version:" & tuple string item 6 of it) & tr of td of ("Support Group: " & tuple string item 7 of it)) of concatenation ", " of (it as text) of (if (xpath "/BESAPI/Query/Evaluation/Plurality" of xml documents of file "c:\users\bigfix\desktop\results.xml" as text="Plural") then (xpaths "/BESAPI/Query/Result/Tuple/Answer" of xml documents of file "c:\users\bigfix\desktop\results.xml") else (xpaths "/BESAPI/Query/Result/Answer" of xml documents of file "c:\users\bigfix\desktop\results.xml"))
A: <tr><td>Computer: ServerName</td></tr><tr><td>IP Address: 10.10.10.1`</td></tr><tr><td>Root Server: bfRootServer (0)</td></tr><tr><td>OS: Linux Red Hat Enterprise Server 6.9 (2.6.32-696.23.1.el6.x86_64)</td></tr><tr><td>Last Report Time: Fri, 22 Jun 2018 10:26:53 -0500</td></tr><tr><td>BES Agent Version:9.2.1.48</td></tr><tr><td>Support Group: SupportGroup1</td></tr>

This means that you could embed either of these in an actionscript using createfile.

createfile until EOF
{(("Computer: " & tuple string item 0 of it) & "%0D%0A" of ("IP Address: " & tuple string item 1 of it) & "%0D%0A" &("Root Server: " & tuple string item 2 of it) & "%0D%0A" &("OS: " & tuple string item 3 of it) & "%0D%0A" &("Last Report Time: " & tuple string item 4 of it & ", " & tuple string item 5 of it) & "%0D%0A" &("BES Agent Version:" & tuple string item 6 of it) & "%0D%0A" &("Support Group: " & tuple string item 7 of it)) of concatenation ", " of (it as text) of (if (xpath "/BESAPI/Query/Evaluation/Plurality" of xml documents of file "c:\users\bigfix\desktop\results.xml" as text="Plural") then (xpaths "/BESAPI/Query/Result/Tuple/Answer" of xml documents of file "c:\users\bigfix\desktop\results.xml") else (xpaths "/BESAPI/Query/Result/Answer" of xml documents of file "c:\users\bigfix\desktop\results.xml"))}
EOF
copy __creatfile "c:\path\newfile.txt"

Later,
Jgo

1 Like

I edited the results to put forum code tags on it.

Forgive my ignorance but how would I execute the code to parse the xml file?
I’m using curl and unix bash shell to execute the relevance query that dumps the results to the xml file.

Thanks,
Tony

I would have two actions in a bseline. Action 1 would run REST api and bash shell action, saving the XML to a local file. Then in action 2 I would execute the Creatfile example from above to parse your folder. You could do it all in one action with sed and awl, but I figure there are many examples of that or regex you could find… so I gave you an actionscript to execute. On action script you will need to execute the action as action script as opposed to sh.
-Jgo

1 Like

Thanks again jgo…will give it a try