rename plugin fixbot -> fixbot_nexus, add fixbot_logwatch plugin, fix some random bugs
--- a/.hgignore Mon Sep 15 00:31:12 2008 +0300
+++ b/.hgignore Mon Sep 15 00:53:59 2008 +0300
@@ -4,4 +4,4 @@
\.pyc$
^twistd.(log|pid)$
^twisted/plugins/dropin.cache$
-
+^run/\w+\.pid$
--- a/fixbot/api.py Mon Sep 15 00:31:12 2008 +0300
+++ b/fixbot/api.py Mon Sep 15 00:53:59 2008 +0300
@@ -1,5 +1,6 @@
+from twisted.application import internet, service
from twisted.internet import protocol, reactor
-from twisted.python import log
+from twisted.python import log, usage
from datetime import datetime
import sys
@@ -172,16 +173,8 @@
protocol = ClientProtocol
def __init__ (self) :
- log.msg("Connecting to %s:%d" % (SERVER_HOST, PORT))
- reactor.connectTCP(SERVER_HOST, PORT, self)
-
self.connection = None
- def run (self) :
- log.startLogging(sys.stderr)
-
- reactor.run()
-
def connected (self, connection) :
log.msg("Connected!")
self.connection = connection
@@ -209,4 +202,27 @@
def __init__ (self, nexus) :
self.nexus = nexus
-
+
+class ClientOptions (usage.Options) :
+ optParameters = [
+ ( "api-server", "s", "127.0.0.1", "address of API server to connect to" ),
+ ( "api-port", "P", 34888, "port of API server to connect to", int ),
+ ]
+
+ optFlags = [
+
+ ]
+
+def makeService (client_module_factory, config) :
+ s = service.MultiService()
+
+ # the API client
+ module_factory = client_module_factory()
+
+ log.msg("Connecting to API server on [%s:%d]" % (config['api-server'], config['api-port']))
+ api_client = internet.TCPClient(config['api-server'], config['api-port'], module_factory)
+
+ api_client.setServiceParent(s)
+
+ return s
+
--- a/fixbot/fifo.py Mon Sep 15 00:31:12 2008 +0300
+++ b/fixbot/fifo.py Mon Sep 15 00:53:59 2008 +0300
@@ -15,6 +15,8 @@
def __init__ (self, path) :
self.path = path
+ self.fd = None
+
self._open()
def _open (self) :
--- a/fixbot/irc.py Mon Sep 15 00:31:12 2008 +0300
+++ b/fixbot/irc.py Mon Sep 15 00:53:59 2008 +0300
@@ -53,7 +53,7 @@
msg = msg.replace("\n", "\\n").replace("\r", "\\r").replace("\0", "\\0")
- self.notice(CHANNEL, msg)
+ self.notice(self.channel, msg)
def sendEvent (self, event) :
self.send("[%s.%s] %s" % (event.module.name, event.type, event.msg))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/fixbot/logwatch.py Mon Sep 15 00:53:59 2008 +0300
@@ -0,0 +1,29 @@
+from twisted.internet import protocol, reactor
+from twisted.python import log
+import sys
+
+import api
+import logwatch_config as config
+
+class LogWatchModule (api.Module) :
+ name = "logs"
+ version = 0x0005
+
+ event_types = [
+ "error",
+ "sudo",
+ "ssh",
+ "all"
+ ]
+
+ def handleConnect (self) :
+ for source in config.sources() :
+ source.setModule(self)
+
+ def error (self, msg) :
+ self.sendEvent("error", msg)
+
+def makeService (config) :
+ return api.makeService(LogWatchModule, config)
+
+
--- a/fixbot/logwatcher.py Mon Sep 15 00:31:12 2008 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-from twisted.internet import protocol, reactor
-from twisted.python import log
-import sys
-
-import api
-import logwatch_config as config
-
-class LogWatchModule (api.Module) :
- name = "logs"
- version = 0x0005
-
- event_types = [
- "error",
- "sudo",
- "ssh",
- "all"
- ]
-
- def handleConnect (self) :
- for source in config.sources() :
- source.setModule(self)
-
- def error (self, msg) :
- self.sendEvent("error", msg)
-
-if __name__ == '__main__' :
- LogWatchModule().run()
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/twisted/plugins/fixbot_logwatch_plugin.py Mon Sep 15 00:53:59 2008 +0300
@@ -0,0 +1,31 @@
+from zope.interface import implements
+
+from twisted.python import usage
+from twisted.plugin import IPlugin
+from twisted.application.service import IServiceMaker
+
+from twisted.application import internet
+
+from fixbot import api, logwatch
+
+class LogwatchOptions (api.ClientOptions) :
+ optParameters = [
+
+ ]
+
+ optFlags = [
+
+ ]
+
+class MyServiceMaker (object) :
+ implements(IServiceMaker, IPlugin)
+ tapname = "fixbot_logwatch"
+ description = "A SysAdmin's best friend (Logwatcher)"
+ options = LogwatchOptions
+
+ def makeService (self, config) :
+ return logwatch.makeService(config)
+
+serviceMaker = MyServiceMaker()
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/twisted/plugins/fixbot_nexus_plugin.py Mon Sep 15 00:53:59 2008 +0300
@@ -0,0 +1,39 @@
+from zope.interface import implements
+
+from twisted.python import usage
+from twisted.plugin import IPlugin
+from twisted.application.service import IServiceMaker
+
+from twisted.application import internet
+
+from fixbot import nexus
+
+class NexusOptions (usage.Options) :
+ optParameters = [
+# ( "uid", "u", "fixbot", "user to run as" ),
+# ( "gid", "g", "nogroup", "group to run as" ),
+ ( "irc-hostname", "s", "irc.fixme.fi", "IRC server hostname", ),
+ ( "irc-port", "p", 6667, "IRC server port", int ),
+ ( "irc-nickname", "n", "FixBotDev", "IRC nickname", ),
+ ( "irc-username", "U", "fixbot", "IRC username", ),
+ ( "irc-channel", "c", "#fixme-test", "IRC channel", ),
+ ( "api-listen", "l", "127.0.0.1", "address for API server to listen on" ),
+ ( "api-port", "P", 34888, "port for API server to listen on", int ),
+ ]
+
+ optFlags = [
+
+ ]
+
+class MyServiceMaker (object) :
+ implements(IServiceMaker, IPlugin)
+ tapname = "fixbot_nexus"
+ description = "A SysAdmin's best friend"
+ options = NexusOptions
+
+ def makeService (self, config) :
+ return nexus.makeService(config)
+
+serviceMaker = MyServiceMaker()
+
+
--- a/twisted/plugins/fixbot_plugin.py Mon Sep 15 00:31:12 2008 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-from zope.interface import implements
-
-from twisted.python import usage
-from twisted.plugin import IPlugin
-from twisted.application.service import IServiceMaker
-
-from twisted.application import internet
-
-from fixbot import nexus
-
-class NexusOptions (usage.Options) :
- optParameters = [
-# ( "uid", "u", "fixbot", "user to run as" ),
-# ( "gid", "g", "nogroup", "group to run as" ),
- ( "irc-hostname", "s", "irc.fixme.fi", "IRC server hostname", ),
- ( "irc-port", "p", 6667, "IRC server port", int ),
- ( "irc-nickname", "n", "FixBotDev", "IRC nickname", ),
- ( "irc-username", "U", "fixbot", "IRC username", ),
- ( "irc-channel", "c", "#fixme-test", "IRC channel", ),
- ( "api-listen", "l", "127.0.0.1", "address for API server to listen on" ),
- ( "api-port", "P", 34888, "port for API server to listen on", int ),
- ]
-
- optFlags = [
-
- ]
-
-class MyServiceMaker (object) :
- implements(IServiceMaker, IPlugin)
- tapname = "fixbot"
- description = "A SysAdmin's best friend"
- options = NexusOptions
-
- def makeService (self, config) :
- return nexus.makeService(config)
-
-serviceMaker = MyServiceMaker()
-
-