3 export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
5 # NOTE: Must be an absolute path to guarantee it is read.
6 INSTALLPATH=/usr/share/monitor/
7 $INSTALLPATH/commands/shconfig.py > $INSTALLPATH/monitorconfig.sh
8 source $INSTALLPATH/monitorconfig.sh
9 cd ${MONITOR_SCRIPT_ROOT}
11 DATE=`date +%Y-%m-%d-%T`
12 MONITOR_PID="${MONITOR_SCRIPT_ROOT}/SKIP"
18 mail -s "$subject" $exception_email <<EOF
24 echo "#######################################"; echo "Running Monitor at $DATE"; echo "######################################"
25 echo "Performing API test"
26 API=$(${MONITOR_SCRIPT_ROOT}/tools/testapi.py)
27 if [ "$API" != "ok" ] ; then
28 # NOTE: Do not try to run any commands if the API is obviously broken.
29 echo "API IS DOWN : "`date`
30 send_mail "API IS DOWN: canceled monitor run for `date`" "have a nice day..."
34 if [ -f $MONITOR_PID ] ; then
36 echo "KILLING Monitor"
37 PID=`cat $MONITOR_PID`
40 ${MONITOR_SCRIPT_ROOT}/tools/kill.cmd.sh $PID
43 echo "No PID to be killed."
47 echo "SKIPPING Monitor"
51 echo $$ > $MONITOR_PID
53 # SETUP act_all database if it's not there.
54 if [ ! -f ${MONITOR_SCRIPT_ROOT}/actallsetup.flag ]; then
55 if ! python -c 'import database; database.dbLoad("act_all")' 2>/dev/null ; then
56 touch ${MONITOR_SCRIPT_ROOT}/actallsetup.flag
62 AGENT=`ps ax | grep ssh-agent | grep -v grep`
64 if [ -z "$AGENT" ] ; then
65 echo "starting ssh agent"
66 # if no agent is running, set it up.
67 ssh-agent > ${MONITOR_SCRIPT_ROOT}/agent.sh
68 source ${MONITOR_SCRIPT_ROOT}/agent.sh
69 ssh-add /etc/planetlab/myops_ssh_key.rsa
70 ssh-add /etc/planetlab/debug_ssh_key.rsa
71 ssh-add /etc/planetlab/root_ssh_key.rsa
73 #TODO: should add a call to ssh-add -l to check if the keys are loaded or not.
74 source ${MONITOR_SCRIPT_ROOT}/agent.sh
76 # CHECK AGENT IS UP AND RUNNING
77 count=$( ssh-add -l | wc -l )
78 if [ $count -lt 3 ] ; then
79 send_mail "ssh-agent is not up and running." "Add keys before monitoring can continue"
83 ${MONITOR_SCRIPT_ROOT}/commands/syncwithplc.py $DATE || :
84 service plc restart monitor
86 echo "Performing FindAll Nodes"
87 #########################
89 ${MONITOR_SCRIPT_ROOT}/commands/findall.py $DATE || :
90 ps ax | grep BatchMode | grep -v grep | awk '{print $1}' | xargs -r kill || :
91 # clean up stray 'locfg' processes that hang around inappropriately...
92 ps ax | grep locfg | grep -v grep | awk '{print $1}' | xargs -r kill || :
95 ${MONITOR_SCRIPT_ROOT}/commands/repair.py $DATE || :
96 ${MONITOR_SCRIPT_ROOT}/commands/policy.py $DATE || :
97 curl -s 'http://summer.cs.princeton.edu/status/tabulator.cgi?table=table_nodeview&formatcsv' > /var/lib/monitor/comon/$DATE.comon.csv || :
99 #${MONITOR_SCRIPT_ROOT}/statistics/add-google-record.py --email email --password password --database MonitorStats --sheet NodeHistory `${MONITOR_SCRIPT_ROOT}/statistics/get-records.py nodes`
100 #${MONITOR_SCRIPT_ROOT}/statistics/add-google-record.py --email email --password password --database MonitorStats --sheet SiteHistory `${MONITOR_SCRIPT_ROOT}/statistics/get-records.py sites`
102 cp ${MONITOR_SCRIPT_ROOT}/monitor.log ${MONITOR_ARCHIVE_ROOT}/`date +%F-%H:%M`.monitor.log
103 service plc restart monitor || :
108 # NOTE: check log for major sections.
109 wc=`grep -E "^(findbad|findbadpcu|nodebad|pcubad|sitebad|apply-policy)$" ${MONITOR_SCRIPT_ROOT}/monitor.log | wc -l`
110 if [[ $wc -ge 6 ]] ; then
111 send_mail "A:finished monitor run for $SD at $D" "Thank you..."
113 send_mail "ERROR finished monitor run for $SD at $D" "Missing some sections:
114 $(grep -E "findbad|findbadpcu|nodebad|pcubad|sitebad|apply-policy" ${MONITOR_SCRIPT_ROOT}/monitor.log)"