Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load more config from MongoDB #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
from pymongo import ReplicaSetConnection, ReadPreference
except ImportError:
ReplicaSetConnection = None
ReadPreference = None
ReadPreference = None

from shinken.basemodule import BaseModule
from shinken.log import logger

Expand All @@ -66,7 +66,7 @@ def get_instance(plugin):
username = getattr(plugin, 'username', '')
password = getattr(plugin, 'password', '')
replica_set = getattr(plugin, 'replica_set', '')

instance = Mongodb_generic(plugin, uri, database, username, password, replica_set)
return instance

Expand All @@ -86,8 +86,8 @@ def __init__(self, mod_conf, uri, database, username, password, replica_set):
'replica_set because your pymongo lib is too old. '
'Please install it with a 2.x+ version from '
'https://github.com/mongodb/mongo-python-driver/downloads')
return None
return None

# Some used variable init
self.con = None
self.db = None
Expand All @@ -106,7 +106,7 @@ def init(self):
else:
self.con = Connection(self.uri)
# END

self.db = getattr(self.con, self.database)
if self.username != '' and self.password != '':
self.db.authenticate(self.username, self.password)
Expand All @@ -125,7 +125,16 @@ def get_objects(self):

r = {}

tables = ['hosts', 'services', 'contacts', 'commands', 'timeperiods']
tables = ['hosts',
'services',
'contacts',
'commands',
'timeperiods'
'contactgroups',
'hostgroups',
'servicegroups',
'realms',
'timeperiods']
for t in tables:
r[t] = []

Expand All @@ -145,7 +154,7 @@ def get_objects(self):
def get_uniq_id(self, t, i):
#by default we will return a very uniq id
u = str(int(uuid.uuid4().int))

is_tpl = (getattr(i, 'register', '1') == '0')
if is_tpl:
return 'tpl-%s' % getattr(i, 'name', u)
Expand All @@ -165,7 +174,7 @@ def get_uniq_id(self, t, i):

print "Unknown TYPE in migration!"
return u



# Function called by the arbiter so we import the objects in our databases
Expand All @@ -179,7 +188,7 @@ def import_objects(self, data):
logger.error("Your python version is too old. Please update to a 2.6 version to use this feature")
return False


for t in data:
col = getattr(self.db, t)
print "Saving objects %s" % t
Expand All @@ -188,10 +197,10 @@ def import_objects(self, data):
print "Element", e
e['_id'] = self.get_uniq_id(t, e)
col.save(e)


return True



#################################### WebUI parts ############################
Expand All @@ -212,10 +221,10 @@ def get_ui_common_preference(self, key):
return None

return e.get(key)

# We will get in the mongodb database the user preference entry, and get the key
# they are asking us

def get_ui_user_preference(self, user, key):
if not self.db:
print "[Mongodb]: error Problem during init phase"
Expand Down