Test for existence of an inspector/operator?

Sigh … I found the solution to this last week and failed to bookmark the result, and now I can’t find it again.

I’m trying to put together a comprehensive “OS” value, using the “product info string” and “releaseid” for Windows, “kernel” and “codename” for Linux, etc. The problem is that, unless I do tests for Windows/Linux/Mac and craft the output to only use inspectors/operators that each OS supports, I get errors. Again, I know I saw a syntax that would allow for outputting nothing instead of an error if an inspector/operator doesn’t exist for an OS … I just can’t find it. anyone here have the magic words?

  • John

I check for Native vs Proxy agents in relevance as

if exists property "in proxy agent context" then not in proxy agent context else true

Hope it helps…

2 Likes

How about leveraging the introspective inspector “property”?

https://developer.bigfix.com/relevance/reference/property.html

Examples from a Windows machine:

Q: exists property “rpm”
A: False
T: 0.212 ms
I: singular boolean

Q: exists property “registry”
A: True
T: 0.146 ms
I: singular boolean

Q: exists property “product info string”
A: True
T: 0.134 ms
I: singular boolean

Q: exists property “releaseid”
A: False
T: 0.199 ms
I: singular boolean

Aram, do you know why the second method below doesn’t work? Since I’m on Windows I was expecting the second statement to also output “N/A”. I think ideally people would want to use the shorter pipe/error method when building up a complex or long relevant statement. Is there a workaround for this, or should we stick to if/then/else when using inspectors that may not exist on the client?

q: if (exists property "codename") then codename of operating system else "N/A"
A: N/A
T: 0.316 ms
I: singular string

q: (codename of operating system) | "N/A"
E: class OperationNotDefined

Good question! The pipe “|” operator is able to catch evaluation errors during runtime, but it will not catch syntax or parsing errors (which occur prior to evaluation/runtime).

CC’ing @AlanM in case he has additional context to add.

2 Likes

That appears to work for base properties (like “operating system”), but not sub-properties (like “version of operating system”).

Q: version of operating system
A: 10.0.14393.693
T: 0.047 ms
I: singular version

Q: exists property "version of operating system"
A: False
T: 0.197 ms
I: singular boolean

Q: exists property "operating system"
A: True
T: 0.152 ms
I: singular boolean

I need to test for the sub-properties.

I don’t understand what you mean here. What is “in proxy agent context” and how does it apply to my question?

It’s the name of a property, which may or may not exist on the client. Just an example of checking existence of an inspector.

Got it. Thanks. :slight_smile:

(Sorry for being dense.) :confused:

Hmm the syntax even seems to be there but doesn’t work the way we’d like.

q: name of operating system
A: Win7
T: 0.025 ms
I: singular string

q: version of operating system
A: 6.1.7601
T: 0.039 ms
I: singular version

q: exists property "releaseid" of type "operating system"
A: True
T: 0.127 ms
I: singular boolean

q: releaseid of operating system
E: Singular expression refers to nonexistent object.

But there might be something that can be done with pipe operators, at least if we cast all the results to string…

q: (releaseid of it as string | version of it as string) of operating system
A: 6.1.7601
T: 0.079 ms
I: singular string

Also, plurals don’t seem to throw an error …

q: releaseids of operating system
T: 0.054 ms
I: plural string

Jason, I think John wanted a solution for inspectors that don’t exist for a particular os. So I have been testing with codename since it’s not on Windows. But I noticed you are testing with releaseid, which is supported on Mac & Windows. So that gives different results. I have not been able to get plurals or the pipe operator working for non-existent properties.

q: windows of operating system
A: True
I: singular boolean

q: exists property "releaseid"
A: True
I: singular boolean

q: releaseid of operating system
E: Singular expression refers to nonexistent object.

q: releaseids of operating system
I: plural string

q: exists property "codename"
A: False
I: singular boolean

q: codename of operating system
E: class OperationNotDefined

q: codenames of operating system
E: class OperationNotDefined

q: (codename of it as string) of operating system
E: class OperationNotDefined

Guarded Relevance to the rescue. It will trap the language error where the pipe inspector is not quite clever enough to do so.

q: exists true whose ( if true then ( some dodgy expression ) else false )
A: False

q: if (exists true whose ( if true then ( exists codename of operating system ) else false )) then (codename of operating system as string ) else (“The relevance does not work on this version/platform of BigFix”)
A: The relevance does not work on this version/platform of BigFix

q: if (exists true whose ( if true then ( exists name of operating system ) else false )) then (name of operating system as string ) else (“The relevance does not work on this version/platform of BigFix”)
A: Win2016

q: if (exists true whose ( if true then ( exists releaseid of operating system ) else false )) then (releaseid of operating system as string ) else (“The relevance does not work on this version/platform of BigFix”)
A: 1607

4 Likes

THIS!! This is what I was looking for! Thanks very much, @brolly33!

You have it right. The relevance breakdown must be able to understand the syntax, and the pipe operator merely handles the error and as codename isn’t on Windows yet… it generates an error

2 Likes

In answer to the detecting if property exists for Version of Operating System example using introspectors:

Q: exists properties "version" of result type of property "operating system"
A: True

can also nest further…

Q: major revision of version of operating system
A: 6

Q: exists property "major revision" of result type of properties "version" of result type of property "operating system"
A: True
4 Likes

Ah … didn’t know about “result type”. Thanks muchly!

Result type is new to me as well. Thanks much!