Basic Rule Elements¶
Summary: The basic elements comprising an iRule.
Basic iRule elements¶
iRules are made up of these basic elements:
- Event declarations
- Operators
- iRule commands
when HTTP_REQUEST {
set LogString "Client [IP::client_addr]:[TCP::client_port]"
log local0. "$LogString -> [HTTP::host]:[HTTP::uri] Cookie: [HTTP::header "Cookie"]"
}when HTTP_RESPONSE {
set SetCookie [HTTP::header value "Set-Cookie:"]
log local0. "$LogString <- [IP::server_addr]:[TCP::server_port] [HTTP::status] Set-Cookie: $SetCookie"
# foreach aHeader [HTTP::header names] {
# log local0. "$aHeader: [HTTP::header value $aHeader]"
#}
}
}
Operators¶
An iRule operator compares two operands in an expression. In addition
to using the Tcl standard operators, you can use the operators listed
in Table 13.1.
Table 13.1 iRule operators
iRule Operators
Operator
Syntax
Relational Operators
Logical Operators
For example, you can use the contains operator to compare a variable
operand to a constant. You do this by creating an if statement that
represents the following: “If the HTTP URI contains aol, send to
pool aol_pool.” The following shows an iRule that performs this
action.
An iRule based on the contains operator:
when HTTP_REQUEST {
if { [HTTP::uri] contains "aol" } {
pool aol_pool
} else {
pool all_pool
}
}
iRule commands¶
An iRule command within an iRule causes the LTM system to take some
action, such as querying for data, manipulating data, or specifying a
traffic destination. The types of commands that you can include within
iRules are:
- Statement commands - These commands cause actions such as selecting a traffic destination or assigning a SNAT translation address. An example of a statement command is pool <name>, which directs traffic to the named load balancing pool.
- Query commands - These commands search for header and content data. An example of a query command is IP::remote_addr, which searches for and returns the remote IP address of a connection.
- Data manipulation commands -These commands perform data manipulation such as inserting headers into HTTP requests. An example of a data manipulation command is HTTP::header remove <name>, which removes the last occurrence of the named header from a request or response. .
- Utility commands - These commands are functions that are useful for parsing and manipulating content. An example of a utility command is ‘’’decode_uri <string>*, which decodes the named string using HTTP URI encoding and returns the result. For more information on using utility commands, see Using utility commands.
The BIG-IP API Reference documentation contains community-contributed content. F5 does not monitor or control community code contributions. We make no guarantees or warranties regarding the available code, and it may contain errors, defects, bugs, inaccuracies, or security vulnerabilities. Your access to and use of any code available in the BIG-IP API reference guides is solely at your own risk.