def run_program(args_array, func_dict, **kwargs): """Function: run_program Description: Creates class instance and controls flow of the program. Set a program lock to prevent other instantiations from running. Arguments: (input) args_array -> Dict of command line options and values. (input) func_dict -> Dict of function calls and associated options. """ cmdline = gen_libs.get_inst(sys) args_array = dict(args_array) func_dict = dict(func_dict) cfg = gen_libs.load_module(args_array["-c"], args_array["-d"]) cfg.mongo = gen_libs.load_module(cfg.mongo_cfg, args_array["-d"]) cfg, status_flag, err_msg = validate_create_settings(cfg) if status_flag: log = gen_class.Logger(cfg.log_file, cfg.log_file, "INFO", "%(asctime)s %(levelname)s %(message)s", "%Y-%m-%dT%H:%M:%SZ") str_val = "=" * 80 log.log_info("%s:%s Initialized" % (cfg.host, cfg.exchange_name)) log.log_info("%s" % (str_val)) log.log_info("Exchange Name: %s" % (cfg.exchange_name)) log.log_info("Queue Configuration:") for queue in cfg.queue_list: log.log_info("\tQueue Name: %s, Routing Key: %s" % (queue["queue"], queue["routing_key"])) log.log_info("To Email: %s" % (cfg.to_line)) log.log_info("%s" % (str_val)) try: flavor_id = cfg.exchange_name prog_lock = gen_class.ProgramLock(cmdline.argv, flavor_id) # Intersect args_array & func_dict to find which functions to call. for opt in set(args_array.keys()) & set(func_dict.keys()): func_dict[opt](cfg, log, **kwargs) del prog_lock except gen_class.SingleInstanceException: log.log_warn("rmq_metadata lock in place for: %s" % (flavor_id)) log.log_close() else: print("Error: Problem in configuration file or directory setup.") print(err_msg)
def run_program(args_array, func_dict, **kwargs): """Function: run_program Description: Creates class instance and controls flow of the program. Create a program lock to prevent other instantiations from running. Arguments: (input) args_array -> Dict of command line options and values. (input) func_dict -> Dictionary list of functions and options. """ cmdline = gen_libs.get_inst(sys) args_array = dict(args_array) func_dict = dict(func_dict) cfg, status_flag, err_msgs = load_cfg(args_array["-c"], args_array["-d"]) if status_flag: log = gen_class.Logger(cfg.log_file, cfg.log_file, "INFO", "%(asctime)s %(levelname)s %(message)s", "%Y-%m-%dT%H:%M:%SZ") str_val = "=" * 80 log.log_info("%s:%s Initialized" % (cfg.host, cfg.exchange_name)) log.log_info("%s" % (str_val)) log.log_info("Exchange Name: %s" % (cfg.exchange_name)) log.log_info("Exchange Type: %s" % (cfg.exchange_type)) log.log_info("Valid Queues: %s" % (cfg.valid_queues)) log.log_info("Email Archive: %s" % (cfg.email_dir)) log.log_info("%s" % (str_val)) try: flavor_id = args_array.get("-y", cfg.exchange_name) prog_lock = gen_class.ProgramLock(cmdline.argv, flavor_id) # Intersect args_array & func_dict to find which functions to call. for opt in set(args_array.keys()) & set(func_dict.keys()): func_dict[opt](cfg, log, **kwargs) del prog_lock except gen_class.SingleInstanceException: log.log_warn("mail_2_rmq lock in place for: %s" % (flavor_id)) log.log_close() else: print("Error: Problem(s) in configuration file.") for line in err_msgs: print(line)
def run_program(args_array, func_dict, **kwargs): """Function: run_program Description: Controls the running of the program and sets up a logger class for the running instance of the program. Arguments: (input) args_array -> Dict of command line options and values. (input) func_dict -> Dict of function calls and associated options. """ args_array = dict(args_array) func_dict = dict(func_dict) cfg, status_flag, msg_list = load_cfg(args_array["-c"], args_array["-d"]) # Disable email capability if option detected if args_array.get("-n", False): cfg.to_line = None if status_flag: log = gen_class.Logger(cfg.log_file, cfg.log_file, "INFO", "%(asctime)s %(levelname)s %(message)s", "%Y-%m-%dT%H:%M:%SZ") str_val = "=" * 80 log.log_info("%s Initialized" % (args_array["-r"])) log.log_info("%s" % (str_val)) log.log_info("Project: %s" % (args_array["-r"])) log.log_info("Project Directory: %s" % (args_array["-p"])) log.log_info("%s" % (str_val)) # Intersect args_array & func_dict to find which functions to call. for opt in set(args_array.keys()) & set(func_dict.keys()): func_dict[opt](args_array, cfg, log, **kwargs) log.log_close() else: print("Error: Problem(s) in configuration file.") print("Message(s):") for item in msg_list: print(item)
def setUp(self): """Function: setUp Description: Initialization for integration testing. Arguments: """ self.base_dir = "test/integration/rmq_2_sysmon" self.test_path = os.path.join(os.getcwd(), self.base_dir) self.config_path = os.path.join(self.test_path, "config") self.cfg = gen_libs.load_module("rabbitmq", self.config_path) log_path = os.path.join(self.test_path, self.cfg.log_dir) self.cfg.log_file = os.path.join(log_path, self.cfg.log_file) self.cfg.message_dir = os.path.join(self.test_path, self.cfg.message_dir) self.log = gen_class.Logger(self.cfg.log_file, self.cfg.log_file, "INFO", "%(asctime)s %(levelname)s %(message)s", "%Y-%m-%dT%H:%M:%SZ") self.connect_true = "Connected to RabbitMQ node"
def setUp(self): """Function: setUp Description: Initialization for integration testing. Arguments: """ self.base_dir = "test/integration/rmq_2_sysmon" self.test_path = os.path.join(os.getcwd(), self.base_dir) self.config_path = os.path.join(self.test_path, "config") self.cfg = gen_libs.load_module("rabbitmq", self.config_path) log_path = os.path.join(self.test_path, self.cfg.log_dir) self.cfg.log_file = os.path.join(log_path, self.cfg.log_file) self.cfg.message_dir = os.path.join(self.test_path, self.cfg.message_dir) self.log = gen_class.Logger(self.cfg.log_file, self.cfg.log_file, "INFO", "%(asctime)s %(levelname)s %(message)s", "%Y-%m-%dT%H:%M:%SZ") self.rmq = rabbitmq_class.RabbitMQCon( self.cfg.user, self.cfg.passwd, self.cfg.host, self.cfg.port, exchange_name=self.cfg.exchange_name, exchange_type=self.cfg.exchange_type, queue_name=self.cfg.queue_list[0]["queue"], routing_key=self.cfg.queue_list[0]["routing_key"], x_durable=self.cfg.x_durable, q_durable=self.cfg.q_durable, auto_delete=self.cfg.auto_delete) self.line = "Test_Me_File" self.subj = "Test_Me" self.test_file = None
def setUp(self): """Function: setUp Description: Initialization for integration testing. Arguments: """ class MethodTest(object): """Class: MethodTest Description: Class which is a representation of a method module. Methods: __init__ -> Initialize configuration environment. """ def __init__(self): """Method: __init__ Description: Initialization instance of the CfgTest class. Arguments: """ self.routing_key = "intr-test" self.method = MethodTest() self.base_dir = "test/integration/rmq_2_sysmon" self.test_path = os.path.join(os.getcwd(), self.base_dir) self.config_path = os.path.join(self.test_path, "config") self.cfg = gen_libs.load_module("rabbitmq", self.config_path) log_path = os.path.join(self.test_path, self.cfg.log_dir) self.cfg.log_file = os.path.join(log_path, self.cfg.log_file) self.cfg.message_dir = os.path.join(self.test_path, self.cfg.message_dir) self.cfg.queue_list[0]["directory"] = os.path.join( self.test_path, self.cfg.queue_list[0]["directory"]) self.log = gen_class.Logger(self.cfg.log_file, self.cfg.log_file, "INFO", "%(asctime)s %(levelname)s %(message)s", "%Y-%m-%dT%H:%M:%SZ") self.rmq = rabbitmq_class.RabbitMQCon( self.cfg.user, self.cfg.passwd, self.cfg.host, self.cfg.port, exchange_name=self.cfg.exchange_name, exchange_type=self.cfg.exchange_type, queue_name=self.cfg.queue_list[0]["queue"], routing_key=self.cfg.queue_list[0]["routing_key"], x_durable=self.cfg.x_durable, q_durable=self.cfg.q_durable, auto_delete=self.cfg.auto_delete) self.body = '{"Server": "SERVER_NAME.domain.name"}' self.body2 = '["Server", "SERVER_NAME.domain.name"]' self.sysmon_file = os.path.join(self.cfg.queue_list[0]["directory"], "SERVER_NAME_pkgs.json") self.log_chk = "process_msg: Processing message body from Routing Key" self.non_proc_msg = "Incorrect type"