Пример #1
0
 def notify(self, eventid, message, files=[]):
     mail = create_mail(mfrom=self.setting['mail_from'],
                        mto=self.setting['mail_to'],
                        subject=self.setting['subject'] + ' Event ID: ' + eventid,
                        message=message,
                        attachment_paths=files)
     send_mail(mfrom=self.setting['mail_from'],
               mpassword=self.setting['password'],
               mto=self.setting['mail_to'],
               mserver=self.setting['server'],
               mport=self.setting['port'],
               mailcontent=mail)
Пример #2
0
    def record(self, eventid, duration):
        eventdirs = []
        processed_files = {}
        datasource = self.setting.get('datasource', [])
        if isinstance(datasource, str):
            datasource = [datasource]

        for ds in datasource:
            eventdir = os.path.join(self.homedir, 'data', 'recorder', ds, eventid)
            eventdirs.append(eventdir)
            processed_files[eventdir] = set()

        sleep(self.setting.get('interval', 1))
        finishtime = time() + duration
        is_last = False

        while True:
            now = time()
            next = now + self.setting['interval']
            if now > finishtime:
               is_last = True 

            for dir in eventdirs:
                new_files = self.get_newfiles(dir, processed_files[dir])
                if not new_files:
                    continue

                mail = create_mail(mfrom=self.setting['mail_from'],
                                   mto=self.setting['mail_to'],
                                   subject=self.setting['subject'] + ' Event ID: ' + eventid,
                                   attachment_paths=new_files)
                send_mail(mfrom=self.setting['mail_from'],
                          mpassword=self.setting['password'],
                          mto=self.setting['mail_to'],
                          mserver=self.setting['server'],
                          mport=self.setting['port'],
                          mailcontent=mail)
                processed_files[dir].update(new_files)

            now = time()
            if is_last or now > finishtime:
                break
            if next > now:
                sleep(next - now)