import psycopg2
from intelmq.lib.bot import Bot, sys

class PostgreSQLBot(Bot):

    def init(self):
        try:
            self.logger.debug("Connecting to PostgreSQL")
            self.con = psycopg2.connect(
                                   database=self.parameters.database,
                                   user=self.parameters.user,
                                   password=self.parameters.password,
                                   host=self.parameters.host,
                                   port=self.parameters.port
                                  )
            self.cur = self.con.cursor()
            self.logger.info("Connected to PostgreSQL")

        except psycopg2.DatabaseError, e:
            self.logger.error("Problem found when bot tried to connect to PostgreSQL (%s)." % e)
            self.stop()


    def process(self):
        event = self.receive_message()
        if event:
            
            evdict  = event.to_dict()
            keys    = ", ".join(evdict.keys())
            values  = evdict.values()
            fvalues = len(values) * "%s, "
            query   = "INSERT INTO logentry (" + keys + ") VALUES (" + fvalues[:-2] + ")"
            
            try:
                self.cur.execute(query, values)
            except psycopg2.DatabaseError, e:
                self.logger.error("Problem found when bot tried to insert data into PostgreSQL (%s)." % e)
                self.stop()
                
            self.con.commit()
        self.acknowledge_message()


if __name__ == "__main__":
    bot = PostgreSQLBot(sys.argv[1])
    bot.start()

@@ -94,33 +94,16 @@
 (self):%0A
-        try:%0A    
         
@@ -148,20 +148,16 @@
 reSQL%22)%0A
-    
         
@@ -217,19 +217,16 @@
         
-   
 database
@@ -252,19 +252,16 @@
 tabase,%0A
-   
         
@@ -343,19 +343,16 @@
         
-   
 password
@@ -410,19 +410,16 @@
         
-   
 host=sel
@@ -469,19 +469,16 @@
         
- 
-  
 port=sel
@@ -531,22 +531,18 @@
     
-  )%0A  
+)%0A
         
   se
@@ -529,34 +529,32 @@
       )%0A        
-  
 self.cur = self.
@@ -566,20 +566,16 @@
 ursor()%0A
-    
         
@@ -623,173 +623,8 @@
 %22)%0A%0A
-        except psycopg2.DatabaseError, e:%0A            self.logger.error(%22Problem found when bot tried to connect to PostgreSQL (%25s).%22 %25 e)%0A            self.stop()%0A%0A%0A
     
@@ -985,29 +985,8 @@
    %0A
-            try:%0A    
     
@@ -1029,206 +1029,8 @@
 es)%0A
-            except psycopg2.DatabaseError, e:%0A                self.logger.error(%22Problem found when bot tried to insert data into PostgreSQL (%25s).%22 %25 e)%0A                self.stop()%0A                %0A
     
@@ -1051,24 +1051,25 @@
 on.commit()%0A
+%0A
         self

Update postgresql.py