logging.debug("SELECT e.id, e.data FROM services s RIGHT JOIN events e ON s.id = e.service_id WHERE e.id > %s AND %s %s e.valid = 1 LIMIT %s"%(str(idor0),sqlwhere_string,and_op,str(count)))
self.crs.execute(sqlwhere_string,sqlparams)
self.crs.execute("SELECT e.id, e.data FROM services s RIGHT JOIN events e ON s.service_id = e.service_id WHERE e.id > %s AND %s %s e.valid = 1 LIMIT %s"%(str(idor0),sqlwhere_string,and_op,str(count)))
row=self.crs.fetchall()
row=self.crs.fetchall()
ifrow:
ifrow:
...
@@ -415,14 +419,11 @@ class MySQL(Object):
...
@@ -415,14 +419,11 @@ class MySQL(Object):
else:
else:
maxid=self.getLastEventId()
maxid=self.getLastEventId()
# logging.debug("MAX ID = %s", str(maxid))
events=[json.loads(r["data"])forrinrow]
#for r in row:
# logging.debug(json.loads(r["data"]))
return{
return{
"lastid":maxid,
"lastid":maxid,
# "lastid": row[-1]['id'] if row else str(id),
"events":events
"events":[json.loads(r["data"])forrinrow]
}
}
...
@@ -455,8 +456,8 @@ class MySQL(Object):
...
@@ -455,8 +456,8 @@ class MySQL(Object):
definsertLastReceivedId(self,client,id):
definsertLastReceivedId(self,client,id):
logging.debug("INSERT INTO last_events(client_id, event_id, timestamp) VALUES(%s, %s, NOW())"%(str(client["id"]),id))
logging.debug("insertLastReceivedId: id %i for client %i(%s)"%(id,client["id"],client["hostname"]))
self.crs.execute("INSERT INTO last_events(client_id, event_id, timestamp) VALUES(%s, %s, NOW())"%(str(client["id"]),id))
self.crs.execute("INSERT INTO last_events(client_id, event_id, timestamp) VALUES(%s, %s, NOW())",(client["id"],id))
defgetLastEventId(self):
defgetLastEventId(self):
self.crs.execute("SELECT MAX(id) as id FROM events")
self.crs.execute("SELECT MAX(id) as id FROM events")
...
@@ -465,16 +466,13 @@ class MySQL(Object):
...
@@ -465,16 +466,13 @@ class MySQL(Object):
returnrow['id']ifrow['id']isnotNoneelse0
returnrow['id']ifrow['id']isnotNoneelse0
defgetLastReceivedId(self,client):
defgetLastReceivedId(self,client):
client_id=client["id"]
self.crs.execute("SELECT MAX(event_id) as id FROM last_events WHERE client_id = %s",client["id"])