*Catch exceptions caused by mktime(1970,1,1,...) on Windows
[shinken.git] / bin / shinken-reactionner
blob5dadabcc2f13bff4d8dd73b7b02a0cf8454bf07b
1 #!/usr/bin/env python
2 #Copyright (C) 2009-2010 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
5 # Gregory Starck, g.starck@gmail.com
7 #This file is part of Shinken.
9 #Shinken is free software: you can redistribute it and/or modify
10 #it under the terms of the GNU Affero General Public License as published by
11 #the Free Software Foundation, either version 3 of the License, or
12 #(at your option) any later version.
14 #Shinken is distributed in the hope that it will be useful,
15 #but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 #GNU Affero General Public License for more details.
19 #You should have received a copy of the GNU Affero General Public License
20 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
23 #This class is an application for launch actions
24 #like notifications or event handlers
25 #The actionner listen configuration from Arbiter in a port (first argument)
26 #the configuration gived by arbiter is schedulers where actionner will take
27 #actions.
28 #When already launch and have a conf, actionner still listen to arbiter (one
29 #a timeout) if arbiter wants it to have a new conf, actionner forgot old
30 #chedulers (and actions into) take new ones and do the (new) job.
32 import sys, os
33 import getopt
34 import ConfigParser
37 #Try to load shinken lib.
38 #Maybe it's not in our python path, so we detect it
39 #it so (it's a untar install) we add .. in the path
40 try:
41 import shinken
42 except ImportError, e:
43 if hasattr(sys.modules['__main__'], '__file__'):
44 my_path = os.path.abspath(sys.modules['__main__'].__file__)
45 elts = os.path.dirname(my_path).split(os.sep)[:-1]
46 sys.path.append(os.sep.join(elts))
47 elts.append('shinken')
48 sys.path.append(os.sep.join(elts))
51 from shinken.daemons.reactionnerdaemon import Reactionner, usage
55 #lets go to the party
56 if __name__ == "__main__":
57 #Manage the options
58 try:
59 opts, args = getopt.getopt(sys.argv[1:], "hrdc::w", ["help", "replace", "daemon", "config=", "debug=", "easter"])
60 except getopt.GetoptError, err:
61 # print help information and exit:
62 print str(err) # will print something like "option -a not recognized"
63 usage(sys.argv[0])
64 sys.exit(2)
65 #Default params
66 config_file = None
67 is_daemon=False
68 do_replace=False
69 debug=False
70 debug_file=None
71 for o, a in opts:
72 if o in ("-h", "--help"):
73 usage(sys.argv[0])
74 sys.exit()
75 elif o in ("-r", "--replace"):
76 do_replace = True
77 elif o in ("-c", "--config"):
78 config_file = a
79 elif o in ("-d", "--daemon"):
80 is_daemon = True
81 elif o in ("--debug"):
82 debug = True
83 debug_file = a
84 else:
85 print "Sorry, the option",o, a, "is unknown"
86 usage(sys.argv[0])
87 sys.exit()
90 daemon = Reactionner(config_file, is_daemon, do_replace, debug, debug_file)
92 daemon.main()