[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a

Sebastien Coavoux s.coavoux at free.fr
Tue Feb 28 22:06:26 UTC 2012


The following commit has been merged in the debian/master branch:
commit cb4919d472ba2d0b56a447791636581b7a6a76e2
Author: Sebastien Coavoux <s.coavoux at free.fr>
Date:   Wed Nov 16 23:13:50 2011 +0100

    Add : Multiple instance writing in the same NDO database. This try seems to work :)

diff --git a/etc/shinken-specific.cfg b/etc/shinken-specific.cfg
index 791f753..e3a462f 100755
--- a/etc/shinken-specific.cfg
+++ b/etc/shinken-specific.cfg
@@ -246,7 +246,7 @@ define module{
        # you need to synchronize shinken instance_id otherwise it
        # override/delete other ones.
        # Warning : This decrease performances because it query the db
-       # for every new instance id needed (one per scheduler)
+       # more often
        synchronise_database_id    1
 }
 
diff --git a/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker.py b/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker.py
index f758676..7650995 100644
--- a/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker.py
+++ b/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker.py
@@ -96,36 +96,10 @@ class Ndodb_Mysql_broker(BaseModule):
         new_b = copy.deepcopy(b)
     
         if 'instance_id' in new_b.data:
+            # We've got problem with instance_id == 0 so we add 1 every where
+            new_b.data['instance_id'] = new_b.data['instance_id'] + 1
             
-            if self.synchronise_database_id != 1:
-                # We've got problem with instance_id == 0 so we add 1 every where
-                new_b.data['instance_id'] = new_b.data['instance_id'] + 1
-            
-            #We have to synchronise database id
-            #so we wait for the instance name
-            elif 'instance_name' not in new_b.data :
-                self.todo.append(new_b)
-                #print("No instance name for %s : " % new_b.data)
-                return  
-                  
-            #We convert the id to write properly in the base using the 
-            #instance_name to reuse the instance_id in the base.
-            else:
-                new_b.data['instance_id'] = self.convert_id(new_b.data['instance_id'],new_b.data['instance_name'])
-                self.todo.append(new_b)
-                for brok in self.todo :
-                    #We have to put the good instance ID to all brok waiting
-                    #in the list then execute the query
-                    brok.data['instance_id']=new_b.data['instance_id']
-                    queries = BaseModule.manage_brok(self, brok)
-                    if queries is not None:
-                        for q in queries :
-                            self.db.execute_query(q)
-
-                self.todo=[]
-                return
-
-        #Executed if we don't synchronise or there is no instance_id
+
         queries = BaseModule.manage_brok(self,new_b)
         
         if queries is not None:
diff --git a/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker_sync.py b/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker_sync.py
index 2a5438d..ec627df 100644
--- a/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker_sync.py
+++ b/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker_sync.py
@@ -23,6 +23,12 @@
 #The managed_brok function is called by Broker for manage the broks. It calls
 #the manage_*_brok functions that create queries, and then run queries.
 
+#This Class is pretty much a copy from the Ndodb_Mysql_broker one.
+#It has been done to able multiple supervision process to write in the same
+#MySQL database. If your Shinken is alone this class won't be loaded at runtime.
+#This class is a bit more cpu consuming than the previous one, but cache are here to prevent
+#Shinken from querying the MySQL database too much ;)
+
 
 import copy
 import time
