For easier testing when using curl, I’d use the method I describe at Bes Properties that are not set or unkown causing relevance query issue to store the relevance query in an external file.
In an external file, we don’t have to do the URL-encoding, we can have curl do that for us. We also can have line breaks in the query to make it much more readable.
The query itself could have some more error handling in it. In my case I’ll create a file ‘query.txt’ with the following content:
(
id of it,
name of it | "<hostname not reported>"
, concatenation ";" of (ip addresses of it as string)
, value of result from (bes property "User name" whose (default flag of it)) of it | "<none>"
) of bes computers whose
(
exists (ip addresses of it) whose (it as string contains "192.168.")
)
This handles computers that have no one logged on at the moment, and computers with multiple IP addresses. For debugging I also return the IP addresses of the computer, feel free to remove that property if you don’t want it.
To send the query, from the directory in which query.txt is present, I execute
curl --insecure --user username:password --data-urlencode "output=json" -X POST "https://bes-root.local:52311/api/query" --data-urlencode "relevance@query.txt"
Because I include the “output=json” header in the command line, the results are in JSON format. You can leave that out if you prefer dealing with the XML output format. When I run this one, my query returns results in this format (some snipped for readability):
{"result":[[9024435,"rhel8-sv1.domain.home","192.168.1.82;192.168.122.1","<none>"],[10545704,"WEBUI","192.168.1.99","Administrator"],[11635830,"OSD","192.168.1.152","<none>"],[539193122,"BES-ROOT","192.168.1.151","Administrator"]],"plural":true,"type":"( string, string, string )","evaltime_ms":1}
edit: modified the query to also return the BES Computer ID, and to trap cases where the BES Computer name has not been reported (a case can occur where a computer is queried before its hostname has been reported to the server)