Skip to content

Commit 56d4d10

Browse files
author
Quentin Bouget
committed
Fix: #603 host to host servicedependecies
Using auto-computing of servicedependencies
1 parent 4f2bbe2 commit 56d4d10

File tree

5 files changed

+67
-2
lines changed

5 files changed

+67
-2
lines changed

shinken/objects/servicedependency.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def explode(self, hostgroups, services):
181181
dep_hnames.extend([m.strip() for m in hg.members])
182182

183183
if not hasattr(sd, 'dependent_host_name'):
184-
sd.dependent_host_name = getattr(sd, 'host_name', '')
184+
sd.dependent_host_name = ''
185185

186186
if sd.dependent_host_name != '':
187187
dep_hnames.extend([n.strip() for n in sd.dependent_host_name.split(',')])
@@ -214,6 +214,13 @@ def explode(self, hostgroups, services):
214214
sname = service.service_description
215215
if sname in snames:
216216
special_singles[sname].add(service.host_name)
217+
if hnames:
218+
# host_names without dependent_host_names
219+
# => host to host dependencies
220+
for sname in snames:
221+
# Should log something when a host does not
222+
# match any service
223+
special_singles[sname] &= set(hnames)
217224

218225
special_dep_singles = {}
219226
for sname in dep_snames:

test/etc/servicedependency_auto_computing/hosts.cfg

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,21 @@ define host {
3333
host_name h5
3434
address 127.0.0.6
3535
}
36+
37+
define host {
38+
use generic-host
39+
host_name h6
40+
address 127.0.0.7
41+
}
42+
43+
define host {
44+
use generic-host
45+
host_name h7
46+
address 127.0.0.8
47+
}
48+
49+
define host {
50+
use generic-host
51+
host_name h8
52+
address 127.0.0.9
53+
}

test/etc/servicedependency_auto_computing/servicedependencies.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ define servicedependency{
1212
service_description svc0
1313
dependent_service_description svc3
1414
}
15+
16+
define servicedependency{
17+
host_name h6, h7
18+
service_description svc4
19+
dependent_service_description svc5
20+
}

test/etc/servicedependency_auto_computing/services.cfg

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,17 @@ define service {
5151
check_command nothing
5252
host_name h3, h4, h5
5353
}
54+
55+
define service {
56+
use generic-service
57+
service_description svc4
58+
check_command nothing
59+
host_name h6, h7, h8
60+
}
61+
62+
define service {
63+
use generic-service
64+
service_description svc5
65+
check_command nothing
66+
host_name h6, h7, h8
67+
}

test/test_servicedependency_auto_computing.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_matching_svc(self):
5454

5555
def test_multiple_srv_description(self):
5656
services = self.conf.services
57-
expected_dep_svc = {'h1': ['svc2'], 'h2': ['svc2'],\
57+
expected_dep_svc = {'h1': ['svc2'], 'h2': ['svc2'],
5858
'h3': ['svc2', 'svc3'], 'h4': ['svc2', 'svc3']}
5959
svcs = []
6060
svcs.append(services.find_srv_by_name_and_hostname('h1', 'svc1'))
@@ -70,6 +70,26 @@ def test_multiple_srv_description(self):
7070
description.remove(dep_svc.service_description)
7171
self.assertEqual(description, [])
7272

73+
def test_host_to_host_dependency(self):
74+
services = self.conf.services
75+
servicedependencies = self.conf.servicedependencies
76+
svcs = []
77+
svcs.append(services.find_srv_by_name_and_hostname('h6', 'svc4'))
78+
svcs.append(services.find_srv_by_name_and_hostname('h7', 'svc4'))
79+
for svc in svcs:
80+
self.assertIsNotNone(svc)
81+
dep_svcs = [info_dep[0] for info_dep in svc.act_depend_of_me]
82+
self.assertNotEqual(dep_svcs, [])
83+
for dep_svc in dep_svcs:
84+
self.assertEqual(dep_svc.host_name, svc.host_name)
85+
self.assertEqual(dep_svc.service_description, 'svc5')
86+
87+
# Check that host8 was not caught in the process
88+
h8_svc4 = services.find_srv_by_name_and_hostname('h8', 'svc4')
89+
90+
self.assertIsNotNone(h8_svc4)
91+
self.assertFalse(h8_svc4.act_depend_of_me)
92+
7393

7494
if __name__ == '__main__':
7595
unittest.main()

0 commit comments

Comments
 (0)