Clean : (Grégory Starck) clean of some getattr code, bis.
[shinken.git] / shinken / modules / dummy_arbiter.py
blob359d72e165df6358e85ec90b12e3b6dc9119328a
1 #!/usr/bin/python
2 #Copyright (C) 2009 Gabes Jean, naparuba@gmail.com
4 #This file is part of Shinken.
6 #Shinken is free software: you can redistribute it and/or modify
7 #it under the terms of the GNU Affero General Public License as published by
8 #the Free Software Foundation, either version 3 of the License, or
9 #(at your option) any later version.
11 #Shinken is distributed in the hope that it will be useful,
12 #but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 #GNU Affero General Public License for more details.
16 #You should have received a copy of the GNU Affero General Public License
17 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
20 #This Class is an example of an Arbiter module
21 #Here for the configuration phase AND running one
24 #This text is print at the import
25 print "Detected module : Dummy module for Arbiter"
28 import time
29 from shinken.external_command import ExternalCommand
33 properties = {
34 'type' : 'dummy_arbiter',
35 'external' : True,
36 'phases' : ['configuration', 'running'],
40 #called by the plugin manager to get a broker
41 def get_instance(plugin):
42 print "Get a Dummy arbiter module for plugin %s" % plugin.get_name()
43 instance = Dummy_arbiter(plugin.get_name())
44 return instance
48 #Just print some stuff
49 class Dummy_arbiter:
50 def __init__(self, name):
51 self.name = name
53 #Called by Arbiter to say 'let's prepare yourself guy'
54 def init(self):
55 print "Initilisation of the dummy arbiter module"
56 self.return_queue = self.properties['from_queue']
59 def get_name(self):
60 return self.name
63 #Ok, main function that is called in the CONFIGURATION phase
64 def get_objects(self):
65 print "[Dummy] ask me for objects to return"
66 r = {'hosts' : []}
67 h = {'name' : 'dummy host from dummy arbiter module',
68 'register' : '0',
71 r['hosts'].append(h)
72 print "[Dummy] Returning to Arbiter the hosts:", r
73 return r
76 #When you are in "external" mode, that is the main loop of your process
77 def main(self):
78 while True:
79 print "Raise a external command as example"
80 e = ExternalCommand('Viva la revolution')
81 self.return_queue.put(e)
82 time.sleep(1)