Forum Discussion

lovleen_arora_2's avatar
lovleen_arora_2
Icon for Nimbostratus rankNimbostratus
Jul 22, 2016

Help to write the Monitor script

Hi, my server response is like this, when I accss the URL on HTTPS

 

{"myStatus":"OK","datapowerStatus":{"status":"OK","message":"{\"result\": {\"domain\": \"My_StubServices\"}}","millisecondsTaken":47},"myDatabaseStatus":{"status":"OK","message":"DBName: my-training-db","millisecondsTaken":11},"loggingDatabaseStatus":{"status":"OK","message":"DBName: my-training-log-db","millisecondsTaken":69}}

 

My intention is to write a monitor (HTTPS), so it search the string "OK" in the response, and then counts it, and if the count is equal or more than 4, then set the monitor as pass.

 

thanks in advance.

 

9 Replies

  • have you started with something we could help with or expect a full solution here?

     

  • I would appreciate if a full solution or a steps involved can be described a bit in detail please.

     

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    Will you clarify if the content of the response containing the "OK" string is returned in a single or multiple lines?

     

  • thanks for looking into this, actually on the webpage it displays the response in 2 lines as text, nothing special..and another thing would there be much difference because the url is HTTPS and not HTTP. Regards

     

  • this shows pretty well how to go about it

     

    https://devcentral.f5.com/s/articles/ltm-external-monitors-the-basics

     

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    This one should do it:

    !/bin/sh
     these arguments supplied automatically for all external pingers:
     $1 = IP (::ffff:nnn.nnn.nnn.nnn notation or hostname)
     $2 = port (decimal, host byte order)
     $3 and higher = additional arguments
    
     $MONITOR_NAME = name of the monitor
    
     In this sample script, $3 is the regular expression
    
    
     Name of the pidfile
    pidfile="/var/run/$MONITOR_NAME.$1..$2.pid"
    
     Send signal to the process group to kill our former self and any children
     as external monitors are run with SIGHUP blocked
    if [ -f $pidfile ]
    then
       kill -9 -`cat $pidfile` > /dev/null 2>&1
    fi
    
    echo "$$" > $pidfile
    
     Remove the IPv6/IPv4 compatibility prefix
    node_ip=`echo $1 | sed 's/::ffff://'`
    
     Using the nc utility to get data from the server.
     Search the data received for the expected expression.
    
    count=$(echo -en "GET / HTTP/1.0\n\n\n\n" | nc $node_ip $2 2>/dev/null | egrep -v '200 OK' 2>/dev/null | tr -d -c 'OK' 2>/dev/null | awk '{ print length; }' 2>/dev/null)
    
    if [ ! -z "$count" ]
    then
        count=$(($count+0))
        if [ $count -gt 8 ]
        then
         Remove the pidfile before the script echoes anything to stdout and is killed by bigd
        rm -f $pidfile
        echo "up"
        fi
    fi
    
     Remove the pidfile before the script ends
    rm -f $pidfile
    
     END.
    

    You need to modify it to put in the URI specific for your application.

    Edit: The count should be 8 or greater.

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    OK you can use a standard monitor, which is preferred over an external monitor, and use the following as the receive string:

    :\"OK\".*:\"OK\".*:\"OK\".*:\"OK\"

    .