*Remove a leftover test file
[shinken.git] / shinken / arbiterlink.py
blobbe0c439228a7fa569af562891c060bfcbf3429d1
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/>.
21 import socket
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 class ArbiterLink(SatelliteLink):
28 id = 0
29 my_type = 'arbiter'
30 properties={'arbiter_name' : StringProp(),
31 'host_name' : StringProp(default=socket.gethostname()),
32 'address' : StringProp(),
33 'port' : IntegerProp(default='7770'),
34 'spare' : BoolProp(default='0'),
35 'modules' : ListProp(default='', to_send=True),
36 # 'polling_interval': {'required': False, 'default' : '1', 'pythonize': to_int, 'to_send' : True},
37 'manage_arbiters' : BoolProp(default='0'),
38 'timeout' : IntegerProp(default='3', fill_brok=['full_status']),
39 'data_timeout' : IntegerProp(default='120', fill_brok=['full_status']),
40 'max_check_attempts' : IntegerProp(default='3', fill_brok=['full_status']),
43 running_properties = {'con' : StringProp(default=None),
44 'broks' : ListProp(default=[]),
45 'alive' : BoolProp(default=False, fill_brok=['full_status']), # DEAD or not
46 'attempt' : IntegerProp(default=0, fill_brok=['full_status']), # the number of failed attempt
47 'reachable' : IntegerProp(default=False, fill_brok=['full_status']), # can be network ask or not (dead or check in timeout or error)
48 'configuration_errors' : StringProp(default=[]),
51 macros = {}
54 def get_name(self):
55 return self.arbiter_name
58 #Check is required prop are set:
59 #contacts OR contactgroups is need
60 def is_correct(self):
61 state = True #guilty or not? :)
62 cls = self.__class__
64 for prop in cls.properties:
65 if not hasattr(self, prop) and cls.properties[prop]['required']:
66 print self.get_name(), " : I do not have", prop
67 state = False #Bad boy...
68 return state
71 def is_me(self):
72 print "Hostname:%s, gethostname:%s" % (self.host_name, socket.gethostname())
73 return self.host_name == socket.gethostname()
76 def give_satellite_cfg(self):
77 return {'port' : self.port, 'address' : self.address, 'name' : self.arbiter_name}
80 def do_not_run(self):
81 if self.con == None:
82 self.create_connexion()
83 try:
84 self.con.do_not_run()
85 return True
86 except Pyro.errors.URIError , exp:
87 self.con = None
88 return False
89 except Pyro.errors.ProtocolError , exp:
90 self.con = None
91 return False
95 class ArbiterLinks(SatelliteLinks):
96 name_property = "name"
97 inner_class = ArbiterLink
100 #We must have a realm property, so we find our realm
101 def linkify(self, modules):
102 self.linkify_s_by_plug(modules)
105 def linkify_s_by_plug(self, modules):
106 for s in self:
107 new_modules = []
108 for plug_name in s.modules:
109 plug = modules.find_by_name(plug_name.strip())
110 if plug != None:
111 new_modules.append(plug)
112 else:
113 print "Error : the module %s is unknow for %s" % (plug_name, s.get_name())
114 s.modules = new_modules