ltm rule command getfieldΒΆ

iRule(1)		      BIG-IP TMSH Manual		      iRule(1)



getfield
       Splits a string on a character or string. and returns the string
       corresponding to the specific field.

SYNOPSIS
       getfield STRING SEPARATOR FIELD_NUMBER

DESCRIPTION
       A custom iRule function which splits a string on a character or string,
       and returns the string corresponding to the specific field.

       Syntax

       getfield   

	    * Splits a string on a character or string, and returns the string
	      corresponding to the specific field. The field_number parameter is
	      1 indexed.

RETURN VALUE
VALID DURING
       ANY_EVENT

EXAMPLES
	Extract specific columns from a data group list match:

	class HostRedirects {
	www.domain.com https://www.domain.com/
	host.domain.com http://host2.domain.com/
	another.domain.com https://www.domain.com/another
	}
	rule HostRedirects {
	when HTTP_REQUEST {
	  set row [findclass [HTTP::host] $::HostRedirects]
	  if { not ($row eq "")}{
	    HTTP::redirect [getfield $row " " 2][HTTP::uri]
	    return
	  }
	}
	}

	To extract only the hostname from the host header (strips any trailing
	   ":###" port specification)

	when HTTP_REQUEST {
	  set hostname [getfield [HTTP::host] ":" 1]
	}

	To redirect any request for a domain.com host to the same
	hostname.subdomain @ domain.org (uses a multi-character split string
	and field_number 1 to extract only those characters in the hostname
	before the split string.):

	when HTTP_REQUEST {
	  if { [HTTP::host] contains "domain.com"} {
	    HTTP::redirect https://[getfield [HTTP::host] ".domain.com" 1].domain.org[HTTP::uri]
	  }
	}

	     * When used to compare a valid IP address (by Joe)


	set addr "10.10.10.10"
	set a [getfield $addr "." 1]
	set b [getfield $addr "." 2]
	set c [getfield $addr "." 3]
	set d [getfield $addr "." 4]

	# Or use scan instead to parse the IP octets to variables $a $b $c $d
	scan $addr {%d.%d.%d.%d} a b d c

	if { (0 <= $a) && ($a <= 255) &&
	     (0 <= $b) && ($b <= 255) &&
	     (0 <= $c) && ($c <= 255) &&
	     (0 <= $d) && ($d <= 255) } {
	log local0. "$addr is a valid IP Address"
	} else {
	  log local0. "$addr is NOT a valid IP Address"
	}

HINTS
SEE ALSO
CHANGE LOG
       @BIGIP-9.0.0 --First introduced the command.



BIG-IP				  2017-01-31			      iRule(1)