<\/span><\/h3>\nA typical iRule contains four main components.<\/p>\n
These are :<\/p>\n
rule NAME<\/strong> {
when EVENT<\/strong> {
if { conditional_statement<\/strong> } {
action_when_condition_true<\/strong>
}
}
}
<\/strong><\/p>\n\n- Name<\/strong> – The name a) Must begin with a letter b) contain no special characters or spaces. A naming best practice is to capitalize first letter of trailing words.<\/li>\n
- Event<\/strong> – Events define multiple points during a client session, the iRule is then triggered when the specified event occurs. There are more than 50 types of Events such as HTTP_REQUEST, CLIENT_ACCEPTED etc.<\/li>\n
- Conditional Statement<\/strong> – If a particular condition exists A condition is built based on relational\/logical operators (explained further within the Rule Operators section). The following shows an example is the matching the string ‘txt’ at the end of an uri ; the condition would be if { [HTTP::uri] ends_with “txt” }<\/span>.<\/li>\n
- Perform an action<\/strong> – An action determines the response to a condition statement.<\/li>\n<\/ul>\n
<\/span>Rule Operators<\/strong><\/span><\/h3>\nThere are 2 types of Rule operators. These are :
<\/strong><\/p>\n<\/span>1. Logical Operators<\/strong><\/span><\/h4>\nThere are 3 logical operators for use within an iRule. These are :<\/p>\n
\n- and<\/strong> – performs a logical and comparison between 2 values<\/li>\n
- not<\/strong> – performs a logical not on a value<\/li>\n
- or<\/strong> – performs a logical or comparison between 2 values<\/li>\n<\/ul>\n
<\/span>2. Relational Operators <\/strong><\/span><\/h4>\nBelow shows the various relational strings operators :<\/p>\n
\n- contains <\/strong>– tests if one string contains another string.<\/li>\n
- ends_with<\/strong> – tests if one strings ends with another string.<\/li>\n
- equals<\/strong> – tests if one string equals another string.<\/li>\n
- matches_glob <\/strong>– implements glob style matching within a comparison.<\/li>\n
- matches_regex<\/strong> – tests if one string matches a regular expression.<\/li>\n
- starts_with<\/strong> – tests if one string starts with another string.<\/li>\n
- switch<\/strong> – evaluates one of several scripts, depending on a given value.<\/li>\n<\/ul>\n