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

Naparuba naparuba at gmail.com
Tue Feb 28 22:14:50 UTC 2012


The following commit has been merged in the debian/master branch:
commit 148d1655a7a05d2bb2d9f892902ec8bda19eb9bc
Author: Naparuba <naparuba at gmail.com>
Date:   Thu Jan 19 16:17:07 2012 +0100

    Add : mongodb module for the arbiter, to load hosts object from it.

diff --git a/etc/shinken-specific.cfg b/etc/shinken-specific.cfg
index 72f8902..fb676af 100755
--- a/etc/shinken-specific.cfg
+++ b/etc/shinken-specific.cfg
@@ -610,9 +610,18 @@ define arbiter{
        address		localhost   ;IP or DNS adress
        port		7770
        spare		0
-#      uncomment the line below if you want to use the GLPI and NSCA modules
-#      modules		CommandFile,GLPIImport, NSCA, VMWare_auto_linking, TSCA
-       modules		NSCA
+#      uncomment the line below if you want to use some modules for your arbiter
+#      modules		CommandFile, Mongodb, NSCA, VMWare_auto_linking
+
+# List of interesting modules :
+#  CommandFile              : open the named pipe nagios.cmd
+#  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
+
 
 #      Uncomment these lines in a HA architecture so the master
 #      and slaves know how long they may wait for each other
@@ -622,14 +631,6 @@ define arbiter{
 #       max_check_attempts      3     ;  if at least max_check_attempts ping failed, the node is DEAD
 
 
-
-# List of interesting modules :
-#  CommandFile              : open the named pipe nagios.cmd
-#  PickleRetentionArbiter   : save data before exiting
-#  NSCA                     : NSCA server
-#  VMWare_auto_linking      : lookup at Vphere server for dependencies
-#  GLPIImport               : import hosts from GLPI
-#  TSCA                     : TSCA server
        }
 
 
diff --git a/shinken/modules/mongodb_arbiter.py b/shinken/modules/mongodb_arbiter.py
new file mode 100644
index 0000000..34b3ba5
--- /dev/null
+++ b/shinken/modules/mongodb_arbiter.py
@@ -0,0 +1,90 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#Copyright (C) 2009 Gabes Jean, naparuba at gmail.com
+#
+#This file is part of Shinken.
+#
+#Shinken is free software: you can redistribute it and/or modify
+#it under the terms of the GNU Affero General Public License as published by
+#the Free Software Foundation, either version 3 of the License, or
+#(at your option) any later version.
+#
+#Shinken is distributed in the hope that it will be useful,
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#GNU Affero General Public License for more details.
+#
+#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 job is to get configuration data (mostly hosts) from a mongodb database.
+"""
+
+#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.
+
+from pymongo.connection import Connection
+
+from shinken.basemodule import BaseModule
+
+
+properties = {
+    'daemons' : ['arbiter'],
+    'type' : 'mongodb',
+    'external' : False,
+    'phases' : ['configuration'],
+}
+
+# called by the plugin manager to get a module instance
+def get_instance(plugin):
+    print "[MongoDB Importer Module] : Get Mongodb importer instance for plugin %s" % plugin.get_name()
+    server   = plugin.server
+    database = plugin.database
+
+    instance = Mongodb_arbiter(plugin, server, database)
+    return instance
+
+# Retrieve hosts from a Mongodb
+class Mongodb_arbiter(BaseModule):
+    def __init__(self, mod_conf, server, database):
+        BaseModule.__init__(self, mod_conf)
+        self.server     = server
+        self.database   = database
+        # Some used varaible init
+        self.con = None
+        self.db = None
+
+
+    # Called by Arbiter to say 'let's prepare yourself guy'
+    def init(self):
+        print "[Mongodb Importer Module] : Try to open a Mongodb connection to %s:%s" % (self.server, self.database)
+        try:
+            self.con = Connection(self.server)
+            self.db = getattr(self.con, self.database)
+        except Exception, e:
+            print "Mongodb Module : Error %s:" % e
+            raise
+        print "[Mongodb Importer Module] : Connection OK"
+
+
+    # Main function that is called in the CONFIGURATION phase
+    def get_objects(self):
+        if not self.db:
+            print "[Mongodb Importer Module] : Problem during init phase"
+            return {}
+
+        r = {'hosts' : []}
+
+        cur = self.db.hosts.find({})
+        for h in cur:
+            print "DBG: mongodb: get host", h
+            # We remove a mongodb specific property, the _id
+            del h['_id']
+            # And we add an imported_from property to say it came from
+            # mongodb
+            h['imported_from'] = 'mongodb:%s:%s' % (self.server, self.database)
+            r['hosts'].append(h)
+
+        return r
diff --git a/shinken/webui/plugins_skonf/newhosts/newhosts.py b/shinken/webui/plugins_skonf/newhosts/newhosts.py
index a736883..fb21dc4 100644
--- a/shinken/webui/plugins_skonf/newhosts/newhosts.py
+++ b/shinken/webui/plugins_skonf/newhosts/newhosts.py
@@ -101,10 +101,13 @@ def post_validatehost():
     print "Got forms in /newhosts/validatehost call"
     _id = app.request.forms.get('_id', 'unknown-host')
     tags = app.request.forms.get('tags', '')
-    host_name = app.request.forms.get('host_name', 'unamed')
+    host_name = app.request.forms.get('host_name', None)
 
     print "DUMP FORMS", app.request.forms
     print "Got in request form", _id, host_name, tags
+    if not host_name:
+        print "BAD HOST NAME for post_validatehost bail out"
+        return None
 
     host = {'_id' : _id, 'host_name' : host_name, 'use' : tags}
     print "Saving", host, "in", app.db.hosts
@@ -116,7 +119,7 @@ def post_validatehost():
     r = app.db.discovered_hosts.remove({'_id' : _id})
     print "result", r
 
-    return None#{'app' : app}
+    return None
 
 
 
diff --git a/shinken/webui/plugins_skonf/newhosts/views/newhosts_results.tpl b/shinken/webui/plugins_skonf/newhosts/views/newhosts_results.tpl
index 77dafa3..640cdde 100644
--- a/shinken/webui/plugins_skonf/newhosts/views/newhosts_results.tpl
+++ b/shinken/webui/plugins_skonf/newhosts/views/newhosts_results.tpl
@@ -18,8 +18,8 @@
 	 <span class="row">
 	   <input name="_id" type="hidden" value="{{h['_id']}}"/>
 	   <span class="cell">
-             <label for="hostname">Hostname:</label>
-             <input name="hostname" type="text" tabindex="1" value="{{h['host_name']}}" id="form-host_name-{{h['host_name']}}"/>
+             <label for="host_name">Hostname:</label>
+             <input name="host_name" type="text" tabindex="1" value="{{h['host_name']}}" id="form-host_name-{{h['host_name']}}"/>
            </span>
 	   <span class="cell">
 	     <label for="tags">Tags:</label>

-- 
UNNAMED PROJECT



More information about the Pkg-nagios-changes mailing list