Advertisement
TimRiker

rule_lb-star-s.example.org

Mar 9th, 2021 (edited)
1,256
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # rule_lb-star-s.example.org
  2. # This file exports live pool status for BigIPReport
  3. # add the rule to shared-* and add dns alias to shared-* for any F5
  4. # Tim Riker <Tim@Rikers.org>
  5.  
  6. when HTTP_REQUEST {
  7.     if { ([class match [IP::client_addr] equals private_net]) } {
  8.         switch -glob -- [HTTP::host] {
  9.             lb-*-s.example.org {
  10.                 # get pool status for BIG IP Report
  11.                 set poolname [HTTP::path]
  12.                 if { [catch {
  13.                     set poolmembers [members -list $poolname]
  14.                     set returnjson "\{\n\t\"success\"\:true,\n\t\"poolname\": \"$poolname\",\n\t\"memberstatuses\": \{"
  15.                     set membercount [llength $poolmembers]
  16.                     set i 0
  17.                     foreach poolmember $poolmembers {
  18.                         incr i
  19.                         set memberarr [split $poolmember " "]
  20.                         set memberip [lindex $memberarr 0]
  21.                         set memberport [lindex $memberarr 1]
  22.                         set status [LB::status pool $poolname member $memberip $memberport]
  23.                         set returnjson "$returnjson\n\t\t\"$memberip\:$memberport\"\:\t\"$status\""
  24.                         if { $i != $membercount } {
  25.                             set returnjson "$returnjson,"
  26.                         }
  27.                     }
  28.                     set returnjson "$returnjson\n\t\}\n\}"
  29.                     HTTP::respond 200 content $returnjson Content-Type application/json Access-Control-Allow-Origin "*" Connection close
  30.                 } ] } {
  31.                     set returnjson "\{\"success\"\:false,\"error\"\:\{\"code\"\: 404,\"message\"\: \"No pool named $poolname\"\}\}"
  32.                     HTTP::respond 404 content $returnjson Content-Type application/json Access-Control-Allow-Origin "*" Connection close
  33.                 }
  34.                 event disable
  35.                 return
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
RAW Paste Data Copied
Advertisement