示例#1
0
 def testJournalWriteAlertDB4(self):
     ''' Test writing of Alert log queue after reading from DB '''
     # This test does not work with duplicate checking -- probably don't want it to 
     keep_ADC = self.force_env('TEAL_ALERT_DUPLICATE_CHECK', 'No')
     self.teal = Teal('data/journal_test/events_002.conf','stderr',msgLevel=self.msglevel)
     # Events
     je = Journal('DB test input EVENTS', file='data/journal_test/events_002.json')
     je.insert_in_db(truncate=True, no_delay=True)
     # Alerts
     ja = Journal('DB test input ALERTS', file='data/journal_test/alerts_002.json')
     ja.insert_in_db(truncate=False, no_delay=True)
     # Check events
     jedb = Journal('Read DB test EVENTS')
     jedb.select_from_db('event')
     self.assertTrue(je.deep_match(jedb, ignore_delay=True, ignore_times=False, ignore_rec_id=False))
     # Check alerts
     jadb = Journal('Read DB test ALERTS')
     jadb.select_from_db('alert')
     self.assertTrue(ja.deep_match(jadb, ignore_delay=True, ignore_times=False, ignore_rec_id=False))
     # Now insert into the Delivery Queue and make sure all come out 
     jadb.inject_queue(get_service(SERVICE_ALERT_DELIVERY_Q), progress_cb=None, fail_on_invalid=False, no_delay=True)
     listeners = get_service(SERVICE_ALERT_DELIVERY).listeners
     for listener in listeners:
         name = listener.get_name()
         if name == 'Journal':
             j_out_all = listener.journal
     self.assertTrue(j_out_all.wait_for_entries(6))
     self.assertTrue(j_out_all.deep_match(jadb, ignore_delay=True, ignore_times=True))
     self.teal.shutdown()
     self.restore_env('TEAL_ALERT_DUPLICATE_CHECK', keep_ADC)
     return
示例#2
0
    def testGeneralFilters(self):
        """test alert delivery with global and local filtering"""
        j_in_dq = Journal("j_in_DQ", "data/alert_delivery_test/listener_failure/inject_DQ_alerts.json")
        dq_q = get_service(SERVICE_ALERT_DELIVERY_Q)
        # Get the AlertListenerJournal journals
        listeners = get_service(SERVICE_ALERT_DELIVERY).listeners
        for listener in listeners:
            name = listener.get_name()
            if name == "AllAlerts":
                j_out_all = listener.journal
            if name == "OnlyAnalyzer1":
                j_out_analyzer1 = listener.journal
        # inject
        j_in_dq.inject_queue(dq_q)
        # Create a TEAL alert
        create_teal_alert("XXXXXXXX", "no reason at all", "medium well", loc_instance="YYY")

        # Get expected values
        j_out_all_exp = Journal("all_exp", "data/alert_delivery_test/analyzer_filter/alerts_out_all.json")
        j_out_analyzer1_exp = Journal("analyzer1", "data/alert_delivery_test/analyzer_filter/alerts_out_analyzer1.json")
        # wait for stuff to come out
        self.assertTrue(j_out_all.wait_for_entries(len(j_out_all_exp) + 3))
        self.assertTrue(j_out_analyzer1.wait_for_entries(len(j_out_analyzer1_exp)))
        # Check that it was what was expected

        # Can't really check this because the location is unique for each machine and run
        #  Make sure only 3 extra
        self.assertEqual(len(j_out_all) - len(j_out_all_exp), 3)
        # self.assertTrue(j_out_all.deep_match(j_out_all_exp, ignore_delay=True, ignore_times=True))
        self.assertTrue(j_out_analyzer1.deep_match(j_out_analyzer1_exp, ignore_delay=True, ignore_times=True))
        return
