Add : child_dependencies/ parent_dependencies in livestatus module.
[shinken.git] / shinken / schedulerlink.py
blob65618b90d62aaafb3dbc648d23b85a288e08e726
1 #!/usr/bin/env python
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 #Scheduler is like a satellite for dispatcher
23 from shinken.satellitelink import SatelliteLink, SatelliteLinks
24 from shinken.util import to_int, to_bool, to_split
25 from shinken.property import UnusedProp, BoolProp, IntegerProp, FloatProp, CharProp, StringProp, ListProp
27 from shinken.pyro_wrapper import Pyro
30 class SchedulerLink(SatelliteLink):
31 id = 0
33 #Ok we lie a little here because we are a mere link in fact
34 my_type = 'scheduler'
36 properties={
37 'scheduler_name': StringProp(
38 fill_brok=['full_status']),#, 'pythonize': None},
39 'address': StringProp(
40 fill_brok=['full_status']),#, 'pythonize': to_bool},
41 'port': IntegerProp(
42 default='7768',
43 fill_brok=['full_status']),
44 'spare': BoolProp(
45 default='0',
46 fill_brok=['full_status']),
47 'modules': ListProp(
48 default=''),
49 'weight': IntegerProp(
50 default='1',
51 fill_brok=['full_status']),
52 'manage_arbiters': IntegerProp(
53 default='0'),
54 'use_timezone': StringProp(
55 default='NOTSET',
56 override=True),
57 'timeout': IntegerProp(
58 default='3',
59 fill_brok=['full_status']),
60 'data_timeout': IntegerProp(
61 default='120',
62 fill_brok=['full_status']),
63 'max_check_attempts': IntegerProp(
64 default='3',
65 fill_brok=['full_status']),
66 'realm' : StringProp(default=''),
68 running_properties = {'con': StringProp(
69 default=None),
70 'alive': StringProp(
71 default=False,
72 fill_brok=['full_status']), # DEAD or not
73 'attempt': StringProp(
74 default=0,
75 fill_brok=['full_status']), # the number of failed attempt
76 'reachable': StringProp(
77 default=False,
78 fill_brok=['full_status']), # can be network ask or not (dead or check in timeout or error)
79 'conf': StringProp(
80 default=None),
81 'need_conf': StringProp(
82 default=True),
83 'broks': StringProp(
84 default=[]),
85 'configuration_errors' : StringProp(default=[]),
87 macros = {}
90 def get_name(self):
91 return self.scheduler_name
94 def run_external_command(self, command):
95 if self.con == None:
96 self.create_connexion()
97 if not self.alive:
98 return None
99 print "Send command", command
100 try:
101 self.con.run_external_command(command)
102 except Pyro.errors.URIError , exp:
103 self.con = None
104 return False
105 except Pyro.errors.ProtocolError , exp:
106 self.con = None
107 return False
108 except TypeError , exp:
109 print ''.join(Pyro.util.getPyroTraceback(exp))
110 except Pyro.errors.CommunicationError , exp:
111 self.con = None
112 return False
116 def register_to_my_realm(self):
117 self.realm.schedulers.append(self)
120 def give_satellite_cfg(self):
121 return {'port' : self.port, 'address' : self.address, 'name' : self.scheduler_name, 'instance_id' : self.id, 'active' : self.conf!=None}
124 #Some parameters can give as 'overriden parameters' like use_timezone
125 #so they will be mixed (in the scheduler) with the standard conf send by the arbiter
126 def get_override_configuration(self):
127 r = {}
128 properties = self.__class__.properties
129 for prop in properties:
130 entry = properties[prop]
131 if entry.override:
132 r[prop] = getattr(self, prop)
133 return r
135 class SchedulerLinks(SatelliteLinks):
136 name_property = "name"
137 inner_class = SchedulerLink