Skip to content

Commit 9a6cc27

Browse files
committed
Allow a module to be related with other modules (restoring this feature if any portable module require this)
1 parent efd34bd commit 9a6cc27

File tree

8 files changed

+57
-46
lines changed

8 files changed

+57
-46
lines changed

alignak/modulesmanager.py

+9
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def __init__(self, daemon):
7474
self.daemon = daemon
7575
self.daemon_type = daemon.type
7676
self.daemon_name = daemon.name
77+
self.modules = {}
7778
self.modules_assoc = []
7879
self.instances = []
7980
self.to_restart = []
@@ -136,6 +137,7 @@ def load(self, modules):
136137
"function" % module.python_name)
137138
raise AttributeError
138139

140+
self.modules[module.uuid] = module
139141
self.modules_assoc.append((module, python_module))
140142
logger.info("Imported '%s' for %s", module.python_name, module.name)
141143
except ImportError as exp: # pragma: no cover, simple protection
@@ -233,6 +235,13 @@ def get_instances(self):
233235
alignak_module.properties = python_module.properties.copy()
234236
alignak_module.my_daemon = self.daemon
235237
logger.info("Alignak starting module '%s'", alignak_module.get_name())
238+
logger.info("Alignak starting module '%s'", getattr(alignak_module, 'modules', None))
239+
if getattr(alignak_module, 'modules', None):
240+
modules = []
241+
for module_uuid in alignak_module.modules:
242+
if module_uuid in self.modules:
243+
modules.append(self.modules[module_uuid])
244+
alignak_module.modules = modules
236245
logger.debug("Module '%s', parameters: %s",
237246
alignak_module.get_name(), alignak_module.__dict__)
238247
try:

alignak/objects/host.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class Host(SchedulingItem): # pylint: disable=R0904
171171

172172
# Realm stuff
173173
'realm_name':
174-
StringProp(default=u''),
174+
StringProp(default=u'', fill_brok=['full_status']),
175175
'got_default_realm':
176176
BoolProp(default=False),
177177

alignak/objects/module.py

+29-9
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ class Module(Item):
8787
# Old "deprecated" property - replaced with type
8888
'module_types':
8989
ListProp(default=[u''], split_on_comma=True),
90-
# Do not manage modules having modules
91-
# 'modules':
92-
# ListProp(default=[''], split_on_comma=True)
90+
# Allow a module to be related some other modules
91+
'modules':
92+
ListProp(default=[''], split_on_comma=True),
9393

9494
# Module log level
9595
'log_level':
@@ -128,9 +128,9 @@ def __init__(self, params=None, parsing=True):
128128
# Old "deprecated" property - replaced with type
129129
'module_types':
130130
ListProp(default=[''], split_on_comma=True),
131-
# Do not manage modules having modules
132-
# 'modules':
133-
# ListProp(default=[''], split_on_comma=True)
131+
# Allow a module to be related some other modules
132+
'modules':
133+
ListProp(default=[''], split_on_comma=True),
134134

135135
'enabled':
136136
BoolProp(default=True),
@@ -237,9 +237,29 @@ class Modules(Items):
237237
inner_class = Module
238238

