remove concept of event_types, the event.type is now just sent as a string
authorTero Marttila <terom@fixme.fi>
Fri, 05 Feb 2010 21:48:14 +0200
changeset 58 31a17b0b5159
parent 57 31e7421e98af
child 59 43806d334fb4
remove concept of event_types, the event.type is now just sent as a string
etc/fixbot-logwatch.py
fixbot/api.py
fixbot/example.py
fixbot/irc.py
fixbot/logwatch/__init__.py
fixbot/utmp.py
--- a/etc/fixbot-logwatch.py	Fri Feb 05 21:39:51 2010 +0200
+++ b/etc/fixbot-logwatch.py	Fri Feb 05 21:48:14 2010 +0200
@@ -19,6 +19,9 @@
         filters.all,
     )),
     UnixDatagramSocket("test", os.path.join(logwatch_dir, "test.sock"), (
+        filters.sudo,
+        filters.ssh,
+        filters.cron_killer,
         filters.all,
     )),
 )
--- a/fixbot/api.py	Fri Feb 05 21:39:51 2010 +0200
+++ b/fixbot/api.py	Fri Feb 05 21:48:14 2010 +0200
@@ -14,14 +14,11 @@
     # module's name
     name = None
 
-    # list of valid event types (strings)
-    event_types = None
-
     def __str__ (self) :
         return "Module %s:" % (self.name)
     
     def __repr__ (self) :
-        return "<module %s with events: %s>" % (self.name, ", ".join(self.event_types))
+        return "<module %s>" % (self.name, )
 
 class Event (object) :
     # the ModuleInfo object
@@ -30,15 +27,13 @@
     # the event type as a string
     type = None
 
-    # event message as a string (under 255 bytes in length!)
+    # event message as a string (up to 64k, although that won't fit onto IRC..)
     msg = None
 
     # timestamp as a datetime.datetime
     when = None
 
     def __init__ (self, module, type, msg) :
-        assert type in module.event_types, "Invalid event-type %s for %r" % (type, self.module)
-        
         self.module = module
         self.type = type
         self.msg = msg
@@ -99,7 +94,6 @@
         m = ModuleInfo()
         
         m.name = i.readVarLen('B')
-        m.event_types = list(buffer.readStringStream(i, 'B'))
         m.addr = self.transport.getPeer()
 
         log.msg("Got mod_init for %r" % m)
@@ -115,7 +109,7 @@
     def on_module_event (self, i) :
         self._assert(self.module, "module_event with None self.module!")
 
-        event_type = i.readEnum(self.module.event_types)
+        event_type = i.readVarLen('B')
         event_msg = i.readVarLen('H')
         
         e = Event(self.module, event_type, event_msg)
@@ -138,13 +132,12 @@
         o = self.startCommand('module_init')
         o.writeVarLen('B', self.factory.secret)
         o.writeVarLen('B', self.factory.name)
-        buffer.writeStringStream(o, 'B', self.factory.event_types)
 
         self.send(o)
 
     def sendEvent (self, event) :
         o = self.startCommand('module_event')
-        o.writeEnum(self.factory.event_types, event.type)
+        o.writeVarLen('B', event.type)
         o.writeVarLen('H', event.msg[:2**16])
 
         self.send(o)
--- a/fixbot/example.py	Fri Feb 05 21:39:51 2010 +0200
+++ b/fixbot/example.py	Fri Feb 05 21:48:14 2010 +0200
@@ -8,10 +8,6 @@
     name = "example"
     version = 0x0001
     
-    event_types = [
-        "example"
-    ]
-
     def handleConnect (self) :
         self.sendEvent("example", "this is an example event")
         self.disconnect()
--- a/fixbot/irc.py	Fri Feb 05 21:39:51 2010 +0200
+++ b/fixbot/irc.py	Fri Feb 05 21:48:14 2010 +0200
@@ -112,7 +112,7 @@
             try :
                 module, addr = self.nexus.getModuleInfo(cmd)
 
-                return "%s from %s. Events: %s. See `commands %s' for a list of commands" % (module.name, addr, ', '.join(module.event_types), module.name)
+                return "%s from %s. See `commands %s' for a list of commands" % (module.name, addr, module.name)
 
             except KeyError :
                 raise ReplyException("No command/module called `%s'. See `help commands'" % cmd)
--- a/fixbot/logwatch/__init__.py	Fri Feb 05 21:39:51 2010 +0200
+++ b/fixbot/logwatch/__init__.py	Fri Feb 05 21:48:14 2010 +0200
@@ -8,13 +8,6 @@
 class LogWatchModule (api.Module) :
     name = "logs"
     
-    event_types = [
-        "error",
-        "sudo",
-        "ssh",
-        "all"
-    ]
-
     def __init__ (self, config) :
         """
             Initialize with logwatch_sources from config
--- a/fixbot/utmp.py	Fri Feb 05 21:39:51 2010 +0200
+++ b/fixbot/utmp.py	Fri Feb 05 21:48:14 2010 +0200
@@ -94,10 +94,6 @@
     name = "wtmp"
     version = 0x0001
     
-    event_types = [
-        "wtmp",
-    ]
-
     def handleConnect (self) :
         log.msg("Following default wtmp file...")