fixbot/logwatch/sources.py
author Tero Marttila <terom@fixme.fi>
Fri, 05 Feb 2010 21:16:19 +0200
changeset 53 21ab25ffa1e8
parent 51 342850300d6a
child 54 395182b7ea0f
permissions -rw-r--r--
implement SyslogFilter
48
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
     1
"""
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
     2
    Implementations of the various sources of log data
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
     3
"""
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
     4
51
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
     5
from twisted.internet import protocol, reactor
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
     6
from twisted.python import log
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
     7
40
b9fdb7710768 move logwatch*.py to separate fixbot.logwatch package, and move logwatch_sources to etc/fixbot-logwatch.py
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
     8
from fixbot import fifo
51
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
     9
from fixbot.logwatch import message
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    10
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    11
class LogSource (object) :
48
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    12
    """
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    13
        Reads lines of log data from some file or other source.
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    14
    """
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    15
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    16
    def __init__ (self, name, filters) :
48
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    17
        """
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    18
            name            - label lines read from this source
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    19
            filters         - LogFilter chain to pass lines through
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    20
        """
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    21
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    22
        # set later on
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    23
        self.module = None
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    24
        
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    25
        # what filters to apply
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    26
        self.filters = filters
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    27
        
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    28
        # name, for display purposes
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    29
        self.name = name
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    30
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    31
        # used to gather data together into lines
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    32
        self.buf = ""
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    33
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    34
    def setModule (self, module) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    35
        self.module = module
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    36
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    37
    def handleError (self, msg) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    38
        log.err(msg)
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    39
        self.module.error(msg)
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    40
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    41
    def handleData (self, data) :
48
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    42
        """
51
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    43
            Feed binary data into the buffer, processing all lines via handleLine()
48
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    44
        """
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    45
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    46
        data = self.buf + data
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    47
        
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    48
        while "\n" in data :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    49
            line, data = data.split("\n", 1)
51
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    50
            
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    51
            # full line
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    52
            self.handleLine(line)
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    53
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    54
        self.buf = data
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    55
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    56
    def handleLine (self, line) :
51
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    57
        """
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    58
            Parse given line into a SyslogMessage, and pass it to handleMessage
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    59
        """
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    60
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    61
        # parse
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    62
        try :
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    63
            msg = message.SyslogMessage(line)
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    64
    
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    65
        except Exception, e :
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    66
            # log and ignore
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    67
            log.err(e, "Invalid syslog message from source %s: %s" % (self.name, line))
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    68
    
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    69
        else :
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    70
            # handle the structured message
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    71
            self.handleMessage(msg)
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    72
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    73
    def handleMessage (self, msg) :
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    74
        """
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    75
            Process the given SyslogMessage
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    76
        """
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    77
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    78
        # XXX: filters should accept messages...
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    79
        line = str(msg)
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    80
        log.msg(repr(msg))
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    81
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    82
        for filter in self.filters :
40
b9fdb7710768 move logwatch*.py to separate fixbot.logwatch package, and move logwatch_sources to etc/fixbot-logwatch.py
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    83
            # let the filter process the line
53
21ab25ffa1e8 implement SyslogFilter
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
    84
            out = filter.match(msg)
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    85
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    86
            if out :
48
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    87
                # unpack
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    88
                type, msg = out
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    89
40
b9fdb7710768 move logwatch*.py to separate fixbot.logwatch package, and move logwatch_sources to etc/fixbot-logwatch.py
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    90
                # positive match, send
48
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    91
                log.msg("\t%s: %s" % (type, msg))
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    92
                
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    93
                # drop until we have a module
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    94
                if self.module :
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    95
                    self.module.sendEvent(type, msg)
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    96
                
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    97
                # ok, first hit does it
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    98
                break
40
b9fdb7710768 move logwatch*.py to separate fixbot.logwatch package, and move logwatch_sources to etc/fixbot-logwatch.py
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    99
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   100
            elif out is False :
40
b9fdb7710768 move logwatch*.py to separate fixbot.logwatch package, and move logwatch_sources to etc/fixbot-logwatch.py
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   101
                # negative match, stop processing
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   102
                return
40
b9fdb7710768 move logwatch*.py to separate fixbot.logwatch package, and move logwatch_sources to etc/fixbot-logwatch.py
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   103
48
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   104
            elif out is None :
