BigFix action script reference parameter

I need some help with the below for action script I’m writing to lookup PC IPSubnet and search for that in textfile to return the PC Physical location.

parameter "_SubnetAddress" = "{concatenation ";" of (subnet addresses of it as string) whose (it != "127.0.0.0") of ip interfaces of network}"
parameter "_NrSubnets" = "{number of ((addresses of it as string) whose (it != "127.0.0.1") of ip interfaces of network)}"

parameter  "_SN1" = "{tuple string item 2 of concatenation ", " of substrings separated by ";" of "155.119.0.0;132.22.22.0;143.44.33.0"}"
parameter  "_SN2" = "{parameter "_SubnetAddress"}"

Ouput from Fixlet debugger
STATUS: Running action…

Command succeeded parameter "_SubnetAddress" = "192.168.0.0;143.16.192.140"
Command succeeded parameter "_NrSubnets" = "2"
Command succeeded parameter  "_SN1" = "143.44.33.0"
Command succeeded parameter  "_SN2" = "192.168.0.0;143.16.192.140"

--- Result ---
Evaluation completed successfully!


parameter  "_SN3" = "{tuple string item 2 of concatenation ", " of substrings separated by ";" of parameter "_SubnetAddress"}"

the last line of code fails with

_"Command failed (Relevance clauses must be surrounded by { and } guards.) parameter "_SN3" = "{tuple string item 2 of concatenation ", " of substrings separated by ";" of 'parameter "_SubnetAddress"'}"_

I’ve tried different combinations but all failed

Does anyone have idea how you can referenc/use a parameter inside parameter.

The idea would be that I search the IPInfo file for each IP Subnet and store that value for later to be used in the action script.

If it would not work with parameter any other ideas would be appreciated.

thx.

1 Like

Pro tip - when posting relevance code or script, please highlight your code and click the ‘code’ tag above the editor window (the </> symbol) to prevent the Forum software from displaying it incorrectly. I already edited your post though to fix that.

When referencing a parameter inside of a substitution, it’s literally just parameter "parameter name" . No extra quotes needed. It looks like you had a single quote around the whole 'parameter "x"' reference.

Try

parameter "_SN3" = "{tuple string item 2 of concatenation ", " of substrings separated by ";" of parameter "_SubnetAddress"}"
1 Like

Hi Jason,
Thx for pointing that out, It’s now working with the parameter.

Next question and that might be a bit more challenging is following
We have workstations that have multiple NIC’s, and in that scenario I would like to be able to discover the location for each IP Subnet. I’ve already search the forum and did not find real solution for While Loop using Action Scripts. The possibility of using VBScript could be done but makes it complex as we have mixed environment of Windows, Linux, HP-UX so would have to come up with script/solution for each flavor if we want to down that path. I might do it anyway for Windows devices but if there is any other way how to achieve this would be appreciated.

Issue trying to solve is the following. We have sites (mainly plant operations) where workstations have multiple NIC’s. Some of these NIC’s are connected to internal networks (10.x.x.x/172.16.x.x) but at same time also have primary NIC which is used to communicate to BigFix and other systems, this also determine which relay should be used for downloading software/os patches etc. With our current discovery script we run into issues where workstation was downloading content from regional relay vs. local relay because of multiple NIC’s and incorrect site assignment.

Below is some sample code I’m working with.
If you look at parameter “_SubnetAddress1” where I have 3 IP Subnets I would like to get location for each subnet and then determine best option.

IPSubnetInfo.csv has following format
155.119.0.0;255.255.0.0;EU - BELGIUM - BRUSSELS INNOVATION CENTER - 0257

The file is being distributed through BigFix as file part of the Master Action Site.

parameter “_SubnetAddress” = "{concatenation “;” of (subnet addresses of it as string) whose (it != “127.0.0.0”) of ip interfaces of network}"
parameter “_NrSubnets” = “{number of ((addresses of it as string) whose (it != “127.0.0.1”) of ip interfaces of network)}”

parameter “_SubnetAddress1” = "155.119.0.0;192.168.0.0;143.44.33.0"
parameter “_SubnetAddress2” = "155.119.0.0"
parameter “_NrSubnets1” = “{number of “155.119.0.0;192.168.0.0;143.44.33.0”}”

parameter “_SN0” = "{tuple string item 0 of concatenation “, " of substrings separated by “;” of “155.119.0.0;192.168.0.0;143.44.33.0”}”

parameter “_IPFile” = “D:\Data\IPSubnetInfo.csv”

