def main(args): # initialise the RulesSpec parser rule_spec_parser = RulesSpec(args.rules_spec) rule_spec_parser.load_rules_from_spec() rule_spec_parser.perform_section_checks() # initialize the DatabaseOptions object db_options = DatabaseOptions(args.rocksdb_options) # Create DatabaseLogs object db_logs = DatabaseLogs( args.log_files_path_prefix, db_options.get_column_families() ) # Create the Log STATS object db_log_stats = LogStatsParser( args.log_files_path_prefix, args.stats_dump_period_sec ) data_sources = { DataSource.Type.DB_OPTIONS: [db_options], DataSource.Type.LOG: [db_logs], DataSource.Type.TIME_SERIES: [db_log_stats] } if args.ods_client: data_sources[DataSource.Type.TIME_SERIES].append(OdsStatsFetcher( args.ods_client, args.ods_entity, args.ods_tstart, args.ods_tend, args.ods_key_prefix )) triggered_rules = rule_spec_parser.get_triggered_rules( data_sources, db_options.get_column_families() ) rule_spec_parser.print_rules(triggered_rules)
def main(args): # initialise the RulesSpec parser rule_spec_parser = RulesSpec(args.rules_spec) rule_spec_parser.load_rules_from_spec() rule_spec_parser.perform_section_checks() # initialize the DatabaseOptions object db_options = DatabaseOptions(args.rocksdb_options) # Create DatabaseLogs object db_logs = DatabaseLogs(args.log_files_path_prefix, db_options.get_column_families()) # Create the Log STATS object db_log_stats = LogStatsParser(args.log_files_path_prefix, args.stats_dump_period_sec) data_sources = { DataSource.Type.DB_OPTIONS: [db_options], DataSource.Type.LOG: [db_logs], DataSource.Type.TIME_SERIES: [db_log_stats] } if args.ods_client: data_sources[DataSource.Type.TIME_SERIES].append( OdsStatsFetcher(args.ods_client, args.ods_entity, args.ods_tstart, args.ods_tend, args.ods_key_prefix)) triggered_rules = rule_spec_parser.get_triggered_rules( data_sources, db_options.get_column_families()) rule_spec_parser.print_rules(triggered_rules)
class TestAllRulesTriggered(unittest.TestCase): def setUp(self): # load the Rules this_path = os.path.abspath(os.path.dirname(__file__)) ini_path = os.path.join(this_path, 'input_files/triggered_rules.ini') self.db_rules = RulesSpec(ini_path) self.db_rules.load_rules_from_spec() self.db_rules.perform_section_checks() # load the data sources: LOG and OPTIONS log_path = os.path.join(this_path, 'input_files/LOG-0') options_path = os.path.join(this_path, 'input_files/OPTIONS-000005') db_options_parser = DatabaseOptions(options_path) self.column_families = db_options_parser.get_column_families() db_logs_parser = DatabaseLogs(log_path, self.column_families) self.data_sources = { DataSource.Type.DB_OPTIONS: [db_options_parser], DataSource.Type.LOG: [db_logs_parser] } def test_triggered_conditions(self): conditions_dict = self.db_rules.get_conditions_dict() rules_dict = self.db_rules.get_rules_dict() # Make sure none of the conditions is triggered beforehand for cond in conditions_dict.values(): self.assertFalse(cond.is_triggered(), repr(cond)) for rule in rules_dict.values(): self.assertFalse( rule.is_triggered(conditions_dict, self.column_families), repr(rule) ) # # Trigger the conditions as per the data sources. # trigger_conditions(, conditions_dict) # Get the set of rules that have been triggered triggered_rules = self.db_rules.get_triggered_rules( self.data_sources, self.column_families ) # Make sure each condition and rule is triggered for cond in conditions_dict.values(): if cond.get_data_source() is DataSource.Type.TIME_SERIES: continue self.assertTrue(cond.is_triggered(), repr(cond)) for rule in rules_dict.values(): self.assertIn(rule, triggered_rules) # Check the suggestions made by the triggered rules for sugg in rule.get_suggestions(): self.assertIn(sugg, RuleToSuggestions[rule.name]) for rule in triggered_rules: self.assertIn(rule, rules_dict.values()) for sugg in RuleToSuggestions[rule.name]: self.assertIn(sugg, rule.get_suggestions())
class TestAllRulesTriggered(unittest.TestCase): def setUp(self): # load the Rules this_path = os.path.abspath(os.path.dirname(__file__)) ini_path = os.path.join(this_path, 'input_files/triggered_rules.ini') self.db_rules = RulesSpec(ini_path) self.db_rules.load_rules_from_spec() self.db_rules.perform_section_checks() # load the data sources: LOG and OPTIONS log_path = os.path.join(this_path, 'input_files/LOG-0') options_path = os.path.join(this_path, 'input_files/OPTIONS-000005') db_options_parser = DatabaseOptions(options_path) self.column_families = db_options_parser.get_column_families() db_logs_parser = DatabaseLogs(log_path, self.column_families) self.data_sources = { DataSource.Type.DB_OPTIONS: [db_options_parser], DataSource.Type.LOG: [db_logs_parser] } def test_triggered_conditions(self): conditions_dict = self.db_rules.get_conditions_dict() rules_dict = self.db_rules.get_rules_dict() # Make sure none of the conditions is triggered beforehand for cond in conditions_dict.values(): self.assertFalse(cond.is_triggered(), repr(cond)) for rule in rules_dict.values(): self.assertFalse( rule.is_triggered(conditions_dict, self.column_families), repr(rule)) # # Trigger the conditions as per the data sources. # trigger_conditions(, conditions_dict) # Get the set of rules that have been triggered triggered_rules = self.db_rules.get_triggered_rules( self.data_sources, self.column_families) # Make sure each condition and rule is triggered for cond in conditions_dict.values(): if cond.get_data_source() is DataSource.Type.TIME_SERIES: continue self.assertTrue(cond.is_triggered(), repr(cond)) for rule in rules_dict.values(): self.assertIn(rule, triggered_rules) # Check the suggestions made by the triggered rules for sugg in rule.get_suggestions(): self.assertIn(sugg, RuleToSuggestions[rule.name]) for rule in triggered_rules: self.assertIn(rule, rules_dict.values()) for sugg in RuleToSuggestions[rule.name]: self.assertIn(sugg, rule.get_suggestions())