Trying to parse value from text file and add to property

@SLB, It looks like that is coming up with “none” as well… so, I am checking the servers to make sure the info I was given is correct… but, I think it will work… thank you, for the contribution!

That is always going to be a clunky workflow.
Your server owner is asking you to do something, you’re asking us how to do it, we’re asking for clarifications of things you don’t know, you’re having to go back and ask the server owners…there is too much lost in translation.

You really need to be able to look at their setup, directly, or you’re going to spend way too much time going back and forth on this.

But - we have a solution! The WebUI Query App is tailor-made for this. You can test things out in an interface like QnA, targeting their test server, and iterate over that to figure out what’s needed.

On your WebUI page, open Apps → Query
On the right side, open the ‘Devices Targeted’ button, filter & find one of the test servers.
Then you can build your relevance a step at a time, send the query, and see what the results look like.

Like, start off with pathnames of files of folders "/", that way you can figure out if the filename they’re giving you is even right.

Here I created a test of what you described:

root@ubusrv1:~# hostname
ubusrv1

root@ubusrv1:~# ls /local/info/ubusrv1/installed.version
/local/info/ubusrv1/installed.version

root@ubusrv1:~# cat /local/info/ubusrv1/installed.version
#some text
#Sun Mar 16 11:02:28 EDT 2025
installed.version=8.x.x.x.x

Now I can use Query to navigate through that, a piece at a time. After selecting my server ‘ubusrv1’ as the target, I step through running each of these queries; the answer informs my next query:

computer name
--> ubusrv1

pathnames of folders of folders "/"
--> "Device","Results"
--> "ubusrv1","/bin"
--> "ubusrv1","/boot"
--> "ubusrv1","/cdrom"
--> "ubusrv1","/dev"
--> "ubusrv1","/etc"
--> "ubusrv1","/home"
--> "ubusrv1","/lib"
--> "ubusrv1","/lib32"
--> "ubusrv1","/lib64"
--> "ubusrv1","/libx32"
--> "ubusrv1","/local"
--> "ubusrv1","/loki"
--> "ubusrv1","/lost+found"
--> "ubusrv1","/media"
--> "ubusrv1","/mnt"
--> "ubusrv1","/opt"
--> "ubusrv1","/proc"
--> "ubusrv1","/root"
--> "ubusrv1","/run"
--> "ubusrv1","/sbin"
--> "ubusrv1","/snap"
--> "ubusrv1","/srv"
--> "ubusrv1","/sys"
--> "ubusrv1","/tmp"
--> "ubusrv1","/usr"
--> "ubusrv1","/var"
#so, there *is* a folder '/local'

pathnames of folders of folders "/local"
--> /local/info

pathnames of folders of folders "/local/info"
--> /local/info/ubusrv1

# I expect the 'installed.version' file to be there, so let's check for it:

pathnames of files  of folders "/local/info/ubusrv1"
--> /local/info/ubusrv1/installed.version

# great, the file is there.  What is in it?

lines  of files "/local/info/ubusrv1/installed.version"
--> Device Results
--> ubusrv1	#some text
--> ubusrv1	#Sun Mar 16 11:02:28 EDT 2025
--> ubusrv1	installed.version=8.x.x.x.x

# Now that we know we can read the file, let's go ahead and craft the path dynamically - we know the file pathname contains the computername so let's build it that way

lines  of files ("/local/info/" & computer name & "/installed.version")
--> exact same result, the file lines are still there

#Now retrieve just the part after 'installed.version=' from the lines of the file

following texts of firsts "installed.version=" of lines of files ("/local/info/" & computer name & "/installed.version")
--> 	8.x.x.x.x

So, that’s what you need in your Property relevance: following texts of firsts "installed.version=" of lines of files ("/local/info/" & computer name & "/installed.version")
You need to replace the ‘/local/info’ path with whatever the real path is in your environment.

This relevance works, I can see it live in the Query app…if it doesn’t work for you, then something’s not correct in the way you’ve described the file content, or the path to us. But, now that you see the steps I went through to find that path and content in Query, at least you should be able to reproduce that and figure out what of our assumptions was incorrect.

Hope this helps!

2 Likes

Now using @JasonWalker relevance, you can drop into a property.

Make the changes to the path as Jason stated and then name the property to whatever you want it to be.

setting "MyLittleProperty"="{following texts of firsts "installed.version=" of lines of files ("/local/info/" & computer name & "/installed.version")}" on "{parameter "action issue date" of action}" for client

1 Like

We don’t always get to chose how things go, but thank you, @JasonWalker! That’s a lot of good info… I will validate and let you know…

Thanks, @D.Dean, I will def try that as well…

Just wanted to let you all know that the linux one worked! I just have to get the windows on working now… Thank you all for your help!!

1 Like

@D.Dean, @gus or anyone else… I do have one more question… I ultimately have four different relevances, three for linux and one for windows… individually, each relevance will work, but how do I chain them together? I tried using “or” between them but it complains about needing to have a boolean result… any thoughts? Thanks, again… you have all been very helpful!

You could nest a few if...then...else statements

