*Fix : satellites links where send with 'con' information. It's not a good thing...
[shinken.git] / bin / shinken-reactionner
blob745ae3c04719e3304aa0e2b88f122044fede1516
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/>.
22 #This class is an application for launch actions
23 #like notifications or event handlers
24 #The actionner listen configuration from Arbiter in a port (first argument)
25 #the configuration gived by arbiter is schedulers where actionner will take
26 #actions.
27 #When already launch and have a conf, actionner still listen to arbiter (one
28 #a timeout) if arbiter wants it to have a new conf, actionner forgot old
29 #chedulers (and actions into) take new ones and do the (new) job.
31 import sys, os
32 import getopt
33 import ConfigParser
35 ## Make sure people are using Python 2.5 or higher
36 if sys.version_info < (2,4):
37 print "Shinken requires as a minimum Python 2.4.x, sorry"
38 sys.exit(1)
39 elif sys.version_info >= (3,):
40 print "Shinken is not yet compatible with Python3k, sorry"
41 sys.exit(1)
44 #Pyro 4 dbg
45 sys.path.insert(0,'.')
48 #Try to load shinken lib.
49 #Maybe it's not in our python path, so we detect it
50 #it so (it's a untar install) we add .. in the path
51 try :
52 from shinken.util import to_bool
53 if hasattr(sys.modules['__main__'], '__file__'):
54 my_path = os.path.abspath(sys.modules['__main__'].__file__)
55 elts = os.path.dirname(my_path).split(os.sep)[:-1]
56 elts.append('shinken')
57 sys.path.append(os.sep.join(elts))
58 except ImportError:
59 if hasattr(sys.modules['__main__'], '__file__'):
60 #Now add in the python path the shinken lib
61 #if we launch it in a direct way and
62 #the shinken is not a python lib
63 my_path = os.path.abspath(sys.modules['__main__'].__file__)
64 elts = os.path.dirname(my_path).split(os.sep)[:-1]
65 sys.path.append(os.sep.join(elts))
66 elts.append('shinken')
67 sys.path.append(os.sep.join(elts))
69 try:
70 import shinken.pyro_wrapper
71 except ImportError:
72 print "Shinken require the Python Pyro module. Please install it."
73 sys.exit(1)
75 Pyro = shinken.pyro_wrapper.Pyro
78 from shinken.satellite import Satellite
79 from shinken.util import to_int, to_bool
81 VERSION = "0.4"
84 #Our main APP class
85 class Reactionner(Satellite):
86 do_checks = False #I do not do checks
87 do_actions = True #just actions like notifications
88 #default_port = 7769
90 properties = {
91 'workdir' : {'default' : '/usr/local/shinken/var', 'pythonize' : None, 'path' : True},
92 'pidfile' : {'default' : '/usr/local/shinken/var/reactionnerd.pid', 'pythonize' : None, 'path' : True},
93 'port' : {'default' : '7769', 'pythonize' : to_int},
94 'host' : {'default' : '0.0.0.0', 'pythonize' : None},
95 'user' : {'default' : 'shinken', 'pythonize' : None},
96 'group' : {'default' : 'shinken', 'pythonize' : None},
97 'idontcareaboutsecurity' : {'default' : '0', 'pythonize' : to_bool},
98 'use_ssl' : {'default' : '0', 'pythonize' : to_bool},
99 'certs_dir' : {'default' : 'etc/certs', 'pythonize' : None},
100 'ca_cert' : {'default' : 'etc/certs/ca.pem', 'pythonize' : None},
101 'server_cert' : {'default': 'etc/certs/server.pem', 'pythonize' : None},
102 'hard_ssl_name_check' : {'default' : '0', 'pythonize' : to_bool},
106 ################### Process launch part
107 def usage(name):
108 print "Shinken Reactionner Daemon, version %s, from :" % VERSION
109 print " Gabes Jean, naparuba@gmail.com"
110 print " Gerhard Lausser, Gerhard.Lausser@consol.de"
111 print "Usage: %s [options] [-c configfile]" % name
112 print "Options:"
113 print " -c, --config"
114 print "\tConfig file."
115 print " -d, --daemon"
116 print "\tRun in daemon mode"
117 print " -r, --replace"
118 print "\tReplace previous running scheduler"
119 print " -h, --help"
120 print "\tPrint detailed help screen"
121 print " --debug"
122 print "\tDebug File. Default : no use (why debug a bug free program? :) )"
126 #lets go to the party
127 if __name__ == "__main__":
128 #Manage the options
129 try:
130 opts, args = getopt.getopt(sys.argv[1:], "hrdc::w", ["help", "replace", "daemon", "config=", "debug=", "easter"])
131 except getopt.GetoptError, err:
132 # print help information and exit:
133 print str(err) # will print something like "option -a not recognized"
134 usage(sys.argv[0])
135 sys.exit(2)
136 #Default params
137 config_file = None
138 is_daemon=False
139 do_replace=False
140 debug=False
141 debug_file=None
142 for o, a in opts:
143 if o in ("-h", "--help"):
144 usage(sys.argv[0])
145 sys.exit()
146 elif o in ("-r", "--replace"):
147 do_replace = True
148 elif o in ("-c", "--config"):
149 config_file = a
150 elif o in ("-d", "--daemon"):
151 is_daemon = True
152 elif o in ("--debug"):
153 debug = True
154 debug_file = a
155 else:
156 print "Sorry, the option",o, a, "is unknown"
157 usage(sys.argv[0])
158 sys.exit()
161 p = Reactionner(config_file, is_daemon, do_replace, debug, debug_file)
162 #import cProfile
163 p.main()
164 #command = """p.main()"""
165 #cProfile.runctx( command, globals(), locals(), filename="var/Shinken.profile" )