示例#3
0
 def testDemo1EventQ(self):
     '''Test that the first demo flow works -- Inject Event Q'''
     self.teal = Teal('data/teal_test/configurationtest_05_auto.conf', 'stderr', msgLevel=self.msglevel, 
                      commit_alerts=False, commit_checkpoints=False, run_mode=TEAL_RUN_MODE_HISTORIC)
     j_in = Journal('j_in', file='data/demo/data_sample_demo_NEW_001.json')
     j_out_aaq = Journal('j_out_aaq')
     j_out_dq = Journal('j_out_dq')
     j_out_lis = Journal('j_out_lis')
     q_in = registry.get_service(SERVICE_EVENT_Q)
     q_out_aaq = registry.get_service(SERVICE_ALERT_ANALYZER_Q)
     q_out_dq = registry.get_service(SERVICE_ALERT_DELIVERY_Q)
     q_out_dq.register_listener(j_out_dq)
     q_out_aaq.register_listener(j_out_aaq)
     listeners = get_service(SERVICE_ALERT_DELIVERY).listeners
     for listener in listeners:
         if listener.get_name() == 'outputJournal':
             j_out_lis = listener.journal
     j_in.inject_queue(q_in)
     self.assertTrue(j_out_lis.wait_for_entries(3))
     j_exp_aaq = Journal('j_exp_aaq', 'data/teal_test/data_sample_demo_NEW_001_AAQ_Result.json')
     self.assertTrue(j_out_aaq.deep_match(j_exp_aaq, ignore_delay=True, ignore_times=True))
     j_exp_dq = Journal('j_exp_dq', 'data/teal_test/data_sample_demo_NEW_001_DQ_Result.json')
     self.assertTrue(j_out_dq.deep_match(j_exp_dq, ignore_delay=True, ignore_times=True))
     j_exp_lis = Journal('j_exp_lis', 'data/teal_test/data_sample_demo_NEW_001_LIS_Result.json')
     self.assertTrue(j_out_lis.deep_match(j_exp_lis, ignore_delay=True, ignore_times=True))
     
     q_out_aaq.unregister_listener(j_out_aaq)        
     q_out_dq.unregister_listener(j_out_dq)
     self.teal.shutdown()
示例#4
0
 def testGeneralFilters(self):
     """test alert delivery with global and local filtering"""
     j_in_dq = Journal("j_in_DQ", "data/alert_delivery_test/data_sample_inject_DQ.json")
     # p rint str(j_in_dq)
     dq_q = get_service(SERVICE_ALERT_DELIVERY_Q)
     # Get the AlertListenerJournal journals
     listeners = get_service(SERVICE_ALERT_DELIVERY).listeners
     for listener in listeners:
         name = listener.get_name()
         # p rint name
         if name == "AllAlerts":
             j_out_all = listener.journal
         if name == "OnlyAlertId":
             j_out_alert_id = listener.journal
         if name == "OnlyAlertIdUrgent":
             j_out_ai_urgent = listener.journal
     # inject
     j_in_dq.inject_queue(dq_q)
     # wait for stuff to come out
     self.assertTrue(j_out_all.wait_for_entries(5))
     self.assertTrue(j_out_alert_id.wait_for_entries(3))
     self.assertTrue(j_out_ai_urgent.wait_for_entries(2))
     #
     j_out_all_exp = Journal("j_out_all_exp", "data/alert_delivery_test/data_sample_out_all_alerts.json")
     self.assertTrue(j_out_all.deep_match(j_out_all_exp, ignore_delay=True, ignore_times=True))
     j_out_alert_id_exp = Journal("j_out_alert_id_exp", "data/alert_delivery_test/data_sample_out_alert_id.json")
     self.assertTrue(j_out_alert_id.deep_match(j_out_alert_id_exp, ignore_delay=True, ignore_times=True))
     j_out_ai_urgent_exp = Journal("j_out_ai_urgent_exp", "data/alert_delivery_test/data_sample_out_ai_urgent.json")
     self.assertTrue(j_out_ai_urgent.deep_match(j_out_ai_urgent_exp, ignore_delay=True, ignore_times=True))
     return