@@ -37,7 +43,7 @@ properties = {
 
 from shinken.db_mysql import DBMysql
 from shinken.basemodule import BaseModule
-#Do we need?	 	
+
 import _mysql_exceptions
 
 def de_unixify(t):
@@ -136,7 +142,7 @@ class Ndodb_Mysql_broker_sync(BaseModule):
 
 
     #Create the database connection
-    #TODO : finish (begin :) ) error catch and conf parameters...
+    #TODO : Choose a behavior when exception is catch
     def connect_database(self):
     
         try :
@@ -150,7 +156,7 @@ class Ndodb_Mysql_broker_sync(BaseModule):
 
             print "[MysqlDB] Module raise an exception : %s . Please check the arguments!" % exp
             #Do we need?
-            #exit 
+            #sys.exit(2) 
 
 
     def get_instance_id(self,name):
@@ -233,9 +239,9 @@ class Ndodb_Mysql_broker_sync(BaseModule):
             return row[0]
 
 
-    def get_hostgroup_id_by_id_sync(self, hostgp_obj_id, instance_id):
+    def get_max_hostgroup_id_sync(self):
  
-        query = u"SELECT hostgroup_id from nagios_hostgroups where hostgroup_object_id='%s' and instance_id='%s'" % (hostgp_obj_id,instance_id)
+        query = u"SELECT max(hostgroup_id) + 1 from nagios_hostgroups"
         self.db.execute_query(query)
         row = self.db.fetchone ()
         if row is None or len(row) < 1:
@@ -275,9 +281,9 @@ class Ndodb_Mysql_broker_sync(BaseModule):
             return row[0]
     
     
-    def get_servicegroup_id_by_id_sync(self, svcgp_obj_id, instance_id):
+    def get_max_servicegroup_id_sync(self):
  
-        query = u"SELECT servicegroup_id from nagios_servicegroups where servicegroup_object_id='%s' and instance_id='%s'" % (svcgp_obj_id,instance_id)
+        query = u"SELECT max(servicegroup_id) + 1 from nagios_servicegroups"
         self.db.execute_query(query)
         row = self.db.fetchone ()
         if row is None or len(row) < 1:
@@ -297,9 +303,9 @@ class Ndodb_Mysql_broker_sync(BaseModule):
         else:
             return row[0]
 
-    def get_contactgroup_id_by_id_sync(self, ctcgp_obj_id, instance_id):
+    def get_max_contactgroup_id_sync(self):
  
-        query = u"SELECT contactgroup_id from nagios_contactgroups where contactgroup_object_id='%s' and instance_id='%s'" % (ctcgp_obj_id,instance_id)
+        query = u"SELECT max(contactgroup_id) + 1 from nagios_contactgroups"
         self.db.execute_query(query)
         row = self.db.fetchone ()
         if row is None or len(row) < 1:
@@ -460,7 +466,7 @@ class Ndodb_Mysql_broker_sync(BaseModule):
         return [query, hoststatus_query]
 
 
-    #A host have just be create, database is clean, we INSERT it
+    #A service have just been created, database is clean, we INSERT it
     def manage_initial_service_status_brok(self, b):
         #new_b = copy.deepcopy(b)
 
@@ -541,9 +547,12 @@ class Ndodb_Mysql_broker_sync(BaseModule):
         self.db.execute_query(object_query)
 
         hostgroup_id = self.get_hostgroup_object_id_by_name_sync(data['hostgroup_name'],data['instance_id'])
-        hostgp_id = self.get_hostgroup_id_by_id_sync(hostgroup_id,data['instance_id'])
+        
+        #We can't get the id of the hostgroup in the base because we don't have inserted it yet!
+        #So we get a suitable id in this table an fix it for the hostgroup and hostgroup_member
+        hostgp_id = self.get_max_hostgroup_id_sync()
 
-        hostgroups_data = { 'instance_id' :  data['instance_id'],
+        hostgroups_data = { 'hostgroup_id' : hostgp_id, 'instance_id' :  data['instance_id'],
                            'config_type' : 0, 'hostgroup_object_id' : hostgroup_id,
                            'alias' : data['alias']
             }
@@ -578,11 +587,11 @@ class Ndodb_Mysql_broker_sync(BaseModule):
         self.db.execute_query(object_query)
 
         servicegroup_id = self.get_servicegroup_object_id_by_name_sync(data['servicegroup_name'],data['instance_id'])
-        svcgp_id = self.get_servicegroup_id_by_id_sync(servicegroup_id,data['instance_id'])
+        svcgp_id = self.get_max_servicegroup_id_sync()
         
 
 
-        servicegroups_data = {'instance_id' :  data['instance_id'],
+        servicegroups_data = {'servicegroup_id' : svcgp_id, 'instance_id' :  data['instance_id'],
                            'config_type' : 0, 'servicegroup_object_id' : servicegroup_id,
                            'alias' : data['alias']
             }
@@ -752,7 +761,7 @@ class Ndodb_Mysql_broker_sync(BaseModule):
         return [query, hoststatus_query]
 
 
-    #Ok the host is updated
+    #Ok the service is updated
     def manage_update_service_status_brok(self, b):
         data = b.data
 
@@ -837,9 +846,7 @@ class Ndodb_Mysql_broker_sync(BaseModule):
 
 
 
-    #A new host group? Insert it
-    #We need to do something for the members prop (host.id, host_name)
-    #They are for host_hostgroup table, with just host.id hostgroup.id
+    #A new contact group? Insert it
     def manage_initial_contactgroup_status_brok(self, b):
         data = b.data
 
@@ -851,9 +858,9 @@ class Ndodb_Mysql_broker_sync(BaseModule):
         self.db.execute_query(object_query)
 
         contactgroup_id = self.get_contactgroup_object_id_by_name_sync(data['contactgroup_name'],data['instance_id'])
-        ctcgp_id = self.get_contactgroup_id_by_id_sync(contactgroup_id, data['instance_id'])
+        ctcgp_id = self.get_max_contactgroup_id_sync()
 
-        contactgroups_data = { 'instance_id' :  data['instance_id'],
+        contactgroups_data = {'contactgroup_id' : ctcgp_id, 'instance_id' :  data['instance_id'],
                            'config_type' : 0,
                            'contactgroup_object_id' : contactgroup_id,
                            'alias' : data['alias']

-- 
UNNAMED PROJECT



More information about the Pkg-nagios-changes mailing list