Technical posts/Weblogic

웹로직 상태체크 해서 이메일 보내기

ODB 2020. 7. 8. 12:48

웹로직 managed 서버가 running이 아니거나 web application이 active 상태가 아닌경우 이메일을 보내는 스크립트

급하고 무식하게 후다닥 짜서 개발기와 운영기에 물려서 사용하는중

#/bin/sh

DOMAIN_HOME='/weblogic/home/domain/home/base_domain'
DOMAIN_NAME='base_domain'
ADMIN_NAME='AdminServer'
ADMIN_PORT=7001
HOSTNAME=`cat /proc/sys/kernel/hostname`

genScript()
{
echo "connect(  url='t3://`hostname`:${ADMIN_PORT}', adminServerName='${ADMIN_NAME}')" > ${DOMAIN_HOME}/status.py
echo "servers=cmo.getServers()" >> ${DOMAIN_HOME}/status.py
echo "for server in servers:" >> ${DOMAIN_HOME}/status.py
echo " print'|s',state(server.getName(),server.getType())" >> ${DOMAIN_HOME}/status.py
echo " print'|s Listen Address:',server.getListenAddress(),':',server.getListenPort()" >> ${DOMAIN_HOME}/status.py
echo " " >> ${DOMAIN_HOME}/status.py
echo "cd('AppDeployments')" >> ${DOMAIN_HOME}/status.py
echo "deploymentsList=cmo.getAppDeployments()" >> ${DOMAIN_HOME}/status.py
echo "for app in deploymentsList:" >> ${DOMAIN_HOME}/status.py
echo "      domainConfig()" >> ${DOMAIN_HOME}/status.py
echo "      cd ('/AppDeployments/'+app.getName()+'/Targets')" >> ${DOMAIN_HOME}/status.py
echo "      mytargets = ls(returnMap='true')" >> ${DOMAIN_HOME}/status.py
echo "      domainRuntime()" >> ${DOMAIN_HOME}/status.py
echo "      cd('AppRuntimeStateRuntime')" >> ${DOMAIN_HOME}/status.py
echo "      cd('AppRuntimeStateRuntime')" >> ${DOMAIN_HOME}/status.py
echo "      for targetinst in mytargets:" >> ${DOMAIN_HOME}/status.py
echo "            curstate4=cmo.getCurrentState(app.getName(),targetinst)" >> ${DOMAIN_HOME}/status.py
echo "            print '|--', app.getApplicationName(), ' | ', app.getModuleType(), ' | ',  targetinst, ' | ', curstate4, ' | ', app.getAbsoluteSourcePath()" >> ${DOMAIN_HOME}/status.py
echo " " >> ${DOMAIN_HOME}/status.py
}


isAdmRunning=`ps -ef |grep Name=${ADMIN_NAME} |grep -v grep |wc -l`
if [ "${isAdmRunning}" = "1" ]; then
 . ${DOMAIN_HOME}/bin/setDomainEnv.sh
 genScript
 java weblogic.WLST status.py |grep \ > server_status.out
        isMsvrRunning=`cat ${DOMAIN_HOME}/server_status.out | grep \|s | grep "UNKNOWN"| wc -l`
        if [ "${isMsvrRunning}" != "0" ]; then
          grep \| ${DOMAIN_HOME}/server_status.out | awk '{ print $0"   " }' | mail -s "${HOSTNAME} one of managed server is not running" admin@email.com
          echo "Check Managed Servers"
          echo "`cat  ${DOMAIN_HOME}/server_status.out | grep \|s`"
        else
          echo "Managed servers are all RUNNING status"
        fi

        numOfApplications=`cat ${DOMAIN_HOME}/server_status.out |grep \|-- | wc -l`
        deploymentCheck=`cat ${DOMAIN_HOME}/server_status.out | grep \|-- | grep "STATE_ACTIVE"| wc -l`

        if [ "${deploymentCheck}" != "${numOfApplications}" ]; then
          grep \| ${DOMAIN_HOME}/server_status.out | awk '{ print $0"   " }' | mail -s "${HOSTNAME} one of web applications are not Active" admin@email.com
          echo "Check current deployments"
          echo "`cat  ${DOMAIN_HOME}/server_status.out | grep \|--`"
        else
          echo "All deployments are Active status"
        fi


else
    echo "${HOSTNAME} AdminServer is not running" | mail -s "${HOSTNAME} AdminServer is not running" admin@email.com
fi

도메인정보, 이메일정보만 바꿔서 사용하면 된다
도메인홈에 status.py를 생성하고 AdminServer가 실행중인지, managed server가 다 running인지, 운영중인 어플리케이션이 Active 아닌것이 있는지 확인해준다.
크론탭에 5분마다 실행되도록 걸어놓고 사용중인데 쓸만하다 꽤괜..

"이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다."