QNA scripting need

is there any way to script qna calls? Let’s say I have 20 relevancies. Not really interested in copy/paste 20 times into a QNA window

In the BES Client Folder, there’s a qna.exe that can take a command-line parameter of a file containing queries.
The input file would be a series of relevance queries, one per line, including the Q: at the front.
I’m using this method from a Scheduled Task to run a query and take some actions based on the query output.

2 Likes

Are you using the Linux/Unix/Mac qna? I believe it can take a parameter for a file containing queries as well.

I am using windows machines

Do you have an example of the argument needed for qna?

On windows…

You’re aware of the Fixlet Debugger? It comes with the BES Console installation, and is available for download from the “Utilities” link near the bottom of the page at http://support.bigfix.com/bes/install/downloadbes.html (at least it’s available when DeveloperWorks is online). You can run the standalone Fixlet Debugger even on machines that don’t have BigFix installed at all.

If this utility is new to you, let me know and we can talk about how to use it.

If Fixlet Debugger doesn’t work for you and you really need to use qna.exe, the following is an example of typing out the content of my query file (c:\temp\query.txt) and then using qna.exe to evaluate it. So you could have the query.txt file open in notepad, evaluate it, change it, then evaluate it again as needed…

C:\Program Files (x86)\BigFix Enterprise\BES Client>type c:\temp\query.txt
q: now

q: name of operating system

q: version of operating system


C:\Program Files (x86)\BigFix Enterprise\BES Client>qna c:\temp\query.txt
Q: now
A: Tue, 05 Jun 2018 09:06:23 -0500

Q: name of operating system
A: Win10

Q: version of operating system
A: 10.0.16299.371
2 Likes

Thanks that worked. I only wanted to use qna.exe since that is already on all boxes. The other one would have to be copied manually (yuk).

Scripting QnA across boxes is essentially what analyses are or BigFix query – is there a reason you need to script these calls across all these machines?

1 Like

It was not across boxes I needed it. I was just tired of copy/paste one relevance at a time from the GUI to a cna session to see if true or not.

If I had 20 relevancies, that would get tiresome in a hurry.

Is the data from these queries something that you want to persist within your BigFix environment? If so, then why not implement as an Analysis in a custom site once you’ve worked out the individual relevance statements in QNA on your development endpoint or via the Query tool in WebUI as per @strawgate?

No, just one off checks to see why a task is not relevant on a machine.

Not sure if this is kind of what you are looking for and this is a really simple example using separate txt files for each relevance you want to send to the qna.exe via powershell…

test.txt contents:
exists key whose {(}value “DisplayName” of it as string contains “Google Chrome”{)} of keys “hklm\software\microsoft\windows\currentversion\uninstall” of {(}x64 registries;x32 registries{)}

test2.txt contents:
exists key whose {(}value “DisplayName” of it as string contains “Mozilla Firefox”{)} of keys “hklm\software\microsoft\windows\currentversion\uninstall” of {(}x64 registries;x32 registries{)}

(notice you have to surround the parentheses in the relevance with {} in order for them to write to the qna.exe otherwise you’d get an error)

powershell script to automate it with qna:

$relevance1 = Get-Content “C:\Program Files (x86)\BigFix Enterprise\BES Client\test.txt”
$relevance2 = Get-Content “C:\Program Files (x86)\BigFix Enterprise\Bes Client\test2.txt"
Invoke-item “C:\Program Files (x86)\BigFix Enterprise\BES Client\qna.exe"
start-sleep -Seconds 2
[System.windows.forms.sendkeys]::Sendwait(”$relevance1”)
start-sleep -Seconds 2
[System.windows.forms.sendkeys]::Sendwait("~")
Start-Sleep -Seconds 2
[System.windows.forms.sendkeys]::Sendwait("$relevance2")
Start-Sleep -Seconds 2
[System.windows.forms.sendkeys]::Sendwait("~")

The “~” is the enter key

Also note that using this method you don’t want to click on anything else as it’s expecting the qna.exe to be the active window when sending the text from the files. Clicking on anything else interrupts it.

Dunno if you noticed, but qna.exe accepts an input file as a command-line parameter.

1 Like

Thank you! I did not notice that. this was just something similar to what I’ve used for other programs in the past.

interesting…and potentially useful…

How can you get the qna.exe to run using the local client evaluator, to prevent errors like “No Inspector Context”?

Im not aware of any way to use QnA with Local Client Evaluation on the command line

I think you might make some headway in searching on “Client Compliance API”. I haven’t used it, but my understanding is that it involves submitting an XML file to query the client and then reading results out of an output XML. I believe this is the method that the Fixlet Debugger uses to evaluate in client context.

https://developer.bigfix.com/other/cc-api/

i’ll look into the compliance api.
it’s been cropping up on my radar lately, so it looks like the fates are driving me there…