Action Parameter to define IP Address

I’d like to create an action parameter whereby the console operator can define the external IP address of a machine. Rather than it being a free-form text entry field, I’d like for the text entry to be restricted to the IP address format, e.g.:

xxx.xxx.xxx.xxx (where x = 0-9)

I’ve skimmed through the document Creating Parameterized Fixlets v1.0

But didn’t see anything offhand that would allow for this type of data entry in an action parameter. Anyone have any ideas?

Thanks a lot.

1 Like

I don’t think that’s supported. I think you will have to accept whatever the user types in, then in your actionscript validate their entry using a regular expression that only matches IPv4 addresses. Then you can use something like the “continue if” statement to bail out early if needed.

My bad, I didn’t actually read that document that you helpfully provided… :grin: I thought you were asking about the “action parameter query” command in actionscript.

But if you look on page 13 of that document, they do provide a way to create a custom validation function as shown in the “validatePort” example. So you could create a similar function that validated against a IPv4 regular expression, before you got into the action.

1 Like

Thanks Sean. I has seen the validation and presume I could validate to make sure a number is between say 0 and 255, but I’m still not sure how to concatenate the four octets with a period… maybe I would just have to request them as four separate values with validation? E.g:

validateIP : function (validationObj ) {
	var currentValue = validationObj["currentValue"];
	if ( currentValue < 0 || currentValue > 255 ) {
		return "IP octet specified [“+currentValue+”] is outside of valid range of 0-255";
	}
}
<Value><![CDATA[{
	"1IP": {
	    "Name": "firstIP",
	    "Title": "First Octet:",
	    "Description": "Enter the first octet",
	    "UIType": "Textbox",
		"CustomValidator" : "validateIP"
	},
	"2IP": {
	    "Name": "secondIP",
	    "Title": "Second Octet:",
	    "Description": "Enter the second octet",
	    "UIType": "Textbox",
		"CustomValidator" : "validateIP"
	}	
	"3IP": {
	    "Name": "thirdIP",
	    "Title": "Third Octet:",
	    "Description": "Enter the third octet",
	    "UIType": "Textbox",
		"CustomValidator" : "validateIP"
	}	
	"4IP": {
	    "Name": "fourthIP",
	    "Title": "Fourth Octet:",
	    "Description": "Enter the fourth octet",
	    "UIType": "Textbox",
		"CustomValidator" : "validateIP"
	}			
    }]]></Value>

Just not sure if a) the above is correct, and b) if so, where to go from there! :smile:

I would just validate the IP as one parameter, via something like this:

validateIP : function (validationObj ) {
var currentValue = validationObj["currentValue"];
if ( !currentValue.match(/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/)) {
return "IP specified [“+currentValue+”] is invalid";
}
}
<![CDATA[{
"IPAddress": {
"Name": "ipAddress",
"Title": "IP Address:",
"Description": "Enter the IP address",
"UIType": "Textbox",
"CustomValidator" : "validateIP"
}	
}]]>
1 Like

That is far smarter; thanks Sean! I’ll give it a go and update with the results :smile:

1 Like

OK, so working through the how-to document, it’s not laid out in a very clear manner where exactly all of these individual parts tie together, but I did eventually successfully create and import the default parameterized fixlet from the following sections:

  • BES File Template
  • Bootstrap Section
  • Parameter Metadata Tag (Parameter)
  • Action Section

After importing, I made some fixlet description changes, exported again and modified the fields (for the last two sections) to my requirements for: Parameter Metadata Tag, Parameter Validator Tags, and the ActionScript (to write the inputted External IP Address to a registry key) as such:

(Note: the below code directly follows the “SANSID” entry if you are using the default template…)

	<MIMEField>
		<Name>ParameterMetadataTag</Name>
		<Value><![CDATA[{
			"IP_Address": {
			"Name": "IPAddress",
			"Title": "External IP Address:",
			"Description": "Enter the External IP address",
			"UIType": "Textbox",
			"CustomValidator" : "validateIP"
		}	
		}]]></Value>
	</MIMEField>
	
	<MIMEField>
		<Name>ParameterValidatorTag</Name>
		<Value><![CDATA[{
			validateIP:function(validationObj) {
				var currentValue=validationObj["currentValue"];
				if ( !currentValue.match(/^([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})$/))
					return "The IP specified is invalid";
		}
		}]]></Value>
	</MIMEField>
	
	<MIMEField>
		<Name>x-fixlet-modification-time</Name>
		<Value>Tue, 19 Apr 2016 15:41:43 +0000</Value>
	</MIMEField>
	
	<Domain>BESC</Domain>
	
	<DefaultAction ID="Action1">
		<Description>
			<PreLink>Click </PreLink>
			<Link>here</Link>
			<PostLink> to deploy this action.</PostLink>
		</Description>		
		<ActionScript MIMEType="application/x-Fixlet-Windows-Shell">//
			if {x64 of operating system} 
			regset64 "[HKLM\Software\MyCompany\BigFix]" "External IP"="{parameter "IP_Address" of action}"
			else
			regset "[HKLM\Software\MyCompany\BigFix]" "External IP"="{parameter "IP_Address" of action}"
			endif
		</ActionScript>
	</DefaultAction>
</Fixlet>

I now have a lovely fixlet that requests user input in the IP address format, and kicks if anything other than integers 0-9 are used. It’s not sophisticated enough to lock down entry to only numbers <255, so that’ll be the next step.

Sean - thanks for your time!

1 Like

Great, glad to hear! Nice work. By the way that regex came from 7.16. Matching IPv4 Addresses - Regular Expressions Cookbook [Book] which also has the more correct one:

^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$

Also, when I was testing the initial regex I used this nice site that validates, explains and shows matches for your regular expressions. Pretty cool.

2 Likes

Oh, that’s cool! I have a cheat sheet but an interactive interface is so much better. Thank again.

1 Like

It definitely needs some work.

That is very cool. I have only played around with this a little bit, but this definitely shows some real value.


If you want the list of fixlets that already use the parameterized fixlet library to get an idea of examples, use this Session Relevance:

names of bes fixlets whose(exists mime fields "parameterMetadatatag" of it)
1 Like

@jgstew - thanks!

Note: I updated the Validator Tag’s Regex match to narrow down the input field for the IP address range (lines 6/7 below):

ParameterValidatorTag
</MIMEField>

And also tweaked the Metadata Tag’s “Description” field (line 7 below):

<MIMEField>
		<Name>ParameterMetadataTag</Name>
		<Value><![CDATA[{
			"IP_Address": {
			"Name": "IPAddress",
			"Title": "External IP Address:",
			"Description": "Enter the External IP address in the format: xxx.xxx.xxx.xxx  where xxx=0-255",
			"UIType": "Textbox",
			"CustomValidator" : "validateIP"
		}	
		}]]></Value>
	</MIMEField>
1 Like