Fix : get back LiveStatus as default.
[shinken.git] / shinken / modules / glpi_import_arbiter.py
blobff8127c5cf45d24c355ba081af1c8ce9c9d057a9
1 #!/usr/bin/python
2 #Copyright (C) 2009 Gabes Jean, naparuba@gmail.com
4 #This file is part of Shinken.
6 #Shinken is free software: you can redistribute it and/or modify
7 #it under the terms of the GNU Affero General Public License as published by
8 #the Free Software Foundation, either version 3 of the License, or
9 #(at your option) any later version.
11 #Shinken is distributed in the hope that it will be useful,
12 #but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 #GNU Affero General Public License for more details.
16 #You should have received a copy of the GNU Affero General Public License
17 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
20 #This Class is a plugin for the Shinken Arbiter. It connect to
21 #a GLPI with webservice (xmlrpc, SOAP is garbage) and take all
22 #hosts. Simple way from now
25 import xmlrpclib
27 from shinken.basemodule import BaseModule
29 #This text is print at the import
30 print "Detected module : GLPI importer for Arbiter"
33 properties = {
34 'type' : 'glpi_import',
35 'external' : False,
36 'phases' : ['configuration'],
40 #called by the plugin manager to get a broker
41 def get_instance(plugin):
42 print "Get a Simple GLPI importer arbiter for plugin %s" % plugin.get_name()
43 uri = plugin.uri
44 login_name = plugin.login_name
45 login_password = plugin.login_password
46 if hasattr(plugin, 'use_property'):
47 use_property = plugin.use_property
48 else:
49 use_property = 'otherserial'
50 instance = Glpi_importer_arbiter(plugin, uri, login_name, login_password, use_property)
51 return instance
55 #Just get hostname from a GLPI webservices
56 class Glpi_importer_arbiter(BaseModule):
57 def __init__(self, mod_conf, uri, login_name, login_password, use_property):
58 BaseModule.__init__(self, mod_conf)
59 self.uri = uri
60 self.login_name = login_name
61 self.login_password = login_password
62 self.use_property = use_property
65 #Called by Arbiter to say 'let's prepare yourself guy'
66 def init(self):
67 print "I open the GLPI connexion to %s" % self.uri
68 self.con = xmlrpclib.ServerProxy(self.uri)
69 print "Connexion opened"
70 print "Authentification in progress"
71 arg = {'login_name' : self.login_name , 'login_password' : self.login_password}
72 res = self.con.glpi.doLogin(arg)
73 self.session = res['session']
74 print "My session number", self.session
77 #Ok, main function that will load hosts from GLPI
78 def get_objects(self):
79 r = {'hosts' : []}
80 arg = {'session' : self.session}
81 all_hosts = self.con.glpi.listComputers(arg)
82 print "Get all hosts", all_hosts
83 for host in all_hosts:
84 print "\n\n"
85 print "Host info in GLPI", host
86 arg = {'session' : self.session, 'computer' : host['id']}
87 host_info = self.con.glpi.getComputer(arg)
88 print "Host info", host_info
89 h = {'host_name' : host_info['name'],
90 'alias' : host_info['name'],
91 'address' : host_info['name'],
93 #Then take use only if there is a value inside
94 if host_info[self.use_property] != '':
95 h['use'] = host_info[self.use_property]
97 r['hosts'].append(h)
98 print "Returning to Arbiter the hosts:", r
99 return r