cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with External monitor returning value

drhaskins
Nimbostratus
Nimbostratus

I am attempting to write an external monitor to determine which of our three databases is the "master." We need to first ssh to the server and then run a command. This command should return either a 'true' or 'fals'

 

#!/bin/sh

 

# 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://'`

 

/bin/expect<<EOF

  log_file -noappend /var/tmp/mongo_status.log

  spawn /bin/ssh svc_f5_mongo@10.xx.yy.zz

  sleep 1;

  expect "password:"

  send "***********"

  expect "svc_f5"

  send "/bin/mongo -u ******** -p ******** --authenticationDatabase admin --eval 'printjson(db.isMaster())'|grep 'ismaster' | cut -c15-18\r"

  sleep 4

  send "exit\r"

EOF

 

status=$?

 

echo "$status"

 

if [ $status -eq 0 ]

then

# Remove the pidfile before the script echoes anything to stdout and is killed by bigd    

  rm -f $pidfile

  echo "up"

fi

 

# Remove the pidfile before the script ends

rm -f $pidfile

 

I have been unable to determine the the value from expect.

 

Any suggestions would be most appreciated.

 

Thank you

1 REPLY 1

Simon_Blakely
F5 Employee
F5 Employee

You need to understand the behaviour of External monitors and stdout

 

K7444: Requirements for external monitor output

 

-----

Custom external monitors must observe the following output requirements:

  • If a server meets the external monitor criteria, the external monitor must send data to stdout.
  • Note: Any data on stdout results in an Available status. The data does not have to be specific to the condition of the server.
  • Note: Any standard output stops the script from running. To ensure that the necessary operations occur, F5 recommends that you clean up any temporary files, perform logging, etc., before the system performs the standard output operation.
  • If a server fails to meet the external monitor criteria, the external monitor must not send any data to stdout.

-----

 

Looking at your script, you have

 

status=$?   echo "$status"

This will terminate the script here, and mark the monitor as "Available".

 

If you need to log something from the script for development purposes, use *logger* to log into /var/log/ltm