2 #Copyright (C) 2009-2010 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
5 # Gregory Starck, g.starck@gmail.com
6 # Hartmut Goebel, h.goebel@goebel-consult.de
8 #This file is part of Shinken.
10 #Shinken is free software: you can redistribute it and/or modify
11 #it under the terms of the GNU Affero General Public License as published by
12 #the Free Software Foundation, either version 3 of the License, or
13 #(at your option) any later version.
15 #Shinken is distributed in the hope that it will be useful,
16 #but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 #GNU Affero General Public License for more details.
20 #You should have received a copy of the GNU Affero General Public License
21 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
23 from shinken
.objects
.item
import Item
, Items
25 from shinken
.property import BoolProp
, StringProp
, ListProp
27 class Hostdependency(Item
):
32 # service_description Service D
33 # dependent_host_name Host C
34 # dependent_service_description Service F
35 # execution_failure_criteria o
36 # notification_failure_criteria w,u
38 # dependency_period 24x7
41 'dependent_host_name': StringProp(),
42 'dependent_hostgroup_name': StringProp(default
=''),
43 'host_name': StringProp(),
44 'hostgroup_name': StringProp(default
=''),
45 'inherits_parent': BoolProp(default
='0'),
46 'execution_failure_criteria': ListProp(default
='n'),
47 'notification_failure_criteria': ListProp(default
='n'),
48 'dependency_period': StringProp(default
='')
51 running_properties
= {}
53 #Give a nice name output, for debbuging purpose
54 #(debugging happens more often than expected...)
56 return self
.dependent_host_name
+'/'+self
.host_name
60 class Hostdependencies(Items
):
61 def delete_hostsdep_by_id(self
, ids
):
66 #We create new servicedep if necessery (host groups and co)
68 #The "old" dependencies will be removed. All dependencies with
69 #more than one host or a host group will be in it
72 #Then for every host create a copy of the dependency with just the host
73 #because we are adding services, we can't just loop in it
74 hostdeps
= self
.items
.keys()
77 if hd
.is_tpl(): #Exploding template is useless
79 hnames
= hd
.dependent_host_name
.split(',')
84 new_hd
.dependent_host_name
= hname
85 self
.items
[new_hd
.id] = new_hd
86 hstdep_to_remove
.append(id)
87 self
.delete_hostsdep_by_id(hstdep_to_remove
)
90 def linkify(self
, hosts
, timeperiods
):
91 self
.linkify_hd_by_h(hosts
)
92 self
.linkify_hd_by_tp(timeperiods
)
93 self
.linkify_h_by_hd()
96 def linkify_hd_by_h(self
, hosts
):
100 dh_name
= hd
.dependent_host_name
101 h
= hosts
.find_by_name(h_name
)
102 dh
= hosts
.find_by_name(dh_name
)
104 hd
.dependent_host_name
= dh
105 except AttributeError , exp
:
109 #We just search for each hostdep the id of the host
110 #and replace the name by the id
111 def linkify_hd_by_tp(self
, timeperiods
):
114 tp_name
= hd
.dependency_period
115 tp
= timeperiods
.find_by_name(tp_name
)
116 hd
.dependency_period
= tp
117 except AttributeError , exp
:
121 #We backport host dep to host. So HD is not need anymore
122 def linkify_h_by_hd(self
):
124 depdt_hname
= hd
.dependent_host_name
125 if hd
.is_tpl() or depdt_hname
is None: continue
126 dp
= getattr(hd
, 'dependency_period', None)
127 depdt_hname
.add_host_act_dependancy(hd
.host_name
, hd
.notification_failure_criteria
, dp
, hd
.inherits_parent
)
128 depdt_hname
.add_host_chk_dependancy(hd
.host_name
, hd
.execution_failure_criteria
, dp
, hd
.inherits_parent
)
131 #Apply inheritance for all properties
132 def apply_inheritance(self
):
133 #We check for all Host properties if the host has it
134 #if not, it check all host templates for a value
135 for prop
in Hostdependency
.properties
:
136 self
.apply_partial_inheritance(prop
)
138 #Then implicit inheritance
139 #self.apply_implicit_inheritance(hosts)
141 h
.get_customs_properties_by_inheritance(self
)