Bes Properties that are not set or unkown causing relevance query issue

Hi,

When running a relevance query in the presentation debugger bes computer properties that are “not set” or “unknown” are showing in the debugger but when running the code using curl If the property is “not set” or “unknown” the query returns nothing. The properties that are giving me the problem In the below query are “_ServerResponsibilityGroup,”, “_Org” and “_patch_group”

("Computer ID: " & id of it as string, "Computer Name: " & name of it, "DNS Name: " & hostname of it, "IP Address: " & ip address of it as string, "Root Server: " & root server of it, "OS: " & operating system of it, "Last Reported Time: " & last report time of it as string, "Agent Version: " & agent version of it, "Responsibility Group: " & value of results
(it, bes property “_ServerResponsibilityGroup”), "Support Group: " & value of results (it, bes property “_Org”), "Patch Group: " & value of results (it, bes property “_patch_group”))
of bes computers whose ( name of it as lowercase starts with “ComputerName”)

Thanks

I can so relate to that. I faced the same issues until @brolly33 showed me how to overcome this in a Bigfix MasterClass. He has a brilliant blog post that explains the cause and how to avoid the issue. https://www.ibm.com/developerworks/community/blogs/e9d21113-aa93-467e-ac77-a0d20a21eaec/entry/Session_Relevance_Computer_Properties_query_Efficiency?lang=en

2 Likes

Hi Rob,

Thanks for the link for Brolly’s master class. Unfortunately the examples are for multiple computers and I don’t understand how to apply an If statement for error checking for querying a computer by a specified computer name. For example where would I add the if statement to the below bes property that is “not set” ?

"Server Responsibility Group: " & value of results
(it, bes property “_ServerResponsibilityGroup”)) of bes computers whose ( name of it as lowercase starts with “ComputerName”)

Something like this (I just took the one I used for my requirements and changed the computer name and property names so add/remove properties to meet your needs)