示例#5
0
 def testGeneralFilters(self):
     """test alert delivery with global and local filtering"""
     j_in_dq = Journal("j_in_DQ", "data/alert_delivery_test/analyzer_filter/inject_DQ_alerts.json")
     dq_q = get_service(SERVICE_ALERT_DELIVERY_Q)
     # Get the AlertListenerJournal journals
     listeners = get_service(SERVICE_ALERT_DELIVERY).listeners
     for listener in listeners:
         name = listener.get_name()
         if name == "AllAlerts":
             j_out_all = listener.journal
         if name == "OnlyAnalyzer1":
             j_out_analyzer1 = listener.journal
         if name == "AnyButAnalyzer1":
             j_out_not_analyzer1 = listener.journal
         if name == "OnlyAnalyzer2and3":
             j_out_analyzer2and3 = listener.journal
         if name == "AnyButAnalyzer2and3":
             j_out_not_analyzer2and3 = listener.journal
         if name == "AnyButAnalyzer1and2and3":
             j_out_not_analyzer1and2and3 = listener.journal
     # inject
     j_in_dq.inject_queue(dq_q)
     # Get expected values
     j_out_all_exp = Journal("all_exp", "data/alert_delivery_test/analyzer_filter/alerts_out_all.json")
     j_out_analyzer1_exp = Journal("analyzer1", "data/alert_delivery_test/analyzer_filter/alerts_out_analyzer1.json")
     j_out_not_analyzer1_exp = Journal(
         "not_analyzer1", "data/alert_delivery_test/analyzer_filter/alerts_out_not_analyzer1.json"
     )
     j_out_analyzer2and3_exp = Journal(
         "analyzer2and3", "data/alert_delivery_test/analyzer_filter/alerts_out_analyzer2and3.json"
     )
     j_out_not_analyzer2and3_exp = Journal(
         "not_analyzer2and3", "data/alert_delivery_test/analyzer_filter/alerts_out_not_analyzer2and3.json"
     )
     j_out_not_analyzer1and2and3_exp = Journal(
         "not_analyzer1and2and3", "data/alert_delivery_test/analyzer_filter/alerts_out_not_analyzer1and2and3.json"
     )
     # wait for stuff to come out
     self.assertTrue(j_out_all.wait_for_entries(len(j_out_all_exp)))
     self.assertTrue(j_out_analyzer1.wait_for_entries(len(j_out_analyzer1_exp)))
     self.assertTrue(j_out_not_analyzer1.wait_for_entries(len(j_out_not_analyzer1_exp)))
     self.assertTrue(j_out_analyzer2and3.wait_for_entries(len(j_out_analyzer2and3_exp)))
     self.assertTrue(j_out_not_analyzer2and3.wait_for_entries(len(j_out_not_analyzer2and3_exp)))
     self.assertTrue(j_out_not_analyzer1and2and3.wait_for_entries(len(j_out_not_analyzer1and2and3_exp)))
     # Check that it was what was expected
     self.assertTrue(j_out_all.deep_match(j_out_all_exp, ignore_delay=True, ignore_times=True))
     self.assertTrue(j_out_analyzer1.deep_match(j_out_analyzer1_exp, ignore_delay=True, ignore_times=True))
     self.assertTrue(j_out_not_analyzer1.deep_match(j_out_not_analyzer1_exp, ignore_delay=True, ignore_times=True))
     self.assertTrue(j_out_analyzer2and3.deep_match(j_out_analyzer2and3_exp, ignore_delay=True, ignore_times=True))
     self.assertTrue(
         j_out_not_analyzer2and3.deep_match(j_out_not_analyzer2and3_exp, ignore_delay=True, ignore_times=True)
     )
     self.assertTrue(
         j_out_not_analyzer1and2and3.deep_match(
             j_out_not_analyzer1and2and3_exp, ignore_delay=True, ignore_times=True
         )
     )
     return
