示例#1
0
  def tomcat_server_check(self):
     host=self.property.get('tomcat.host')
     port=self.property.get('tomcat.port')
     if port is None or port=='':
         port=None
     url=host
     if port:
         url='{}:{}'.format(url,port)
     logging.info('Start check tomcat server [{}] status.'.format(url))
     ser_monitor=monitor.monitor_server(host=self.property.get('tomcat.host'),port=port,auth=self.property.get('tomcat.auth'))

     if ser_monitor.ping()=='pong':
         count=0
         logging.info(OKSTATUS %{'message':'Server connection check','split':program.split_line})
         applications=ser_monitor.applications(refresh=True)
         logging.info('Start check applications which are needed in server.')
         for application_name in self.property.get('tomcat.applications').split(','):
            _app=applications.get(application_name)
            if _app:
                if _app.status()=='running':
                    logging.info(OKSTATUS %{'message':'Application [{}] check'.format(application_name),'split':program.split_line})
                else:
                    logging.info('Application [{}] status {} [{}]'.format(application_name,program.split_line,_app.status()))
                    if self._application_retry(_app,int(self.property.get('retry.time')))==1:
                        logging.error(FAILSTATUS %{'message':'Application [{}] check'.format(application_name),'split':program.split_line})
                        count+=1
            else:
                logging.error('Application [{}] {} [Undeployed]'.format(application_name,program.split_line))
                count+=1
         if count>0:
             return 1
         return 0
     else:
         logging.error(FAILSTATUS %{'message':'Server connection check','split':program.split_line})
         return 1
 def setUpClass(cls): # setupclass and teardownclass must add classmethod decileam
     cls.service1=monitor.monitor_server('192.168.30.45',port='38811',auth='Basic YWRtaW46YWRtaW4=')
     cls.service2=monitor.monitor_server('192.168.30.322',auth='Basic YWRtaW46YWRtaW4=')