(
name of item 0 of it|"Computer Name missing"
, (if (size of item 1 of it = 1) then ((if it = "" then "No values" else it) of concatenation ";" of values of results (item 0 of it, elements of item 1 of it)) else (if (size of item 1 of it > 1) then (("Duplicates: " & concatenation "|" of ((name of it) & "=" & (id of it as string)) of elements of item 1 of it) as string) else ("Property does not exist")))
, (if (size of item 2 of it = 1) then ((if it = "" then "No values" else it) of concatenation ";" of values of results (item 0 of it, elements of item 2 of it)) else (if (size of item 2 of it > 1) then (("Duplicates: " & concatenation "|" of ((name of it) & "=" & (id of it as string)) of elements of item 2 of it) as string) else ("Property does not exist")))
, (if (size of item 3 of it = 1) then ((if it = "" then "No values" else it) of concatenation ";" of values of results (item 0 of it, elements of item 3 of it)) else (if (size of item 3 of it > 1) then (("Duplicates: " & concatenation "|" of ((name of it) & "=" & (id of it as string)) of elements of item 3 of it) as string) else ("Property does not exist")))
, (if (size of item 4 of it = 1) then ((if it = "" then "No values" else it) of concatenation ";" of values of results (item 0 of it, elements of item 4 of it)) else (if (size of item 4 of it > 1) then (("Duplicates: " & concatenation "|" of ((name of it) & "=" & (id of it as string)) of elements of item 4 of it) as string) else ("Property does not exist")))
, (if (size of item 5 of it = 1) then ((if it = "" then "No values" else it) of concatenation ";" of values of results (item 0 of it, elements of item 5 of it)) else (if (size of item 5 of it > 1) then (("Duplicates: " & concatenation "|" of ((name of it) & "=" & (id of it as string)) of elements of item 5 of it) as string) else ("Property does not exist")))
, (if (size of item 6 of it = 1) then ((if it = "" then "No values" else it) of concatenation ";" of values of results (item 0 of it, elements of item 6 of it)) else (if (size of item 6 of it > 1) then (("Duplicates: " & concatenation "|" of ((name of it) & "=" & (id of it as string)) of elements of item 6 of it) as string) else ("Property does not exist")))
, (if (size of item 7 of it = 1) then ((if it = "" then "No values" else it) of concatenation ";" of values of results (item 0 of it, elements of item 7 of it)) else (if (size of item 7 of it > 1) then (("Duplicates: " & concatenation "|" of ((name of it) & "=" & (id of it as string)) of elements of item 7 of it) as string) else ("Property does not exist")))
, (if (size of item 8 of it = 1) then ((if it = "" then "No values" else it) of concatenation ";" of values of results (item 0 of it, elements of item 8 of it)) else (if (size of item 8 of it > 1) then (("Duplicates: " & concatenation "|" of ((name of it) & "=" & (id of it as string)) of elements of item 8 of it) as string) else ("Property does not exist")))
, (if (size of item 9 of it = 1) then ((if it = "" then "No values" else it) of concatenation ";" of values of results (item 0 of it, elements of item 9 of it)) else (if (size of item 9 of it > 1) then (("Duplicates: " & concatenation "|" of ((name of it) & "=" & (id of it as string)) of elements of item 9 of it) as string) else ("Property does not exist")))
, (if (size of item 10 of it = 1) then ((if it = "" then "No values" else it) of concatenation ";" of values of results (item 0 of it, elements of item 10 of it)) else (if (size of item 10 of it > 1) then (("Duplicates: " & concatenation "|" of ((name of it) & "=" & (id of it as string)) of elements of item 10 of it) as string) else ("Property does not exist")))
, (if (size of item 11 of it = 1) then ((if it = "" then "No values" else it) of concatenation ";" of values of results (item 0 of it, elements of item 11 of it)) else (if (size of item 11 of it > 1) then (("Duplicates: " & concatenation "|" of ((name of it) & "=" & (id of it as string)) of elements of item 11 of it) as string) else ("Property does not exist")))
, (if (size of item 12 of it = 1) then ((if it = "" then "No values" else it) of concatenation ";" of values of results (item 0 of it, elements of item 12 of it)) else (if (size of item 12 of it > 1) then (("Duplicates: " & concatenation "|" of ((name of it) & "=" & (id of it as string)) of elements of item 12 of it) as string) else ("Property does not exist")))
, (if (size of item 13 of it = 1) then ((if it = "" then "No values" else it) of concatenation ";" of values of results (item 0 of it, elements of item 13 of it)) else (if (size of item 13 of it > 1) then (("Duplicates: " & concatenation "|" of ((name of it) & "=" & (id of it as string)) of elements of item 13 of it) as string) else ("Property does not exist")))
, (if (size of item 14 of it = 1) then ((if it = "" then "No values" else it) of concatenation ";" of values of results (item 0 of it, elements of item 14 of it)) else (if (size of item 14 of it > 1) then (("Duplicates: " & concatenation "|" of ((name of it) & "=" & (id of it as string)) of elements of item 14 of it) as string) else ("Property does not exist")))
, (if (size of item 15 of it = 1) then ((if it = "" then "No values" else ((((year of it as string & "/" &  month of it as two digits & "/" &  day_of_month of it as two digits) of date (local time zone) of it & " " & (two digit hour of it as string & ":" & two digit minute of it as string) of time (local time zone) of it)) of (it as time))) of concatenation ";" of values of results (item 0 of it, elements of item 15 of it)) else (if (size of item 15 of it > 1) then (("Duplicates: " & concatenation "|" of ((name of it) & "=" & (id of it as string)) of elements of item 15 of it) as string) else ("Property does not exist")))
) 
of 
(
elements of item 0 of it 
,item 1 of it
,item 2 of it
,item 3 of it
,item 4 of it
,item 5 of it
,item 6 of it
,item 7 of it
,item 8 of it
,item 9 of it
,item 10 of it
,item 11 of it
,item 12 of it
,item 13 of it
,item 14 of it
,item 15 of it
) 
of 
(
set of BES computers whose (name of it as uppercase is "MYCOMPUTER")
, set of bes properties whose (name of it as lowercase = ("Property1") as lowercase) 
, set of bes properties whose (name of it as lowercase = ("Property2") as lowercase) 
, set of bes properties whose (name of it as lowercase = ("Property3") as lowercase) 
, set of bes properties whose (name of it as lowercase = ("Property4") as lowercase) 
, set of bes properties whose (name of it as lowercase = ("Property5") as lowercase) 
, set of bes properties whose (name of it as lowercase = ("Property6") as lowercase) 
, set of bes properties whose (name of it as lowercase = ("Property7") as lowercase) 
, set of bes properties whose (name of it as lowercase = ("Property8") as lowercase) 
, set of bes properties whose (name of it as lowercase = ("Property9") as lowercase) 
, set of bes properties whose (name of it as lowercase = ("Property10") as lowercase) 
, set of bes properties whose (name of it as lowercase = ("Property11") as lowercase) 
, set of bes properties whose (name of it as lowercase = ("Property12") as lowercase) 
, set of bes properties whose (name of it as lowercase = ("Property13") as lowercase) 
, set of bes properties whose (name of it as lowercase = ("Property14") as lowercase) 
, set of bes properties whose (name of it as lowercase = ("Property15") as lowercase) 
)

