CSM TCL Script Help

Unanswered Question

Hey guys,


I have a requirement to write a probe that looks at a web page and reads a number from it...0 being ok and 1 being error.


This is being used to report the status of another application running on that server.


Does anyone have anything similar that I could take a look at?


If that's not possible I could possibly read from a txt file instead if that's easier?


I have the example scripts from the cisco site but with my limited programming knowledge it's proving tricky to understand!


Thanks for your help.


Anthony

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 0 (0 ratings)
Loading.
Gilles Dufour Fri, 04/18/2008 - 06:25
User Badges:
  • Cisco Employee,

Here is an example on how to read the status code from an http server.

You should be able to adjust the regexp to catch your server status.


more csm_httpprobe.tcl

#!name = HTTPCONTENT_PROBE

########################################################################################

#

# Description :

# Script sends a http 1.0 GET request to a idmsprod server cluster to determine if

# servers are functional

#

# CSM version :

# 4.2 (5)

#

# Parameters :

# [debugFlag]

# regquestHeader - HTTP request to send e.g "GET /yahoo.html HTTP/1.0"

# debugFlag - default 0. Do NOT turn on while multiple probes are configured

#

# Example config :

# probe httpProbe script

# script HTTPCONTENT_PROBE "GET /yahoo.html HTTP/1.0" 0

#

########################################################################################


#-------------------------------------------

# debug procedure

# set the EXIT_MSG environment varaible to help debug

# also print the debug message when debug flag is on

#-------------------------------------------


proc csm_debug { msg } {

global debug ip port EXIT_MSG


set EXIT_MSG $msg

if { [ info exists ip ] && [ info exists port ] } {

set EXIT_MSG "[ info script ]:$ip:$port: $EXIT_MSG "

}

if { [ info exists debug ] && $debug } {

puts $EXIT_MSG

}

}




#-------------------------------------------

# main

#-------------------------------------------


# parse cmd line args and initialize variables

csm_debug "initializing varaible"

if { $argc < 1 } {

set EXIT_MSG "ERR config: script HTTPCONTENT_PROBE

_PROBE_SCRIPT \"GET / HTTP/1.0\" html 0"

puts $EXIT_MSG

exit 5001

}


set ip $csm_env(realIP)

set port $csm_env(realPort)

# if port is zero the use well known http port 80

if { $port == 0} {

set port 80

}


set requestHeader [ lindex $argv 0 ]

set expectFileType [ lindex $argv 1 ]

set debug [ lindex $argv 2 ]

if { $debug == "" } {

set debug 0

}

# open connection

csm_debug "opening socket"

set sock [ socket $ip $port ]



# send http requeset to server

csm_debug "sending request : $requestHeader"

puts -nonewline $sock "$requestHeader\n\n"

flush $sock


# read string back from server

csm_debug "receiving response"

set lines [ read $sock ]


# close connection

csm_debug "closing socket"

close $sock



# parsing http response to decide if probe success or failed

# all the following condition casing probe faile. should return exit 5001

if { ![ regexp -nocase "^HTTP/1\.\[0-9\] (\[0-9\]\[0-9\]\[0-9\])" $lines match statuscode ] } {

csm_debug "probe fail : can't find status code"

exit 5001

}


if { $statuscode != "200" } {

csm_debug "probe fail : status code is $statuscode"

exit 5001

}



if { ![ regexp -nocase "Please type the Livelink Administrator password in the" $lines ]} {

csm_debug "probe fail : does not find correct text"

exit 5001

}



# Everything went fine. probe exit with success exit_code 5000

csm_debug "probe success"

exit 5000


Actions

This Discussion