Q: (if (linux of it) then (if (name of it as lowercase contains "redhat") then ("{Linux relevance 1 here}") else ((if (name of it as lowercase contains "centos") then ("{Linux relevance 2 here}") else ((if (name of it as lowercase contains "rocky") then ("{Linux relevance 3 here}") else ("{Other Linux}")))))) else ((if (windows of it) then ("Windows relevance here") else (nothing)))) of operating system
A: Windows relevance here
T: 0.090 ms
I: plural string
2 Likes

Thanks, @SLB… I’ll give it a try…

So, it seems I’ve come across a new issue and I’m not sure if I should start a new topic or not, but… It looks like I need to get this custom property into BFI… As far as I can tell, it only exists in the console, but is there a way to get this new property into BFI reports? You’ll have to forgive my ignorance as I’ve never done this before… thanks!

In BFI you can go to Management – Computer Properties, and where you create the property you can link it to one of the properties you already have in the console.

1 Like

Fantastic… thank you @Jeff !

Thanks @SLB, I was able to get this to work with the “linux” key word as it didn’t like that… but, using “redhat” and 'Windows" it is working like a champ… thanks, very much!

2 Likes

Good to hear you got something that works for you.

The “linux” inspector was added from 11.0.2 so yeah, if you are 10.x or an earlier version of 11 then that may cause some issues, or maybe is doesn’t include the Linux variant you have deployed.

https://developer.bigfix.com/relevance/reference/operating-system.html

Good to know… thank you.

OK, I thought it was working, but I’ve been trying many different versions of this, and can’t get it to work all together. I can get the individual pieces to work, but not the whole thing… Any help will be greatly appreciated… This is what I’m trying to do in essence:

if ((name of operating system as lowercase starts with “linux”) and (exists file “/filepath/” & computer name & “/installed.version”)) then
(following texts of firsts “installed.version=” of lines of files (“/filepath/” & computer name & “/installed.version”))

else if ((name of operating system as lowercase starts with “linux”) and (exists file “/filepath/” & dns name & “/installed.version”)) then
(following texts of firsts “installed.version=” of lines of files (“/filepath/” & dns name & “/installed.version”))

else if ((name of operating system as lowercase starts with “linux”) and (exists file “/filepath/” & dns name & “/installed.version”)) then
(following texts of firsts “installed.version=” of lines of files (“/filepath/” & dns name & “/installed.version”))

else if ((name of operating system as lowercase starts with “win”) then (following texts of firsts “installed.version=” of lines of files ("C:\filepath" & dns name & “\installed.version”)))

else (nothing)

One issue is your Linux file checks are missing the parenthesis to create the file path object

(exists file "/filepath/" & computer name & "/installed.version"))

should be

(exists file ("/filepath/" & computer name & "/installed.version")))

I think the if…then…else nests are a bit off too, though it does get harder to build these with multiple nested statements. See if this works

if ((name of operating system as lowercase starts with "linux") and (exists file ("/filepath/" & computer name & "/installed.version"))) then (following texts of firsts "installed.version=" of lines of files ("/filepath/" & computer name & "/installed.version")) else (if ((name of operating system as lowercase starts with "linux") and (exists file ("/filepath/" & dns name & "/installed.version"))) then (following texts of firsts "installed.version=" of lines of files ("/filepath/" & dns name & "/installed.version")) else (if ((name of operating system as lowercase starts with "linux") and (exists file ("/filepath/" & dns name & "/installed.version"))) then (following texts of firsts "installed.version=" of lines of files ("/filepath/" & dns name & "/installed.version")) else (if (name of operating system as lowercase starts with "win") then (following texts of firsts "installed.version=" of lines of files ("C:\filepath\" & dns name & "\installed.version")) else (following texts of firsts "installed.version=" of lines of files ("C:\filepath\" & dns name & "\installed.version")))))

Just as another option, if your Linux env is either /filepath/{computer name} or ‘/filepath/{dns name}’, rather than checking for each folder presence, check for both variants. and avoid some of the nested if…then…else, though this does take longer to process when catering for possible duplication scenario (i.e. computer name and dns name are different but folders and files exists for both).

Q: (if (name of it as lowercase contains "linux") then (unique values of (following texts of firsts "installed.version=" of lines of files "installed.version" of folders (computer name; dns name) of folders "/filepath")) else ((if (windows of it) then (following texts of firsts "installed.version=" of lines of files ("C:\filepath" & dns name & "\installed.version")) else (nothing)))) of operating system
A: 8.x.x.x.x
T: 122893

TIP: Use the preformatted text feature when pasting relevance to avoid quotes ("") being replaced by smart quotes (“”) :wink:
image

2 Likes

Thanks @SLB, I will give that a try and let you know… much appreciated!

That looks much better… am getting linux and windows now… thank you very much!

I’ve been trying to tie this new custom property to a software product… I can run reports and see servers and/or software products that are associated to the property, but not all software is correctly associated to it yet… I need to be able to report on all product XXX with this new version, but am not having any luck… is there a way to tie this property to a custom signature? Or, is there another way to do that? Thanks