3
# -*- coding: utf-8 -*-
5
# Copyright (C) 2009-2012:
6
# Gabes Jean, naparuba@gmail.com
7
# Gerhard Lausser, Gerhard.Lausser@consol.de
8
# Gregory Starck, g.starck@gmail.com
9
# Hartmut Goebel, h.goebel@goebel-consult.de
11
# This file is part of Shinken.
13
# Shinken is free software: you can redistribute it and/or modify
14
# it under the terms of the GNU Affero General Public License as published by
15
# the Free Software Foundation, either version 3 of the License, or
16
# (at your option) any later version.
18
# Shinken is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU Affero General Public License for more details.
23
# You should have received a copy of the GNU Affero General Public License
24
# along with Shinken. If not, see <http://www.gnu.org/licenses/>.
27
# This Class is a plugin for the Shinken Arbiter. It connect to
28
# a GLPI with webservice (xmlrpc, SOAP is garbage) and take all
29
# hosts. Simple way from now
33
from shinken.basemodule import BaseModule
34
from shinken.log import logger
37
'daemons': ['arbiter'],
40
'phases': ['configuration'],
44
# called by the plugin manager to get a broker
45
def get_instance(plugin):
46
logger.info("[GLPI Arbiter] Get a Simple GLPI arbiter for plugin %s" % plugin.get_name())
48
login_name = plugin.login_name
49
login_password = plugin.login_password
50
tag = getattr(plugin, 'tag', "")
51
instance = Glpi_arbiter(plugin, uri, login_name, login_password, tag)
55
# Just get hostname from a GLPI webservices
56
class Glpi_arbiter(BaseModule):
57
def __init__(self, mod_conf, uri, login_name, login_password, tag):
58
BaseModule.__init__(self, mod_conf)
60
self.login_name = login_name
61
self.login_password = login_password
64
# Called by Arbiter to say 'let's prepare yourself guy'
66
logger.info("[GLPI Arbiter] I open the GLPI connection to %s" % self.uri)
67
self.con = xmlrpclib.ServerProxy(self.uri)
68
logger.info("[GLPI Arbiter] Connection opened")
69
logger.info("[GLPI Arbiter] Authentification in progress")
70
arg = {'login_name': self.login_name, 'login_password': self.login_password}
71
res = self.con.glpi.doLogin(arg)
72
self.session = res['session']
73
logger.info("[GLPI Arbiter] My session number %s" % str(self.session))
75
# Ok, main function that will load config from GLPI
76
def get_objects(self):
82
arg = {'session': self.session,
86
all_commands = self.con.monitoring.shinkenCommands(arg)
87
logger.info("[GLPI Arbiter] Get all commands: %s" % str(all_commands))
88
for command_info in all_commands:
89
logger.info("[GLPI Arbiter] Command info in GLPI: %s" % str(command_info))
90
h = {'command_name': command_info['command_name'],
91
'command_line': command_info['command_line'],
93
r['commands'].append(h)
96
all_timeperiods = self.con.monitoring.shinkenTimeperiods(arg)
97
logger.info("[GLPI Arbiter] Get all timeperiods: %s" % str(all_timeperiods))
98
attributs = ['timeperiod_name', 'alias', 'sunday',
99
'monday', 'tuesday', 'wednesday',
100
'thursday', 'friday', 'saturday']
101
for timeperiod_info in all_timeperiods:
102
logger.info("[GLPI Arbiter] Timeperiod info in GLPI: %s" % str(timeperiod_info))
104
for attribut in attributs:
105
if attribut in timeperiod_info:
106
h[attribut] = timeperiod_info[attribut]
108
logger.debug("[GLPI Arbiter] Returning to Arbiter the timeperiods: %s " % str(h))
109
r['timeperiods'].append(h)
112
all_hosts = self.con.monitoring.shinkenHosts(arg)
113
logger.info("[GLPI Arbiter] Get all hosts %s" % str(all_hosts))
114
attributs = ['display_name', 'hostgroups', 'initial_state',
115
'active_checks_enabled', 'passive_checks_enabled', 'obsess_over_host',
116
'check_freshness', 'freshness_threshold', 'event_handler',
117
'event_handler_enabled', 'low_flap_threshold ', 'high_flap_threshold',
118
'flap_detection_enabled', 'flap_detection_options', 'retain_status_information',
119
'retain_nonstatus_information', 'contact_groups', 'first_notification_delay',
120
'notifications_enabled', 'stalking_options', 'notes',
121
'notes_url', 'action_url', 'icon_image',
122
'icon_image_alt', 'vrml_image', 'statusmap_image',
123
'2d_coords', '3d_coords', 'realm',
124
'poller_tag', 'business_impact']
125
for host_info in all_hosts:
126
logger.info("[GLPI Arbiter] Host info in GLPI: %s " % str(host_info))
127
h = {'host_name': host_info['host_name'],
128
'alias': host_info['alias'],
129
'address': host_info['address'],
130
'parents': host_info['parents'],
131
'check_command': host_info['check_command'],
132
'check_interval': host_info['check_interval'],
133
'retry_interval': host_info['retry_interval'],
134
'max_check_attempts': host_info['max_check_attempts'],
135
'check_period': host_info['check_period'],
136
'contacts': host_info['contacts'],
137
'process_perf_data': host_info['process_perf_data'],
138
'notification_interval': host_info['notification_interval'],
139
'notification_period': host_info['notification_period'],
140
'notification_options': host_info['notification_options']}
141
for attribut in attributs:
142
if attribut in host_info:
143
h[attribut] = host_info[attribut]
147
all_templates = self.con.monitoring.shinkenTemplates(arg)
148
logger.info("[GLPI Arbiter] Get all templates: %s" % str(all_templates))
149
attributs = ['name', 'check_interval', 'retry_interval',
150
'max_check_attempts', 'check_period', 'notification_interval',
151
'notification_period', 'notification_options', 'active_checks_enabled',
152
'process_perf_data', 'active_checks_enabled', 'passive_checks_enabled',
153
'parallelize_check', 'obsess_over_service', 'check_freshness',
154
'freshness_threshold', 'notifications_enabled', 'event_handler_enabled',
155
'event_handler', 'flap_detection_enabled', 'failure_prediction_enabled',
156
'retain_status_information', 'retain_nonstatus_information', 'is_volatile',
158
for template_info in all_templates:
159
logger.info("[GLPI Arbiter] Template info in GLPI: %s" % template_info)
160
h = {'register': '0'}
161
for attribut in attributs:
162
if attribut in template_info:
163
h[attribut] = template_info[attribut]
165
r['services'].append(h)
168
all_services = self.con.monitoring.shinkenServices(arg)
169
logger.info("[GLPI Arbiter] Get all services: %s" % str(all_services))
170
attributs = ['host_name', 'hostgroup_name', 'service_description',
171
'use', 'check_command', 'check_interval', 'retry_interval',
172
'max_check_attempts', 'check_period', 'contacts',
173
'notification_interval', 'notification_period', 'notification_options',
174
'active_checks_enabled', 'process_perf_data',
175
'passive_checks_enabled', 'parallelize_check', 'obsess_over_service',
176
'check_freshness', 'freshness_threshold', 'notifications_enabled',
177
'event_handler_enabled', 'event_handler', 'flap_detection_enabled',
178
'failure_prediction_enabled', 'retain_status_information', 'retain_nonstatus_information',
179
'is_volatile', '_httpstink',
180
'display_name', 'servicegroups', 'initial_state',
181
'low_flap_threshold', 'high_flap_threshold', 'flap_detection_options',
182
'first_notification_delay', 'notifications_enabled', 'contact_groups',
183
'stalking_options', 'notes', 'notes_url',
184
'action_url', 'icon_image', 'icon_image_alt',
185
'poller_tag', 'service_dependencies', 'business_impact']
187
for service_info in all_services:
188
logger.info("[GLPI Arbiter] Service info in GLPI: %s" % service_info)
190
for attribut in attributs:
191
if attribut in service_info:
192
h[attribut] = service_info[attribut]
194
r['services'].append(h)
197
all_contacts = self.con.monitoring.shinkenContacts(arg)
198
logger.info("[GLPI Arbiter] Get all contacts: %s" % str(all_contacts))
199
for contact_info in all_contacts:
200
logger.info("[GLPI Arbiter] Contact info in GLPI: %s" % contact_info)
201
h = {'contact_name': contact_info['contact_name'],
202
'alias': contact_info['alias'],
203
'host_notifications_enabled': contact_info['host_notifications_enabled'],
204
'service_notifications_enabled': contact_info['service_notifications_enabled'],
205
'service_notification_period': contact_info['service_notification_period'],
206
'host_notification_period': contact_info['host_notification_period'],
207
'service_notification_options': contact_info['service_notification_options'],
208
'host_notification_options': contact_info['host_notification_options'],
209
'service_notification_commands': contact_info['service_notification_commands'],
210
'host_notification_commands': contact_info['host_notification_commands'],
211
'email': contact_info['email'],
212
'pager': contact_info['pager'],
214
r['contacts'].append(h)
216
logger.debug("[GLPI Arbiter] Returning to Arbiter the data: %s" % str(r))