[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a
Sebastien Coavoux
s.coavoux at free.fr
Tue Feb 28 22:05:06 UTC 2012
The following commit has been merged in the debian/master branch:
commit cee34589eaaf5199db0f406ef393a68bc3ea552a
Author: Sebastien Coavoux <s.coavoux at free.fr>
Date: Mon Sep 26 17:11:39 2011 +0200
Trying to handle mutiple acces to database
diff --git a/etc/shinken-specific.cfg b/etc/shinken-specific.cfg
old mode 100644
new mode 100755
index 55e1089..2774126
--- a/etc/shinken-specific.cfg
+++ b/etc/shinken-specific.cfg
@@ -63,7 +63,6 @@ define poller{
}
-
# Poller can have a nrpe module : commands tagged with
# nrpe_poller as module_type will be managed by this module.
# it will bypass the launch of check_nrpe, and will do the
@@ -106,8 +105,7 @@ define broker{
spare 0
# Which modules to load? LiveSatus and logs by default.
- modules Livestatus, Simple-log, WebUI
-
+ modules Simple-log, ToNdodb_Mysql, Service-Perfdata
# Other interesting modules to add :
# PickleRetentionBroker : save data when quitting
@@ -157,55 +155,7 @@ define module{
module_type webui
host 0.0.0.0 ; mean all interfaces
- port 7767
-
- # CHANGE THIS VALUE!!!!!!!
- auth_secret CHANGE_ME
-
-
- # Advanced options. Do not touch it if you don't
- # know what you are doing
-
- #http_backend wsgiref
- # ; can be also : cherrypy, paste, tornado, twisted
- # ; or gevent
-
- modules Apache_passwd,ActiveDir_UI,Cfg_password
- # Modules for the WebUI.
-
-}
-
-#The log managment for ALL daemons (all in one log, cool isn't it? ).
-define module{
- module_name ActiveDir_UI
- module_type ad_webui
-
-# UNCOMMENT this line to really enable this module and allow it to
-# connect!
-# ldap_uri ldaps://myserver
- username user
- password password
- basedn DC=google,DC=com
-
-}
-
-
-#The log managment for ALL daemons (all in one log, cool isn't it? ).
-define module{
- module_name Apache_passwd
- module_type passwd_webui
-
- # WARNING : put the full PATH for this value!
- passwd /etc/shinken/htpasswd.users
-
-}
-
-
-#The log managment for ALL daemons (all in one log, cool isn't it? ).
-define module{
- module_name Cfg_password
- module_type cfg_password_webui
-
+ port 8080
}
@@ -217,16 +167,18 @@ define module{
define module{
module_name ToNdodb_Mysql
module_type ndodb_mysql
- database ndo ; database name
- user root ; user of the database
- password root ; must be changed
+ database NDO ; database name
+ user nagios ; user of the database
+ password nagios ; must be changed
host localhost ; host to connect to
character_set utf8 ;optionnal, UTF8 is the default
# If you want to mix Shinken AND Nagios/icinga in the same db
- # you need to offset shinken instance id so they will not
- # override/delete other ones. Here for 5 nagios box.
- # nagios_mix_offset 5
+ # 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)
+ synchronise_database_id 1
}
@@ -492,20 +444,12 @@ define module{
#hostname of your machine !!!!
define arbiter{
arbiter_name Arbiter-Master
-# host_name node1 ;result of the hostname command under Unix
- address localhost ;IP or DNS adress
+ host_name ubs-pc ;result of the hostname command under Unix
+ address localhost ;IP or DNS adress
port 7770
spare 0
# uncomment the line below if you want to use the GLPI module and the NSCA one
-# modules CommandFile,GLPIImport, NSCA, VMWare_auto_linking, TSCA
-
-# Uncomment theses lines in a HA architecture so the master
-# and slaves know how much time to wait the other
-# check_interval 60 ; ping it every minute
-# timeout 3 ; 'ping' timeout
-# data_timeout 120 ; 'data send' timeout
-# max_check_attempts 3 ; if at least max_check_attempts ping failed, the node is DEAD
-
+ modules CommandFile
# List of interesting modules :
@@ -550,3 +494,16 @@ define realm{
+
+###Now specific objects that allow easy change in the service/hots behavior
+
+#A result modulation is use to module a check result, like CRITICAL->WARNING here
+#define resultmodulation{
+# resultmodulation_name critical_is_warning ;required
+# exit_codes_match 2 ;optionnal, list of code to change
+# exit_code_modulation 1 ;code that will be put if the code match
+# modulation_period 24x7 ;period when to apply the modulation
+#}
+
+shinken_user=nagios
+shinken_group=nagios
diff --git a/shinken/modules/ndodb_mysql_broker/__init__.py b/shinken/modules/ndodb_mysql_broker/__init__.py
index 3cff48a..6167154 100644
--- a/shinken/modules/ndodb_mysql_broker/__init__.py
+++ b/shinken/modules/ndodb_mysql_broker/__init__.py
@@ -36,7 +36,8 @@ def get_instance(mod_conf):
if not hasattr( mod_conf, 'character_set'):
mod_conf.character_set = 'utf8'
- if not hasattr(mod_conf, 'nagios_mix_offset'):
- mod_conf.nagios_mix_offset = '0'
+ if not hasattr(mod_conf, 'synchronise_database_id'):
+ #TODO : Use a Boolean?
+ mod_conf.synchronise_database_id = '0'
instance = Ndodb_Mysql_broker(mod_conf)
return instance
diff --git a/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker.py b/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker.py
index 9f55ced..6fe0dfb 100644
--- a/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker.py
+++ b/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker.py
@@ -62,7 +62,7 @@ class Ndodb_Mysql_broker(BaseModule):
self.password = conf.password
self.database = conf.database
self.character_set = conf.character_set
- self.nagios_mix_offset = int(conf.nagios_mix_offset)
+ self.synchronise_database_id = int(conf.synchronise_database_id)
#Called by Broker so we can do init stuff
@@ -79,6 +79,9 @@ class Ndodb_Mysql_broker(BaseModule):
self.services_cache = {}
self.hosts_cache = {}
+ #Cache for database id
+ #In order not to query the database every time
+ self.database_id_cache={}
#Get a brok, parse it, and put in in database
#We call functions like manage_ TYPEOFBROK _brok that return us queries
@@ -88,11 +91,12 @@ class Ndodb_Mysql_broker(BaseModule):
# We've got problem with instance_id == 0 so we add 1 every where
if 'instance_id' in new_b.data:
- #For nagios mix install, move more than 1
- if self.nagios_mix_offset != 0:
- new_b.data['instance_id'] = new_b.data['instance_id'] + self.nagios_mix_offset
+ #For nagios mix install, we convert the id to write properly in the base
+ if self.synchronise_database_id == 1:
+ new_b.data['instance_id'] = self.convert_id(new_b.data['instance_id'])
else:
new_b.data['instance_id'] = new_b.data['instance_id'] + 1
+ print new_b.data
queries = BaseModule.manage_brok(self, new_b)
if queries is not None:
@@ -108,6 +112,33 @@ class Ndodb_Mysql_broker(BaseModule):
self.db.connect_database()
+
+ def get_instance_id(self):
+ query = u"SELECT max(instance_id) as ID from nagios_instances"
+ self.db.execute_query(query)
+ row = self.db.fetchone()
+
+ if len(row)<1:
+ return -1
+ #We are the first process writing in base
+ if row is None:
+ return 1
+ else:
+ return row[0]+1
+
+
+
+ def convert_id(self,id):
+ #Look if we have already encountered this id
+ if id in self.database_id_cache :
+ return self.database_id_cache[id]
+ else :
+ data_id = self.get_instance_id()
+ self.database_id_cache[id]=data_id
+ return data_id
+
+
+
def get_host_object_id_by_name(self, host_name):
#First look in cache.
if host_name in self.hosts_cache:
@@ -502,7 +533,7 @@ class Ndodb_Mysql_broker(BaseModule):
#Only the host is impacted
where_clause = {'host_object_id' : host_id}
- #Just update the host status
+ #Just update teh host status
hoststatus_data = {'next_check' : de_unixify(data['next_chk'])}
hoststatus_query = self.db.create_update_query('hoststatus' , hoststatus_data, where_clause)
--
UNNAMED PROJECT
More information about the Pkg-nagios-changes
mailing list