<NME> glpi_arbiter.py
<BEF> ADDFILE
<MSG> Merge pull request #3 from ddurieux/master

Module arbiter load all configuration from GLPI (plugin monitoring) by webservice
<DFF> @@ -0,0 +1,171 @@
+#!/usr/bin/python
+#Copyright (C) 2011 Durieux David, d.durieux@siprossii.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 Class is a plugin for the Shinken Arbiter. It connect to
+#a GLPI with webservice (xmlrpc, SOAP is garbage) and take all
+#hosts. Simple way from now
+
+
+import xmlrpclib
+
+from shinken.basemodule import BaseModule
+
+#This text is print at the import
+print "Detected module : GLPI importer configuration for Arbiter"
+
+
+properties = {
+    'daemons' : ['arbiter'],
+    'type' : 'glpi',
+    'external' : False,
+    'phases' : ['configuration'],
+    }
+
+
+#called by the plugin manager to get a broker
+def get_instance(plugin):
+    print "Get a Simple GLPI arbiter for plugin %s" % plugin.get_name()
+    uri = plugin.uri
+    login_name = plugin.login_name
+    login_password = plugin.login_password
+    if hasattr(plugin, 'use_property'):
+        use_property = plugin.use_property
+    else:
+        use_property = 'otherserial'
+    instance = Glpi_arbiter(plugin, uri, login_name, login_password, use_property)
+    return instance
+
+
+
+#Just get hostname from a GLPI webservices
+class Glpi_arbiter(BaseModule):
+    def __init__(self, mod_conf, uri, login_name, login_password, use_property):
+        BaseModule.__init__(self, mod_conf)
+        self.uri = uri
+        self.login_name = login_name
+        self.login_password = login_password
+        self.use_property = use_property
+
+
+    #Called by Arbiter to say 'let's prepare yourself guy'
+    def init(self):
+        print "I open the GLPI connection to %s" % self.uri
+        self.con = xmlrpclib.ServerProxy(self.uri)
+        print "Connexion opened"
+        print "Authentification in progress"
+        arg = {'login_name' : self.login_name , 'login_password' : self.login_password}
+        res = self.con.glpi.doLogin(arg)
+        self.session = res['session']
+        print "My session number", self.session
+
+
+    #Ok, main function that will load hosts from GLPI
+    def get_objects(self):
+        r = {'commands' : [],
+             'timeperiods' : [],
+             'hosts' : [],
+             'contacts' : []}
+        arg = {'session' : self.session}
+
+        # Get commands
+        all_commands = self.con.monitoring.shinkenCommands(arg)
+        print "Get all commands", all_commands
+        for command_info in all_commands:
+            print "\n\n"
+            print "Command info in GLPI", command_info
+            h = {'command_name' : command_info['command_name'],
+                 'command_line' : command_info['command_line'],
+                 }
+
+            #Then take use only if there is a value inside
+            if command_info[self.use_property] != '':
+                h['use'] = command_info[self.use_property]
+
+            r['commands'].append(h)
+
+        # Get timeperiods
+        all_timeperiods = self.con.monitoring.shinkenTimeperiods(arg)
+        print "Get all timeperiods", all_timeperiods
+        for timeperiod_info in all_timeperiods:
+            print "\n\n"
+            print "Timeperiod info in GLPI", timeperiod_info
+            h = {'timeperiod_name' : timeperiod_info['timeperiod_name'],
+                 'sunday' : timeperiod_info['sunday'],
+                 'monday' : timeperiod_info['monday'],
+                 'tuesday' : timeperiod_info['tuesday'],
+                 'wednesday' : timeperiod_info['wednesday'],
+                 'thursday' : timeperiod_info['thursday'],
+                 'friday' : timeperiod_info['friday'],
+                 'saturday' : timeperiod_info['saturday'],
+                 }
+            #Then take use only if there is a value inside
+            if timeperiod_info[self.use_property] != '':
+                h['use'] = timeperiod_info[self.use_property]
+
+            r['timeperiods'].append(h)
+
+        # Get hosts
+        all_hosts = self.con.monitoring.shinkenHosts(arg)
+        print "Get all hosts", all_hosts
+        for host_info in all_hosts:
+            print "\n\n"
+            print "Host info in GLPI", host_info
+            h = {'host_name' : host_info['host_name'],
+                 'address' : host_info['address'],
+                 'parents' : host_info['parents'],
+                 'check_command' : host_info['check_command'],
+                 'check_interval' : host_info['check_interval'],
+                 'retry_interval' : host_info['retry_interval'],
+                 'max_check_attempts' : host_info['max_check_attempts'],
+                 'check_period' : host_info['check_period'],
+                 'contacts' : host_info['contacts'],
+                 }
+            #Then take use only if there is a value inside
+            if host_info[self.use_property] != '':
+                h['use'] = host_info[self.use_property]
+
+            r['hosts'].append(h)
+
+        # Get contacts
+        all_contacts = self.con.monitoring.shinkenContacts(arg)
+        print "Get all contacts", all_contacts
+        for contact_info in all_contacts:
+            print "\n\n"
+            print "Contact info in GLPI", contact_info
+            h = {'contact_name' : contact_info['contact_name'],
+                 'alias' : contact_info['alias'],
+                 'host_notifications_enabled' : contact_info['host_notifications_enabled'],
+                 'service_notifications_enabled' : contact_info['service_notifications_enabled'],
+                 'service_notification_period' : contact_info['service_notification_period'],
+                 'host_notification_period' : contact_info['host_notification_period'],
+                 'service_notification_options' : contact_info['service_notification_options'],
+                 'host_notification_options' : contact_info['host_notification_options'],
+                 'service_notification_commands' : contact_info['service_notification_commands'],
+                 'host_notification_commands' : contact_info['host_notification_commands'],
+                 'email' : contact_info['email'],
+                 'pager' : contact_info['pager'],
+                 }
+            #Then take use only if there is a value inside
+            if contact_info[self.use_property] != '':
+                h['use'] = contact_info[self.use_property]
+
+            r['contacts'].append(h)
+
+        #print "Returning to Arbiter the hosts:", r
+        return r

