Virtual_ Server_ Monitoring_(iRule)

Problem this snippet solves:

Hi Community,

The goal is to get a html page with the status of the virtual servers. For this we need the following: 1) "VirtualServers_Monitorizados.txt" (this file contains the name of the virtual servers that you want to monitor)

2) "virtualserver_list.sh" (This script reads the contents of the file "VirtualServers_Monitorizados.txt" and generates a class file called "lista_vs_poolmembers.class")

3) "lista_vs_poolmembers.class" (is generated by script "virtualserver_list.sh" and this file contains the virtual servers names, ips, pools and members pools with a particular structure) STRUCTURE: VirtualServerName/VirtualServerIP:VirtualServerPort/PoolName/PoolMember1:PoolMemberPort1,PoolMember2:PoolMemberPort2,

4) "iRule_Monitorizacion.tcl" (this iRule reads the content of the file "lista_vs_poolmembers.class" and generate a dynamic html page with the virtual servers and members status)

The "virtualserver_list.sh" script can be run with crontab: - Create a file in the following path /etc/cron.daily/virtualserver_list.cron - Change the permissions by entering chmod +755 /etc/cron.daily/virtualserver_status_list.cron

For iRule can read from a external file: - Create a external datagroup Main >> Local Traffic >> iRules Select Data Group List Click create enter name: lista_vs_poolmembers enter Type: External Path / Filename: /var/class/lista_vs_poolmembers.class File Content: String

The last steps are: - Create a new iRule - Create a new Virtual Server and assign the iRule. Through this service we obtain monitoring

In my scenario I get the Virtual Servers Status connecting to "http://IP_Virtual_Server_Monitor/status"

I've attachmented a ZIP file with: - virtualserver_list.sh - iRule_Monitorizacion.tcl - file example for "VirtualServers_Monitorizados.txt"

Thanks David Díez

Code :

######################################################################################
######################################################################################
###                                                                                ###                                                                           
### Nombre: Monitorizacion_Virtual_Servers                                         ###  
### Autor: David Diez  @  Siemens Enterprise Communications                        ###             
### Fecha: 05/11/2010                                                              ###
### Descripcion: Genera una pagina HTML al vuelo con el estado actual de los       ###
###              Virtual Servers y Nodos. Lee los datos de un Data Group (.class)  ###
###              generado por un bash script que se ejecuta 1 o 2 veces/dia        ###
###                                                                                ###
######################################################################################
######################################################################################

when HTTP_REQUEST {
        if { [HTTP::uri] eq "/status" } {
                set html_status_gral ""
                set general_status "UP"
                set response_init "BIGIP Monitorizacion Servicios Virtuales - \
                [clock format [clock seconds]]

BIGIP Virtual Server Status - \ [clock format [clock seconds]]

" set response_total "\ \ \ \ " foreach { selectedvs } [class get lista_vs_poolmembers] { if { [catch { set aux_response "" set vs_status "DOWN" scan $selectedvs {%[^/]/%[^/]/%[^/]/%[^/]} vs_name vs_addr_port \ poolname list_members set members_list [split $list_members ","] set num_members [llength $members_list] #la lista de members termina en coma con lo q el ultimo no existe set num_members [expr $num_members-1] # si no hay miembros en el Pool es que no hay POOL Asignado if { $num_members == 0 } { continue } for {set x 0} {$x<$num_members} {incr x} { set nodo_actual [lindex $members_list $x] scan $nodo_actual {%[^:]:%[^:]} addr port # El primer nodo no tiene que crear fila ya que esta creada # mas abajo cuando se escribe el nombre y direccion del virtual Server if { $x == 0} { switch -glob [LB::status pool $poolname member $addr $port] { "up" { set vs_status "UP" append aux_response "\ " } "down" { append aux_response "\ " } "session_enabled" { append aux_response "\ " } "session_disabled" { append aux_response "\ " } Default { append aux_response "\ " } } #SWITCH END } else { switch -glob [LB::status pool $poolname member $addr $port] { "up" { set vs_status "UP" append aux_response "\ " } "down" { append aux_response "\ " } "session_enabled" { append aux_response "\ " } "session_disabled" { append aux_response "\ " } Default { append aux_response "\ " } } #SWITCH END } #ELSE } # FOR END # En este punto ya sabemos el estado de los nodos y del Virtual Server. # Hay que a?adir por la izquierda el estado de VS a rsponse if {[ string equal $vs_status "DOWN" ] == 1 } { set general_status "DOWN" set response "\ \ " } else { set response "\ \ " } append response $aux_response # En cuanto uno de los VS est? DOWN cambiamos el valor de la variable ya # status general ya que hay q marcar down elstatus general append response_total $response } errmsg] } { # no hacemos nada.. Ya que el VS es erroneo o no tiene pool asignado continue #append response_total "\ #" } } append response_total "
Virtual ServerVS IPVS StatusNodosNodos Status
$addr:$portUP
$addr:$portDOWN
$addr:$portENABLED
$addr:$portDISABLED
$addr:$portINVALID
$addr:$portUP
$addr:$portDOWN
$addr:$portENABLED
$addr:$portDISABLED
$addr:$portINVALID
\ $vs_name$vs_addr_port$vs_status
\ $vs_name$vs_addr_port$vs_status
PRUEBA2INVALID
" if {[ string equal $general_status "UP" ] == 1 } { append html_status_gral "\ \
ESTADO GENERAL
UP
" } else { append html_status_gral "\ \
ESTADO GENERAL
DOWN
" } HTTP::respond 200 content "$response_init $html_status_gral $response_total"\ "Content-Type" "text/html" "Cache-Control"\ "no-cache, must-revalidate" "Expires" "Mon, 27 Oct 2010 05 } }
Published Mar 18, 2015
Version 1.0

Was this article helpful?

No CommentsBe the first to comment