def run(self):
     """Démarre le thread d'écoute du log openzwave."""
     self._pluginLog.info('Monitor openzwave manager is started.')
     self.running = True
     ozwTail = Tailer(open(self.ozwlogfile,  'rb'))
     for line in ozwTail.follow(delay=0.01):
         if line : self.cb_logNode(line)
         if self._stop.isSet() or not self.running : break
     self.running = False
     self._pluginLog.info('Monitor openzwave manager is stopped.')
Пример #2
0
    def _devenv_compile(options, solution, version):
        proj_extension = MsvcCompiler._get_project_file_ext(version)
        devenv = MsvcCompiler._get_devenv_path(version)
        compiler_version = MsvcCompiler._get_compiler_version(
            version, options.build_platform)

        project = os.path.normpath(
            os.path.join(options.build_dir, 'ALL_BUILD' + proj_extension))
        solutionConfig = '%s|%s' % (options.build_config.capitalize(),
                                    options.build_platform)

        if options.verbose:
            print('Compiler       : %s' % compiler_version)
            print('Compile type   : %s' % options.compile_type)
            print('Devenv         : %s' % devenv)
            print('Solution       : %s' % solution)
            print('Project        : %s' % project)
            print('Solution Config: %s' % solutionConfig)
            print('Configuration  : %s' % options.build_config)
            print('Platform       : %s' % options.build_platform)

        with TempDir() as temp_dir:
            output = MsvcCompiler._create_log_filename(temp_dir.path,
                                                       options.compile_type,
                                                       options.build_config)

            command = 'devenv.exe "%s" /%s "%s" /project "%s" /projectconfig %s /out "%s"' % \
                      (solution, options.compile_type.capitalize(), \
                       solutionConfig, project, \
                       options.build_config.capitalize(), output)

            if options.verbose:
                print('Command: %s' % command)

            process = subprocess.Popen(command, \
                                       stdout=subprocess.PIPE, stderr=subprocess.STDOUT, \
                                       shell=True, bufsize=1, cwd=os.path.dirname(devenv))

            # Wait a max of 10secs to see if the output file will open
            total_time = 0.0
            while not os.path.isfile(output) and total_time < 10.0:
                total_time += .5
                time.sleep(total_time)

            # Tail the output from the log file to the console
            with open(output) as build_output:
                tailer = Tailer(build_output)
                for line in tailer.follow(terminate=process.poll):
                    print(line)
                    if process.poll() != None:
                        break

        return process.returncode
Пример #3
0
    def _devenv_compile(options, solution, version):
        proj_extension = MsvcCompiler._get_project_file_ext(version)
        devenv = MsvcCompiler._get_devenv_path(version)
        compiler_version = MsvcCompiler._get_compiler_version(version, options.build_platform)

        project = os.path.normpath(os.path.join(options.build_dir, 'ALL_BUILD' + proj_extension))
        solutionConfig = '%s|%s' % (options.build_config.capitalize(), options.build_platform)

        if options.verbose:
            print('Compiler       : %s' % compiler_version)
            print('Compile type   : %s' % options.compile_type)
            print('Devenv         : %s' % devenv)
            print('Solution       : %s' % solution)
            print('Project        : %s' % project)
            print('Solution Config: %s' % solutionConfig)
            print('Configuration  : %s' % options.build_config)
            print('Platform       : %s' % options.build_platform)

        with TempDir() as temp_dir:
            output = MsvcCompiler._create_log_filename(temp_dir.path, options.compile_type, options.build_config)
            
            command = 'devenv.exe "%s" /%s "%s" /project "%s" /projectconfig %s /out "%s"' % \
                      (solution, options.compile_type.capitalize(), \
                       solutionConfig, project, \
                       options.build_config.capitalize(), output)

            if options.verbose:
                print('Command: %s' % command)

            process = subprocess.Popen(command, \
                                       stdout=subprocess.PIPE, stderr=subprocess.STDOUT, \
                                       shell=True, bufsize=1, cwd=os.path.dirname(devenv))

            # Wait a max of 10secs to see if the output file will open
            total_time = 0.0
            while not os.path.isfile(output) and total_time < 10.0:
                total_time += .5
                time.sleep(total_time)

            # Tail the output from the log file to the console
            with open(output) as build_output:
                tailer = Tailer(build_output)
                for line in tailer.follow(terminate=process.poll):
                    print(line)
                    if process.poll() != None:
                        break

        return process.returncode
