Exemplo n.º 1
0
class JournalTest(TealTestCase):


    def setUp(self):        
        self.teal = Teal('data/common/configurationtest.conf', 'stderr', msgLevel=self.msglevel, commit_alerts=False, commit_checkpoints=False)

    def tearDown(self):
        self.teal.shutdown()

    def testJournalLoadSave(self):
        ''' Test loading and saving a json file ''' 
        Journal('test journal', file='data/journal_test/data_sample_001_NEW.json')
        # TODO: Clean up the file after it gets created
        #j.save('data/journal_test/data_sample_001_NEW_AUTO_OUT.json')
        return
    
    def testJournalQueue(self):
        ''' Test injecting the Journal through a queue'''
        lq = ListenableQueue('test journal queue')
        j = Journal('test journal -- input', file='data/journal_test/data_sample_001_NEW.json')
        j_rec = Journal('j_rec -- output')
        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
Exemplo n.º 2
0
class AlertTestDuplicateSupport(TealTestCase):
    
    def testDisableDup(self):
        ''' Test That disable dup works'''
        self.teal = Teal('data/common/configurationtest.conf', 'stderr', msgLevel=self.msglevel, commit_alerts=False, commit_checkpoints=False)
        am = get_service(SERVICE_ALERT_MGR)
        self.assertEqual(len(am.in_mem_alerts), 0)
        self.assertEqual(len(am.in_mem_alerts_duplicate), 0)
        self.assertEqual(len(am.active_alerts_open), 0)
        create_teal_alert('XXXXXXXX', 'no reason at all', 'medium well', loc_instance="YYY")
        self.assertEqual(len(am.in_mem_alerts), 1)
        self.assertEqual(len(am.in_mem_alerts_duplicate), 0)
        self.assertEqual(len(am.active_alerts_open), 1)
        create_teal_alert('XXXXXXXX', 'no reason at all', 'medium well', loc_instance="YYY")
        self.assertEqual(len(am.in_mem_alerts), 2)
        self.assertEqual(len(am.in_mem_alerts_duplicate), 1)
        self.assertEqual(len(am.active_alerts_open), 1)
        create_teal_alert('XXXXXXXX', 'no reason at all', 'medium well', loc_instance="YYY", disable_dup=True)
        self.assertEqual(len(am.in_mem_alerts), 3)
        self.assertEqual(len(am.in_mem_alerts_duplicate), 1)
        self.assertEqual(len(am.active_alerts_open), 2)
        create_teal_alert('XXXXXXXX', 'no reason at all', 'medium well', loc_instance="YYY", disable_dup=True)
        self.assertEqual(len(am.in_mem_alerts), 4)
        self.assertEqual(len(am.in_mem_alerts_duplicate), 1)
        self.assertEqual(len(am.active_alerts_open), 3)
        create_teal_alert('XXXXXXXX', 'no reason at all', 'medium well', loc_instance="YYY")
        self.assertEqual(len(am.in_mem_alerts), 5)
        self.assertEqual(len(am.in_mem_alerts_duplicate), 2)
        self.assertEqual(len(am.active_alerts_open), 3)
        self.teal.shutdown()
        return
Exemplo n.º 3
0
class JournalTestWithOptionalData(TealTestCase):


    def setUp(self):
        self.teal = Teal('data/common/configurationtest.conf', 'stderr', msgLevel=self.msglevel, commit_alerts=False, commit_checkpoints=False)

    def tearDown(self):
        self.teal.shutdown()

#    def testJournalLoadSave(self):
#        ''' Test loading and saving a json file with optional fields. ''' 
#        j = Journal('test journal', file='data/journal_test/data_sample_002_NEW.json')
#        j.save('data/journal_test/data_sample_002_NEW_AUTO_OUT.json')
#        return
    
    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
Exemplo n.º 4
0
class TealTestDemoEventQ(TealTestCase):
    '''Test the demo configuration ''' 
        
    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()
