iRule

Components

Using TCL language, http://tmml.sourceforge.net/doc/tcl/index.html Operators: https://clouddocs.f5.com/api/irules/Operators.html Functions: https://clouddocs.f5.com/api/irules/Functions.html Statements: https://clouddocs.f5.com/api/irules/Statements.html Commands: https://clouddocs.f5.com/api/irules/Commands.html Disabled commands: https://clouddocs.f5.com/api/irules/DisabledTclCommands.html Events: Between the time when a connection flows into TMOS, and out the other side, there are a series of internal states that are reached by that connection. Each of these states equate to an event in the iRule language. State can be: Global such as CLIENT_ACCEPTED Profile specific such as HTTP_REQUEST, CLIENTSSL_CLIENTCERT, RTSP_RESPONSE, and so on when EVENT_NAME { TCL-CODE } List of Events: https://clouddocs.f5.com/api/irules/Events.html

iRules Syntax

Variables

set msg "Hello, World!" # Local Variable
set ::myGlobal "Hello, World!" # Global variable, REMEMBER to unset
unset msg
unset msg r vbl

set r [expr rand()]
set vbl in[expr {rand() >= 0.5}]
set reqArray([IP::client_addr]) [getfield [string tolower [HTTP::uri]] "?" 2]

# append data to variable
set var 0
for {set i 1} {$i<=10} {incr i} {
   append var "," $i
}
puts $var # Prints 0,1,2,3,4,5,6,7,8,9,10

#Join values
concat " a b {c   " d "  e} f"
will return "a b {c d e} f" as its result.

# Increase values
Add one to the contents of the variable x:
  incr x

Add 42 to the contents of the variable x:
  incr x 42

Switch command

Some iRule Samples

iRule Event

  • CLIENT_ACCEPTED: triggered when a client has established a connection

Reference

  • iRules 101: https://community.f5.com/t5/technical-articles/irules-101-01-introduction-to-irules/ta-p/283452

  • CLIENT_ACCEPTED: https://clouddocs.f5.com/api/irules/CLIENT_ACCEPTED.html

Last updated