示例#6
0
    def testStateOtherStatesIM(self):
        '''test alert state NEW in memory'''
        self.teal = Teal('data/alert_test/test.conf', 'stderr', msgLevel=self.msglevel, commit_alerts=False, commit_checkpoints=False)

        j_in_dq = Journal('j_in_DQ', 'data/alert_test/inject_DQ_alerts.json')
        tq = ListenableQueue('test LQ')
        ql = CheckAlertStateListener(7)
        tq.register_listener(ql)
        j_in_dq.inject_queue(tq, progress_cb=None, fail_on_invalid=False, no_delay=True)
        ql.my_event.wait()
        self.assertEquals(ql.count, 7)
        ta1 = ql.alerts[0]
        am = get_service(SERVICE_ALERT_MGR)
        # TODO: Should not be hardcoded rec ids after this 
        self.assertRaisesTealError(AlertMgrError, 'Operation not allowed on duplicate alert', am.close, 5)
        self.assertRaisesTealError(AlertMgrError, 'Operation not allowed on duplicate alert', am.close, 6)
        self.assertRaisesTealError(AlertMgrError, 'Current alert state does not allow this operation', am.reopen, ta1.rec_id)
        am.close(ta1.rec_id)
        self.assertEquals(ta1.state, ALERT_STATE_CLOSED)
        self.assertRaisesTealError(AlertMgrError, 'Current alert state does not allow this operation', am.close, ta1.rec_id)
        self.assertRaisesTealError(AlertMgrError, 'Alert with specified record id not found', am.close, 23456)
        self.assertEquals(ql.alerts[1].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[2].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[3].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[4].state, ALERT_STATE_CLOSED)
        self.assertEquals(ql.alerts[5].state, ALERT_STATE_CLOSED)
        self.assertEquals(ql.alerts[6].state, ALERT_STATE_OPEN)
        # reopen it 
        self.assertRaisesTealError(AlertMgrError, 'Alert with specified record id not found', am.reopen, 23456)
        self.assertRaisesTealError(AlertMgrError, 'Operation not allowed on duplicate alert', am.reopen, 5)
        self.assertRaisesTealError(AlertMgrError, 'Operation not allowed on duplicate alert', am.reopen, 6)
        am.reopen(ta1.rec_id)
        self.assertEquals(ta1.state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[1].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[2].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[3].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[4].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[5].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[6].state, ALERT_STATE_OPEN)
        am.close(3)
        self.assertEquals(ta1.state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[1].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[2].state, ALERT_STATE_CLOSED)
        self.assertEquals(ql.alerts[3].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[4].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[5].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[6].state, ALERT_STATE_OPEN)
        am.reopen(3)
        self.assertEquals(ta1.state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[1].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[2].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[3].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[4].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[5].state, ALERT_STATE_OPEN)
        self.assertEquals(ql.alerts[6].state, ALERT_STATE_OPEN)
        self.teal.shutdown()
        return
示例#7
0
 def testFilter(self):
     ''' Test that a duplicate is filtered when backed by a database
     '''
     j = Journal('AlertAnalyzer', 'data/alert_test/inject_DQ_alerts.json')
     j.inject_queue(registry.get_service(SERVICE_ALERT_DELIVERY_Q))
 
     alj = find_listener()
     alj.journal.wait_for_entries(4)
     
     out_j = Journal('AlertListener', 'data/alert_filter_test/unfiltered_alerts.json')
     self.assertTrue(alj.journal.deep_match(out_j, ignore_times=True))
示例#8
0
 def testSmtpAlertListener(self):
     ''' Test the SMTP Alert Listener '''
     server = start_smtp_server()
     
     t = teal.Teal('data/alert_listener_test/test_01.conf', msgLevel=self.msglevel, logFile='stderr', commit_alerts=False, commit_checkpoints=False)
     
     in_j = Journal('SMTP Journal', 'data/alert_test/inject_DQ_alerts.json')
     in_j.inject_queue(registry.get_service(SERVICE_ALERT_DELIVERY_Q))
     
     self.assertTrue(server.compare_messages(gen_message_list(in_j)))
     
     t.shutdown()
