コード例 #1
0
 def test_setupMail(self):
     username = '******'
     hostname = '127.0.0.1'
     port = 25
     ssl = False
     mail_from = '*****@*****.**'
     mail_to = '*****@*****.**'
     password = '******'
     properties_mock = self.mocker.mock()
     properties_mock.get_value('mail_username')
     self.mocker.result(username)
     properties_mock.get_value('mail_hostname')
     self.mocker.result(hostname)
     properties_mock.get_value('mail_port')
     self.mocker.result(port)
     properties_mock.get_value('mail_ssl')
     self.mocker.result(ssl)
     properties_mock.get_value('mail_to')
     self.mocker.result(mail_to)
     properties_mock.get_value('mail_from')
     self.mocker.result(mail_from)
     getpass_mock = self.mocker.replace('getpass.getpass')
     getpass_mock()
     self.mocker.result(password)
     mail_action = self.mocker.mock()
     mail_mock = self.mocker.replace('log4tailer.notifications.Mail')
     mail_mock(mail_from, mail_to, hostname, username, password, port, ssl)
     self.mocker.result(mail_action)
     mail_action.connectSMTP()
     self.mocker.result(True)
     self.mocker.replay()
     utils.setup_mail(properties_mock)
コード例 #2
0
ファイル: LogTailer.py プロジェクト: CedricGatay/alerta-jul
 def resumeBuilder(self):
     resume = Resume(self.arrayLog)
     notify_defaults = ('mail', 'print')
     properties = self.properties
     if properties:
         notification_type = properties.get_value('analyticsnotification')
         analyticsgap = properties.get_value('analyticsgaptime')
         if notification_type and notification_type not in notify_defaults:
             resume.notification_type(notification_type)
         elif notification_type == 'mail':
             if not self.mailIsSetup():
                 mailAction = setup_mail(properties)
                 resume.setMailNotification(mailAction)
             else:
                 resume.setMailNotification(self.mailAction)
         if analyticsgap:
             resume.setAnalyticsGapNotification(analyticsgap)
     if self.silence:
         # if no notify has been setup and we are in daemonized mode 
         # we need to flush the reporting to avoid filling up memory.
         resume.is_daemonized = True
     # check if inactivity action on the self.actions and set the inactivity 
     # on the resume object. If inactivity is flagged, will be then
     # reported.
     inactivity_action = self.__getAction(notifications.Inactivity)
     if inactivity_action:
         resume.add_notifier(inactivity_action)
     return resume
コード例 #3
0
ファイル: test_mailaction.py プロジェクト: qrees/log4tailer
    def test_setupMail(self):
        def getpass():
            return "111"

        mailaction = utils.setup_mail(PropertiesStub(), getpass)
        self.assertTrue(isinstance(mailaction, notifications.Mail))
コード例 #4
0
ファイル: test_mailaction.py プロジェクト: qrees/log4tailer
    def test_setupMail(self):
        def getpass():
            return "111"

        mailaction = utils.setup_mail(PropertiesStub(), getpass)
        self.assertTrue(isinstance(mailaction, notifications.Mail))
コード例 #5
0
ファイル: __init__.py プロジェクト: CedricGatay/alerta-jul
def initialize(options):
    loglevels = defaults['loglevels']
    logcolors = defaults['logcolors']
    actions = defaults['actions']
    config = options.configfile or defaults['alt_config']
    if options.version:
        print __version__
        sys.exit(0)
    if os.path.exists(config):
        logger.info("Configuration file [%s] found" % config)
        defaults['properties'] = parse_config(config)
        loglevels.parse_config(defaults['properties'])
        logcolors.parse_config(defaults['properties'])
    properties = defaults['properties']
    if options.pause:
        defaults['pause'] = int(options.pause)
    if options.throttle:
        throttle = float(options.throttle)
        defaults['throttle'] = throttle
    if options.silence and properties:
        mailAction = setup_mail(properties)
        actions.append(mailAction)
        defaults['silence'] = True
    if options.nomailsilence:
        # silence option with no mail
        # up to user to provide notification by mail 
        # or do some kind of reporting 
        defaults['silence'] = True
    if options.mail and properties:
        mailAction = setup_mail(properties)
        actions.append(mailAction)
    if options.filter:
        # overrides Print notifier
        actions[0] = notifications.Filter(re.compile(options.filter))
    if options.tailnlines:
        defaults['nlines'] = int(options.tailnlines)
    if options.target:
        defaults['target'] = options.target
    if options.inactivity:
        inactivityAction = notifications.Inactivity(options.inactivity, 
                properties)
        if inactivityAction.getNotificationType() == 'mail':
            if options.mail or options.silence:
                inactivityAction.setMailNotification(actions[len(actions)-1])
            else:
                mailAction = setup_mail(properties)
                inactivityAction.setMailNotification(mailAction)
        actions.append(inactivityAction)
    if options.cornermark:
        cornermark = notifications.CornerMark(options.cornermark)
        actions.append(cornermark)
    if options.post and properties:
        defaults['post'] = True
        poster = notifications.Poster(properties)
        actions.append(poster)
    if options.executable and properties:
        executor = notifications.Executor(properties)
        actions.append(executor)
    if options.screenshot and properties:
        printandshoot = notifications.PrintShot(properties)
        actions[0] = printandshoot