Citrix Monitor for XenApp or XenDesktop

Problem this snippet solves:

This TMSH script quickly and easily creates a monitor for Citrix XenApp or XenDesktop on an LTM. Instructions for importing and executing this TMSH script are found in the F5 deployment guide. The script takes three inputs, username, password and appname and then automatically calculates the POST Content-Length to create a customized, specialized monitor for your Citrix environment.

Download the zip file

Code :

################## TMSH Script Loader ##################
## ## This code will load the script below onto a  ## ##
## ## BIG-IP: just copy this entire file to the    ## ##
## ## BIG-IP and run "sh this_file.tcl"            ## ##
                                                   ## ## 
if cat $0 | grep -v '## ##$' | b merge - ; then    ## ##
   echo "TMSH script loaded successfully."         ## ##
  exit 0                                          ## ## 
else                                               ## ##
   echo "Failed to load TMSH script."              ## ##
  exit -1                                         ## ## 
fi                                                 ## ##
                                                   ## ## 
################## TMSH Script Loader ##################

script create-citrix-monitor.tcl {
proc script::help { } {
    tmsh::add_help "Create a monitor for Citrix XenApp version 5.x \n\
          " 
}

proc script::run { } {
    if { $tmsh::argc < 4 } {
       puts "Requires four arguments:      you have not supplied via the command line. Switching to Interactive Mode."
       set username [getFeedback "What is the username " "g.washington"]
       set password [getFeedback "What is the password?" "password"]
       set appname [getFeedback "What is the appname?" "notepad"]
       set domain [getFeedback "What is the domain name?" "corpdomain"]
   }
   if { $tmsh::argc == 5 } {
       set username [lindex $tmsh::argv 1]
       set password [lindex $tmsh::argv 2]
       set appname [lindex $tmsh::argv 3]
       set domain [lindex $tmsh::argv 4]
    }

    set ver [tmsh::version]
   if { ($ver starts''with "10.0") or ($ver starts''with "10.1") } {
       set ver "<10.2"
    }

    set postcontent "permissionsallica30content$username$password$domainBIGIP''CITRIX''MONITOR0.0.0.0" 

    set length [string length $postcontent]
   set escapes [regexp -all {\B} $postcontent]
   # Adding an extra 4 here for the \r\n\r\n automatically added by TMOS <= 10.1
   set contentlength [expr [string length $postcontent] - $escapes + 4]
   # For TMOS >= 10.2, we will now manually add these characters after calculating the content length
   if { $ver equals "<10.2" } {
       set postcontent [append $postcontent "\r\n\r\n"]
    }

    set xmlbrokermonitor "POST /scripts/WPnBr.dll HTTP/1.1\\r\\nContent-Length: $contentlength\\r\\nContent-Type: text/xml\\r\\nConnection: close\\r\\nHost: citrix\\r\\n\\r\\n$postcontent" 

    set monitor_type "http"
   set monitor_name "$appname-CitrixXMLBroker"
   set monitor_interval "3"
   set monitor_timeout "19"
   set send '$xmlbrokermonitor'
   set receive '$appname' 

    tmsh::create / ltm monitor $monitor''type $monitor''name interval $monitor''interval timeout $monitor''timeout send $send recv $receive
   puts "Created monitor $monitor_name, plese attach to the XML Broker pool." 
}

proc getFeedback { question default } {
   puts -nonewline $question
  puts -nonewline " (Default: $default) "
  flush stdout
  set input [gets stdin]
  if { $input equals "" } {
     return $default
  } else {
     return $input
   }
}
}
Published Mar 10, 2015
Version 1.0

Was this article helpful?

No CommentsBe the first to comment