Ejemplo n.º 1
0
 def testshouldReturnFalseMailNotSetup(self):
     self._setupAConfig()
     properties = Property('aconfig')
     properties.parse_properties()
     defaults = getDefaults()
     defaults.properties = properties
     logtailer = LogTailer(defaults)
     self.assertEqual(False, logtailer.mailIsSetup())
Ejemplo n.º 2
0
 def testgetOverridePauseModeLevels(self):
     pauseMode = modes.PauseMode()
     properties = Property(self.configfile)
     properties.parse_properties()
     pauseMode.parse_config(properties)
     for key,value in self.overridenLevelPauses.iteritems():
         key = key.split('pause')[1]
         self.assertEqual(value,pauseMode.getPause(key))
Ejemplo n.º 3
0
 def testFullTriggerFalseBasedOnConfig(self):
     fh = open(CONFIG, 'w')
     fh.write('executor = ls -l\n')
     fh.close()
     properties = Property(CONFIG)
     properties.parse_properties()
     executor = notifications.Executor(properties)
     self.assertEqual(False, executor.full_trigger_active)
     executor.stop()
Ejemplo n.º 4
0
 def testShouldHaveUsernameandAtLeastOneHostnameSetUp(self):
     self._setUpConfigFile()
     properties = Property(self.configfile)
     properties.parse_properties()
     logging.debug(properties.get_keys())
     defaults = self._getDefaults()
     defaults.properties = properties
     logtailer = SSHLogTailer(defaults)
     self.assertTrue(logtailer.sanityCheck())
Ejemplo n.º 5
0
 def testFullTriggerFalseBasedOnConfig(self):
     fh = open(CONFIG, 'w')
     fh.write('executor = ls -l\n')
     fh.close()
     properties = Property(CONFIG)
     properties.parse_properties()
     executor = notifications.Executor(properties)
     self.assertEqual(False, executor.full_trigger_active)
     executor.stop()
Ejemplo n.º 6
0
 def testShouldGetInactivityNotificationTypeifInConfigFile(self):
     fh = open('config.txt', 'w')
     fh.write('inactivitynotification = mail\n')
     fh.close()
     property = Property('config.txt')
     property.parse_properties()
     notifier = notifications.Inactivity(1, property)
     self.assertEqual('mail', notifier.getNotificationType())
     os.remove('config.txt')
Ejemplo n.º 7
0
 def testShouldHaveUsernameandAtLeastOneHostnameSetUp(self):
     self._setUpConfigFile()
     properties = Property(self.configfile)
     properties.parse_properties()
     logging.debug(properties.get_keys())
     defaults = self._getDefaults()
     defaults.properties = properties
     logtailer = SSHLogTailer(defaults)
     self.assertTrue(logtailer.sanityCheck())
Ejemplo n.º 8
0
 def testShouldGetInactivityNotificationTypeifInConfigFile(self):
     fh = open('config.txt','w')
     fh.write('inactivitynotification = mail\n')
     fh.close()
     property = Property('config.txt')
     property.parse_properties()
     notifier = notifications.Inactivity(1,property)
     self.assertEqual('mail',notifier.getNotificationType())
     os.remove('config.txt')
Ejemplo n.º 9
0
 def testIfParametersNotProvidedShouldExit(self):
     fh = open('wrongconfigfile','w')
     fh.write('anything = anything\n')
     fh.close()
     properties = Property('wrongconfigfile')
     properties.parse_properties()
     defaults = self._getDefaults()
     defaults.properties = properties
     logtailer = SSHLogTailer(defaults)
     self.assertFalse(logtailer.sanityCheck())
Ejemplo n.º 10
0
 def testIfParametersNotProvidedShouldExit(self):
     fh = open('wrongconfigfile', 'w')
     fh.write('anything = anything\n')
     fh.close()
     properties = Property('wrongconfigfile')
     properties.parse_properties()
     defaults = self._getDefaults()
     defaults.properties = properties
     logtailer = SSHLogTailer(defaults)
     self.assertFalse(logtailer.sanityCheck())
Ejemplo n.º 11
0
 def __createAConfigWithProperties(self):
     fh = open('config.txt','w')
     regexes = "log$, ^2009-10-12 got something here$ | red, yellow"
     allregex = re.compile('|'.join(regexes.split(',')))
     targetsline = "targets /var/log/messages = "+regexes+"\n"
     fh.write(targetsline)
     fh.write("/var/log/messages = green\n")
     fh.close()
     property = Property('config.txt')
     property.parse_properties()
     return property
