Parsing computer name data into separate fields

Hi all - I could use help on a project I’d like to wipe out as simply as possible within BigFix.

I have computer name information that follows a format such as this:

AAnnnX-#######

or similar… (other variants may include AA-AAAA-#######)

I’d like to break that down and get a string version of the ####### portion of the computer name that I could then use to populate a custom field on the system

It is easy enough me to look for a computer name starts with pattern to find the relevant systems, but I’m not sure how to pull just the numeric part of the name out.

Any tips in this area greatly appreciated as it would save a ton of time doing things manually.

The simple way given your example would be to use the “following text of” in your action script. So let’s say you are trying to create a new property called “subname” (for sub compute name) based on the actual computer name. Your action script could look like:

setting “csg_subname” ="{following text of first “-” of (computer name as lowercase}" on {now} for client

First I always ADD a prefix to my customer client settings (CSG = Champion Solutions Group), so they are easy to locate/find and never conflict with existing or possible new defaults BigFix values.

So you computer name of “AAnnX-XXXX” would set the client setting “csg_subname”= "XXXX"
As you have multiple variants, you will have to play with this to cover them all with some relevance in the applicability or action statement itself (then maybe a IF THEN).

In the relevance part for applicability, you can simply check to see if the custom setting EXISTS or set to Blank to be relevant to run.

How about

q: (following texts of lasts "-" of it as integer) of computer name

q: (following texts of lasts "-" of it as integer) of ("HOSTX-123456";"HOSTY-987654")
A: 123456
A: 987654
T: 0.069 ms
I: plural integer

Thanks for the help so far folks, definitely pushing me along, though some more questions.

In the sample above from @dpowers1 I see:

setting "csg_subname"="{following text of first "-" of (computer name as lowercase}" on {now} for client

Is that missing a closing paren along the way??

Next, to throw a little more fuel on the fire here, things are a bit more muddled than I would like…

Some of the computer names that I would be looking for look a bit more like this:

AA-nnnAnnnnnnnA

The character in the 7th position may change depending on what a computer is used for, as it seems the character in the final alpha position may also be used.

basically, I’ve got a mix of characters in that position including “C” or “G” or others. I may be able to look for the lasts “C” or the lasts “G”, etc. to find what I want, but then again if that same character is at the end of the computer name, fail.

(I really wish that a standard naming convention for these devices had been used, as is now demanded/required to be used, but these systems predate me, so no such luxury)

I’ve got other systems that use another naming convention that is like this:

AA-GRPnnnnnnnA

Those seem pretty consistent and I may be able to look for the last “P” (for that sample) to find the group of digits that I’m looking for (though I can treat the digits as a string) In some cases, I’m seeing systems where there are not digits there though, rather the name was just continued as a standard english word… so something like this:

AA-GRPNAMEHERE

I’d want to exclude those if possible, though I can handle that separately by selecting target computers if necessary…

Thankfully this is mostly a one-time exercise, though it offers an opportunity to learn here and figure out how to best do this if I had to do something similar in the future.

Thanks @JasonWalker much appreciated for the samples that are helping get me on my way.

Yes… the closing parameter is missing…

setting “csg_subname”="{following text of first “-” of (computer name as lowercase)}" on {now} for client

You don’t have to really use the “as lowercase” since you are looking for a simple “-”, but I am use to forcing lower case in most circumstances…

setting “csg_subname”="{following text of first “-” of computer name}" on {now} for client

I think you are going to have to use RegEx in the action statement because of your VARIANTS in the names. But just to give you an example on this thread and using the IF… ELSEIF … ELSE syntax:

if { (following text of first “-” of (computer name as lowercase)) contains “grp”}
setting “csg_subname”="{following text of first “-grp” of (computer name as lowercase)}" on {now} for client
elseif {(following text of first “-” of (computer name as lowercase)) contains “grp2”}
setting “csg_subname”="{following text of first “-grp2” of (computer name as lowercase)}" on {now} for client
else
setting “csg_subname”="{following text of first “-” of (computer name as lowercase)}" on {now} for client
endif

BTW: now lowercase matters…

Soto be clear, you’re looking to retrieve the last sequence of consecutive digits in a hostname, that may be preceded or followed by alphabetic characters right?

Hi @JasonWalker you got it perfectly.
I’m learning my way through it a little, and actually it looks like I might be able to use something like this:

first 7 of (following texts of lasts "W" of it as string) of computer name

That would get me the portion that I would need, assuming I can figure out how many different patterns I might have in the first 6 or so characters of the device name.

I haven’t experimented with this yet, but is it possible to ask for the first 7 following the first 6 of… ?
If so, that would get me what I need as well.

Back again to update @JasonWalker and others, as I did get a chance to experiment…

So, using something like this:

first 7 of (following texts of first 4 of it as string) of computer name

works for what I would want.

(where I can easily change up the number of characters I get back, and the number of characters that occur first)

On the RegEx side, I’d be happy to see some samples of that if anyone has some to look at.

I think this would do it (provided there’s a number in there somewhere)

q: parenthesized parts 1 of matches(regex("[^[:digit:]]([[:digit:]]+)[^[:digit:]]*$"))  of ("HOSTX-123456";"HOSTY-987654";"AA-GRP234567A";"AA-123A456789A")

A: 123456
A: 987654
A: 234567
A: 456789
T: 0.236 ms
I: plural substring

This should match the last set of numbers in a string; starts with something that’s not a number, then groups a sequence of numbers of any length, followed by non-numbers until the end of string.

1 Like

Well, I thought I had it, and the QNA tool shows me close, but it is still not doing what I want, instead failing with little explanation.

So what I would be using on my test run is this:

Action script:

setting "_Custom_Field-Name"="{first 7 of following texts of first "-" of (computer name as lowercase)}" on {now} for client

I’m giving the following a quick try to see if it works on this test batch, but I’m lost as to why the code above didn’t work :frowning:

setting "_Custom_Field-Name"="{first 7 of (following texts of first 7 of it as string) of (computer name as lowercase)}" on {now} for client

No luck with that alternate either.

If I go to update the setting manually, I can confirm (and did) that I have the field name correct, and the basic syntax correct, but apparently when running in the action script, something isn’t quite right and I’m not returning the part of the computer name where expected, or the on {now} for client is making it unhappy (though that doesn’t seem to be the case either).

Definitely confused.

You’re going to kick yourself :slight_smile:

setting "settingname"="value" on "effective time" for client.

You need quotes around "{now}"

setting "_Custom_Field-Name"="{first 7 of following texts of first "-" of (computer name as lowercase)}" on "{now}" for client

@JasonWalker I wish it were that simple, but I’m still failing, even with the quotes around the {now}

(or at least that is what is being reported, though digging down through the action info, I see where the line for the setting is saying completed, so now I’m really confused)

I don’t have any additional actions for the script to perform, but apparently I’m going to see a “failed” notification even where it was successful. If that is the case, I’m OK with that, since my goal is just to see it get done and yes, now I’m seeing where it is completing for me.

Is this set up as a Fixlet, or as a Task?

A Fixlet will evaluate success/failure based on whether the Relevance evaluates to False after you run it.
A Task will evaluate success/failure based on whether the Action Script runs without hitting an error.

If you check the computer properties, is the client setting set and the value correct after you run the action?

What is the Relevance you’re using for this? It should include something along the lines of
not exists setting "_Custom_Field-Name" whose (value of it = first 7 of following texts of first "-" of (computer name as lowercase)" of client

Thanks Jason, that explains it well as the issue is that I’m running a Fixlet not a Task and it was without any real relevance that would compute as “True” to show it was done.

Good to hear.
It should evaluate to “true” when a change is needed, and to “false” when complete (as in “not relevant because it is fixed”).