CDH 서비스 모니터링, 문자 메 일 경고

배경
CDH 서비스 에 이상 이 발생 하면 즉시 통지 할 수 있다.
스 크 립 트 구현
#! /bin/bash
#            
export count=0
#      
export BADserver
#       ,0      ,1      
export sc=0
#        
export lxcount=0 

while true
do
     #        /home/azkaban/serveies.txt       cdh  
     while read line
     do
     #  cloudreaManager restAPI        
     rs=`curl -u user:passwd -X GET http://hdh02.c.p.xyidc:7180/api/v33/clusters/EZCluster/services/$line|jq .healthSummary | sed 's/\"//g'`
     #    ,       
     if [ ${rs} == "BAD" ];
     then
       #     ,     1
       sc=1
       #      
       count=$((count+1))
       #                   
       if [[ "$BADserver" =~ $line ]]
       then
         echo "------------------------------------------------------------------------------$line exits"
       else
        #    ,         
        BADserver=$line,$BADserver
        echo "------------------------------------------------------------------------------BADserver=${BADserver%,}"
       fi    
      fi
     echo -----------------server=$line healthSummary=$rs  count=$count  lxcount=$lxcount------------------    
     done<serveies.txt
     
     #      ,       
     if [ $sc -ge 1 ];
       then
       lxcount=$((lxcount+1))
       echo --------------------------------------------------------------------------------Have some server BAD!!!
     else
       echo --------------------------------------------------------------------------------All server not BAD now
       #     ,      count   0,         ,               
       count=0
       lxcount=0
       BADserver=
     fi
     #     ,      0
     sc=0
     if [ $count -ge 6 -a $lxcount -ge 8 ];
         then
          message="    ,    ,         ${BADserver%,}    !!!"
          #    
          #echo "$message" | mail  -s  "    ${BADserver%,}    "  [email protected]
          #    rest  ,        
           curl "http://xxxx:8080/alarm/sendSms.do?mobile=1515813***5&body=${message}&type=0&producer=CDH"
          echo $message
          #  hive      ,hive    ,          
          if [[ "$BADserver" =~ "hive" ]];
           then
             echo "------------------------------------------------------------------------------restart hive " 
             msg="       hive      ,hive      "
             #curl -u user:passwd -X post http://hdh02.c.p.xyidc:7180/api/v33/clusters/EZCluster/services/hive/commands/restart
             if [[ "$?" =~ "0" ]]
               then
                echo "$msg $BADserver $lxcount" 
               #curl "http://xxx:8080/alarm/sendSms.do?mobile=1515813**&body=${msg}&type=0&producer=CDH"
             fi
          fi
          lxcount=0
          count=0
    fi
    #      
    sleep 3m
done
echo "-----------task is stoped!----------------"

좋은 웹페이지 즐겨찾기