Exemplo n.º 5
0
 def testHistoricOnlyHistoric(self):
     ''' Verify that the historic monitor can only be run in historic mode '''
     self.assertRaisesTealError(TealError, "Historic monitor can only enabled for historic use.  Unsupported value specified: realtime", Teal, 'data/teal_test/bad_hist_mon_01.conf', 'stderr', self.msglevel, 'now', 'realtime')
     self.assertRaisesTealError(TealError, "Historic monitor can only enabled for historic use.  Unsupported value specified: all", Teal, 'data/teal_test/bad_hist_mon_02.conf', 'stderr', self.msglevel, 'now', 'historic')
     # Should run ... clear the DB and run it with no events, so nothing will happen
     self.prepare_db()
     teal = Teal('data/teal_test/bad_hist_mon_03.conf', 'stderr', self.msglevel, 'now', 'historic')
     teal.shutdown()
Exemplo n.º 6
0
 def setUp(self):
     global VFYRULE
     t = Teal('data/tlcommands_test/test.conf',data_only=True)
     teal_path = registry.get_service(registry.TEAL_ROOT_DIR)
     VFYRULE = os.path.join(teal_path,'bin/tlvfyrule')
     t.shutdown()
     
     tmp_data_dir = os.path.join(os.environ.get('TEAL_ROOT_DIR','/opt/teal'),'data')
     self.teal_data_dir = self.force_env('TEAL_DATA_DIR', tmp_data_dir)
     return
Exemplo n.º 7
0
 def testEnabledHistoric(self):
     ''' Verify that historic indicator on enabled plug-in control works '''
     teal = Teal('data/teal_test/good_01.conf', 'stderr', msgLevel=self.msglevel, run_mode='historic', commit_alerts=False, commit_checkpoints=False)
     event_q_lsrs = registry.get_service(SERVICE_EVENT_Q).listener_methods
     self.assertEquals(len(event_q_lsrs), 1)
     names = []
     for lsr_m in event_q_lsrs:
         names.append(lsr_m.__self__.get_name())
     self.assertTrue('AnalyzerTest055a' in names)
     teal.shutdown()
Exemplo n.º 8
0
class TealTestDemoDB(TealTestCase):
    '''Test the demo configuration '''
    
    def testDemo1DB(self):
        '''Test demo flow by injecting into DB'''
        self.prepare_db()
        keep_var = self.force_env('TEAL_TEST_POOL_TIMERS_OFF', 'YES')
        self.teal = Teal('data/teal_test/configurationtest_05_semaphore_auto.conf', 'stderr', 
                         msgLevel=self.msglevel)

        j_in = Journal('j_in', file='data/demo/data_sample_demo_NEW_001.json')
        j_out_eq = Journal('j_out_eq')
        j_out_aaq = Journal('j_out_aaq')
        j_out_dq = Journal('j_out_dq')
        j_out_lis = Journal('j_out_lis')
        q_out_eq = 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_eq.register_listener(j_out_eq)
        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
        try:
            j_in.insert_in_db(progress_cb=None, truncate=False, use_rec_ids=True, no_delay=False, post=True)
        except:
            print 'INSERTION FAILED'
            q_out_eq.unregister_listener(j_out_eq)
            q_out_dq.unregister_listener(j_out_dq)
            q_out_aaq.unregister_listener(j_out_aaq)
            raise
       
        # Yes, only 2: Flush can't be injected to connector, so pool does not get closed, so last event
        # Does not get turned into an alert!
        self.assertTrue(j_out_lis.wait_for_entries(2))

        # Note these connector ('C') versions have one less alert
        #     The analyzer is being run in historic mode (see configuration) if that was 
        #     changed to runtime then the pool would time out and the last alert would be journaled
        j_exp_aaq = Journal('j_exp_aaq', 'data/teal_test/data_sample_demo_NEW_001_AAQ_Result_C.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_C.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_C.json')
        self.assertTrue(j_out_lis.deep_match(j_exp_lis, ignore_delay=True, ignore_times=True))

        q_out_eq.unregister_listener(j_out_eq)
        q_out_dq.unregister_listener(j_out_dq)
        q_out_aaq.unregister_listener(j_out_aaq)
        
        self.teal.shutdown()
        self.restore_env('TEAL_TEST_POOL_TIMERS_OFF', keep_var)