239239
def linkify(self):
240-
"""Link modules
240+
"""Link a module to some other modules
241241
242242
:return: None
243243
"""
244-
warnings.warn("Linking modules to modules (%s) is not managed by Alignak.".format(s=self),
245-
DeprecationWarning, stacklevel=2)
244+
self.linkify_s_by_plug()
245+
246+
def linkify_s_by_plug(self):
247+
"""Link a module to some other modules
248+
249+
:return: None
250+
"""
251+
for module in self:
252+
new_modules = []
253+
for related in getattr(module, 'modules', []):
254+
related = related.strip()
255+
if not related:
256+
continue
257+
o_related = self.find_by_name(related)
258+
if o_related is not None:
259+
new_modules.append(o_related.uuid)
260+
else:
261+
self.add_error("the module '%s' for the module '%s' is unknown!"
262+
% (related, module.get_name()))
263+
module.modules = new_modules
264+
265+

bin/systemd/default/alignak

+3
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@
3232
#ALIGNAK_CONFIGURATION_FILE=/usr/local/etc/my-alignak.ini
3333
#ALIGNAK_USER=my-alignak
3434
#ALIGNAK_GROUP=my-alignak
35+
36+
# Uncomment to make the daemons raise some log about its cpu and memory consumption every 10 seconds
37+
#ALIGNAK_DAEMON_MONITORING=10

setup.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ def extract_requirement(line):
6161
('share/alignak', ['bin/python-post-install.sh',
6262
'bin/python3-post-install.sh',
6363
'bin/alignak-log-rotate',
64-
'bin/alignak.ico'])
64+
'contrib/images/alignak.ico',
65+
'contrib/images/alignak_128x128.png',
66+
'contrib/images/alignak_blue_logo.png',
67+
'contrib/images/alignak_white_logo.png'])
6568
]
6669
for dir in ['etc', 'bin/manpages/manpages', 'bin/rc.d', 'bin/systemd', 'bin/systemV']:
6770
for subdir, dirs, files in os.walk(dir):

tests/cfg/modules/alignak_module_with_submodules.cfg

+10
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ define module{
77
python_name alignak_module_test
88
modules A,B
99
}
10+
define module{
11+
module_alias A
12+
module_types type
13+
python_name alignak_module_A.module
14+
}
15+
define module{
16+
module_alias B
17+
module_types type
18+
python_name alignak_module_B.module
19+
}

tests/test_aa_properties_default.py

+1
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ class TestModule(PropertiesTester, AlignakTest):
631631
('type', 'unset'),
632632
('daemon', 'unset'),
633633
('module_types', ['']),
634+
('modules', ['']),
634635
('enabled', True),
635636
('log_level', 'INFO'),
636637
('statsd_host', 'localhost'),

tests/test_modules.py

-35
Original file line numberDiff line numberDiff line change
@@ -180,41 +180,6 @@ def test_module_on_module(self):
180180
modules = [m.name for m in self._scheduler_daemon.modules]
181181
assert modules == ['Example', 'inner-retention']
182182

183-
s = {
184-
'alignak': 'My Alignak', 'type': 'scheduler', 'name': 'scheduler-master',
185-
'version': '2.0.0rc3', 'program_start': 1535113067.5402572, 'spare': False,
186-
'load': -41.431089073425724,
187-
'counters': {'modules': 0, 'external-commands': 0, 'satellites.arbiters': 0,
188-
'satellites.schedulers': 0, 'brokers': 1, 'pollers': 1, 'reactionners': 1,
189-
'receivers': 0, 'actions.count': 0, 'actions.scheduled': 1035,
190-
'actions.in_poller': 0, 'actions.zombie': 0, 'checks.count': 1043,
191-
'checks.scheduled': 1035, 'checks.in_poller': 0, 'checks.zombie': 0},
192-
'metrics': [], 'modules': {'internal': {}, 'external': {}},
193-
'monitored_objects': {'timeperiods': 4, 'services': 40, 'servicegroups': 1,
194-
'commands': 11, 'hosts': 1016, 'hostgroups': 2, 'contacts': 2,
195-
'contactgroups': 2, 'notificationways': 2, 'checkmodulations': 0,
196-
'macromodulations': 0, 'servicedependencies': 0,
197-
'hostdependencies': 0, 'arbiters': 0, 'schedulers': 0,
198-
'reactionners': 0, 'brokers': 0, 'receivers': 0, 'pollers': 0,
199-
'realms': 0, 'modules': 0, 'resultmodulations': 0,
200-
'businessimpactmodulations': 0, 'escalations': 0,
201-
'serviceescalations': 0, 'hostescalations': 0, 'hostsextinfo': 0,
202-
'servicesextinfo': 0}, '_freshness': 1535113164,
203-
'latency': {'avg': 0.74, 'min': 0.74, 'max': 0.74},
204-
'livesynthesis': {'hosts_total': 1016, 'hosts_not_monitored': 10, 'hosts_up_hard': 1015,
205-
'hosts_up_soft': 0, 'hosts_down_hard': 0, 'hosts_down_soft': 1,
206-
'hosts_unreachable_hard': 0, 'hosts_unreachable_soft': 0,
207-
'hosts_acknowledged': 0, 'hosts_in_downtime': 0, 'hosts_flapping': 0,
208-
'services_total': 40, 'services_not_monitored': 0,
209-
'services_ok_hard': 40, 'services_ok_soft': 0,
210-
'services_warning_hard': 0, 'services_warning_soft': 0,
211-
'services_critical_hard': 0, 'services_critical_soft': 0,
212-
'services_unknown_hard': 0, 'services_unknown_soft': 0,
213-
'services_unreachable_hard': 0, 'services_unreachable_soft': 0,
214-
'services_acknowledged': 0, 'services_in_downtime': 0,
215-
'services_flapping': 0}
216-
}
217-
218183
def test_modulemanager_1(self):
219184
""" Module manager manages its modules - old form
220185

0 commit comments

Comments
 (0)