author | Tero Marttila <terom@fixme.fi> |
Sat, 20 Feb 2010 23:06:43 +0200 | |
changeset 64 | 8574aeff9b36 |
parent 63 | a849c00b63f8 |
permissions | -rw-r--r-- |
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 |
|
63
a849c00b63f8
move fixbot.fifo to fixbot.logwatch.fifo
Tero Marttila <terom@fixme.fi>
parents:
59
diff
changeset
|
8 |
from fixbot.logwatch import fifo, message |
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
9 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
10 |
class LogSource (object) : |
48
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
11 |
""" |
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
12 |
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
|
13 |
""" |
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
14 |
|
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
15 |
def __init__ (self, name, filters) : |
48
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
16 |
""" |
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
17 |
name - label lines read from this source |
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
18 |
filters - LogFilter chain to pass lines through |
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
19 |
""" |
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
20 |
|
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
21 |
# set later on |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
22 |
self.module = None |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
23 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
24 |
# what filters to apply |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
25 |
self.filters = filters |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
26 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
27 |
# name, for display purposes |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
28 |
self.name = name |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
29 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
30 |
# 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
|
31 |
self.buf = "" |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
32 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
33 |
def setModule (self, module) : |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
34 |
self.module = module |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
35 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
36 |
def handleError (self, msg) : |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
37 |
log.err(msg) |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
38 |
self.module.error(msg) |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
39 |
|
64 | 40 |
def connectionLost (self, reason) : |
41 |
""" |
|
42 |
The transport we were connected to has dropped, possibly as a result of our handlers raising an error? |
|
43 |
""" |
|
44 |
||
45 |
self.handleError("lost LogSource for %s: %s" % (self.name, reason.getErrorMessage())) |
|
46 |
||
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
47 |
def handleData (self, data) : |
48
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
48 |
""" |
51
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
49 |
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
|
50 |
""" |
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
51 |
|
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
52 |
data = self.buf + data |
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 |
while "\n" in data : |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
55 |
line, data = data.split("\n", 1) |
51
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
56 |
|
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
57 |
# full line |
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
58 |
self.handleLine(line) |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
59 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
60 |
self.buf = data |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
61 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
62 |
def handleLine (self, line) : |
51
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
63 |
""" |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
64 |
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
|
65 |
""" |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
66 |
|
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
67 |
# parse |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
68 |
try : |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
69 |
msg = message.SyslogMessage(line) |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
70 |
|
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
71 |
except Exception, e : |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
72 |
# log and ignore |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
73 |
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
|
74 |
|
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
75 |
else : |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
76 |
# handle the structured message |
54
395182b7ea0f
logPrefix magic for LogSource, cleanup handleMessage
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
77 |
log.callWithLogger(self, self.handleMessage, msg) |
51
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
78 |
|
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
79 |
def handleMessage (self, msg) : |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
80 |
""" |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
81 |
Process the given SyslogMessage |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
82 |
""" |
54
395182b7ea0f
logPrefix magic for LogSource, cleanup handleMessage
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
83 |
|
395182b7ea0f
logPrefix magic for LogSource, cleanup handleMessage
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
84 |
# Log incoming lines |
51
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
85 |
log.msg(repr(msg)) |
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
86 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
87 |
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
|
88 |
# let the filter process the line |
53 | 89 |
out = filter.match(msg) |
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
90 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
91 |
if out : |
48
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
92 |
# unpack |
59
43806d334fb4
prepend source name to output type
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
93 |
label, msg = out |
43806d334fb4
prepend source name to output type
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
94 |
|
43806d334fb4
prepend source name to output type
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
95 |
# output tag/type |
43806d334fb4
prepend source name to output type
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
96 |
type = "%s:%s" % (self.name, label) |
48
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
97 |
|
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
|
98 |
# positive match, send |
48
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
99 |
log.msg("\t%s: %s" % (type, msg)) |
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
100 |
|
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
101 |
# drop until we have a module |
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
102 |
if self.module : |
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
103 |
self.module.sendEvent(type, msg) |
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
104 |
|
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
105 |
# ok, first hit does it |
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
106 |
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
|
107 |
|
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
108 |
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
|
109 |
# negative match, stop processing |
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
110 |
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
|
111 |
|
48
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
112 |
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
|
113 |
# no match |
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
114 |
continue |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
115 |
|
48
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
116 |
else : |
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
117 |
raise ValueError(out) |
ba101beeb062
work on logwatch docs, small tweaks
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
118 |
|
64 | 119 |
def logPrefix (self) : |
120 |
return "LogSource(%s)" % (self.name, ) |
|
121 |
||
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
122 |
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
|
123 |
""" |
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
|
124 |
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
|
125 |
""" |
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
|
126 |
|
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
127 |
def __init__ (self, name, path, filters) : |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
128 |
super(File, self).__init__(name, filters) |
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 |
self.path = path |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
131 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
132 |
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
|
133 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
134 |
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
|
135 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
136 |
def errReceived (self, data) : |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
137 |
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
|
138 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
139 |
def outReceived (self, data) : |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
140 |
self.handleData(data) |
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 |
def processEnded (self, reason) : |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
143 |
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
|
144 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
145 |
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
|
146 |
""" |
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
|
147 |
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
|
148 |
""" |
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
|
149 |
|
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
150 |
def __init__ (self, name, path, filters) : |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
151 |
LogSource.__init__(self, name, filters) |
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 |
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
|
154 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
155 |
fifo.Fifo.__init__(self, path) |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
156 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
157 |
def dataReceived (self, data) : |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
158 |
self.handleData(data) |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
159 |
|
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
160 |
def handleEOF (self) : |
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
161 |
self.handleError("!!! EOF on fifo %s, re-opening" % self.name) |
64 | 162 |
self.reopen() |
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
163 |
|
51
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
164 |
class UnixDatagramSocket (LogSource, protocol.DatagramProtocol) : |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
165 |
""" |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
166 |
Stream messages from a UNIX datagram socket |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
167 |
""" |
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 |
# maximum size of the recieved messages |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
170 |
# 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
|
171 |
MAX_PACKET_SIZE = 4096 |
21
aa6df8f9c44a
add initial code back under fixbot/, the git-convert somehow broke
terom@fixme.fi
parents:
diff
changeset
|
172 |
|
51
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
173 |
def __init__ (self, name, path, filters) : |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
174 |
LogSource.__init__(self, name, filters) |
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 |
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
|
177 |
|
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
178 |
# open UNIX socket |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
179 |
reactor.listenUNIXDatagram(path, self, self.MAX_PACKET_SIZE) |
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 |
def datagramReceived (self, data, addr) : |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
182 |
""" |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
183 |
Got message from syslog-ng |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
184 |
""" |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
185 |
|
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
186 |
# handle it as a line of data |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
187 |
self.handleLine(data) |
342850300d6a
implement UnixDatagramSocket and LogSource.handleMessage
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
188 |
|
54
395182b7ea0f
logPrefix magic for LogSource, cleanup handleMessage
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
189 |