Merge branch 'master' of ssh://lausser,shinken@shinken.git.sourceforge.net/gitroot...
[shinken.git] / shinken / arbiterlink.py
blobb0210acb2240998884ce330a5229cead8edb9f5a
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/>.
23 import socket
25 from shinken.satellitelink import SatelliteLink, SatelliteLinks
26 from shinken.property import BoolProp, IntegerProp, StringProp, ListProp
28 class ArbiterLink(SatelliteLink):
29 id = 0
30 my_type = 'arbiter'
31 properties = {
32 'arbiter_name': StringProp(),
33 'host_name': StringProp(default=socket.gethostname()),
34 'address': StringProp(),
35 'port': IntegerProp(default='7770'),
36 'spare': BoolProp(default='0'),
37 'modules': ListProp(default='', to_send=True),
38 # 'polling_interval': {'required': False, 'default' : '1', 'pythonize': to_int, 'to_send' : True},
39 'manage_arbiters': BoolProp(default='0'),
40 'timeout': IntegerProp(default='3', fill_brok=['full_status']),
41 'data_timeout': IntegerProp(default='120', fill_brok=['full_status']),
42 'max_check_attempts': IntegerProp(default='3', fill_brok=['full_status']),
45 running_properties = {
46 'con': StringProp(default=None),
47 'broks': ListProp(default=[]),
48 'alive': BoolProp(default=False, fill_brok=['full_status']), # DEAD or not
49 'attempt': IntegerProp(default=0, fill_brok=['full_status']), # the number of failed attempt
50 'reachable': IntegerProp(default=False, fill_brok=['full_status']), # can be network ask or not (dead or check in timeout or error)
51 'configuration_errors': StringProp(default=[]),
54 macros = {}
57 def get_name(self):
58 return self.arbiter_name
61 #Check is required prop are set:
62 #contacts OR contactgroups is need
63 def is_correct(self):
64 state = True #guilty or not? :)
65 cls = self.__class__
67 for prop, entry in cls.properties.items():
68 if not hasattr(self, prop) and entry.required:
69 print self.get_name(), " : I do not have", prop
70 state = False #Bad boy...
71 return state
74 def is_me(self):
75 print "Hostname:%s, gethostname:%s" % (self.host_name, socket.gethostname())
76 return self.host_name == socket.gethostname()
79 def give_satellite_cfg(self):
80 return {'port' : self.port, 'address' : self.address, 'name' : self.arbiter_name}
83 def do_not_run(self):
84 if self.con is None:
85 self.create_connexion()
86 try:
87 self.con.do_not_run()
88 return True
89 except Pyro.errors.URIError , exp:
90 self.con = None
91 return False
92 except Pyro.errors.ProtocolError , exp:
93 self.con = None
94 return False
98 class ArbiterLinks(SatelliteLinks):
99 name_property = "name"
100 inner_class = ArbiterLink
103 #We must have a realm property, so we find our realm
104 def linkify(self, modules):
105 self.linkify_s_by_plug(modules)
108 def linkify_s_by_plug(self, modules):
109 for s in self:
110 new_modules = []
111 for plug_name in s.modules:
112 plug = modules.find_by_name(plug_name.strip())
113 if plug is not None:
114 new_modules.append(plug)
115 else:
116 print "Error : the module %s is unknow for %s" % (plug_name, s.get_name())
117 s.modules = new_modules