Exemplo n.º 9
0
class AlertListenerFailureTest(TealTestCase):
    """Test the alert delivery (filters and listeners)"""

    def setUp(self):
        """Setup Teal"""
        # Not testing duplicates, so OK to turn off
        self.keep_ADC = self.force_env("TEAL_ALERT_DUPLICATE_CHECK", "No")
        self.teal = Teal(
            "data/alert_delivery_test/listener_failure/test.conf",
            "stderr",
            msgLevel=self.msglevel,
            commit_alerts=False,
            commit_checkpoints=False,
        )
        return

    def tearDown(self):
        """Teardown teal"""
        self.teal.shutdown()
        self.restore_env("TEAL_ALERT_DUPLICATE_CHECK", self.keep_ADC)
        return

    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
Exemplo n.º 10
0
class TEALShutdownModeTest3b(TealTestCase):
    ''' Test setting of shutdown mode works '''
    
    def setUp(self):
        self.t = Teal('data/checkpoint_test/shutdown_immediate.conf', 'stderr', msgLevel=self.msglevel, data_only=True)  
          
    def tearDown(self):
        self.t.shutdown()
    
    def testSettingImmediateShutdownMode(self):
        ''' Test that the shutdown mode to immediate works config '''  
        self.assertEqual(SHUTDOWN_MODE_IMMEDIATE, registry.get_service(registry.SERVICE_SHUTDOWN_MODE))
Exemplo n.º 11
0
class TEALShutdownModeTest1(TealTestCase):
    ''' Test setting of shutdown mode works '''
    
    def setUp(self):
        self.t = Teal('data/tlcommands_test/test.conf', 'stderr', msgLevel=self.msglevel, data_only=True)  
          
    def tearDown(self):
        self.t.shutdown()
    
    def testDefaultShutdownMode(self):
        ''' Test that the shutdown mode correctly defaults '''  
        self.assertEqual(SHUTDOWN_MODE_DEFERRED, registry.get_service(registry.SERVICE_SHUTDOWN_MODE))
Exemplo n.º 12
0
class AlertDeliveryTest(TealTestCase):
    """Test the alert delivery (filters and listeners)"""

    def setUp(self):
        """Setup Teal"""
        self.keep_ADC = self.force_env("TEAL_ALERT_DUPLICATE_CHECK", "No")
        self.teal = Teal(
            "data/alert_delivery_test/test_local_filters.conf",
            "stderr",
            msgLevel=self.msglevel,
            commit_alerts=False,
            commit_checkpoints=False,
        )
        return

    def tearDown(self):
        """Teardown teal"""
        self.teal.shutdown()
        self.restore_env("TEAL_ALERT_DUPLICATE_CHECK", self.keep_ADC)
        return

    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
Exemplo n.º 13
0
class TEALShutdownModeTest2(TealTestCase):
    ''' Test setting of shutdown mode works '''
    
    def setUp(self):
        self.keep_mode = self.force_env(TEAL_SHUTDOWN_MODE, SHUTDOWN_MODE_DEFERRED)
        self.t = Teal('data/tlcommands_test/test.conf', 'stderr', msgLevel=self.msglevel, data_only=True)  
          
    def tearDown(self):
        self.t.shutdown()
        self.restore_env(TEAL_SHUTDOWN_MODE, self.keep_mode)
    
    def testSettingDeferredShutdownMode(self):
        ''' Test that the shutdown mode being set to deferred works '''  
        self.assertEqual(SHUTDOWN_MODE_DEFERRED, registry.get_service(registry.SERVICE_SHUTDOWN_MODE))