parameter “_Region” = "{if exists (lines of it) whose (it contains (parameter “_SN0”)) of file (parameter “_IPFile”) then tuple string item 0 of (concatenation ", " of (substrings separated by " - " of tuple string item 2 of (concatenation “, " of (substrings separated by “;” of (lines of file (parameter “_IPFile”)) whose (it as string contains (parameter “_SN0”)))))) else “NOK”}”

parameter “_Country” = "{if exists (lines of it) whose (it contains (parameter “_SN0”)) of file (parameter “_IPFile”) then tuple string item 1 of (concatenation ", " of (substrings separated by " - " of tuple string item 2 of (concatenation “, " of (substrings separated by “;” of (lines of file (parameter “_IPFile”)) whose (it as string contains (parameter “_SN0”)))))) else “NOK”}”

parameter “_SiteName” = "{if exists (lines of it) whose (it contains (parameter “_SN0”)) of file (parameter “_IPFile”) then tuple string item 2 of (concatenation ", " of (substrings separated by " - " of tuple string item 2 of (concatenation “, " of (substrings separated by “;” of (lines of file (parameter “_IPFile”)) whose (it as string contains (parameter “_SN0”)))))) else “NOK”}”

parameter “_SAPID” = "{if exists (lines of it) whose (it contains (parameter “_SN0”)) of file (parameter “_IPFile”) then tuple string item 3 of (concatenation ", " of (substrings separated by " - " of tuple string item 2 of (concatenation “, " of (substrings separated by “;” of (lines of file (parameter “_IPFile”)) whose (it as string contains (parameter “_SN0”)))))) else “NOK”}”

Thx for all the help.

1 Like

Before I dig in too much on the relevance you’re using for this, can I ask whether you’ve looked at whether the Location Property Wizard can handle this for you?

Using the Wizard, you can paste in spreadsheet entries to map IP Ranges or IP Subnets to define a “Location” property. You could also use the wizard to apply any key/value mapping based on custom relevance statements. The results get applied as both a client setting (you can reference the setting in Client Relevance to build additional logic off of it) as well as a Global Property (so you can view results in the Console or Web Reports).

A common use might be to apply Location settings based on subnet addresses or ranges, and then use another Task (or the Wizard itself, in a second run) to apply Relay Affiliation Seeklists or Relay Affiliation Advertisement Lists based on the resulting Location settings.

1 Like

Just as a test, I’d try to run this in the debugger (and maybe substitute in some test values for the _SubnetAddress1 value and a literal path to the file while testing).

(tuple string item 2 of it) of (concatenation ", " of substrings separated by ";" of it) of items 0 of (elements of item 0 of it, elements of item 1 of it) whose (item 0 of it contains item 1 of it) of (set of lines of file (parameter "_IPFile"), set of substrings separated by ";" of parameter "_SubnetAddress1")

This reads the entire file into a set of lines, reads the individual values for _SubnetAddress1 into another set, and then uses set comparisons to find all the matches. It should be somewhat more efficient than if we re-read the file several times to match each subnet.

If that works, we can repeat the splitting on the " - " character at the end.

1 Like

Jason,
thx for the info really helpful. I’m still getting to know the whole relevance logic, which frustrates the hell out of me that’s why I’ve resorted back to small vbscript (dynamically written) when the action runs.

script logic is the following
read IPInfo file in dictionary object ==> This is is similar to Hash table
retrieve all valid IPAddress;ipsubnet, Subnetmask from all adapters on the workstation (excl. loopback, 169.254.x)

search for any match of ipsubnet,ipsubnetmask n the dictionary object
i’m using below cases to determine the right location

'Logic to determine right location
’Option 1: only 1 valid location ==> select valid location Seeklist: SAPID Valid location
’Option 2: multiple locations with Valid/NOT FOUND included ==> select valid location (excl. NOT FOUND) Seeklist: SAPID Valid location
’Option 3: multiple locations with Valid/VPN/NOT FOUND included ==> select valid location (excl. VPN/NOT FOUND) Seeklist: SAPID Valid location
’Option 4: multiple locations with Valid/VPN included ==> select valid location (excl. VPN/NOT FOUND) Seeklist: SAPID Valid location
‘Option 5: multiple locations with VPN/NOT Found included ==> select VPN location (excl. NOT FOUND) Seeklist: VPN
’Option 6: multiple locations with NOT Found included ==> select NOT FOUND location (excl. NOT FOUND) Seeklist: VPN’
'Option 7: RFC1918 address (Single) ==> Check if it’s valid address by pinging int.pg.com Seeklist: Valid: Location | NotValid: VPN

I will definitely look at your relevance and see if i can do something similar.

Thx for all help and patience, much appreciated

2 Likes