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

Sebastien Coavoux s.coavoux at free.fr
Tue Feb 28 22:05:10 UTC 2012


The following commit has been merged in the debian/master branch:
commit 69e7b07c15d95d430faaef1740e50e33968becd8
Author: Sebastien Coavoux <s.coavoux at free.fr>
Date:   Mon Sep 26 20:49:00 2011 +0200

    Starting to handle exception in Mysql module

diff --git a/shinken/db_mysql.py b/shinken/db_mysql.py
index 08a4f82..d3457af 100644
--- a/shinken/db_mysql.py
+++ b/shinken/db_mysql.py
@@ -28,6 +28,8 @@ import MySQLdb
 from MySQLdb import IntegrityError
 from MySQLdb import ProgrammingError
 
+#Do we need?
+import _mysql_exceptions
 
 class DBMysql(DB):
     def __init__(self, host, user, password, database, character_set, table_prefix = ''):
@@ -41,16 +43,24 @@ class DBMysql(DB):
 
     #Create the database connection
     #TODO : finish (begin :) ) error catch and conf parameters...
+    #Import to catch exception
     def connect_database(self):
-        #self.db = MySQLdb.connect (host = "localhost", user = "root", passwd = "root", db = "merlin")
-        self.db = MySQLdb.connect (host = self.host, user = self.user, \
+        
+       try :
+            self.db = MySQLdb.connect (host = self.host, user = self.user, \
                                        passwd = self.password, db = self.database)
-        self.db.set_character_set(self.character_set)
-        self.db_cursor = self.db.cursor ()
-        self.db_cursor.execute('SET NAMES %s;' % self.character_set)
-        self.db_cursor.execute('SET CHARACTER SET %s;' % self.character_set)
-        self.db_cursor.execute('SET character_set_connection=%s;' % self.character_set)
-        #Thanks http://www.dasprids.de/blog/2007/12/17/python-mysqldb-and-utf-8 for utf8 code :)
+            
+            self.db.set_character_set(self.character_set)
+            self.db_cursor = self.db.cursor ()
+            self.db_cursor.execute('SET NAMES %s;' % self.character_set)
+            self.db_cursor.execute('SET CHARACTER SET %s;' % self.character_set)
+            self.db_cursor.execute('SET character_set_connection=%s;' % self.character_set)
+           #Thanks http://www.dasprids.de/blog/2007/12/17/python-mysqldb-and-utf-8 for utf8 code :)
+
+       except _mysql_exceptions.OperationalError as exp:
+            print "[MysqlDB] Module raise an exception : %s . Please check the arguments!" % exp
+            #Do we need?
+            #exit()
 
 
     #Just run the query
diff --git a/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker.py b/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker.py
index 6fe0dfb..38b52a3 100644
--- a/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker.py
+++ b/shinken/modules/ndodb_mysql_broker/ndodb_mysql_broker.py
@@ -28,6 +28,7 @@ import copy
 import time
 import sys
 
+
 properties = {
     'daemons' : ['broker'],
     'type' : 'ndodb_mysql',
@@ -37,6 +38,9 @@ properties = {
 
 from shinken.db_mysql import DBMysql
 from shinken.basemodule import BaseModule
+#Do we need?
+import _mysql_exceptions
+
 
 def de_unixify(t):
     return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t))
@@ -109,8 +113,14 @@ class Ndodb_Mysql_broker(BaseModule):
     #Create the database connection
     #TODO : finish (begin :) ) error catch and conf parameters...
     def connect_database(self):
-        self.db.connect_database()
-
+    
+        try :
+            self.db.connect_database()
+            
+        except _mysql_exceptions.OperationalError as exp:
+            print "[MysqlDB] Module raise an exception : %s . Please check the arguments!" % exp
+            #Do we need?
+            #exit         
 
 
     def get_instance_id(self):

-- 
UNNAMED PROJECT



More information about the Pkg-nagios-changes mailing list