Exemplo n.º 14
0
class TEALShutdownModeTest4(TealTestCase):
    ''' Test setting of shutdown mode ignored '''
    
    def setUp(self):
        self.keep_mode = self.force_env(TEAL_SHUTDOWN_MODE, SHUTDOWN_MODE_IMMEDIATE)
        self.t = Teal('data/tlcommands_test/test.conf', 'stderr', msgLevel=self.msglevel, data_only=True, run_mode=TEAL_RUN_MODE_HISTORIC, commit_alerts=False)  
          
    def tearDown(self):
        self.t.shutdown()
        self.restore_env(TEAL_SHUTDOWN_MODE, self.keep_mode)
    
    def testSettingImmediateShutdownMode(self):
        ''' Test that the shutdown mode to immediate ignored if HISTORIC '''  
        self.assertEqual(SHUTDOWN_MODE_DEFERRED, registry.get_service(registry.SERVICE_SHUTDOWN_MODE))
Exemplo n.º 15
0
class TEALShutdownModeTest3a(TealTestCase):
    ''' Test setting of shutdown mode works '''
    
    def setUp(self):
        self.keep_mode = self.force_env(TEAL_SHUTDOWN_MODE, SHUTDOWN_MODE_IMMEDIATE)
        self.t = Teal('data/tlcommands_test/test.conf', 'stderr', msgLevel=self.msglevel, data_only=True)  
          
    def tearDown(self):
        self.t.shutdown()
        self.restore_env(TEAL_SHUTDOWN_MODE, self.keep_mode)
    
    def testSettingImmediateShutdownMode(self):
        ''' Test that the shutdown mode to immediate works ENV '''  
        self.assertEqual(SHUTDOWN_MODE_IMMEDIATE, registry.get_service(registry.SERVICE_SHUTDOWN_MODE))
Exemplo n.º 16
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
Exemplo n.º 17
0
 def setUp(self):
     self.teal = Teal(
         "data/common/configurationtest.conf",
         "stderr",
         msgLevel=self.msglevel,
         commit_alerts=False,
         commit_checkpoints=False,
     )
Exemplo n.º 18
0
 def setUp(self): 
     # Setup to use the tllsckpt command
     t = Teal('data/tlcommands_test/test.conf', 'stderr', msgLevel=self.msglevel, data_only=True)
     teal_path = registry.get_service(registry.TEAL_ROOT_DIR)
     self.tllsckpt = os.path.join(teal_path,'bin/tllsckpt')
     t.shutdown()
     
     self.prepare_db()
     
     # Need to have checkpointing to DB off so this doesn't interfer with the other instance of TEAL's checkpoints       
     self.teal = Teal('data/checkpoint_test/noop_monitor.conf','stderr',msgLevel=self.msglevel, commit_checkpoints=False)
     self.db = registry.get_service(registry.SERVICE_DB_INTERFACE)
     self.query = self.db.gen_select(
                  [EVENT_CPF_CHKPT_ID, EVENT_CPF_NAME, EVENT_CPF_STATUS, EVENT_CPF_EVENT_RECID, EVENT_CPF_DATA],
                  db_interface.TABLE_CHECKPOINT)
     self.query_mon_data = self.db.gen_select([EVENT_CPF_DATA], db_interface.TABLE_CHECKPOINT, 
                                              where="${0} = 'monitor_event_queue'".format(EVENT_CPF_NAME), where_fields=[EVENT_CPF_NAME])
     self.truncate = self.db.gen_truncate(db_interface.TABLE_CHECKPOINT)