{'commit': 'diff --git a/etc/shinken-specific.cfg b/etc/shinken-specific.cfg\nindex 02974e35e..c206e4364 100644\n--- a/etc/shinken-specific.cfg\n+++ b/etc/shinken-specific.cfg\n@@ -343,6 +343,20 @@ define module{\n #\t\t\t   field in GLPI (Inventory number:  in the web interface)\n }\n \n+#You know GLPI? You can load all configuration from this app (\n+#with the webservices plugins for GLPI, in xmlrpc mode\n+# and with plugin monitoring for GLPI)\n+#All configuration read from this will be added to the others of the\n+#standard flat file\n+define module{\n+       module_name      GLPI\n+       module_type      glpi\n+       uri \t\thttp://localhost/glpi/plugins/webservices/xmlrpc.php\n+       login_name\tglpi\n+       login_password\tglpi\n+}\n+\n+\n #You know NSCA? You can send check results to shinken\n #using send_nsca command\n define module{\ndiff --git a/shinken/modules/glpi_arbiter.py b/shinken/modules/glpi_arbiter.py\nnew file mode 100644\nindex 000000000..e9204eb68\n--- /dev/null\n+++ b/shinken/modules/glpi_arbiter.py\n@@ -0,0 +1,171 @@\n+#!/usr/bin/python\n+#Copyright (C) 2011 Durieux David, d.durieux@siprossii.com\n+#\n+#This file is part of Shinken.\n+#\n+#Shinken is free software: you can redistribute it and/or modify\n+#it under the terms of the GNU Affero General Public License as published by\n+#the Free Software Foundation, either version 3 of the License, or\n+#(at your option) any later version.\n+#\n+#Shinken is distributed in the hope that it will be useful,\n+#but WITHOUT ANY WARRANTY; without even the implied warranty of\n+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+#GNU Affero General Public License for more details.\n+#\n+#You should have received a copy of the GNU Affero General Public License\n+#along with Shinken.  If not, see <http://www.gnu.org/licenses/>.\n+\n+\n+#This Class is a plugin for the Shinken Arbiter. It connect to\n+#a GLPI with webservice (xmlrpc, SOAP is garbage) and take all\n+#hosts. Simple way from now\n+\n+\n+import xmlrpclib\n+\n+from shinken.basemodule import BaseModule\n+\n+#This text is print at the import\n+print "Detected module : GLPI importer configuration for Arbiter"\n+\n+\n+properties = {\n+    \'daemons\' : [\'arbiter\'],\n+    \'type\' : \'glpi\',\n+    \'external\' : False,\n+    \'phases\' : [\'configuration\'],\n+    }\n+\n+\n+#called by the plugin manager to get a broker\n+def get_instance(plugin):\n+    print "Get a Simple GLPI arbiter for plugin %s" % plugin.get_name()\n+    uri = plugin.uri\n+    login_name = plugin.login_name\n+    login_password = plugin.login_password\n+    if hasattr(plugin, \'use_property\'):\n+        use_property = plugin.use_property\n+    else:\n+        use_property = \'otherserial\'\n+    instance = Glpi_arbiter(plugin, uri, login_name, login_password, use_property)\n+    return instance\n+\n+\n+\n+#Just get hostname from a GLPI webservices\n+class Glpi_arbiter(BaseModule):\n+    def __init__(self, mod_conf, uri, login_name, login_password, use_property):\n+        BaseModule.__init__(self, mod_conf)\n+        self.uri = uri\n+        self.login_name = login_name\n+        self.login_password = login_password\n+        self.use_property = use_property\n+\n+\n+    #Called by Arbiter to say \'let\'s prepare yourself guy\'\n+    def init(self):\n+        print "I open the GLPI connection to %s" % self.uri\n+        self.con = xmlrpclib.ServerProxy(self.uri)\n+        print "Connexion opened"\n+        print "Authentification in progress"\n+        arg = {\'login_name\' : self.login_name , \'login_password\' : self.login_password}\n+        res = self.con.glpi.doLogin(arg)\n+        self.session = res[\'session\']\n+        print "My session number", self.session\n+\n+\n+    #Ok, main function that will load hosts from GLPI\n+    def get_objects(self):\n+        r = {\'commands\' : [],\n+             \'timeperiods\' : [],\n+             \'hosts\' : [],\n+             \'contacts\' : []}\n+        arg = {\'session\' : self.session}\n+\n+        # Get commands\n+        all_commands = self.con.monitoring.shinkenCommands(arg)\n+        print "Get all commands", all_commands\n+        for command_info in all_commands:\n+            print "\\n\\n"\n+            print "Command info in GLPI", command_info\n+            h = {\'command_name\' : command_info[\'command_name\'],\n+                 \'command_line\' : command_info[\'command_line\'],\n+                 }\n+\n+            #Then take use only if there is a value inside\n+            if command_info[self.use_property] != \'\':\n+                h[\'use\'] = command_info[self.use_property]\n+\n+            r[\'commands\'].append(h)\n+\n+        # Get timeperiods\n+        all_timeperiods = self.con.monitoring.shinkenTimeperiods(arg)\n+        print "Get all timeperiods", all_timeperiods\n+        for timeperiod_info in all_timeperiods:\n+            print "\\n\\n"\n+            print "Timeperiod info in GLPI", timeperiod_info\n+            h = {\'timeperiod_name\' : timeperiod_info[\'timeperiod_name\'],\n+                 \'sunday\' : timeperiod_info[\'sunday\'],\n+                 \'monday\' : timeperiod_info[\'monday\'],\n+                 \'tuesday\' : timeperiod_info[\'tuesday\'],\n+                 \'wednesday\' : timeperiod_info[\'wednesday\'],\n+                 \'thursday\' : timeperiod_info[\'thursday\'],\n+                 \'friday\' : timeperiod_info[\'friday\'],\n+                 \'saturday\' : timeperiod_info[\'saturday\'],\n+                 }\n+            #Then take use only if there is a value inside\n+            if timeperiod_info[self.use_property] != \'\':\n+                h[\'use\'] = timeperiod_info[self.use_property]\n+\n+            r[\'timeperiods\'].append(h)\n+\n+        # Get hosts\n+        all_hosts = self.con.monitoring.shinkenHosts(arg)\n+        print "Get all hosts", all_hosts\n+        for host_info in all_hosts:\n+            print "\\n\\n"\n+            print "Host info in GLPI", host_info\n+            h = {\'host_name\' : host_info[\'host_name\'],\n+                 \'address\' : host_info[\'address\'],\n+                 \'parents\' : host_info[\'parents\'],\n+                 \'check_command\' : host_info[\'check_command\'],\n+                 \'check_interval\' : host_info[\'check_interval\'],\n+                 \'retry_interval\' : host_info[\'retry_interval\'],\n+                 \'max_check_attempts\' : host_info[\'max_check_attempts\'],\n+                 \'check_period\' : host_info[\'check_period\'],\n+                 \'contacts\' : host_info[\'contacts\'],\n+                 }\n+            #Then take use only if there is a value inside\n+            if host_info[self.use_property] != \'\':\n+                h[\'use\'] = host_info[self.use_property]\n+\n+            r[\'hosts\'].append(h)\n+\n+        # Get contacts\n+        all_contacts = self.con.monitoring.shinkenContacts(arg)\n+        print "Get all contacts", all_contacts\n+        for contact_info in all_contacts:\n+            print "\\n\\n"\n+            print "Contact info in GLPI", contact_info\n+            h = {\'contact_name\' : contact_info[\'contact_name\'],\n+                 \'alias\' : contact_info[\'alias\'],\n+                 \'host_notifications_enabled\' : contact_info[\'host_notifications_enabled\'],\n+                 \'service_notifications_enabled\' : contact_info[\'service_notifications_enabled\'],\n+                 \'service_notification_period\' : contact_info[\'service_notification_period\'],\n+                 \'host_notification_period\' : contact_info[\'host_notification_period\'],\n+                 \'service_notification_options\' : contact_info[\'service_notification_options\'],\n+                 \'host_notification_options\' : contact_info[\'host_notification_options\'],\n+                 \'service_notification_commands\' : contact_info[\'service_notification_commands\'],\n+                 \'host_notification_commands\' : contact_info[\'host_notification_commands\'],\n+                 \'email\' : contact_info[\'email\'],\n+                 \'pager\' : contact_info[\'pager\'],\n+                 }\n+            #Then take use only if there is a value inside\n+            if contact_info[self.use_property] != \'\':\n+                h[\'use\'] = contact_info[self.use_property]\n+\n+            r[\'contacts\'].append(h)\n+\n+        #print "Returning to Arbiter the hosts:", r\n+        return r\n', 'commit_subject': 'Merge pull request #3 from ddurieux/master', 'repo_name': 'naparuba/shinken', 'committer': {'name': 'Gabès Jean', 'email': 'c8e019fb2d4dd0d355144f4fa37aa9b8f4b57451@gmail.com', 'time_sec': '1306843921', 'tz_offset': '-420', 'date': {'seconds': '1306843921'}}, 'commit_tree': '053c26561172e7dd8efd5b1381afc5cd3e7d96eb', 'commit_message': 'Merge pull request #3 from ddurieux/master\n\nModule arbiter load all configuration from GLPI (plugin monitoring) by webservice', 'language_name': 'PHP', 'license': 'agpl-3.0', 'hunks': '@@ -0,0 +1,171 @@\n+#!/usr/bin/python\n+#Copyright (C) 2011 Durieux David, d.durieux@siprossii.com\n+#\n+#This file is part of Shinken.\n+#\n+#Shinken is free software: you can redistribute it and/or modify\n+#it under the terms of the GNU Affero General Public License as published by\n+#the Free Software Foundation, either version 3 of the License, or\n+#(at your option) any later version.\n+#\n+#Shinken is distributed in the hope that it will be useful,\n+#but WITHOUT ANY WARRANTY; without even the implied warranty of\n+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+#GNU Affero General Public License for more details.\n+#\n+#You should have received a copy of the GNU Affero General Public License\n+#along with Shinken.  If not, see <http://www.gnu.org/licenses/>.\n+\n+\n+#This Class is a plugin for the Shinken Arbiter. It connect to\n+#a GLPI with webservice (xmlrpc, SOAP is garbage) and take all\n+#hosts. Simple way from now\n+\n+\n+import xmlrpclib\n+\n+from shinken.basemodule import BaseModule\n+\n+#This text is print at the import\n+print "Detected module : GLPI importer configuration for Arbiter"\n+\n+\n+properties = {\n+    \'daemons\' : [\'arbiter\'],\n+    \'type\' : \'glpi\',\n+    \'external\' : False,\n+    \'phases\' : [\'configuration\'],\n+    }\n+\n+\n+#called by the plugin manager to get a broker\n+def get_instance(plugin):\n+    print "Get a Simple GLPI arbiter for plugin %s" % plugin.get_name()\n+    uri = plugin.uri\n+    login_name = plugin.login_name\n+    login_password = plugin.login_password\n+    if hasattr(plugin, \'use_property\'):\n+        use_property = plugin.use_property\n+    else:\n+        use_property = \'otherserial\'\n+    instance = Glpi_arbiter(plugin, uri, login_name, login_password, use_property)\n+    return instance\n+\n+\n+\n+#Just get hostname from a GLPI webservices\n+class Glpi_arbiter(BaseModule):\n+    def __init__(self, mod_conf, uri, login_name, login_password, use_property):\n+        BaseModule.__init__(self, mod_conf)\n+        self.uri = uri\n+        self.login_name = login_name\n+        self.login_password = login_password\n+        self.use_property = use_property\n+\n+\n+    #Called by Arbiter to say \'let\'s prepare yourself guy\'\n+    def init(self):\n+        print "I open the GLPI connection to %s" % self.uri\n+        self.con = xmlrpclib.ServerProxy(self.uri)\n+        print "Connexion opened"\n+        print "Authentification in progress"\n+        arg = {\'login_name\' : self.login_name , \'login_password\' : self.login_password}\n+        res = self.con.glpi.doLogin(arg)\n+        self.session = res[\'session\']\n+        print "My session number", self.session\n+\n+\n+    #Ok, main function that will load hosts from GLPI\n+    def get_objects(self):\n+        r = {\'commands\' : [],\n+             \'timeperiods\' : [],\n+             \'hosts\' : [],\n+             \'contacts\' : []}\n+        arg = {\'session\' : self.session}\n+\n+        # Get commands\n+        all_commands = self.con.monitoring.shinkenCommands(arg)\n+        print "Get all commands", all_commands\n+        for command_info in all_commands:\n+            print "\\n\\n"\n+            print "Command info in GLPI", command_info\n+            h = {\'command_name\' : command_info[\'command_name\'],\n+                 \'command_line\' : command_info[\'command_line\'],\n+                 }\n+\n+            #Then take use only if there is a value inside\n+            if command_info[self.use_property] != \'\':\n+                h[\'use\'] = command_info[self.use_property]\n+\n+            r[\'commands\'].append(h)\n+\n+        # Get timeperiods\n+        all_timeperiods = self.con.monitoring.shinkenTimeperiods(arg)\n+        print "Get all timeperiods", all_timeperiods\n+        for timeperiod_info in all_timeperiods:\n+            print "\\n\\n"\n+            print "Timeperiod info in GLPI", timeperiod_info\n+            h = {\'timeperiod_name\' : timeperiod_info[\'timeperiod_name\'],\n+                 \'sunday\' : timeperiod_info[\'sunday\'],\n+                 \'monday\' : timeperiod_info[\'monday\'],\n+                 \'tuesday\' : timeperiod_info[\'tuesday\'],\n+                 \'wednesday\' : timeperiod_info[\'wednesday\'],\n+                 \'thursday\' : timeperiod_info[\'thursday\'],\n+                 \'friday\' : timeperiod_info[\'friday\'],\n+                 \'saturday\' : timeperiod_info[\'saturday\'],\n+                 }\n+            #Then take use only if there is a value inside\n+            if timeperiod_info[self.use_property] != \'\':\n+                h[\'use\'] = timeperiod_info[self.use_property]\n+\n+            r[\'timeperiods\'].append(h)\n+\n+        # Get hosts\n+        all_hosts = self.con.monitoring.shinkenHosts(arg)\n+        print "Get all hosts", all_hosts\n+        for host_info in all_hosts:\n+            print "\\n\\n"\n+            print "Host info in GLPI", host_info\n+            h = {\'host_name\' : host_info[\'host_name\'],\n+                 \'address\' : host_info[\'address\'],\n+                 \'parents\' : host_info[\'parents\'],\n+                 \'check_command\' : host_info[\'check_command\'],\n+                 \'check_interval\' : host_info[\'check_interval\'],\n+                 \'retry_interval\' : host_info[\'retry_interval\'],\n+                 \'max_check_attempts\' : host_info[\'max_check_attempts\'],\n+                 \'check_period\' : host_info[\'check_period\'],\n+                 \'contacts\' : host_info[\'contacts\'],\n+                 }\n+            #Then take use only if there is a value inside\n+            if host_info[self.use_property] != \'\':\n+                h[\'use\'] = host_info[self.use_property]\n+\n+            r[\'hosts\'].append(h)\n+\n+        # Get contacts\n+        all_contacts = self.con.monitoring.shinkenContacts(arg)\n+        print "Get all contacts", all_contacts\n+        for contact_info in all_contacts:\n+            print "\\n\\n"\n+            print "Contact info in GLPI", contact_info\n+            h = {\'contact_name\' : contact_info[\'contact_name\'],\n+                 \'alias\' : contact_info[\'alias\'],\n+                 \'host_notifications_enabled\' : contact_info[\'host_notifications_enabled\'],\n+                 \'service_notifications_enabled\' : contact_info[\'service_notifications_enabled\'],\n+                 \'service_notification_period\' : contact_info[\'service_notification_period\'],\n+                 \'host_notification_period\' : contact_info[\'host_notification_period\'],\n+                 \'service_notification_options\' : contact_info[\'service_notification_options\'],\n+                 \'host_notification_options\' : contact_info[\'host_notification_options\'],\n+                 \'service_notification_commands\' : contact_info[\'service_notification_commands\'],\n+                 \'host_notification_commands\' : contact_info[\'host_notification_commands\'],\n+                 \'email\' : contact_info[\'email\'],\n+                 \'pager\' : contact_info[\'pager\'],\n+                 }\n+            #Then take use only if there is a value inside\n+            if contact_info[self.use_property] != \'\':\n+                h[\'use\'] = contact_info[self.use_property]\n+\n+            r[\'contacts\'].append(h)\n+\n+        #print "Returning to Arbiter the hosts:", r\n+        return r\n', 'addition_count': 171, 'deletion_count': 0, 'src_file': '/dev/null', 'tgt_file': 'b/shinken/modules/glpi_arbiter.py', 'file_extension': '.py', 'before_file': 'ADDFILE', 'message': 'Merge pull request #3 from ddurieux/master\n\nModule arbiter load all configuration from GLPI (plugin monitoring) by webservice', 'author_name': 'Gabès Jean', 'lang': 'py'}