X-Git-Url: http://git.onelab.eu/?p=monitor.git;a=blobdiff_plain;f=automate-default.sh;h=d691c6651ad33b6a52ef76cb7e0693759851a99e;hp=73dc1103e196119807b9b4c27a3921fe219d761b;hb=HEAD;hpb=0d3d555aa76958ef55d946b21028be976a84e113 diff --git a/automate-default.sh b/automate-default.sh index 73dc110..d691c66 100755 --- a/automate-default.sh +++ b/automate-default.sh @@ -1,17 +1,33 @@ #!/bin/bash +export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin + # NOTE: Must be an absolute path to guarantee it is read. -source /usr/share/monitor-server/monitorconfig.py +INSTALLPATH=/usr/share/monitor/ +$INSTALLPATH/commands/shconfig.py > $INSTALLPATH/monitorconfig.sh +source $INSTALLPATH/monitorconfig.sh cd ${MONITOR_SCRIPT_ROOT} set -e DATE=`date +%Y-%m-%d-%T` -MONITOR_PID="$HOME/monitor/SKIP" +MONITOR_PID="${MONITOR_SCRIPT_ROOT}/SKIP" + +function send_mail () +{ + subject=$1 + body=$2 + mail -s "$subject" $exception_email < $MONITOR_PID -echo "Performing Findbad Nodes" -######################### -# 1. FINDBAD NODES -rm -f ${MONITOR_DATA_ROOT}/production.findbad2.pkl -${MONITOR_SCRIPT_ROOT}/findbad.py --increment --cachenodes --debug=0 --dbname="findbad2" $DATE || : -cp ${MONITOR_DATA_ROOT}/production.findbad2.pkl ${MONITOR_DATA_ROOT}/production.findbad.pkl -ps ax | grep BatchMode | grep -v grep | awk '{print $1}' | xargs kill || : +# SETUP act_all database if it's not there. +if [ ! -f ${MONITOR_SCRIPT_ROOT}/actallsetup.flag ]; then + if ! python -c 'import database; database.dbLoad("act_all")' 2>/dev/null ; then + touch ${MONITOR_SCRIPT_ROOT}/actallsetup.flag + fi +fi + + +set +e +AGENT=`ps ax | grep ssh-agent | grep -v grep` +set -e +if [ -z "$AGENT" ] ; then + echo "starting ssh agent" + # if no agent is running, set it up. + ssh-agent > ${MONITOR_SCRIPT_ROOT}/agent.sh + source ${MONITOR_SCRIPT_ROOT}/agent.sh + ssh-add /etc/planetlab/myops_ssh_key.rsa + ssh-add /etc/planetlab/debug_ssh_key.rsa + ssh-add /etc/planetlab/root_ssh_key.rsa +fi +#TODO: should add a call to ssh-add -l to check if the keys are loaded or not. +source ${MONITOR_SCRIPT_ROOT}/agent.sh + +# CHECK AGENT IS UP AND RUNNING +count=$( ssh-add -l | wc -l ) +if [ $count -lt 3 ] ; then + send_mail "ssh-agent is not up and running." "Add keys before monitoring can continue" + exit +fi -echo "Performing Findbad PCUs" +${MONITOR_SCRIPT_ROOT}/commands/syncwithplc.py $DATE || : +service plc restart monitor + +echo "Performing FindAll Nodes" ######################### -# 2. FINDBAD PCUS -rm -f ${MONITOR_DATA_ROOT}/production.findbadpcus2.pkl -${MONITOR_SCRIPT_ROOT}/findbadpcu.py --increment --refresh --debug=0 --dbname=findbadpcus2 $DATE || : -cp ${MONITOR_DATA_ROOT}/production.findbadpcus2.pkl ${MONITOR_DATA_ROOT}/production.findbadpcus.pkl +# 1. FINDBAD NODES +${MONITOR_SCRIPT_ROOT}/commands/findall.py $DATE || : +ps ax | grep BatchMode | grep -v grep | awk '{print $1}' | xargs -r kill || : # clean up stray 'locfg' processes that hang around inappropriately... -ps ax | grep locfg | grep -v grep | awk '{print $1}' | xargs kill || : - -echo "Generating web data" -# badcsv.txt -${MONITOR_SCRIPT_ROOT}/printbadcsv.py | grep -v loading | tr -d ' ' > badcsv.txt -cp badcsv.txt /plc/data/var/www/html/monitor/ -${MONITOR_SCRIPT_ROOT}/showlatlon.py | head -9 | awk 'BEGIN {print ""} { print ""} END{print "
", $0, "
"}' | sed -e 's\|\\g' > /plc/data/var/www/html/monitor/regions.html - -echo "Performing uptime changes for sites, nodes, and pcus" -######################## -# 3. record last-changed for sites, nodes and pcus. -${MONITOR_SCRIPT_ROOT}/sitebad.py --increment || : -${MONITOR_SCRIPT_ROOT}/nodebad.py --increment || : -${MONITOR_SCRIPT_ROOT}/pcubad.py --increment || : - -echo "Converting pkl files to phpserial" -######################### -# 4. convert pkl to php serialize format. -${MONITOR_SCRIPT_ROOT}/pkl2php.py -i findbadpcus2 -o findbadpcus -${MONITOR_SCRIPT_ROOT}/pkl2php.py -i act_all -o act_all -${MONITOR_SCRIPT_ROOT}/pkl2php.py -i plcdb_hn2lb -o plcdb_hn2lb -${MONITOR_SCRIPT_ROOT}/pkl2php.py -i findbad -o findbadnodes -${MONITOR_SCRIPT_ROOT}/pkl2php.py -i ad_dbTickets -o ad_dbTickets -${MONITOR_SCRIPT_ROOT}/pkl2php.py -i idTickets -o idTickets - -echo "Archiving pkl files" -######################### -# Archive pkl files. -for f in findbad act_all findbadpcus l_plcnodes site_persistflags node_persistflags pcu_persistflags ; do - cp ${MONITOR_DATA_ROOT}/production.$f.pkl ${MONITOR_ARCHIVE_ROOT}/`date +%F-%H:%M`.production.$f.pkl -done - -echo "Running grouprins on all dbg nodes" -############################ -# 5. Check if there are any nodes in dbg state. Clean up afterward. -${MONITOR_SCRIPT_ROOT}/grouprins.py --mail=1 \ - --nodeselect 'state=DEBUG&&boot_state=(rins|dbg|boot)' \ - --stopselect 'state=BOOT&&kernel=2.6.22.19-vs2.3.0.34.9.planetlab' \ - --reboot || : -${MONITOR_SCRIPT_ROOT}/findbad.py --increment --cachenodes --debug=0 --dbname="findbad" --nodeselect 'state=DEBUG&&boot_state=dbg||state=DEBUG&&boot_state=boot' || : - -echo "Collecting RT database dump" -########################## -# 6. cache the RT db locally. -python ${MONITOR_SCRIPT_ROOT}/rt.py +ps ax | grep locfg | grep -v grep | awk '{print $1}' | xargs -r kill || : + + +${MONITOR_SCRIPT_ROOT}/commands/repair.py $DATE || : +${MONITOR_SCRIPT_ROOT}/commands/policy.py $DATE || : +curl -s 'http://summer.cs.princeton.edu/status/tabulator.cgi?table=table_nodeview&formatcsv' > /var/lib/monitor/comon/$DATE.comon.csv || : +#${MONITOR_SCRIPT_ROOT}/statistics/add-google-record.py --email email --password password --database MonitorStats --sheet NodeHistory `${MONITOR_SCRIPT_ROOT}/statistics/get-records.py nodes` +#${MONITOR_SCRIPT_ROOT}/statistics/add-google-record.py --email email --password password --database MonitorStats --sheet SiteHistory `${MONITOR_SCRIPT_ROOT}/statistics/get-records.py sites` + +cp ${MONITOR_SCRIPT_ROOT}/monitor.log ${MONITOR_ARCHIVE_ROOT}/`date +%F-%H:%M`.monitor.log +service plc restart monitor || : rm -f $MONITOR_PID + +D=`date +%F-%H:%M` + +# NOTE: check log for major sections. +wc=`grep -E "^(findbad|findbadpcu|nodebad|pcubad|sitebad|apply-policy)$" ${MONITOR_SCRIPT_ROOT}/monitor.log | wc -l` +if [[ $wc -ge 6 ]] ; then + send_mail "A:finished monitor run for $SD at $D" "Thank you..." +else + send_mail "ERROR finished monitor run for $SD at $D" "Missing some sections: + $(grep -E "findbad|findbadpcu|nodebad|pcubad|sitebad|apply-policy" ${MONITOR_SCRIPT_ROOT}/monitor.log)" +fi +