Exemplo n.º 19
0
 def testStateIncompleteDB(self):
     ''' Test alert gets created in memory in incomplete state'''
     self.teal = Teal('data/alert_test/test.conf', 'stderr', msgLevel=self.msglevel, commit_alerts=True, commit_checkpoints=False)
     am = get_service(SERVICE_ALERT_MGR)
     t_alert = am.allocate('TestAlert', {})
     self.assertEquals(t_alert.state, ALERT_STATE_INCOMPLETE)
     # No metadata
     self.assertRaises(KeyError, am.commit, t_alert)
     self.teal.shutdown()
Exemplo n.º 20
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
Exemplo n.º 21
0
 def setUp(self):
     """Setup Teal"""
     self.keep_ADC = self.force_env("TEAL_ALERT_DUPLICATE_CHECK", "No")
     self.teal = Teal(
         "data/alert_delivery_test/test_local_filters.conf",
         "stderr",
         msgLevel=self.msglevel,
         commit_alerts=False,
         commit_checkpoints=False,
     )
     return
Exemplo n.º 22
0
 def setUp(self):
     """Setup Teal"""
     # Not testing duplicates, so OK to turn off
     self.keep_ADC = self.force_env("TEAL_ALERT_DUPLICATE_CHECK", "No")
     self.teal = Teal(
         "data/alert_delivery_test/listener_failure/test.conf",
         "stderr",
         msgLevel=self.msglevel,
         commit_alerts=False,
         commit_checkpoints=False,
     )
     return
Exemplo n.º 23
0
 def testDBtruncate(self):
     ''' Test that the DB tables correctly truncate '''
     # Truncate the tables 
     self.prepare_db()
     teal = Teal('data/aaaa_assumptions_test/minimal.conf', 'stderr', msgLevel=self.msglevel, data_only=True, commit_alerts=False, commit_checkpoints=False)
     self.dbi = registry.get_service(SERVICE_DB_INTERFACE)
     self.cnxn = self.dbi.get_connection()
     self.cursor = self.cnxn.cursor()
     # Check the tables
     self._check_rows(db_interface.TABLE_EVENT_LOG, 0)
     self._check_rows(db_interface.TABLE_ALERT_LOG, 0)
     self._check_rows(db_interface.TABLE_ALERT2ALERT, 0)
     self._check_rows(db_interface.TABLE_CHECKPOINT, 0)
     self.cnxn.close()
     teal.shutdown()
     
     teal = Teal('data/aaaa_assumptions_test/minimal.conf', 'stderr', msgLevel=self.msglevel)
     self.dbi = registry.get_service(SERVICE_DB_INTERFACE)
     self.cnxn = self.dbi.get_connection()
     self.cursor = self.cnxn.cursor()
     # Check the tables
     self._check_rows(db_interface.TABLE_EVENT_LOG, 0)
     self._check_rows(db_interface.TABLE_ALERT_LOG, 0)
     self._check_rows(db_interface.TABLE_ALERT2ALERT, 0)
     self._check_rows(db_interface.TABLE_CHECKPOINT, 1)
     self.cnxn.close()
     teal.shutdown()
Exemplo n.º 24
0
 def testJournalWriteEventDB1(self):
     ''' Test writing to Event log DB basic
     '''
     self.teal = Teal('data/journal_test/events_001.conf','stderr',msgLevel=self.msglevel)
     j = Journal('DB test journal to write', file='data/journal_test/events_001.json')
     j.insert_in_db(truncate=True, no_delay=True)
     jdb = Journal('DB test journal to read')
     jdb.select_from_db('event')
     self.assertTrue(j.deep_match(jdb, ignore_delay=True, ignore_times=False, ignore_rec_id=False))
     #p rint j
     #p rint jdb
     self.teal.shutdown()
     return
