Clean : (Grégory Starck) clean of some getattr code, bis.
[shinken.git] / shinken / modules / syslog_broker.py
blobcf600ef282de23dd67587377dcbc2c3861116ef9
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 a plugin for the Shinken Broker. It is in charge
21 #to brok log into the syslog
24 import syslog
27 #This text is print at the import
28 print "I am simple syslog Broker"
31 properties = {
32 'type' : 'syslog',
33 'external' : False,
34 'phases' : ['running'],
38 #called by the plugin manager to get a broker
39 def get_instance(plugin):
40 print "Get a Syslog broker for plugin %s" % plugin.get_name()
42 #Catch errors
43 #path = plugin.path
44 instance = Syslog_broker(plugin.get_name())
45 return instance
49 #Class for the Merlindb Broker
50 #Get broks and puts them in merlin database
51 class Syslog_broker:
52 def __init__(self, name):
53 self.name = name
56 #Called by Broker so we can do init stuff
57 #TODO : add conf param to get pass with init
58 #Conf from arbiter!
59 def init(self):
60 pass
61 #self.q = self.properties['to_queue']
64 def get_name(self):
65 return self.name
68 #Get a brok, parse it, and put in in database
69 #We call functions like manage_ TYPEOFBROK _brok that return us queries
70 def manage_brok(self, b):
71 type = b.type
72 manager = 'manage_'+type+'_brok'
73 if hasattr(self, manager):
74 f = getattr(self, manager)
75 f(b)
78 #A service check have just arrived, we UPDATE data info with this
79 def manage_log_brok(self, b):
80 data = b.data
81 syslog.syslog(data['log'].encode('UTF-8'))
84 # def main(self):
85 # while True:
86 # b = self.q.get() # can block here :)
87 # self.manage_brok(b)