Periodic iCall script to auto-generate NodeIP-to-NodeName datagroup
Problem this snippet solves: Hi Folks, the iCall script and handler below can be used to auto-generate a NodeIP-to-NodeName datagroup on scheduled intervals. The auto-generate datagroup can then be used to resolve the [LB::server addr] output to the coresponsing node name label using the [class match -value] syntax. Cheers, Kai How to use this snippet: Tweak the periodic intervals (in seconds) of the iCall handler as needed. Import the provided iCall script and handler using the tmsh load config merge from-terminal syntax Take a look to the configured data-groups and LTM logfiles to verify the results. Use [class match -value [LB::server addr] DG_IP_2_NODENAME] within an iRule to resolve the name of a selected pool member. Code : sys icall script DataGroup_NodeIP_to_NodeName { app-service none definition { set nodelist "" set nodecounter 0 # tmsh::log "iCall: Starting to enumerate existing node objects..." foreach partition [tmsh::get_config auth partition] { set partition "/[tmsh::get_name $partition]" # tmsh::log "iCall: Processing Partition: $partition" tmsh::cd $partition set nodes [tmsh::get_config /ltm node] foreach node $nodes { # tmsh::log "Processing Node : $partition/[tmsh::get_name $node]" append nodelist "\"[tmsh::get_field_value $node "address"]\" \{ data \"[tmsh::get_name $node]\" \}\n" incr nodecounter } # tmsh::log "Finished Partition: $partition" } tmsh::cd "/Common" if { not ([tmsh::list /ltm data-group] contains "ltm data-group internal DG_IP_2_NODENAME") } then { tmsh::log "iCall: Created the data-group \"DG_IP_2_NODENAME\"." tmsh::create /ltm data-group internal "DG_IP_2_NODENAME" type "string" } else { # tmsh::log "iCall: The DataGroup does exist." } eval "tmsh::modify /ltm data-group internal DG_IP_2_NODENAME \{ records replace-all-with \{ $nodelist \} \}" tmsh::log "iCall: Updated the data-group DG_IP_2_NODENAME with \"$nodecounter\" entries." } description none events none } sys icall handler periodic DataGroup_NodeIP_to_NodeName { first-occurrence 2016-09-12:00:00:00 interval 60 script DataGroup_NodeIP_to_NodeName } Tested this on version: 12.0670Views0likes1CommentControlling Bots
Problem this snippet solves: Webbots, you can't live with them, you can't live without them... This iRule determines if a webbot is accessing your systems and assigns them to a lower priority resource. The first example includes the bot list inside the rule and uses the switch statement to find a match. Code : when HTTP_REQUEST { switch -glob [string tolower [HTTP::header User-Agent]] { "*scooter*" - "*slurp*" - "*msnbot*" - "*fast-*" - "*teoma*" - "*googlebot*" { # Send bots to the bot pool pool slow_webbot_pool } default { # Send all other requests to a default pool pool default_pool } } } ### or if you prefer data groups ### ---- String Class ---- class bots { "scooter" "slurp" "msnbot" "fast-" "teoma" "googlebot" } ---- iRule ---- when HTTP_REQUEST { if { [matchclass [string tolower [HTTP::header User-Agent]] contains $::bots] } { pool slow_webbot_pool } else { pool default_pool } } Tested this on version: 10.0577Views0likes1CommentVariable Length URI Lookup
Problem this snippet solves: This iRule uses findclass to perform class lookup for URI's of varying path length, returning the value for the longest path matched. This example uses the lookup value for pool selection, but of course could be modified to send a redirect perform some other appropriate action. This rule should only be used on v9. If using v10 or v11, it's recommended to use "class match" instead of findclass. Code : when HTTP_REQUEST { set lookup [HTTP::path] set i 1 while { $i > 0 }{ set myPool [findclass $lookup $::myPools " "] if {$myPool != ""}{ pool $myPool # log local0. "Path: [HTTP::path] Pool: $myPool" break } else { set i [string last "/" [string range $lookup 0 [expr [string length $lookup]-2]]] set lookup [string range $lookup 0 $i] } } } ### Required Class: ### # (Note all paths are represented twice, once with a trailing slash and once without. # That format is critical for proper functioning of the iRule above if legal URI's for which # the match must succeed may be submitted without the trailing slash.) class myPools { "/this pool6" "/this/ pool6" "/this/is pool5" "/this/is/ pool5" "/this/is/my pool4" "/this/is/my/ pool4" "/this/is/my/path pool3" "/this/is/my/path/ pool3" "/this/is/my/path/ok pool2" "/this/is/my/path/ok/ pool2" "/this/is/my/path/ok/file.html pool1" } Tested this on version: 9.0408Views0likes1Comment