Exemplo n.º 25
0
 def testJournalWriteEventDB3(self):
     ''' Test reading from event DB with a subset of fields 
     '''
     self.teal = Teal('data/journal_test/events_001.conf','stderr',msgLevel=self.msglevel)
     j = Journal('DB test journal to write', file='data/journal_test/events_001.json')
     j.insert_in_db(truncate=True, use_rec_ids=False, no_delay=True)
     jdb = Journal('DB test journal to read')
     jdb.select_from_db('event', event_fields=[EVENT_ATTR_REC_ID, EVENT_ATTR_EVENT_ID])
     jexp = Journal('DB expected', 'data/journal_test/events_004.json')
     self.assertTrue(jexp.deep_match(jdb, ignore_delay=True, ignore_times=False, ignore_rec_id=True))
     #p rint j
     #p rint jdb
     self.teal.shutdown()
     return
Exemplo n.º 26
0
class AlertAnalyzerSubclassTest3(TealTestCase):
    '''Test the alert analyzer can be subclassed '''

    def setUp(self):
        '''Setup Teal'''
        self.keep_ADC = self.force_env('TEAL_ALERT_DUPLICATE_CHECK', 'Yes') 
        self.remove_env('TEAL_ALERT_DUPLICATE_CHECK')   # Get rid of environment variable so configuration will be used
        self.teal = Teal('data/alert_analyzer_test/test02.conf', "stderr", msgLevel=self.msglevel, commit_alerts=False, commit_checkpoints=False)
    
    def tearDown(self):
        '''Teardown teal'''
        self.teal.shutdown()
        self.restore_env('TEAL_ALERT_DUPLICATE_CHECK', self.keep_ADC)

    def testAlertAnalyzerSubclassing01_3(self):
        ''' Test that the alert analyzer subclass works properly and that environment section in configuration works correctly  '''
        # 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)
Exemplo n.º 27
0
class TealTestSemaphoreInit(TealTestCase):
    '''Test the situation where TEAL starts and then shuts down immediately without
    processing events. Testing to ensure the monitor semaphore which is touched during
    shutdown is initialized correctly.'''

    
    def setUp(self):
        '''Setup Teal'''
        self.teal = Teal('data/checkpoint_test/configurationtest_05_semaphore.conf', 'stderr', msgLevel=self.msglevel)
        return
    
    def tearDown(self):
        '''Teardown teal'''

        if self.teal is not None:
            self.teal.shutdown()
        return    
    

    def testTealSemaphoreInit(self):
        '''Test checkpoint value after inserting into an empty db.'''
        # If there is a problem, the shutdown process would throw
        # an exception.
        return
Exemplo n.º 28
0
 def testJournalWriteAlertDB3(self):
     ''' Test getting only some fields of an alert '''
     self.teal = Teal('data/journal_test/events_001.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 alerts
     jadb = Journal('Read DB test ALERTS')
     jadb.select_from_db('alert', include_alert_assoc=False, alert_fields=[ALERT_ATTR_REC_ID, ALERT_ATTR_ALERT_ID, ALERT_ATTR_RECOMMENDATION])
     jaexp = Journal('DB test expected', 'data/journal_test/alerts_005.json')
     self.assertTrue(jaexp.deep_match(jadb, ignore_delay=True, ignore_times=False, ignore_rec_id=False))
     #p rint ja
     #p rint jadb
     self.teal.shutdown()
     return
Exemplo n.º 29
0
 def testJournalWriteAlertDB2(self):
     ''' Test getting alerts without associations '''
     self.teal = Teal('data/journal_test/events_001.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 alerts
     jadb = Journal('Read DB test ALERTS')
     jadb.select_from_db('alert', include_alert_assoc=False)
     jaexp = Journal('DB test expected', 'data/journal_test/alerts_003.json')
     self.assertTrue(jaexp.deep_match(jadb, ignore_delay=True, ignore_times=False, ignore_rec_id=False))
     #p rint ja
     #p rint jadb
     self.teal.shutdown()
     return
Exemplo n.º 30
0
 def testJournalWriteAlertDB1(self):
     ''' Test writing of Alert log DB basic '''
     self.teal = Teal('data/journal_test/events_001.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))
     #p rint je
     #p rint jedb
     # 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))
     #p rint ja
     #p rint jadb
     self.teal.shutdown()
     return