def main(): # populate secrets from environment variables populate_secrets() # parse command line arguments args = parse_args(sys.argv[1:]) # setup logging setup_logging(args) EventComparer().run()
def ensure_table(): populate_secrets() conn = pymysql.connect(host='localhost', user=CONFIG['MYSQL_USER'], password=CONFIG['MYSQL_PASS'], db=CONFIG['MYSQL_DB'], charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) try: with conn.cursor() as cursor: sql = 'SHOW TABLES;' logger.debug('EXECUTE: %s', sql) cursor.execute(sql) tmp = cursor.fetchall() tables = [x['Tables_in_zm'] for x in tmp] logger.debug('Tables: %s', sorted(tables)) if ANALYSIS_TABLE_NAME in tables: logger.debug('Table %s exists', ANALYSIS_TABLE_NAME) return logger.warning('Table %s does not exist; creating', ANALYSIS_TABLE_NAME) parts = [ 'CREATE TABLE `%s` (' % ANALYSIS_TABLE_NAME, "`MonitorId` int(10) unsigned NOT NULL DEFAULT '0',", "`ZoneId` int(10) unsigned NOT NULL DEFAULT '0',", "`EventId` int(10) unsigned NOT NULL DEFAULT '0',", "`FrameId` int(10) unsigned NOT NULL DEFAULT '0',", "`FrameType` tinytext,", "`AnalyzerName` VARCHAR(30) NOT NULL,", "`RuntimeSec` decimal(10,2) DEFAULT '0.00',", "`Results` text,", "`IgnoredResults` text,", "KEY `EventId` (`EventId`),", "KEY `MonitorId` (`MonitorId`),", "KEY `ZoneId` (`ZoneId`),", "KEY `FrameId` (`FrameId`),", "KEY `AnalyzerName` (`AnalyzerName`),", "PRIMARY KEY (`EventId`, `MonitorId`, `ZoneId`, `FrameId`, " "`AnalyzerName`)", ") ENGINE=InnoDB DEFAULT CHARSET='utf8mb4';" ] sql = ' '.join(parts) logger.debug('EXECUTE: %s', sql) cursor.execute(sql) conn.commit() with conn.cursor() as cursor: sql = 'SHOW TABLES;' logger.debug('EXECUTE: %s', sql) cursor.execute(sql) tmp = cursor.fetchall() tables = [x['Tables_in_zm'] for x in tmp] logger.debug('Tables: %s', sorted(tables)) if ANALYSIS_TABLE_NAME in tables: logger.warning('Ok, table %s successfully created', ANALYSIS_TABLE_NAME) return logger.critical('ERROR: Failed creating table %s', ANALYSIS_TABLE_NAME) raise RuntimeError('Failed creating table %s' % ANALYSIS_TABLE_NAME) finally: conn.close()
def main(): # populate secrets from environment variables logger.info('Populating secrets') populate_secrets() logger.info('Done populating secrets') # parse command line arguments args = parse_args(sys.argv[1:]) # set logging level if args.verbose > 1: set_log_debug(logger) else: set_log_info(logger) ZmEventRetrier().run(do_sleep=args.sleep)
def main(): # populate secrets from environment variables populate_secrets() # parse command line arguments args = parse_args(sys.argv[1:]) # set logging level if args.verbose > 1: set_log_debug(logger) elif args.verbose > 0: set_log_info(logger) if args.oneshot: ZmArchivedToS3(dry_run=args.dry_run).run() else: ZmArchivedToS3(dry_run=args.dry_run).loop(do_sleep=args.sleep)
def main(): # setsid so we can continue running even if caller dies if os.environ.get('NO_SETSID', None) != 'true': os.setsid() # populate secrets from environment variables populate_secrets() # parse command line arguments args = parse_args(sys.argv[1:]) # setup logging setup_logging(args) # initial log logger.warning('Triggered; EventId=%s MonitorId=%s Cause=%s', args.event_id, args.monitor_id, args.cause) # run... run(args)
:param level: logging level; see the :py:mod:`logging` constants. :type level: int :param format: logging formatter format string :type format: str """ formatter = logging.Formatter(fmt=format) logger.handlers[0].setFormatter(formatter) logger.setLevel(level) if __name__ == "__main__": args = parse_args(sys.argv[1:]) # set logging level if args.verbose > 1: set_log_debug() else: set_log_info() populate_secrets() start_dt = parse(args.START_TIME) end_dt = parse(args.END_TIME) script = ZmFrameExporter(os.environ['MYSQL_USER'], os.environ['MYSQL_PASS'], os.environ['MYSQL_DB']) script.run(start_dt, end_dt, monitor_ids=args.monitor_ids, object_names=args.object_names, complete=args.complete)