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
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.
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"
39 elif sys
.version_info
>= (3,):
40 print "Shinken is not yet compatible with Python3k, sorry"
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
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
))
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
))
70 import shinken
.pyro_wrapper
72 print "Shinken require the Python Pyro module. Please install it."
75 Pyro
= shinken
.pyro_wrapper
.Pyro
78 from shinken
.satellite
import Satellite
79 from shinken
.util
import to_int
, to_bool
85 class Reactionner(Satellite
):
86 do_checks
= False #I do not do checks
87 do_actions
= True #just actions like notifications
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
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
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"
120 print "\tPrint detailed help screen"
122 print "\tDebug File. Default : no use (why debug a bug free program? :) )"
126 #lets go to the party
127 if __name__
== "__main__":
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"
143 if o
in ("-h", "--help"):
146 elif o
in ("-r", "--replace"):
148 elif o
in ("-c", "--config"):
150 elif o
in ("-d", "--daemon"):
152 elif o
in ("--debug"):
156 print "Sorry, the option",o
, a
, "is unknown"
161 p
= Reactionner(config_file
, is_daemon
, do_replace
, debug
, debug_file
)
164 #command = """p.main()"""
165 #cProfile.runctx( command, globals(), locals(), filename="var/Shinken.profile" )