CSS Scripted keepalive

Unanswered Question
Aug 19th, 2010

Hi Guys,


I have a requirment to write a script to check the following;


Check a number of tcp ports, a perform a HTTP GET then look for a string match in the returned page.


Now, I am not really a coder but I can script the tcp port check and also the url get however I am not sure how to look for a string match.


Has anyone got an example or indeed done this before.


Thanks for you advice.


Scott

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 0 (0 ratings)
Loading.
Gilles Dufour Thu, 08/19/2010 - 05:05

You can look into existing http scriot with the command "show scrip ap-kal-httptag"


You will see that the command you need is 'socket waitfor ....' which will wait to see the string you want or timeout and declare the server down.


Gilles.

scott-goodwin Fri, 08/20/2010 - 03:05

Thankyou,


I managed to get it working, I will post on here later as it maybe usefull for others.


Thanks


Scott

scott-goodwin Fri, 08/20/2010 - 04:12

!--- No echo.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!--- Parameters: Website IP, Web Page, Webstring, TCP Port(s)
!
!--- Description:
!--- This script will open and close a socket on the user specified ports.
!--- The close will be a FIN rather than a RST. If one of the ports fails,
!--- the service will be declared down
!--- If the ports are seen as up the script will then connect to the webserver
!--- Issue a GET and search the response for the defined string, if the search
!--- fails the service is deemed as down
!
!--- Failure Upon:
!--- 1. Not establishing a connection with the host on one of the specified port                                                                             s.
!--- 2. Unable to find the string in the GET request response.
!
!---
!--- Will handle out of sockets scenario.
!--- will handle unable to connect.
!
!--- Written By Scott Goodwin
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


!-- Set the tcp connection error numbers


set OUT-OF-SOCKETS "785"
set NO-CONNECT "774"



!--- Make sure the user has a qualified number of arguments.


if ${ARGS}[#] "LT" "4"
  echo "Usage: ap-kal-custom-sg \'WebSiteIP WebPage WebString tcpPort1 [tcpPort2 tcpPort3...]\'"
  exit script 1
endbranch


!--- Set variables corresponding to the args.


set SERVICE "${ARGS}[1]"
set WebSite "${ARGS}[1]"
set WebPage "${ARGS}[2]"
set WebString "${ARGS}[3]"
set WebPort "80"


!--- Cycle through the variables to the tcpPorts


var-shift ARGS
var-shift ARGS
var-shift ARGS


while ${ARGS}[#] "GT" "0"
  set TCP-PORT "${ARGS}[1]"
  var-shift ARGS
echo "${TCP-PORT}"
  function SOCKET_CONNECT call


!--- If out of sockets, exit, and look for sockets on the next KAL interval.

  if RETURN "==" "${OUT-OF-SOCKETS}"
    set EXIT_MSG "Exceeded number of available sockets, skipping until next interval."
    exit script 0
  endbranch



!--- Valid connection, look to see if it was good.

  if RETURN "==" "${NO-CONNECT}"
    set EXIT_MSG "Connect: Failed to connect to ${SERVICE}:${TCP-PORT}"
    exit script 1
  endbranch
endbranch


no set EXIT_MSG



function SOCKET_CONNECT begin
  set CONTINUE_ON_ERROR "1"
  socket connect host ${SERVICE} port ${TCP-PORT} tcp 2000
  set SOCKET-STAT "${STATUS}"
  set CONTINUE_ON_ERROR "0"
  socket disconnect ${SOCKET} graceful
  function SOCKET_CONNECT return "${SOCKET-STAT}"
function SOCKET_CONNECT end






no set CONTINUE_ON_ERROR
no set EXIT_MSG


!-- Now check the url, perform a GET request and search for the defined string



echo "Requesting ${WebPage} from ${WebSite} on port ${WebPort}."



!--- Connect to the remote server.


set EXIT_MSG "Connect:  Failed.  Could not connect to ${WebSite} on port ${WebPort}"
set CONTINUE_ON_ERROR "1"
socket connect host ${WebSite} port ${WebPort} tcp
if ${STATUS} "NEQ" "0"
  exit script 1
endbranch
no set CONTINUE_ON_ERROR



!--- Request the desired Web page.


set EXIT_MSG "Send:  Failed.  Could not send to ${WebSite}:${WebPort}"
socket send ${SOCKET} "GET ${WebPage} HTTP/1.0\n\nHost: ${WebSite}:${WebPort}\n"



!--- Look for the Web string.


set EXIT_MSG "Waitfor:  Failed.  Did not find [${WebString}]"
set CONTINUE_ON_ERROR "1"
socket waitfor ${SOCKET} "${WebString}" case-sensitive
if ${STATUS} "NEQ" "0"
  exit script 1
endbranch
no set CONTINUE_ON_ERROR



!--- Disconnect from the server.

no set EXIT_MSG

Actions

This Discussion