Pastebin

Paste #4860: Pattern

< previous paste - next paste>

Pasted by Anonymous Coward

Download View as text

class Pattern:
    def __init__(self, message=None, timestamp=None, timezone=None, host=None, program=None, pid=None):
        self.message    = message
        self.timestamp  = timestamp
        self.timezone   = timezone
        self.host       = host
        self.program    = program
        self.pid        = pid
        self.match_message   = (message is None)
        self.match_timestamp = (timestamp is None)
        self.match_timezone  = (timezone is None)
        self.match_host     = (host is None)
        self.match_program  = (program is None)
        self.match_pid      = (pid is None)

    def match(self, event):
        if self.message:
            if re.search(self.message, event.message):
                self.match_message = True
            else:
                self.match_message = False
        if self.timestamp:
            if re.search(self.timestamp, event.timestamp):
                self.match_timestamp = True
            else:
                self.match_timestamp = False
        if self.timezone:
            if re.search(self.timezone, event.timezone):
                self.match_timezone = True
            else:
                self.match_timezone = False
        if self.host:
            if re.search(self.host, event.host):
                self.match_host = True
            else:
                self.match_host = False
        if self.program:
            if re.search(self.program, event.program):
                self.match_program = True
            else:
                self.match_program = False
        if self.pid:
            if re.search(self.pid, event.pid):
                self.match_pid = True
            else:
                self.match_pid = False
        return self.match_program and self.match_pid and self.match_host and self.match_timezone and self.match_message and self.match_timestamp


New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.