示例#9
0
 def testJournalQueue(self):
     ''' Test injecting a Journal containing optional fields through a queue'''
     lq = ListenableQueue('test journal queue')
     j = Journal('test journal', file='data/journal_test/data_sample_002_NEW.json')
     j_rec = Journal('j_rec')
     lq.register_listener(j_rec)
     j.inject_queue(lq)
     while len(j) != len(j_rec):
         # p rint ('waiting for queue to process %s of %s' % (str(len(j_rec)), str(len(j))))
         sleep(1.0)
     #p rint j
     #p rint j_rec
     self.assertTrue(j.deep_match(j))
     self.assertTrue(j.deep_match(j_rec, ignore_delay=True))
     return
示例#10
0
 def testNegativeAlertIdMatch(self):
     ''' Runs a noise filter with all but one kind of alert id (negative match of alert id)'''
     self.prepare_db()
     t = teal.Teal('data/alert_filter_test/test_12.conf',msgLevel=self.msglevel,logFile='stderr')
     
     j = Journal('AlertAnalyzer', 'data/alert_filter_test/inject_DQ_alerts.json')
     j.inject_queue(registry.get_service(SERVICE_ALERT_DELIVERY_Q))
 
     alj = find_listener()
     alj.journal.wait_for_entries(3)
     
     out_j = Journal('AlertListener', 'data/alert_filter_test/negative_alerts.json')
     self.assertTrue(alj.journal.deep_match(out_j, ignore_times=True))
     
     t.shutdown()
示例#11
0
 def testPartialNoiseFilter(self):
     ''' Runs a noise filter with some values '''
     self.prepare_db()
     t = teal.Teal('data/alert_filter_test/test_05.conf',msgLevel='warn',logFile='stderr')
     
     j = Journal('AlertAnalyzer', 'data/alert_filter_test/inject_DQ_alerts.json')
     j.inject_queue(registry.get_service(SERVICE_ALERT_DELIVERY_Q))
 
     alj = find_listener()
     alj.journal.wait_for_entries(4)
     
     out_j = Journal('AlertListener', 'data/alert_filter_test/partial_alerts.json')
     self.assertTrue(alj.journal.deep_match(out_j, ignore_times=True))
     
     t.shutdown()
示例#12
0
    def testEmptyNoiseFilter(self):
        ''' Runs a noise filter with no values '''
        self.prepare_db()
        t = teal.Teal('data/alert_filter_test/test_03.conf',msgLevel='warn',logFile='stderr')

        dq = registry.get_service(SERVICE_ALERT_DELIVERY)
        self.assertEqual(dq.filters[0].get_name(),'NoiseAlertFilter')
                
        j = Journal('AlertAnalyzer', 'data/alert_filter_test/inject_DQ_alerts.json')
        j.inject_queue(registry.get_service(SERVICE_ALERT_DELIVERY_Q))
    
        alj = find_listener()
        alj.journal.wait_for_entries(7)
        
        out_j = Journal('AlertListener', 'data/alert_filter_test/empty_alerts.json')
        self.assertTrue(alj.journal.deep_match(out_j, ignore_times=True))

        t.shutdown()
示例#13
0
    def testAnalyzers(self):
        ''' Validate functionality of both analyzer types '''
        self.prepare_db()
        t = teal.Teal('data/alert_filter_test/test_11.conf',msgLevel=self.msglevel,logFile='stderr')
        j = Journal('AlertAnalyzer', 'data/alert_filter_test/inject_DQ_alerts.json')
        j.inject_queue(registry.get_service(SERVICE_ALERT_DELIVERY_Q))
    
        aif = find_listener('AlertFilterIfNameListener')
        aif.journal.wait_for_entries(5)
        
        anif = find_listener('AlertFilterIfNotNameListener')
        anif.journal.wait_for_entries(4)
        
        out_jif = Journal('AlertListener', 'data/alert_filter_test/ifname_alerts.json')
        self.assertTrue(aif.journal.deep_match(out_jif, ignore_times=True))

        out_jnif = Journal('AlertListener', 'data/alert_filter_test/ifnotname_alerts.json')
        self.assertTrue(aif.journal.deep_match(out_jnif, ignore_times=True))
        
        t.shutdown()
