*Catch exceptions caused by mktime(1970,1,1,...) on Windows
[shinken.git] / bin / shinken-broker
blob0ca6ab6eacb6c4c2b754c210a3ae34d240da00ac
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 interface for Broker
24 #The broker listen configuration from Arbiter in a port (first argument)
25 #the configuration gived by arbiter is schedulers where broker will take broks.
26 #When already launch and have a conf, broker still listen to arbiter
27 # (one a timeout)
28 #if arbiter whant it to have a new conf, broker forgot old chedulers
29 #(and broks into)
30 #take new ones and do the (new) job.
33 import os
34 import sys
35 import getopt
38 #Try to load shinken lib.
39 #Maybe it's not in our python path, so we detect it
40 #it so (it's a untar install) we add .. in the path
41 try:
42 import shinken
43 # HACK : under python2.4, without this, it seems that
44 # modules are not so happy to import
45 if hasattr(sys.modules['__main__'], '__file__'):
46 my_path = os.path.abspath(sys.modules['__main__'].__file__)
47 elts = os.path.dirname(my_path).split(os.sep)[:-1]
48 elts.append('shinken')
49 sys.path.append(os.sep.join(elts))
50 except ImportError, e:
51 # We can have problem in importing with direct launch.
52 # if so we must add the shinken lib in .. of this file to
53 # sys.path
54 if hasattr(sys.modules['__main__'], '__file__'):
55 my_path = os.path.abspath(sys.modules['__main__'].__file__)
56 elts = os.path.dirname(my_path).split(os.sep)[:-1]
57 sys.path.append(os.sep.join(elts))
58 elts.append('shinken')
59 sys.path.append(os.sep.join(elts))
61 from shinken.daemons.brokerdaemon import Broker, usage
63 #lets go to the party
64 if __name__ == "__main__":
65 #Manage the options
66 try:
67 opts, args = getopt.getopt(sys.argv[1:], "hrdc::w", ["help", "replace", "daemon", "config=", "debug=", "easter"])
68 except getopt.GetoptError, err:
69 # print help information and exit:
70 print str(err) # will print something like "option -a not recognized"
71 usage(sys.argv[0])
72 sys.exit(2)
73 #Default params
74 config_file = None
75 is_daemon=False
76 do_replace=False
77 debug=False
78 debug_file=None
79 for o, a in opts:
80 if o in ("-h", "--help"):
81 usage(sys.argv[0])
82 sys.exit()
83 elif o in ("-r", "--replace"):
84 do_replace = True
85 elif o in ("-c", "--config"):
86 config_file = a
87 elif o in ("-d", "--daemon"):
88 is_daemon = True
89 elif o in ("--debug"):
90 debug = True
91 debug_file = a
92 else:
93 print "Sorry, the option",o, a, "is unknown"
94 usage(sys.argv[0])
95 sys.exit()
97 daemon = Broker(config_file, is_daemon, do_replace, debug, debug_file)
99 daemon.main()