I have an JSON object in a file in the client mailbox. It is identified by a suffix, a prefix, AND the client’s BES ID existing in a JSON value in the file. I want to return ANOTHER JSON value from the file IF the file itself is less than 35 days old, returning error “Data Expired” if the file is older and error “Data Missing” if the file doesn’t exist. Is this just too much to handle with a single reference to the file (or, for that matter, the JSON of the file)?
I’m currently identifying the file itself with the following relevance: file (tuple string item 0 of tuple string of ( names of ( files of client folder of site "mailboxsite" ) whose ( name of it starts with "ps-" and name of it ends with "-json" and (value of key "bf" of values of key "IDs" of json of it) as string = computer id as string ) as string )) of client folder of site "mailboxsite"
This is already a little repetitive as it already instantiates a json of it and mentions the client folder of site "mailboxsite" twice, but i suppose that’s unavoidable.
The rest of the logic would go (in psuedo-relevance): if exists IT then (if modification time of IT is greater than (now - (day * 35)) then (value of key "x" of values of key "y" of json of it) else (error “Data Expired”)) else (error “Data Missing”) of IT
Sigh… apparently all it takes for me to figure something out on my own is to first ask everybody else.
Here’s what I came up with shortly after posting… can it be made any less redundant or more efficient? (if (exists it) then (if modification time of it is greater than (now - (day * 35)) then (value of key "x" of values of key "y" of json of it) else (error "data expired")) else (error "data missing")) of (file (tuple string item 0 of tuple string of ( names of ( files of client folder of site "mailboxsite" ) whose ( name of it starts with "ps-" and name of it ends with "-json" and (value of key "bf" of values of key "IDs" of json of it) as string = computer id as string ) as string )) of client folder of site "mailboxsite")
I think I was having issues with the placement of the parentheses last time I was working on this. This time (after asking, of course), no issues…
I’m actually quite interested in the mailboxsite thing.
I wrote a solution to drop CMDB data onto clients, but just went with a large single JSON. I had thought about dropping individual files per client, and then update only if data changed…. Gave up after not finding the documentation I needed, and the added complexity when this worked just fine and was simple.
For file modification time, I have this code that was making sure the file was fully transferred and copy had finished before reading (a just in case thing). I found creation time worked well on Win but had to use modification time for Nix.
if {(windows of operating system)}
continue if {creation time of file (parameter "cmdbfile") < (now + 10 * second)}
else
continue if {modification time of file (parameter "cmdbfile") < (now + 10 * second)}
That’s exactly what I’m doing with this and, while the code to get the individual mailbox files distributed took a while to figure out, it works great. “One big file” for me would be a tad large with data for ~15,000 computers being updated, but I’m tracking changes on another computer and only sending mailbox files to computers when (a) they’ve changed, (b) they’re not there, or (c) they’re older than a month. (I don’t like trusting that old data is accurate, even if it is. Would rather rewrite it every 30 days or so.)
The big plus for me is that there’s no Actions involved, just background server activity.
@straffin about the following statement: "The big plus for me is that there’s no Actions involved, just background server activity" - I remember that if I want to add something to the mailbox site of specific machine, I need to create an action for that. Can you elaborate about this and provide documentation?
I’m using the BigFix Rest API mailbox endpoint from a PowerShell script with a function (below) that sends an individual file (generated and cached locally on the server that’s running the script) for each computer by BES ID.