Ejemplo n.º 12
0
 def testshouldHaveItsOwnColor(self):
     fh = open('config','w')
     fh.write(self.logname+'='+'green\n')
     fh.close()
     properties = Property('config')
     properties.parse_properties()
     log = Log(self.logname,properties)
     log.openLog()
     self.assertTrue(log.ownOutputColor)
     log.closeLog()
     os.remove(self.config)
Ejemplo n.º 13
0
 def testItShouldhaveBuildADictWithAllParamsIfAllParametersOk(self):
     self._setUpConfigFile()
     properties = Property(self.configfile)
     properties.parse_properties()
     logging.debug(properties.get_keys())
     defaults = self._getDefaults()
     defaults.properties = properties
     logtailer = SSHLogTailer(defaults)
     logtailer.sanityCheck()
     self.assertEquals(3,len(logtailer.hostnames.keys()))
     self.assertEquals('username',
             logtailer.hostnames['hostname0']['username'])
Ejemplo n.º 14
0
 def testshouldBuildCommandTailBasedOnHostnamesDict(self):
     self._setUpConfigFile()
     properties = Property(self.configfile)
     properties.parse_properties()
     logging.debug(properties.get_keys())
     defaults = self._getDefaults()
     defaults.properties = properties
     logtailer = SSHLogTailer(defaults)
     logtailer.sanityCheck()
     command = "tail -F /var/log/anylog555 /var/log/anylog1"
     logtailer.createCommands()
     self.assertEquals(command, logtailer.hostnames['hostname0']['command'])
Ejemplo n.º 15
0
 def testItShouldhaveBuildADictWithAllParamsIfAllParametersOk(self):
     self._setUpConfigFile()
     properties = Property(self.configfile)
     properties.parse_properties()
     logging.debug(properties.get_keys())
     defaults = self._getDefaults()
     defaults.properties = properties
     logtailer = SSHLogTailer(defaults)
     logtailer.sanityCheck()
     self.assertEquals(3, len(logtailer.hostnames.keys()))
     self.assertEquals('username',
                       logtailer.hostnames['hostname0']['username'])
Ejemplo n.º 16
0
 def testshouldBuildCommandTailBasedOnHostnamesDict(self):
     self._setUpConfigFile()
     properties = Property(self.configfile)
     properties.parse_properties()
     logging.debug(properties.get_keys())
     defaults = self._getDefaults()
     defaults.properties = properties
     logtailer = SSHLogTailer(defaults)
     logtailer.sanityCheck()
     command = "tail -F /var/log/anylog555 /var/log/anylog1"
     logtailer.createCommands()
     self.assertEquals(command,logtailer.hostnames['hostname0']['command'])
Ejemplo n.º 17
0
 def testTargetsNoColors(self):
     fh = open('config.txt','w')
     regexes = "log$; ^2009-10-12 got something here$"
     targetsline = "targets /var/log/messages = "+regexes+"\n"
     fh.write(targetsline)
     fh.close()
     property = Property('config.txt')
     property.parse_properties()
     self.assertEqual(regexes, 
                      property.get_value('targets /var/log/messages'))
     log = Log('/var/log/messages', property)
     color = log.logTargetColor.get(re.compile('log$'))
     self.assertFalse(color)
     os.remove('config.txt')
Ejemplo n.º 18
0
 def testIfMailNotificationTypeAlreadyAvailablebyMailShouldSetItUp(self):
     mailMocker = mox.Mox()
     mail = mailMocker.CreateMock(notifications.Mail)
     fh = open('config.txt', 'w')
     fh.write('inactivitynotification = mail\n')
     fh.close()
     property = Property('config.txt')
     property.parse_properties()
     notifier = notifications.Inactivity(1, property)
     if notifier.getNotificationType() == 'mail':
         notifier.setMailNotification(mail)
     else:
         self.fail('should be notifier with mail Notification')
     os.remove('config.txt')
