def connect_db(config): ''' Connect to DB ''' db = core.db.SetupDatastore(config=config) try: return db.get_dbc() except Exception as e: logger.error("Failed to connect to datastore: {0}".format(e.message)) return None
if config is False: print "Could not get configuration" sys.exit(1) # Setup Logging logs = core.logs.Logger(config=config, proc_name="monitoring") logger = logs.getLogger() # Listen for signals signal.signal(signal.SIGTERM, shutdown) signal.signal(signal.SIGINT, shutdown) # Open Datastore Connection db = core.db.SetupDatastore(config=config) try: dbc = db.get_dbc() except Exception as e: logger.error("Failed to connect to datastore: {0}".format(e.message)) shutdown(0, None) # Start Scheduler scheduler = BackgroundScheduler() scheduler.start() logger.info("Grabbing targets for initial scheduling") jobs, scheduled = initialize(config, dbc, scheduler, logger) logger.info("Scheduled {0} checks".format(scheduled)) while True: listen(scheduler, config, dbc, logger)
elif signum == 0: sys.exit(1) else: logger.error("Received signal {0} shutting down".format(signum)) sys.exit(1) if __name__ == "__main__": config = core.common.get_config(description="Automatron: Actioning") if config is False: print("Could not get configuration") sys.exit(1) # Setup Logging logs = core.logs.Logger(config=config, proc_name="actioning") logger = logs.getLogger() # Listen for signals signal.signal(signal.SIGTERM, shutdown) signal.signal(signal.SIGINT, shutdown) # Open Datastore Connection db = core.db.SetupDatastore(config=config) try: dbc = db.get_dbc() except Exception as e: logger.error("Failed to connect to datastore: {0}".format(e.message)) shutdown(0, None) while True: listen(config, dbc, logger)