Example #1
0
def main():
    parser = optparse.OptionParser(
        "%prog [options]", version="%prog " + VERSION)
    parser.add_option('-c', '--config',
                      dest="config_file", metavar="INI-CONFIG-FILE",
                      help='Config file')
    parser.add_option('-d', '--daemon', action='store_true',
                      dest="is_daemon",
                      help="Run in daemon mode")
    parser.add_option('-r', '--replace', action='store_true',
                      dest="do_replace",
                      help="Replace previous running broker")
    parser.add_option('--debugfile', dest='debug_file',
                      help=("Debug file. Default: not used "
                            "(why debug a bug free program? :) )"))
    parser.add_option("-p", "--profile",
                      dest="profile",
                      help="Dump a profile file. Need the python cProfile librairy")

    opts, args = parser.parse_args()
    if args:
        parser.error("Does not accept any argument.")

    daemon = Broker(debug=opts.debug_file is not None, **opts.__dict__)
    if not opts.profile:
        daemon.main()
    else:
        # For perf tuning:
        import cProfile
        cProfile.run('''daemon.main()''', opts.profile)
Example #2
0
    def test_pickle_retention(self):
        # get our modules
        mod = pickle_retention_file_generic.Pickle_retention_generic(
            modconf, 'tmp/retention-test.dat')
        try:
            os.unlink(mod.path)
        except:
            pass

        sl = get_instance(mod)
        # Hack here :(
        sl.properties = {}
        sl.properties['to_queue'] = None
        sl.init()

        svc = self.sched.services.find_srv_by_name_and_hostname(
            "test_host_0", "test_ok_0")
        self.scheduler_loop(1, [[svc, 2, 'BAD | value1=0 value2=0']])

        self.sched.get_new_broks()

        # Saving the broks we got
        old_broks = copy.copy(self.sched.broks)

        # Now get a real broker object
        broker = Broker('', False, False, False, None)

        broker.broks = self.sched.broks.values()
        sl.hook_save_retention(broker)  #, l)
        # update the hosts and service in the scheduler in the retention-file

        # Now we clean the source, like if we restart
        broker.broks = []

        self.assertEqual(len(broker.broks), 0)

        r = sl.hook_load_retention(broker)

        # We check we load them :)
        for b in old_broks.values():
            found = False
            for b2 in broker.broks:
                if b2.id == b.id:
                    found = True
            self.assertTrue(found)

        # Ok, we can delete the retention file
        os.unlink(mod.path)
    def test_pickle_retention(self):
        # get our modules
        mod = pickle_retention_file_generic.Pickle_retention_generic(
            modconf, 'tmp/retention-test.dat')
        try:
            os.unlink(mod.path)
        except:
            pass

        sl = get_instance(mod)
        # Hack here :(
        sl.properties = {}
        sl.properties['to_queue'] = None
        sl.init()

        svc = self.sched.services.find_srv_by_name_and_hostname(
            "test_host_0", "test_ok_0")
        self.scheduler_loop(1, [[svc, 2, 'BAD | value1=0 value2=0']])

        self.sched.get_new_broks()

        # Saving the broks we got
        old_broks = copy.copy(self.sched.broks)

        # Now get a real broker object
        broker = Broker('', False, False, False, None)

        broker.broks = self.sched.broks.values()
        sl.hook_save_retention(broker) #, l)
        # update the hosts and service in the scheduler in the retention-file

        # Now we clean the source, like if we restart
        broker.broks = []

        self.assertEqual(len(broker.broks), 0)

        r = sl.hook_load_retention(broker)

        # We check we load them :)
        for b in old_broks.values():
            found = False
            for b2 in broker.broks:
                if b2.id == b.id:
                    found = True
            self.assertTrue(found)

        # Ok, we can delete the retention file
        os.unlink(mod.path)
Example #4
0
def main():
    parser = optparse.OptionParser("%prog [options]",
                                   version="%prog " + VERSION)
    parser.add_option('-c',
                      '--config',
                      dest="config_file",
                      metavar="INI-CONFIG-FILE",
                      help='Config file')
    parser.add_option('-d',
                      '--daemon',
                      action='store_true',
                      dest="is_daemon",
                      help="Run in daemon mode")
    parser.add_option('-r',
                      '--replace',
                      action='store_true',
                      dest="do_replace",
                      help="Replace previous running broker")
    parser.add_option('--debugfile',
                      dest='debug_file',
                      help=("Debug file. Default: not used "
                            "(why debug a bug free program? :) )"))
    parser.add_option(
        "-p",
        "--profile",
        dest="profile",
        help="Dump a profile file. Need the python cProfile librairy")

    opts, args = parser.parse_args()
    if args:
        parser.error("Does not accept any argument.")

    daemon = Broker(debug=opts.debug_file is not None, **opts.__dict__)
    if not opts.profile:
        daemon.main()
    else:
        # For perf tuning:
        import cProfile
        cProfile.run('''daemon.main()''', opts.profile)
from shinken.daemons.brokerdaemon import Broker
from shinken.bin import VERSION

parser = optparse.OptionParser(
    "%prog [options]", version="%prog " + VERSION)
parser.add_option('-c', '--config',
                  dest="config_file", metavar="CONFIG-FILE",
                  help='Config file')
parser.add_option('-d', '--daemon', action='store_true',
                  dest="is_daemon",
                  help="Run in daemon mode")
parser.add_option('-r', '--replace', action='store_true',
                  dest="do_replace",
                  help="Replace previous running broker")
parser.add_option('--debugfile', dest='debug_file',
                  help=("Debug file. Default: not used "
                        "(why debug a bug free program? :) )"))
opts, args = parser.parse_args()
if args:
    parser.error("Does not accept any argument.")

# Protect for windows multiprocessing that will RELAUNCH all
if __name__ == '__main__':
    daemon = Broker(debug=opts.debug_file is not None, **opts.__dict__)
    daemon.main()

# For perf tuning: 
#import cProfile
#cProfile.run('''daemon.main()''', '/tmp/broker.profile')