Hi Rob,

After using the template you’ve provided and reading Brolly’s article again It finally sunk into my thick scull. Two issues though. 1. after http encoding for use with curl in my script I cannot use the output because it is too long and I get an error when trying to edit the script with the vi editor. 2. for some reason the Root Server property is not returning anything. set of bes properties whose (name of it as lowercase = (“Root Server”) as lowercase))

thanks,

I don’t have a property named “Root Server” either. Is that a custom property in your deployment?

Hi Jason,

Root Server is not listed directly under Custom Properties but it is listed under “Client Relay Status”. Anyhow I am able to retrieve it when using the following:

("Computer ID: " & id of it as string, "Computer Name: " & name of it, "DNS Name: " & hostname of it, "IP Address: " & ip address of it as string, "Root Server: " & root server of it, "OS: " & operating system of it, "Last Reported Time: " & last report time of it as string, "Agent Version: " & agent version of it, "Responsibility Group: " & value of results
(it, bes property “_ServerResponsibilityGroup”), "Support Group: " & value of results (it, bes property “_Org”), "Patch Group: " & value of results (it, bes property “_patch_group”))
of bes computers whose ( name of it as lowercase starts with “ComputerName”)

However some computers in my environment do not have the following set so the query returns nothing:

"Responsibility Group: " & value of results
(it, bes property “_ServerResponsibilityGroup”),

Is there not a way to use an if statement for the _ServerResponibilityGroup? Brolly’s master class if awesome but cannot use it in my script.

Thanks,

This method should handle an empty result by using a concatenation of values of results in an elegant way that generically works across singular, plural, empty, or missing results.

If you really cannot refactor your query to work that way (and I think you should!), you could probably do something to change

value of results (it, bes property “_ServerResponsibilityGroup”)
into something like
(value of results (it, bes property “_ServerResponsibilityGroup”) | "no result")
or
(if exists value of it then value of it else "No Value" ) of results (it, bes property “_ServerResponsibilityGroup”)

Hi Jason,

This works (value of results (it, bes property “_ServerResponsibilityGroup”) | “no result”). I did see | “no result” in the relevance guide earlier but I was missing a extra (. The issue I am having with using Brolly’s efficient way of doing queries is that 1. for some reason it does not retrieve the Root Server and 2 after http encoding for curl the line of code is humongous giving me an error in vi that the line is too large.

thanks!

As always Thanks so much for your assistance Jason, you rock!

Just a bit more to round this out…
When I sent a more complex query, I got an error message “String did not contain a closing quotation mark”. I believe that’s because curl was handling the pipe operator “|” as a shell command. My workaround is to change the query file to take ‘relevance=’ off the front and pass that explicitly to curl

curl --insecure --user username --data-urlencode "output=json" -X POST "https://bes-root-server:52311/api/query" --data-urlencode "relevance@query.txt"

Contents of query.txt:

(
  name of item 0 of it|"Computer Name missing", 
  (if (size of item 1 of it = 1) then 
        ((if it = "" then 
            "No values" 
           else it) of concatenation ";" of 
values of results (item 0 of it, 
    elements of item 1 of it)) 
   else 
    (if (size of item 1 of it > 1) then 
          (("Duplicates: " & concatenation "|" of ((name of it) & "=" & (id of it as string)) of elements of item 1 of it) as string) 
       else 
           ("Property does not exist")))
   ) of  (elements of item 0 of it ,item 1 of it) of 
   (set of BES computers whose (name of it as uppercase is "MY-COMPUTERNAME"), 
    set of bes properties whose (name of it as lowercase = ("dmi family") as lowercase))
1 Like

Thanks again Jason, you’ve been very helpful!

How can I add a blank line after the last property?

I’ve tried the following but it did not work:

set of bes properties whose (name of it as lowercase = (“dmi family”) as lowercase) & “%0d%0a”)

Thanks

You’d need to add the blank into the left-most result clause, after the last property retrieved. “Blank line” will depend on how you’re outputting it - to a text file it’d be %0d%0a, in HTML it’d be <BR>

1 Like

As always thanks Jason!