def passes_checks(self): """Return True if the process exists.""" process = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE) output, error = process.communicate() if error: return False for line in output.splitlines(): if self.pattern.upper() in line.upper(): LOGGER.info('[{}] passed check.'.format(self.name, self.description)) return True LOGGER.error('[{}] is NOT currently running.'.format(self.name, self.description)) return False
def check_web_applications(web_applications): """Loop forever, checking the status of *web_applications* every 5 seconds.""" LOGGER.info('Beginning web application checks') while True: for application in web_applications: LOGGER.info('Starting check for process [{}]'.format( application.name)) if not application.passes_checks(): LOGGER.error('Process [{}] failed status check'.format( application.name)) else: LOGGER.info('Process [{}] passed status check'.format( application.name)) time.sleep(5)
def check_web_applications(web_applications): """Loop forever, checking the status of *web_applications* every 5 seconds.""" LOGGER.info('Beginning web application checks') while True: for application in web_applications: LOGGER.info( 'Starting check for process [{}]'.format(application.name)) if not application.passes_checks(): LOGGER.error( 'Process [{}] failed status check'.format( application.name)) else: LOGGER.info( 'Process [{}] passed status check'.format( application.name)) time.sleep(5)
def check_processes(processes): """Loop forever, checking the status of *processes* every 5 seconds.""" LOGGER.info('Beginning process checks') failed_processes = set() suppress_email = False while True: for process in processes: if process in failed_processes: suppress_email = True LOGGER.info('Starting check for process [{}]'.format(process.name)) if not process.passes_checks(suppress_email): LOGGER.error('Process [{}] failed status check'.format( process.name)) failed_processes.add(process) else: LOGGER.info('Process [{}] passed status check'.format( process.name)) if process in failed_processes: del failed_processes[process] time.sleep(5)