Пример #4
0
    def _create_tailer_thread(self) -> FuncThread:
        from tailer import Tailer

        tailer = Tailer(open(self.file_path), end=True)

        def _run_follow(*_):
            try:
                self.started.set()
                for line in tailer.follow(delay=0.25):
                    try:
                        self.callback(line)
                    except Exception:
                        pass
            finally:
                tailer.close()

        return FuncThread(func=_run_follow, on_stop=lambda *_: tailer.close())
Пример #5
0
 def __init__(self, alert_duration=120, max_traffic=10, file_path=None):
     self.file_path = file_path
     if self.file_path is not None:
         self.tailer = Tailer(file_path)
     self.alert_duration = alert_duration
     self.max_traffic = max_traffic
     self.file_path = file_path      # Keep file path to refresh if log rotated
     self.start_time = time.time()
     self.sections = {}              # Most visited sections
     self.alerts = []
     self.in_alert = False
     self.log_book = LogBook(alert_duration)
     self.total_hits = 0
     self.stats_answer = {"2xx": 0, "3xx": 0, "4xx": 0, "5xx": 0}     # Count numbers of 2xx, 3xx, 4xx and 5xx answers
Пример #6
0
 def __init__(self, asynctailer, delay):
     filename = asynctailer.file.name
     super().__init__(name=f'Tailer->FollowThread [file={filename}]')
     self.queue = janus.Queue()
     self.asynctailer = asynctailer
     self.follow_generator = PyTailer.follow(self.asynctailer, delay=delay)
Пример #7
0
class HTTPMonitor:
    """
    Main class
    Instanciates Tailer, LogLine and LogBook.
    Get new log lines, and update statistics & alerts.
    """

    def __init__(self, alert_duration=120, max_traffic=10, file_path=None):
        self.file_path = file_path
        if self.file_path is not None:
            self.tailer = Tailer(file_path)
        self.alert_duration = alert_duration
        self.max_traffic = max_traffic
        self.file_path = file_path      # Keep file path to refresh if log rotated
        self.start_time = time.time()
        self.sections = {}              # Most visited sections
        self.alerts = []
        self.in_alert = False
        self.log_book = LogBook(alert_duration)
        self.total_hits = 0
        self.stats_answer = {"2xx": 0, "3xx": 0, "4xx": 0, "5xx": 0}     # Count numbers of 2xx, 3xx, 4xx and 5xx answers


    def get_new_lines(self):
        """ Get new lines from log file, and update statistics"""
        lines = self.tailer.new_lines()
        log_lines = LogLine.parse_array(lines)
        self.log_book.add_log_lines(log_lines)
        alert = self.update_alert_state()
        for line in log_lines:
            self.add_section(line)
            self.total_hits +=1
            if line.status.startswith('2'):
                self.stats_answer["2xx"] +=1
            elif line.status.startswith('3'):
                self.stats_answer["3xx"] +=1
            elif line.status.startswith('4'):
                self.stats_answer["4xx"] +=1
            elif line.status.startswith('5'):
                self.stats_answer["5xx"] +=1
        return alert



    def add_section(self, log_line):
        """Add a new entry in sections dictionary
        :param log_line: the log_line to add
        """
        section = log_line.get_section()
        if section is not None:
            if section not in self.sections.keys():
                self.sections[section] = 1
            else:
                self.sections[section] += 1

    def update_alert_state(self):
        if len(self.log_book.log_lines) >= self.max_traffic and not self.in_alert:
            self.in_alert = True
            alert = Alert(Alert.alert_state, time.localtime(), len(self.log_book.log_lines))
            self.alerts.append(alert)
            return alert
        elif len(self.log_book.log_lines) < self.max_traffic and self.in_alert:
            self.in_alert = False
            alert = Alert(Alert.idle_state, time.localtime(), len(self.log_book.log_lines))
            self.alerts.append(alert)
            return alert
        return None