Esempio n. 1
0
    def handle_log(self, socket):
        """
        Handle a single log record from /dev/log socket
        :param socket:
        """
        match, severity, facility = BaseSyslogServer.handle_log(self, socket)

        # convert date string to datetime object
        today = datetime.datetime.now().date()
        tslog = datetime.datetime.strptime(match.group('timestamp'),
                                           self.DATE_FORMAT)
        timestamp = datetime.datetime(today.year, tslog.month, tslog.day,
                                      tslog.hour, tslog.minute, tslog.second)

        blocks = match.group('message').split(':')
        process_name = blocks[0]
        message = ':'.join(blocks[1:]).lstrip(' ')

        try:
            position = process_name.index('[')
            pid = int(process_name[position+1:].rstrip(']'))
            process_name = process_name[0:position]
            logrecord = LogRecord(process_name, facility, severity,
                                  str(timestamp), message, pid)
        except ValueError:
            logrecord = LogRecord(process_name, facility, severity,
                                  str(timestamp), message)
        logrecord.log()
Esempio n. 2
0
 def handle_log(self, socket):
     """
     handle a single log received from a UDP socket
     :param socket:
     """
     match, severity, facility = BaseSyslogServer.handle_log(self, socket)
     timestamp = datetime.datetime.now()
     message = match.group('message')
     if message:
         logrecord = LogRecord(self.__class__.__name__, facility, severity,
                               str(timestamp), message)
         logrecord.log()
Esempio n. 3
0
    def handle_log(self, socket):
        """
        Process a single log record that come from a socket
        :param socket:
        """
        log = socket.recv(self.MAX_LOG_SIZE)
        match = self.regexp.match(log)
        if not match:
            record = LogRecord('gsyslogd', syslog.LOG_DAEMON, syslog.LOG_ERR,
                               str(datetime.datetime.now()),
                               "%s: Malformed log: '%s'" % (
                                   self.__class__.__name__, log))
            record.log()
            raise MalformedLog(log)

        # convert priority string into facility and priority
        priority = int(match.group('facility_priority'))
        severity = priority % 8
        facility = (priority - severity) / 8

        return match, severity, facility