2 #Copyright (C) 2009-2010 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
6 #This file is part of Shinken.
8 #Shinken is free software: you can redistribute it and/or modify
9 #it under the terms of the GNU Affero General Public License as published by
10 #the Free Software Foundation, either version 3 of the License, or
11 #(at your option) any later version.
13 #Shinken is distributed in the hope that it will be useful,
14 #but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 #GNU Affero General Public License for more details.
18 #You should have received a copy of the GNU Affero General Public License
19 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
22 from shinken
.util
import to_split
, to_bool
23 from shinken
.item
import Item
, Items
24 from shinken
.property import UnusedProp
, BoolProp
, IntegerProp
, FloatProp
, CharProp
, StringProp
, ListProp
26 class Hostdependency(Item
):
31 # service_description Service D
32 # dependent_host_name Host C
33 # dependent_service_description Service F
34 # execution_failure_criteria o
35 # notification_failure_criteria w,u
37 # dependency_period 24x7
39 properties
={'dependent_host_name': StringProp(),
40 'dependent_hostgroup_name': StringProp(default
=''),
41 'host_name': StringProp(),
42 'hostgroup_name': StringProp(default
=''),
43 'inherits_parent': BoolProp(default
='0'),
44 'execution_failure_criteria': ListProp(default
='n'),
45 'notification_failure_criteria': ListProp(default
='n'),
46 'dependency_period': StringProp(default
='')
48 running_properties
= {}
50 #Give a nice name output, for debbuging purpose
51 #(debugging happens more often than expected...)
53 return self
.dependent_host_name
+'/'+self
.host_name
57 class Hostdependencies(Items
):
58 def delete_hostsdep_by_id(self
, ids
):
63 #We create new servicedep if necessery (host groups and co)
65 #The "old" dependencies will be removed. All dependencies with
66 #more than one host or a host group will be in it
69 #Then for every host create a copy of the dependency with just the host
70 #because we are adding services, we can't just loop in it
71 hostdeps
= self
.items
.keys()
74 if hd
.is_tpl(): #Exploding template is useless
76 hnames
= hd
.dependent_host_name
.split(',')
81 new_hd
.dependent_host_name
= hname
82 self
.items
[new_hd
.id] = new_hd
83 hstdep_to_remove
.append(id)
84 self
.delete_hostsdep_by_id(hstdep_to_remove
)
87 def linkify(self
, hosts
, timeperiods
):
88 self
.linkify_hd_by_h(hosts
)
89 self
.linkify_hd_by_tp(timeperiods
)
90 self
.linkify_h_by_hd()
93 def linkify_hd_by_h(self
, hosts
):
97 dh_name
= hd
.dependent_host_name
98 h
= hosts
.find_by_name(h_name
)
99 dh
= hosts
.find_by_name(dh_name
)
101 hd
.dependent_host_name
= dh
102 except AttributeError , exp
:
106 #We just search for each hostdep the id of the host
107 #and replace the name by the id
108 def linkify_hd_by_tp(self
, timeperiods
):
111 tp_name
= hd
.dependency_period
112 tp
= timeperiods
.find_by_name(tp_name
)
113 hd
.dependency_period
= tp
114 except AttributeError , exp
:
118 #We backport host dep to host. So HD is not need anymore
119 def linkify_h_by_hd(self
):
121 depdt_hname
= hd
.dependent_host_name
122 if hd
.is_tpl() or depdt_hname
is None: continue
123 dp
= getattr(hd
, 'dependency_period', None)
124 depdt_hname
.add_host_act_dependancy(hd
.host_name
, hd
.notification_failure_criteria
, dp
, hd
.inherits_parent
)
125 depdt_hname
.add_host_chk_dependancy(hd
.host_name
, hd
.execution_failure_criteria
, dp
, hd
.inherits_parent
)
128 #Apply inheritance for all properties
129 def apply_inheritance(self
):
130 #We check for all Host properties if the host has it
131 #if not, it check all host templates for a value
132 for prop
in Hostdependency
.properties
:
133 self
.apply_partial_inheritance(prop
)
135 #Then implicit inheritance
136 #self.apply_implicit_inheritance(hosts)
138 h
.get_customs_properties_by_inheritance(self
)