Add : (Denis GERMAIN) check_shinken plugin and interface in the arbiter to get data.
[shinken.git] / bin / shinken-arbiter
blobf98b71f68c46a70cf075a73533db2256bf7ae1be
1 #!/usr/bin/env python
2 #Copyright (C) 2009-2011 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
5 # Gregory Starck, g.starck@gmail.com
6 # Hartmut Goebel, h.goebel@goebel-consult.de
8 #This file is part of Shinken.
10 #Shinken is free software: you can redistribute it and/or modify
11 #it under the terms of the GNU Affero General Public License as published by
12 #the Free Software Foundation, either version 3 of the License, or
13 #(at your option) any later version.
15 #Shinken is distributed in the hope that it will be useful,
16 #but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 #GNU Affero General Public License for more details.
20 #You should have received a copy of the GNU Affero General Public License
21 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
24 """
25 This is the class of the Arbiter. It's role is to read configuration,
26 cut it, and send it to other elements like schedulers, reactionners
27 or pollers. It is also responsible for the high avaibility feature.
28 For example, should a scheduler dies, it sends the late scheduler's conf
29 to another scheduler still available.
30 It also reads orders form users (nagios.cmd) and sends them to schedulers.
31 """
34 import os
35 import sys
36 import optparse
39 # We try to raise up recursion limit on
40 # but we don't have resource module on windows
41 if os.name != 'nt':
42 import resource
43 # All the pickle will ask for a lot of recursion, so we must make
44 # sure to set it at a high value. The maximum recursion depth depends
45 # on the Python version and the process limit "stack size".
46 # The factors used were acquired by testing a broad range of installations
47 stacksize_soft, stacksize_hard = resource.getrlimit(3)
48 if sys.version_info < (2,6):
49 sys.setrecursionlimit(int(stacksize_soft * 0.65 + 1100))
50 elif sys.version_info < (3,):
51 sys.setrecursionlimit(int(stacksize_soft * 1.9 + 3200))
52 else:
53 sys.setrecursionlimit(int(stacksize_soft * 2.4 + 3200))
55 try:
56 import shinken
57 except ImportError:
58 # If importing shinken fails, try to load from current directory
59 # or parent directory to support running without installation.
60 # Submodules will then be loaded from there, too.
61 import imp
62 if not hasattr(os, "getuid") or os.getuid() != 0:
63 imp.load_module('shinken', *imp.find_module('shinken', [".", ".."]))
65 from shinken.daemons.arbiterdaemon import Arbiter
66 from shinken.bin import VERSION
68 parser = optparse.OptionParser(
69 "%prog [options] -c configfile [-c additional_config_file]",
70 version="%prog " + VERSION)
71 parser.add_option('-c', '--config', action='append',
72 dest="config_files", metavar="CONFIG-FILE",
73 help=('Config file (your nagios.cfg). Multiple -c can be '
74 'used, it will be like if all files was just one'))
75 parser.add_option('-d', '--daemon', action='store_true',
76 dest="is_daemon",
77 help="Run in daemon mode")
78 parser.add_option('-r', '--replace', action='store_true',
79 dest="do_replace",
80 help="Replace previous running arbiter")
81 parser.add_option('--debugfile', dest='debug_file',
82 help=("Debug file. Default: not used "
83 "(why debug a bug free program? :) )"))
84 parser.add_option("-v", "--verify-config",
85 dest="verify_only", action="store_true",
86 help="Verify config file and exit")
88 opts, args = parser.parse_args()
89 if not opts.config_files:
90 parser.error("Requires at least one config file (option -c/--config")
91 if args:
92 parser.error("Does not accept any argument. Use option -c/--config")
94 daemon = Arbiter(debug=opts.debug_file is not None, **opts.__dict__)
95 daemon.main()