40
b9fdb7710768 move logwatch*.py to separate fixbot.logwatch package, and move logwatch_sources to etc/fixbot-logwatch.py
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   105
                # no match
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   106
                continue
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   107
48
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   108
            else :
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   109
                raise ValueError(out)
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   110
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   111
class File (LogSource, protocol.ProcessProtocol) :
40
b9fdb7710768 move logwatch*.py to separate fixbot.logwatch package, and move logwatch_sources to etc/fixbot-logwatch.py
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   112
    """
b9fdb7710768 move logwatch*.py to separate fixbot.logwatch package, and move logwatch_sources to etc/fixbot-logwatch.py
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   113
        Stream lines from a regular file using /usr/bin/tail -f
b9fdb7710768 move logwatch*.py to separate fixbot.logwatch package, and move logwatch_sources to etc/fixbot-logwatch.py
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   114
    """
b9fdb7710768 move logwatch*.py to separate fixbot.logwatch package, and move logwatch_sources to etc/fixbot-logwatch.py
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   115
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   116
    def __init__ (self, name, path, filters) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   117
        super(File, self).__init__(name, filters)
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   118
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   119
        self.path = path
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   120
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   121
        log.msg("spawning tail process for %s:%s" % (name, path))
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   122
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   123
        reactor.spawnProcess(self, "/usr/bin/tail", ["tail", "-n0", "--follow=name", path])
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   124
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   125
    def errReceived (self, data) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   126
        self.handleError("tail for %s: %s" % (self.name, data))
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   127
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   128
    def outReceived (self, data) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   129
        self.handleData(data)
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   130
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   131
    def processEnded (self, reason) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   132
        self.handleError("tail process for %s quit: %s" % (self.name, reason.getErrorMessage()))
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   133
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   134
class Fifo (LogSource, fifo.Fifo) :
40
b9fdb7710768 move logwatch*.py to separate fixbot.logwatch package, and move logwatch_sources to etc/fixbot-logwatch.py
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   135
    """
b9fdb7710768 move logwatch*.py to separate fixbot.logwatch package, and move logwatch_sources to etc/fixbot-logwatch.py
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   136
        Stream lines from a fifo object.
b9fdb7710768 move logwatch*.py to separate fixbot.logwatch package, and move logwatch_sources to etc/fixbot-logwatch.py
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   137
    """
b9fdb7710768 move logwatch*.py to separate fixbot.logwatch package, and move logwatch_sources to etc/fixbot-logwatch.py
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   138
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   139
    def __init__ (self, name, path, filters) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   140
        LogSource.__init__(self, name, filters)
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   141
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   142
        log.msg("opening fifo for %s:%s" % (name, path))
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   143
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   144
        fifo.Fifo.__init__(self, path)
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   145
    
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   146
    def dataReceived (self, data) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   147
        self.handleData(data)
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   148
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   149
    def handleEOF (self) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   150
        self.handleError("!!! EOF on fifo %s, re-opening" % self.name)
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   151
        self.reopen()
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   152
    
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   153
    def connectionLost (self, reason) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   154
        super(Fifo, self).connectionLost(reason)
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   155
        self.handleError("lost fifo for %s: %s" % (self.name, reason.getErrorMessage()))
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   156
51
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   157
class UnixDatagramSocket (LogSource, protocol.DatagramProtocol) :
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   158
    """
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   159
        Stream messages from a UNIX datagram socket
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   160
    """
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   161
    
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   162
    # maximum size of the recieved messages
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   163
    # native syslog is 1024, but syslog-ng does better... so 4k
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   164
    MAX_PACKET_SIZE = 4096
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   165
51
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   166
    def __init__ (self, name, path, filters) :
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   167
        LogSource.__init__(self, name, filters)
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   168
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   169
        log.msg("opening unix socket for %s at: %s" % (name, path))
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   170
        
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   171
        # open UNIX socket
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   172
        reactor.listenUNIXDatagram(path, self, self.MAX_PACKET_SIZE)
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   173
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   174
    def datagramReceived (self, data, addr) :
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   175
        """
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   176
            Got message from syslog-ng
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   177
        """
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   178
        
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   179
        # handle it as a line of data
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   180
        self.handleLine(data)
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   181