fixbot/logwatch/sources.py
author Tero Marttila <terom@fixme.fi>
Fri, 05 Feb 2010 22:20:59 +0200
changeset 59 43806d334fb4
parent 54 395182b7ea0f
child 63 a849c00b63f8
permissions -rw-r--r--
prepend source name to output type
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
54
395182b7ea0f logPrefix magic for LogSource, cleanup handleMessage
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
    71
            log.callWithLogger(self, self.handleMessage, msg)
51
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
        """
54
395182b7ea0f logPrefix magic for LogSource, cleanup handleMessage
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
    77
        
395182b7ea0f logPrefix magic for LogSource, cleanup handleMessage
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
    78
        # Log incoming lines
51
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    79
        log.msg(repr(msg))
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    80
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    81
        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
    82
            # let the filter process the line
53
21ab25ffa1e8 implement SyslogFilter
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
    83
            out = filter.match(msg)
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    84
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
    85
            if out :
48
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    86
                # unpack
59
43806d334fb4 prepend source name to output type
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
    87
                label, msg = out
43806d334fb4 prepend source name to output type
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
    88
43806d334fb4 prepend source name to output type
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
    89
                # output tag/type
43806d334fb4 prepend source name to output type
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
    90
                type = "%s:%s" % (self.name, label)
48
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    91
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
    92
                # positive match, send
48
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    93
                log.msg("\t%s: %s" % (type, msg))
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    94
                
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    95
                # drop until we have a module
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    96
                if self.module :
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    97
                    self.module.sendEvent(type, msg)
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    98
                
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    99
                # ok, first hit does it
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   100
                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
   101
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   102
            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
   103
                # negative match, stop processing
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   104
                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
   105
48
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   106
            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
   107
                # no match
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   108
                continue
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   109
48
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   110
            else :
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   111
                raise ValueError(out)
ba101beeb062 work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   112
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   113
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
   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
        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
   116
    """
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
   117
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   118
    def __init__ (self, name, path, filters) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   119
        super(File, self).__init__(name, filters)
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
        self.path = 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
        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
   124
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   125
        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
   126
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   127
    def errReceived (self, data) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   128
        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
   129
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   130
    def outReceived (self, data) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   131
        self.handleData(data)
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   132
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   133
    def processEnded (self, reason) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   134
        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
   135
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   136
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
   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
        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
   139
    """
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
   140
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   141
    def __init__ (self, name, path, filters) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   142
        LogSource.__init__(self, name, filters)
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
        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
   145
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   146
        fifo.Fifo.__init__(self, path)
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   147
    
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   148
    def dataReceived (self, data) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   149
        self.handleData(data)
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   150
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   151
    def handleEOF (self) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   152
        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
   153
        self.reopen()
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   154
    
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   155
    def connectionLost (self, reason) :
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   156
        super(Fifo, self).connectionLost(reason)
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   157
        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
   158
51
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   159
class UnixDatagramSocket (LogSource, protocol.DatagramProtocol) :
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
        Stream messages from a UNIX datagram socket
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   162
    """
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   163
    
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   164
    # maximum size of the recieved messages
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   165
    # 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
   166
    MAX_PACKET_SIZE = 4096
21
aa6df8f9c44a add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff changeset
   167
51
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   168
    def __init__ (self, name, path, filters) :
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   169
        LogSource.__init__(self, name, filters)
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
        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
   172
        
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   173
        # open UNIX socket
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   174
        reactor.listenUNIXDatagram(path, self, self.MAX_PACKET_SIZE)
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
    def datagramReceived (self, data, addr) :
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
            Got message from syslog-ng
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   179
        """
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   180
        
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   181
        # handle it as a line of data
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   182
        self.handleLine(data)
342850300d6a implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   183
54
395182b7ea0f logPrefix magic for LogSource, cleanup handleMessage
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   184
    def logPrefix (self) :
395182b7ea0f logPrefix magic for LogSource, cleanup handleMessage
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   185
        return "LogSource(%s)" % (self.name, )
395182b7ea0f logPrefix magic for LogSource, cleanup handleMessage
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   186