[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a
olivierHa
olivier.hanesse at gmail.com
Tue Feb 28 22:17:57 UTC 2012
The following commit has been merged in the debian/master branch:
commit 008434737c86393e423e72f294d63728ca843e3a
Author: olivierHa <olivier.hanesse at gmail.com>
Date: Wed Feb 1 14:52:37 2012 +0100
Enh: Add host/service dependencies and contactgroups
diff --git a/etc/shinken-specific.cfg b/etc/shinken-specific.cfg
index 3ccac09..5a57a1f 100755
--- a/etc/shinken-specific.cfg
+++ b/etc/shinken-specific.cfg
@@ -590,12 +590,11 @@ define module{
}
-# Hosts and Services configuration can be pulled from a MySQL database
-# All hosts and services read from the database will be added to the others of the
+# Hosts, Services, Contacts and Dependencies configuration can be pulled from a MySQL database
+# All hosts,services,contacts and dependencies read from the database will be added to the others of the
# standard flat file
-# You can easily use an existing database, you just have to define the queries.
+# You can easily use an existing database, you just have to define the queries to suit your database
# It can be a useful module to use for HA too :)
-# Warning : only for hosts and services
define module{
module_name MySQLImport
module_type mysql_import
@@ -606,6 +605,10 @@ define module{
reqhosts SELECT host_name, alias, realm, address ,template AS 'use' FROM hosts
reqservices SELECT host_name, service_description, normal_check_interval, check_command ,template AS 'use' FROM services
reqcontacts SELECT contact_name, email, template AS 'use' FROM contacts
+ reqcontactgroups SELECT contactgroup_name, members FROM contactgroups
+ reqhostdependencies SELECT host_name, dependent_host_name, notification_failure_criteria FROM hostdependencies
+ reqservicedependencies SELECT host_name, service_description, dependent_host_name, dependent_service_description, execution_failure_criteria, notification_failure_criteria FROM servicedependencies
+
}
# Will "tag" hosts by looking at their hostadress, and find the IP
@@ -642,12 +645,13 @@ define arbiter{
# List of interesting modules :
# CommandFile : open the named pipe nagios.cmd
-# Mongodb : load hosts from a mongodb database
+# Mongodb : load hosts from a mongodb database
# PickleRetentionArbiter : save data before exiting
# NSCA : NSCA server
# VMWare_auto_linking : lookup at Vphere server for dependencies
# GLPI : import hosts from GLPI
# TSCA : TSCA server
+# MySQLImport : load configuration from a MySQL database
# Uncomment these lines in a HA architecture so the master
diff --git a/shinken/modules/mysql_import_arbiter.py b/shinken/modules/mysql_import_arbiter.py
index 944ac90..cbf519b 100644
--- a/shinken/modules/mysql_import_arbiter.py
+++ b/shinken/modules/mysql_import_arbiter.py
@@ -16,7 +16,7 @@
#
#You should have received a copy of the GNU Affero General Public License
#along with Shinken. If not, see <http://www.gnu.org/licenses/>.
-
+
#This module imports hosts and services configuration from a MySQL Database
#Queries for getting hosts and services are pulled from shinken-specific.cfg configuration file.
@@ -39,24 +39,26 @@ def get_instance(plugin):
login = plugin.login
password = plugin.password
database = plugin.database
- reqhosts = getattr(plugin, 'reqhosts', None)
- reqservices = getattr(plugin, 'reqservices', None)
- reqcontacts = getattr(plugin, 'reqcontacts', None)
-
- instance = MySQL_importer_arbiter(plugin, host, login, password, database,reqhosts,reqservices, reqcontacts)
+ reqlist = {}
+ reqlist['hosts'] = getattr(plugin, 'reqhosts', None)
+ reqlist['services'] = getattr(plugin, 'reqservices', None)
+ reqlist['contacts'] = getattr(plugin, 'reqcontacts', None)
+ reqlist['contactgroups'] = getattr(plugin, 'reqcontactgroups', None)
+ reqlist['hostdependencies'] = getattr(plugin, 'reqhostdependencies', None)
+ reqlist['servicedependencies'] = getattr(plugin, 'reqservicedependencies', None)
+
+ instance = MySQL_importer_arbiter(plugin, host, login, password, database, reqlist)
return instance
#Retrieve hosts from a MySQL database
class MySQL_importer_arbiter(BaseModule):
- def __init__(self, mod_conf, host, login, password, database, reqhosts,reqservices, reqcontacts):
+ def __init__(self, mod_conf, host, login, password, database, reqlist):
BaseModule.__init__(self, mod_conf)
self.host = host
self.login = login
self.password = password
self.database = database
- self.reqhosts = reqhosts
- self.reqservices = reqservices
- self.reqcontacts = reqcontacts
+ self.reqlist = reqlist
#Called by Arbiter to say 'let's prepare yourself guy'
@@ -71,75 +73,44 @@ class MySQL_importer_arbiter(BaseModule):
print "MySQL Module : Error %d: %s" % (e.args[0], e.args[1])
raise
print "[MySQL Importer Module] : Connection opened"
-
-
+
+
#Main function that is called in the CONFIGURATION phase
def get_objects(self):
if not hasattr(self, 'conn'):
print "[MySQL Importer Module] : Problem during init phase"
return {}
-
- r = {'hosts' : []}
- r['services'] = []
- r['contacts'] = []
- result_set = {}
-
+
+ #Create variables for result
+ r = {}
+
cursor = self.conn.cursor (MySQLdb.cursors.DictCursor)
- if self.reqhosts:
- print "[MySQL Importer Module] : getting hosts configuration from database"
- try:
- cursor.execute (self.reqhosts)
- result_set = cursor.fetchall ()
- except MySQLdb.Error, e:
- print "MySQL Module : Error %d: %s" % (e.args[0], e.args[1])
-
- for row in result_set:
- h = {}
- for column in row:
- if row[column]:
- h[column]= row[column]
- r['hosts'].append(h)
-
- if self.reqservices:
- print "[MySQL Importer Module] : getting services configuration from database"
-
-
- try:
- cursor.execute (self.reqservices)
- result_set = cursor.fetchall ()
- except MySQLdb.Error, e:
- print "MySQL Module : Error %d: %s" % (e.args[0], e.args[1])
-
- for row in result_set:
- h = {}
- for column in row:
- if row[column]:
- h[column]= row[column]
- r['services'].append(h)
-
- cursor.close ()
- self.conn.close ()
- del self.conn
-
- if self.reqcontacts:
- print "[MySQL Importer Module] : getting contacts configuration from database"
-
- try:
- cursor.execute (self.reqcontacts)
- result_set = cursor.fetchall ()
- except MySQLdb.Error, e:
- print "MySQL Module : Error %d: %s" % (e.args[0], e.args[1])
-
- for row in result_set:
- c = {}
- for column in row:
- if row[column]:
- c[column]= row[column]
- r['contacts'].append(c)
-
- cursor.close ()
- self.conn.close ()
- del self.conn
-
+
+ #For all parameters
+ for k,v in self.reqlist.iteritems():
+ r[k] = []
+
+ if(v != None):
+ result_set = {}
+ print "[MySQL Importer Module] : getting %s configuration from database" % (k)
+
+ try:
+ cursor.execute (v)
+ result_set = cursor.fetchall ()
+ except MySQLdb.Error, e:
+ print "MySQL Module : Error %d: %s" % (e.args[0], e.args[1])
+
+ #Create set whith result
+ for row in result_set:
+ h = {}
+ for column in row:
+ if row[column]:
+ h[column]= row[column]
+ r[k].append(h)
+
+ cursor.close ()
+ self.conn.close ()
+ del self.conn
+
print "[MySQL Importer Module] : Returning to Arbiter the object:", r
return r
--
UNNAMED PROJECT
More information about the Pkg-nagios-changes
mailing list