示例#14
0
    def testAlertAnalyzerSubclassing01(self):
        ''' Test that the alert analyzer subclass works properly '''
        # Get the alert listener
        for listener in get_service(SERVICE_ALERT_DELIVERY).listeners:
            if listener.get_name() == 'AllAlerts':
                j_out_all = listener.journal
                
        # Pump in some events
        j_in_event = Journal('j_in_events', 'data/alert_analyzer_test/inject_events01.json')
        j_in_event.inject_queue(get_service(SERVICE_EVENT_Q))
        
        # Check that the analyzer got them -- only len because can't compare locations
        self.assertTrue(j_out_all.wait_for_entries(27))

        # Pump in some alerts
        j_in_alert = Journal('j_in_events', 'data/alert_analyzer_test/inject_alerts01.json')
        j_in_alert.inject_queue(get_service(SERVICE_ALERT_ANALYZER_Q))
        
        # Check that the analyzer got them -- only len because can't compare locations
        self.assertTrue(j_out_all.wait_for_entries(34))

        alertmgr = get_service(SERVICE_ALERT_MGR)
        self.assertEqual(len(alertmgr.in_mem_alerts_duplicate), 0)
    def _execute_rule(self, dir, debug=False, wait_sec=60, wait_num=None, force_save=False, 
                      max_key=None, inject_flush=False):
        '''Run the test defined in the specified directory'''
 
        config = 'data/gear_ruleset_test/' + dir + '/config.conf'
        input = 'data/gear_ruleset_test/' + dir + '/event_input.json'
        base_output = 'data/gear_ruleset_test/' + dir
        test_files =  os.listdir('data/gear_ruleset_test/' + dir)
        # Figure out what output files need to be checked
        out_prefix = 'alert_output'
        out_to_check = [] 
        for filename in test_files:
            base, ext = os.path.splitext(filename)
            if ext != '.json':
                continue
            if base[:len(out_prefix)] == out_prefix:
                out_to_check.append(base[len(out_prefix):])
        # out_to_check now contains the unique part of the output file name
        
        if debug:
            msg_level = 'debug'
        else:
            msg_level = self.msglevel
        # TODO: Make work with duplicate checking
        keep_ADC = self.force_env('TEAL_ALERT_DUPLICATE_CHECK', 'No')
        myteal = teal.Teal(config, 'stderr', msgLevel=msg_level, commit_alerts=False, commit_checkpoints=False) 
        j_in = Journal('j_in', input)
        # get the listeners to get the journals from
        #   Make a list to find
        jl_names = []
        j_out_list = {}
        list_prefix = 'ListenerJournal'
        for up in out_to_check:
            jl_names.append( list_prefix + up)
        listeners = get_service(SERVICE_ALERT_DELIVERY).listeners
        for listener in listeners:
            if listener.get_name() in jl_names:
                j_out_list[listener.get_name()[len(list_prefix):]] = listener.journal
        
        event_q = get_service(SERVICE_EVENT_Q)
        if debug:
            # Print before injection in case problem with injection
            print j_in
        j_in.inject_queue(event_q, no_delay=False, max_key=max_key)
        if inject_flush == True:
            self._inject_flush(event_q)
        for up in out_to_check:
            output = base_output + '/' + out_prefix + up + '.json'
            j_exp = Journal('j_exp' + up, output )
            if wait_num is None:
                wait_num = len(j_exp)
            self.assertTrue(j_out_list[up].wait_for_entries(wait_num, seconds=wait_sec))
            if debug:
                print j_exp
                print j_out_list[up]
                if force_save == True:
                    j_out_list[up].save(output)
            self.assertTrue(j_out_list[up].deep_match(j_exp, ignore_delay=True, ignore_times=True, unordered=True)) 
        myteal.shutdown()
        self.restore_env('TEAL_ALERT_DUPLICATE_CHECK', keep_ADC)
        return
