Add : set 'None' as the default poller_tag value, so a poller can get untaggued AND...
[shinken.git] / shinken / schedulerlink.py
blob2ba775e38b50f05f2d5719c336a6f75a6f395972
1 #!/usr/bin/env python
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/>.
24 #Scheduler is like a satellite for dispatcher
25 from shinken.satellitelink import SatelliteLink, SatelliteLinks
26 from shinken.property import BoolProp, IntegerProp, StringProp, ListProp
28 from shinken.pyro_wrapper import Pyro
31 class SchedulerLink(SatelliteLink):
32 id = 0
34 #Ok we lie a little here because we are a mere link in fact
35 my_type = 'scheduler'
37 properties = {
38 'scheduler_name': StringProp(fill_brok=['full_status']),
39 'address': StringProp(fill_brok=['full_status']),
40 'port': IntegerProp(default='7768', fill_brok=['full_status']),
41 'spare': BoolProp(default='0', fill_brok=['full_status']),
42 'modules': ListProp(default=''),
43 'weight': IntegerProp(default='1', fill_brok=['full_status']),
44 'manage_arbiters': IntegerProp(default='0'),
45 'use_timezone': StringProp(default='NOTSET', override=True),
46 'timeout': IntegerProp(default='3', fill_brok=['full_status']),
47 'data_timeout': IntegerProp(default='120', fill_brok=['full_status']),
48 'max_check_attempts': IntegerProp(default='3', fill_brok=['full_status']),
49 'realm' : StringProp(default=''),
52 running_properties = {
53 'con': StringProp(default=None),
54 'alive': StringProp(default=True, fill_brok=['full_status']), # DEAD or not
55 'attempt': StringProp(default=0, fill_brok=['full_status']), # the number of failed attempt
56 'reachable': StringProp(default=False, fill_brok=['full_status']), # can be network ask or not (dead or check in timeout or error)
57 'conf': StringProp(default=None),
58 'need_conf': StringProp(default=True),
59 'broks': StringProp(default=[]),
60 'configuration_errors' : StringProp(default=[]),
63 macros = {}
66 def get_name(self):
67 return self.scheduler_name
70 def run_external_command(self, command):
71 if self.con is None:
72 self.create_connexion()
73 if not self.alive:
74 return None
75 print "Send command", command
76 try:
77 self.con.run_external_command(command)
78 except Pyro.errors.URIError , exp:
79 self.con = None
80 return False
81 except Pyro.errors.ProtocolError , exp:
82 self.con = None
83 return False
84 except TypeError , exp:
85 print ''.join(Pyro.util.getPyroTraceback(exp))
86 except Pyro.errors.CommunicationError , exp:
87 self.con = None
88 return False
92 def register_to_my_realm(self):
93 self.realm.schedulers.append(self)
96 def give_satellite_cfg(self):
97 return {'port' : self.port, 'address' : self.address, 'name' : self.scheduler_name, 'instance_id' : self.id, 'active' : self.conf is not None}
100 #Some parameters can give as 'overriden parameters' like use_timezone
101 #so they will be mixed (in the scheduler) with the standard conf send by the arbiter
102 def get_override_configuration(self):
103 r = {}
104 properties = self.__class__.properties
105 for prop, entry in properties.items():
106 if entry.override:
107 r[prop] = getattr(self, prop)
108 return r
110 class SchedulerLinks(SatelliteLinks):
111 name_property = "scheduler_name"
112 inner_class = SchedulerLink