Ejemplo n.º 19
0
 def testIfMailNotificationTypeAlreadyAvailablebyMailShouldSetItUp(self):
     mailMocker = mox.Mox()
     mail = mailMocker.CreateMock(notifications.Mail)
     fh = open('config.txt','w')
     fh.write('inactivitynotification = mail\n')
     fh.close()
     property = Property('config.txt')
     property.parse_properties()
     notifier = notifications.Inactivity(1,property)
     if notifier.getNotificationType() == 'mail':
         notifier.setMailNotification(mail)
     else:
         self.fail('should be notifier with mail Notification') 
     os.remove('config.txt')
Ejemplo n.º 20
0
 def testshouldHaveitsOwnTargetSchemesIfProvidedInConfigFile(self):
     fh = open('config.txt','w')
     regexesColors = ("log$ : yellow, on_cyan; ^2009-10-12 got something "
         "here$ : black, on_cyan")
     targetsline = "targets /var/log/messages = "+regexesColors+"\n"
     fh.write(targetsline)
     fh.close()
     property = Property('config.txt')
     property.parse_properties()
     self.assertEqual(regexesColors, 
                      property.get_value('targets /var/log/messages'))
     log = Log('/var/log/messages', property)
     logTargetsColors = {re.compile('log$'): 'yellow, on_cyan',
         re.compile("^2009-10-12 got something here$") : 'black, on_cyan'}
     self.assertEqual(logTargetsColors, log.logTargetColor)
     os.remove('config.txt')
Ejemplo n.º 21
0
 def testResumeBuilderWithAnalyticsFile(self):
     sys.stdout = MemoryWriter()
     reportfile = 'reportfile.txt'
     configfile = 'aconfig'
     fh = open(configfile, 'w')
     fh.write('analyticsnotification = ' + reportfile + '\n')
     fh.close()
     properties = Property(configfile)
     properties.parse_properties()
     defaults = getDefaults()
     defaults.properties = properties
     logtailer = LogTailer(defaults)
     resumeObj = logtailer.resumeBuilder()
     self.assertTrue(isinstance(resumeObj, reporting.Resume))
     self.assertEquals('file', resumeObj.getNotificationType())
     self.assertEquals(reportfile, resumeObj.report_file)
Ejemplo n.º 22
0
    def testReportToAFile(self):
        reportfileFullPath = "reportfile.txt"
        fh = open('aconfig', 'w')
        fh.write('analyticsnotification = ' + reportfileFullPath + '\n')
        fh.write('analyticsgaptime = 0.1\n')
        fh.close()
        properties = Property('aconfig')
        properties.parse_properties()
        self.assertTrue(properties.is_key('analyticsnotification'))
        log = Log('out.log')
        arrayLog = [log]
        resume = reporting.Resume(arrayLog)
        gaptime = 0.1
        resume.setAnalyticsGapNotification(gaptime)
        resume.notification_type(reportfileFullPath)
        fh = open('out.log')
        lines = fh.readlines()
        fh.close()
        logcolors = LogColors()
        msg = Message(logcolors)

        def overgap():
            return gaptime + 1

        def belowgap():
            return gaptime - 0.01

        resume.timer.inactivityEllapsed = overgap

        for line in lines:
            msg.parse(line, log)
            resume.update(msg, log)
            resume.timer.inactivityEllapsed = belowgap
        fh = open(reportfileFullPath)
        reportlength = len(fh.readlines())
        fh.close()
        os.remove(reportfileFullPath)
        self.assertEquals(24, reportlength)
        os.remove('aconfig')
Ejemplo n.º 23
0
    def testReportToAFile(self):
        reportfileFullPath = "reportfile.txt"
        fh = open('aconfig', 'w')
        fh.write('analyticsnotification = ' + reportfileFullPath + '\n')
        fh.write('analyticsgaptime = 0.1\n')
        fh.close()
        properties = Property('aconfig')
        properties.parse_properties()
        self.assertTrue(properties.is_key('analyticsnotification'))
        log = Log('out.log')
        arrayLog = [log]
        resume = reporting.Resume(arrayLog)
        gaptime = 0.1
        resume.setAnalyticsGapNotification(gaptime)
        resume.notification_type(reportfileFullPath)
        fh = open('out.log')
        lines = fh.readlines()
        fh.close()
        logcolors = LogColors()
        msg = Message(logcolors)

        def overgap():
            return gaptime + 1

        def belowgap():
            return gaptime - 0.01

        resume.timer.inactivityEllapsed = overgap

        for line in lines:
            msg.parse(line, log)
            resume.update(msg, log)
            resume.timer.inactivityEllapsed = belowgap
        fh = open(reportfileFullPath)
        reportlength = len(fh.readlines())
        fh.close()
        os.remove(reportfileFullPath)
        self.assertEquals(24, reportlength)
        os.remove('aconfig')
