[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a
Sebastien Coavoux
s.coavoux at free.fr
Tue Feb 28 22:05:29 UTC 2012
The following commit has been merged in the debian/master branch:
commit 217b0e5e40a9126b20b122884fc6e1d486a8d0dd
Author: Sebastien Coavoux <s.coavoux at free.fr>
Date: Wed Sep 28 21:52:15 2011 +0200
I give up for quering the database only once, I will do it properly with 2 queries
diff --git a/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker.py b/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker.py
index 55a4cb5..c4ce292 100644
--- a/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker.py
+++ b/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker.py
@@ -151,18 +151,26 @@ class Ndodb_Mysql_broker(BaseModule):
def get_instance_id(self,name):
- # query = u"SELECT max(instance_id) as ID from nagios_instances"
- query = u"SELECT min(instance_id) from nagios_instances where instance_id + 1 = (select max(instance_id) + 1 from nagios_instances ) or instance_name = '%s';" % name
- self.db.execute_query(query)
- row = self.db.fetchone()
+ query1 = u"SELECT max(instance_id) + 1 from nagios_instances"
+ query2 = u"SELECT instance_id from nagios_instances where instance_name = '%s';" % name
+
+ self.db.execute_query(query1)
+ row1 = self.db.fetchone()
- if len(row)<1:
+ self.db.execute_query(query2)
+ row2 = self.db.fetchone()
+
+ if len(row1)<1 || len(row2)<1 :
return -1
#We are the first process writing in base
- if row[0] is None:
+ elif row1[0] is None:
return 1
+ #No previous instance found return max
+ elif row2[0] is None:
+ return row1[0]
+ #Return the previous instance
else:
- return row[0]
+ return row2[0]
--
UNNAMED PROJECT
More information about the Pkg-nagios-changes
mailing list