示例#16
0
    def testStateOtherStatesDB(self):
        '''test alert state NEW in memory'''
        self.prepare_db()
        self.teal = Teal('data/alert_test/test.conf', 'stderr', msgLevel=self.msglevel, commit_alerts=True, commit_checkpoints=False)

        j_in_dq = Journal('j_in_DQ', 'data/alert_test/inject_DQ_alerts.json')
        tq = ListenableQueue('test LQ')
        ql = CheckAlertStateListener(7)
        tq.register_listener(ql)
        j_in_dq.inject_queue(tq, progress_cb=None, fail_on_invalid=False, no_delay=True)
        ql.my_event.wait()
        self.assertEquals(ql.count, 7)
        ta1 = ql.alerts[0]
        am = get_service(SERVICE_ALERT_MGR)
        self.assertEquals(ta1.state, ALERT_STATE_OPEN)
        # TODO: Really should query to get the recid to use for hardcoded ones in rest of this test case
        self.assertRaisesTealError(AlertMgrError, 'Operation not allowed on duplicate alert', am.close, 5)
        self.assertRaisesTealError(AlertMgrError, 'Operation not allowed on duplicate alert', am.close, 6)
        self.assertRaisesTealError(AlertMgrError, 'Current alert state does not allow this operation', am.reopen, ta1.rec_id)
        am.close(ta1.rec_id)
        # Get duplicates of this one        
        self.assertRaisesTealError(AlertMgrError, 'Current alert state does not allow this operation', am.close, ta1.rec_id)
        self.assertRaisesTealError(AlertMgrError, 'Alert with specified record id not found', am.close, 23456)
        # Note that in memory won't be updated ... only in DB
        # so lets get it from the DB
        dbi = get_service(SERVICE_DB_INTERFACE)
        event_cnxn, cursor =_get_connection(dbi)
        self.assert_alert_closed(dbi, cursor, ta1.rec_id)
        self.assert_alert_open(dbi, cursor, 2)
        self.assert_alert_open(dbi, cursor, 3)
        self.assert_alert_open(dbi, cursor, 4)
        self.assert_alert_closed(dbi, cursor, 5)
        self.assert_alert_closed(dbi, cursor, 6)
        self.assert_alert_open(dbi, cursor, 7)
        self.assertRaisesTealError(AlertMgrError, 'Alert with specified record id not found', am.reopen, 23456)
        self.assertRaisesTealError(AlertMgrError, 'Operation not allowed on duplicate alert', am.reopen, 5)
        self.assertRaisesTealError(AlertMgrError, 'Operation not allowed on duplicate alert', am.reopen, 6)
        # reopen it 
        am.reopen(ta1.rec_id)
        event_cnxn, cursor =_get_connection(dbi, event_cnxn)
        self.assert_alert_open(dbi, cursor, ta1.rec_id)
        self.assert_alert_open(dbi, cursor, 2)
        self.assert_alert_open(dbi, cursor, 3)
        self.assert_alert_open(dbi, cursor, 4)
        self.assert_alert_open(dbi, cursor, 5)
        self.assert_alert_open(dbi, cursor, 6)
        self.assert_alert_open(dbi, cursor, 7)
        am.close(3)
        event_cnxn, cursor =_get_connection(dbi, event_cnxn)
        self.assert_alert_open(dbi, cursor, ta1.rec_id)
        self.assert_alert_open(dbi, cursor, 2)
        self.assert_alert_closed(dbi, cursor, 3)
        self.assert_alert_open(dbi, cursor, 4)
        self.assert_alert_open(dbi, cursor, 5)
        self.assert_alert_open(dbi, cursor, 6)
        self.assert_alert_open(dbi, cursor, 7)
        am.reopen(3)
        event_cnxn, cursor =_get_connection(dbi, event_cnxn)
        self.assert_alert_open(dbi, cursor, ta1.rec_id)
        self.assert_alert_open(dbi, cursor, 2)
        self.assert_alert_open(dbi, cursor, 3)
        self.assert_alert_open(dbi, cursor, 4)
        self.assert_alert_open(dbi, cursor, 5)
        self.assert_alert_open(dbi, cursor, 6)
        self.assert_alert_open(dbi, cursor, 7)
        event_cnxn.close()
        self.teal.shutdown()
        return