Ejemplo n.º 24
0
 def testShouldReportaLogOwnTarget(self):
     logfile = "/any/path/outtarget.log"
     configfile = "aconfig.txt"
     logcolors = LogColors()
     fh = open(configfile, 'w')
     fh.write("targets " + logfile + " = should\n")
     fh.close()
     properties = Property(configfile)
     properties.parse_properties()
     mylog = Log(logfile, properties)
     optional_params = (None, True, logfile)
     self.assertEqual(optional_params,
                      (mylog.ownOutputColor, mylog.patTarget, mylog.path))
     arraylogs = [mylog]
     resume = reporting.Resume(arraylogs)
     message = Message(logcolors, properties=properties)
     logtrace = "log trace info target should be reported"
     message.parse(logtrace, mylog)
     resume.update(message, mylog)
     outLogReport = resume.logsReport[mylog.path]
     numofTargets = 1
     gotnumTargets = outLogReport['TARGET']
     self.assertEquals(numofTargets, gotnumTargets)
Ejemplo n.º 25
0
 def testShouldReportaLogOwnTarget(self):
     logfile = "/any/path/outtarget.log"
     configfile = "aconfig.txt"
     logcolors = LogColors()
     fh = open(configfile, 'w')
     fh.write("targets " + logfile + " = should\n")
     fh.close()
     properties = Property(configfile)
     properties.parse_properties()
     mylog = Log(logfile, properties)
     optional_params = (None, True, logfile)
     self.assertEqual(optional_params, (mylog.ownOutputColor,
         mylog.patTarget, mylog.path))
     arraylogs = [mylog]
     resume = reporting.Resume(arraylogs)
     message = Message(logcolors, properties=properties)
     logtrace = "log trace info target should be reported"
     message.parse(logtrace, mylog)
     resume.update(message, mylog)
     outLogReport = resume.logsReport[mylog.path]
     numofTargets = 1
     gotnumTargets = outLogReport['TARGET']
     self.assertEquals(numofTargets, gotnumTargets)
Ejemplo n.º 26
0
 def testShouldSetupMailNotificationIfAnalyticsNotificationIsSetup(self):
     fh = open('aconfig', 'w')
     fh.write('analyticsnotification = mail\n')
     fh.write('analyticsgaptime = 3600\n')
     fh.close()
     properties = Property('aconfig')
     properties.parse_properties()
     self.assertTrue(properties.is_key('analyticsnotification'))
     arrayLog = [Log('out.log')]
     resume = reporting.Resume(arrayLog)
     mailactionmocker = mox.Mox()
     mailaction = mailactionmocker.CreateMock(notifications.Mail)
     if properties.get_value('analyticsnotification') == 'mail':
         resume.setMailNotification(mailaction)
         self.assertEquals('mail', resume.getNotificationType())
         gaptime = properties.get_value('analyticsgaptime')
         if gaptime:
             resume.setAnalyticsGapNotification(gaptime)
             self.assertEquals(3600, int(resume.getGapNotificationTime()))
     os.remove('aconfig')
Ejemplo n.º 27
0
 def testShouldSetupMailNotificationIfAnalyticsNotificationIsSetup(self):
     fh = open('aconfig', 'w')
     fh.write('analyticsnotification = mail\n')
     fh.write('analyticsgaptime = 3600\n')
     fh.close()
     properties = Property('aconfig')
     properties.parse_properties()
     self.assertTrue(properties.is_key('analyticsnotification'))
     arrayLog = [Log('out.log')]
     resume = reporting.Resume(arrayLog)
     mailactionmocker = mox.Mox()
     mailaction = mailactionmocker.CreateMock(notifications.Mail)
     if properties.get_value('analyticsnotification') == 'mail':
         resume.setMailNotification(mailaction)
         self.assertEquals('mail', resume.getNotificationType())
         gaptime = properties.get_value('analyticsgaptime')
         if gaptime:
             resume.setAnalyticsGapNotification(gaptime)
             self.assertEquals(3600, int(resume.getGapNotificationTime()))
     os.remove('aconfig')