本文整理汇总了Python中shinken.objects.config.Config类的典型用法代码示例。如果您正苦于以下问题:Python Config类的具体用法?Python Config怎么用?Python Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: loadconfig
def loadconfig(configfile):
try:
c = Config()
c.read_config_silent = 1
r = c.read_config(configfile)
b = c.read_config_buf(r)
return (True, b)
except:
return (False, "There was an error reading the configuration file")
开发者ID:pjjw,项目名称:shinken,代码行数:9,代码来源:skonf.py
示例2: loadconfig
def loadconfig(self):
try:
c=Config()
c.read_config_silent=1
r=c.read_config(self.configfile)
self.config=c.read_config_buf(r)
return (True,"Config loaded")
except:
return (False,"There was an error reading the configuration file")
开发者ID:mleinart,项目名称:shinken,代码行数:9,代码来源:libskonf.py
示例3: Converter
class Converter(object):
def __init__(self, file):
logger.load_obj(Dummy())
self.conf = Config()
buf = self.conf.read_config([file])
raw_objects = self.conf.read_config_buf(buf)
self.conf.create_objects_for_type(raw_objects, 'arbiter')
self.conf.create_objects_for_type(raw_objects, 'module')
self.conf.early_arbiter_linking()
self.conf.create_objects(raw_objects)
for mod in self.conf.modules:
if mod.module_type == 'logstore_sqlite':
self.mod_sqlite = get_instance_sqlite(mod)
self.mod_sqlite.init()
if mod.module_type == 'logstore_mongodb':
self.mod_mongodb = get_instance_mongodb(mod)
开发者ID:0pc0deFR,项目名称:shinken,代码行数:17,代码来源:sql2mdb.py
示例4: getconf
def getconf(self, config):
'''
Get the data in the arbiter for a table and some properties
like hosts host_name realm
'''
files = [config]
conf = Config()
conf.read_config_silent = 1
# Get hosts objects
properties = [ 'host_name','use','act_depend_of']
hosts = self.arb.get_objects_properties('hosts', properties)
# Get services dependencies
svcdep_buf = conf.read_config(files)
svc_dep = conf.read_config_buf(svcdep_buf)['servicedependency']
return (hosts, svc_dep)
开发者ID:A3Sec,项目名称:shinken,代码行数:18,代码来源:service_dependency_mapping.py
示例5: getconf
def getconf(self, config):
"""
Get the data in the arbiter for a table and some properties
like hosts host_name realm
"""
files = [config]
conf = Config()
conf.read_config_silent = 1
# Get hosts objects
properties = ["host_name", "use", "act_depend_of"]
hosts = self.arb.get_objects_properties("hosts", properties)
# Get services dependencies
svcdep_buf = conf.read_config(files)
svc_dep = conf.read_config_buf(svcdep_buf)["servicedependency"]
return (hosts, svc_dep)
开发者ID:daniellawrence,项目名称:shinken,代码行数:18,代码来源:service_dependency_mapping.py
示例6: setup_with_file
def setup_with_file(self, path):
# i am arbiter-like
self.broks = {}
self.me = None
self.log = logger
self.log.load_obj(self)
self.config_files = [path]
self.conf = Config()
buf = self.conf.read_config(self.config_files)
raw_objects = self.conf.read_config_buf(buf)
self.conf.create_objects_for_type(raw_objects, 'arbiter')
self.conf.create_objects_for_type(raw_objects, 'module')
self.conf.early_arbiter_linking()
self.conf.create_objects(raw_objects)
self.conf.old_properties_names_to_new()
self.conf.instance_id = 0
self.conf.instance_name = 'test'
# Hack push_flavor, that is set by the dispatcher
self.conf.push_flavor = 0
self.conf.linkify_templates()
self.conf.apply_inheritance()
self.conf.explode()
print "Aconf.services has %d elements" % len(self.conf.services)
self.conf.create_reversed_list()
self.conf.remove_twins()
self.conf.apply_implicit_inheritance()
self.conf.fill_default()
self.conf.remove_templates()
print "conf.services has %d elements" % len(self.conf.services)
self.conf.create_reversed_list()
self.conf.pythonize()
self.conf.linkify()
self.conf.apply_dependencies()
self.conf.explode_global_conf()
self.conf.propagate_timezone_option()
self.conf.create_business_rules()
self.conf.create_business_rules_dependencies()
self.conf.is_correct()
self.confs = self.conf.cut_into_parts()
self.conf.show_errors()
self.dispatcher = Dispatcher(self.conf, self.me)
scheddaemon = Shinken(None, False, False, False, None)
self.sched = Scheduler(scheddaemon)
scheddaemon.sched = self.sched
m = MacroResolver()
m.init(self.conf)
self.sched.load_conf(self.conf)
e = ExternalCommandManager(self.conf, 'applyer')
self.sched.external_command = e
e.load_scheduler(self.sched)
e2 = ExternalCommandManager(self.conf, 'dispatcher')
e2.load_arbiter(self)
self.external_command_dispatcher = e2
self.sched.schedule()
开发者ID:jfbutkiewicz,项目名称:Windows-Setup-for-Shinken,代码行数:57,代码来源:shinken_test.py
示例7: setup_with_file
def setup_with_file(self, path):
time_hacker.set_my_time()
self.print_header()
# i am arbiter-like
self.broks = {}
self.me = None
self.log = logger
self.log.load_obj(self)
self.config_files = [path]
self.conf = Config()
buf = self.conf.read_config(self.config_files)
raw_objects = self.conf.read_config_buf(buf)
self.conf.create_objects_for_type(raw_objects, 'arbiter')
self.conf.create_objects_for_type(raw_objects, 'module')
self.conf.early_arbiter_linking()
# If we got one arbiter defined here (before default) we should be in a case where
# the tester want to load/test a module, so we simulate an arbiter daemon
# and the modules loading phase. As it has its own modulesmanager, should
# not impact scheduler modules ones, especially we are asking for arbiter type :)
if len(self.conf.arbiters) == 1:
arbdaemon = Arbiter([''],[''], False, False, None, None)
# only load if the module_dir is reallyexisting, so was set explicitly
# in the test configuration
if os.path.exists(getattr(self.conf, 'modules_dir', '')):
arbdaemon.modules_dir = self.conf.modules_dir
arbdaemon.load_modules_manager()
# we request the instances without them being *started*
# (for those that are concerned ("external" modules):
# we will *start* these instances after we have been daemonized (if requested)
me = None
for arb in self.conf.arbiters:
me = arb
arbdaemon.modules_manager.set_modules(arb.modules)
arbdaemon.do_load_modules()
arbdaemon.load_modules_configuration_objects(raw_objects)
self.conf.create_objects(raw_objects)
self.conf.instance_id = 0
self.conf.instance_name = 'test'
# Hack push_flavor, that is set by the dispatcher
self.conf.push_flavor = 0
self.conf.load_triggers()
#import pdb;pdb.set_trace()
self.conf.linkify_templates()
#import pdb;pdb.set_trace()
self.conf.apply_inheritance()
#import pdb;pdb.set_trace()
self.conf.explode()
#print "Aconf.services has %d elements" % len(self.conf.services)
self.conf.apply_implicit_inheritance()
self.conf.fill_default()
self.conf.remove_templates()
self.conf.compute_hash()
#print "conf.services has %d elements" % len(self.conf.services)
self.conf.override_properties()
self.conf.linkify()
self.conf.apply_dependencies()
self.conf.set_initial_state()
self.conf.explode_global_conf()
self.conf.propagate_timezone_option()
self.conf.create_business_rules()
self.conf.create_business_rules_dependencies()
self.conf.is_correct()
if not self.conf.conf_is_correct:
print "The conf is not correct, I stop here"
self.conf.dump()
return
self.conf.clean()
self.confs = self.conf.cut_into_parts()
self.conf.prepare_for_sending()
self.conf.show_errors()
self.dispatcher = Dispatcher(self.conf, self.me)
scheddaemon = Shinken(None, False, False, False, None, None)
self.scheddaemon = scheddaemon
self.sched = scheddaemon.sched
scheddaemon.modules_dir = modules_dir
scheddaemon.load_modules_manager()
# Remember to clean the logs we just created before launching tests
self.clear_logs()
m = MacroResolver()
m.init(self.conf)
self.sched.load_conf(self.conf, in_test=True)
e = ExternalCommandManager(self.conf, 'applyer')
self.sched.external_command = e
e.load_scheduler(self.sched)
e2 = ExternalCommandManager(self.conf, 'dispatcher')
e2.load_arbiter(self)
self.external_command_dispatcher = e2
self.sched.conf.accept_passive_unknown_check_results = False
self.sched.schedule()
开发者ID:Aimage,项目名称:shinken,代码行数:95,代码来源:shinken_test.py
示例8: ShinkenTest
class ShinkenTest(unittest.TestCase):
def setUp(self):
self.setup_with_file('etc/shinken_1r_1h_1s.cfg')
def setup_with_file(self, path):
time_hacker.set_my_time()
self.print_header()
# i am arbiter-like
self.broks = {}
self.me = None
self.log = logger
self.log.load_obj(self)
self.config_files = [path]
self.conf = Config()
buf = self.conf.read_config(self.config_files)
raw_objects = self.conf.read_config_buf(buf)
self.conf.create_objects_for_type(raw_objects, 'arbiter')
self.conf.create_objects_for_type(raw_objects, 'module')
self.conf.early_arbiter_linking()
# If we got one arbiter defined here (before default) we should be in a case where
# the tester want to load/test a module, so we simulate an arbiter daemon
# and the modules loading phase. As it has its own modulesmanager, should
# not impact scheduler modules ones, especially we are asking for arbiter type :)
if len(self.conf.arbiters) == 1:
arbdaemon = Arbiter([''],[''], False, False, None, None)
# only load if the module_dir is reallyexisting, so was set explicitly
# in the test configuration
if os.path.exists(getattr(self.conf, 'modules_dir', '')):
arbdaemon.modules_dir = self.conf.modules_dir
arbdaemon.load_modules_manager()
# we request the instances without them being *started*
# (for those that are concerned ("external" modules):
# we will *start* these instances after we have been daemonized (if requested)
me = None
for arb in self.conf.arbiters:
me = arb
arbdaemon.modules_manager.set_modules(arb.modules)
arbdaemon.do_load_modules()
arbdaemon.load_modules_configuration_objects(raw_objects)
self.conf.create_objects(raw_objects)
self.conf.instance_id = 0
self.conf.instance_name = 'test'
# Hack push_flavor, that is set by the dispatcher
self.conf.push_flavor = 0
self.conf.load_triggers()
#import pdb;pdb.set_trace()
self.conf.linkify_templates()
#import pdb;pdb.set_trace()
self.conf.apply_inheritance()
#import pdb;pdb.set_trace()
self.conf.explode()
#print "Aconf.services has %d elements" % len(self.conf.services)
self.conf.apply_implicit_inheritance()
self.conf.fill_default()
self.conf.remove_templates()
self.conf.compute_hash()
#print "conf.services has %d elements" % len(self.conf.services)
self.conf.override_properties()
self.conf.linkify()
self.conf.apply_dependencies()
self.conf.set_initial_state()
self.conf.explode_global_conf()
self.conf.propagate_timezone_option()
self.conf.create_business_rules()
self.conf.create_business_rules_dependencies()
self.conf.is_correct()
if not self.conf.conf_is_correct:
print "The conf is not correct, I stop here"
self.conf.dump()
return
self.conf.clean()
self.confs = self.conf.cut_into_parts()
self.conf.prepare_for_sending()
self.conf.show_errors()
self.dispatcher = Dispatcher(self.conf, self.me)
scheddaemon = Shinken(None, False, False, False, None, None)
self.scheddaemon = scheddaemon
self.sched = scheddaemon.sched
scheddaemon.modules_dir = modules_dir
scheddaemon.load_modules_manager()
# Remember to clean the logs we just created before launching tests
self.clear_logs()
m = MacroResolver()
m.init(self.conf)
self.sched.load_conf(self.conf, in_test=True)
e = ExternalCommandManager(self.conf, 'applyer')
self.sched.external_command = e
e.load_scheduler(self.sched)
e2 = ExternalCommandManager(self.conf, 'dispatcher')
e2.load_arbiter(self)
self.external_command_dispatcher = e2
self.sched.conf.accept_passive_unknown_check_results = False
self.sched.schedule()
#.........这里部分代码省略.........
开发者ID:Aimage,项目名称:shinken,代码行数:101,代码来源:shinken_test.py
示例9: setup_with_file
def setup_with_file(self, path):
time_hacker.set_my_time()
self.print_header()
# i am arbiter-like
self.broks = {}
self.me = None
self.log = logger
self.log.load_obj(self)
self.config_files = [path]
self.conf = Config()
buf = self.conf.read_config(self.config_files)
raw_objects = self.conf.read_config_buf(buf)
self.conf.create_objects_for_type(raw_objects, 'arbiter')
self.conf.create_objects_for_type(raw_objects, 'module')
self.conf.early_arbiter_linking()
self.conf.create_objects(raw_objects)
self.conf.instance_id = 0
self.conf.instance_name = 'test'
# Hack push_flavor, that is set by the dispatcher
self.conf.push_flavor = 0
self.conf.load_triggers()
#import pdb;pdb.set_trace()
self.conf.linkify_templates()
#import pdb;pdb.set_trace()
self.conf.apply_inheritance()
#import pdb;pdb.set_trace()
self.conf.explode()
#print "Aconf.services has %d elements" % len(self.conf.services)
self.conf.apply_implicit_inheritance()
self.conf.fill_default()
self.conf.remove_templates()
self.conf.compute_hash()
#print "conf.services has %d elements" % len(self.conf.services)
self.conf.override_properties()
self.conf.linkify()
self.conf.apply_dependencies()
self.conf.explode_global_conf()
self.conf.propagate_timezone_option()
self.conf.create_business_rules()
self.conf.create_business_rules_dependencies()
self.conf.is_correct()
if not self.conf.conf_is_correct:
print "The conf is not correct, I stop here"
self.conf.dump()
return
self.conf.clean()
self.confs = self.conf.cut_into_parts()
self.conf.prepare_for_sending()
self.conf.show_errors()
self.dispatcher = Dispatcher(self.conf, self.me)
scheddaemon = Shinken(None, False, False, False, None, None)
self.sched = Scheduler(scheddaemon)
scheddaemon.sched = self.sched
scheddaemon.modules_dir = modules_dir
scheddaemon.load_modules_manager()
# Remember to clean the logs we just created before launching tests
self.clear_logs()
m = MacroResolver()
m.init(self.conf)
self.sched.load_conf(self.conf, in_test=True)
e = ExternalCommandManager(self.conf, 'applyer')
self.sched.external_command = e
e.load_scheduler(self.sched)
e2 = ExternalCommandManager(self.conf, 'dispatcher')
e2.load_arbiter(self)
self.external_command_dispatcher = e2
self.sched.conf.accept_passive_unknown_check_results = False
self.sched.schedule()
开发者ID:MPOWER4RU,项目名称:shinken,代码行数:72,代码来源:shinken_test.py
示例10: ShinkenTest
class ShinkenTest(unittest.TestCase, _Unittest2CompatMixIn):
def setUp(self):
self.setup_with_file('etc/shinken_1r_1h_1s.cfg')
def setup_with_file(self, path):
self.print_header()
# i am arbiter-like
self.broks = {}
self.me = None
self.log = logger
self.log.load_obj(self)
self.config_files = [path]
self.conf = Config()
buf = self.conf.read_config(self.config_files)
raw_objects = self.conf.read_config_buf(buf)
self.conf.create_objects_for_type(raw_objects, 'arbiter')
self.conf.create_objects_for_type(raw_objects, 'module')
self.conf.early_arbiter_linking()
self.conf.create_objects(raw_objects)
self.conf.old_properties_names_to_new()
self.conf.instance_id = 0
self.conf.instance_name = 'test'
# Hack push_flavor, that is set by the dispatcher
self.conf.push_flavor = 0
self.conf.load_triggers()
self.conf.linkify_templates()
self.conf.apply_inheritance()
self.conf.explode()
#print "Aconf.services has %d elements" % len(self.conf.services)
self.conf.create_reversed_list()
self.conf.remove_twins()
self.conf.apply_implicit_inheritance()
self.conf.fill_default()
self.conf.remove_templates()
self.conf.compute_hash()
#print "conf.services has %d elements" % len(self.conf.services)
self.conf.create_reversed_list()
self.conf.override_properties()
self.conf.pythonize()
count = self.conf.remove_exclusions()
if count > 0:
self.conf.create_reversed_list()
self.conf.linkify()
self.conf.apply_dependencies()
self.conf.explode_global_conf()
self.conf.propagate_timezone_option()
self.conf.create_business_rules()
self.conf.create_business_rules_dependencies()
self.conf.is_correct()
if not self.conf.conf_is_correct:
print "The conf is not correct, I stop here"
return
self.conf.clean()
self.confs = self.conf.cut_into_parts()
self.conf.prepare_for_sending()
self.conf.show_errors()
self.dispatcher = Dispatcher(self.conf, self.me)
scheddaemon = Shinken(None, False, False, False, None, None)
self.sched = Scheduler(scheddaemon)
scheddaemon.sched = self.sched
scheddaemon.modules_dir = modules_dir
scheddaemon.load_modules_manager()
# Remember to clean the logs we just created before launching tests
self.clear_logs()
m = MacroResolver()
m.init(self.conf)
self.sched.load_conf(self.conf, in_test=True)
e = ExternalCommandManager(self.conf, 'applyer')
self.sched.external_command = e
e.load_scheduler(self.sched)
e2 = ExternalCommandManager(self.conf, 'dispatcher')
e2.load_arbiter(self)
self.external_command_dispatcher = e2
self.sched.schedule()
def add(self, b):
if isinstance(b, Brok):
self.broks[b.id] = b
return
if isinstance(b, ExternalCommand):
self.sched.run_external_command(b.cmd_line)
def fake_check(self, ref, exit_status, output="OK"):
#print "fake", ref
now = time.time()
ref.schedule(force=True)
# now checks are schedule and we get them in
# the action queue
#check = ref.actions.pop()
check = ref.checks_in_progress[0]
self.sched.add(check) # check is now in sched.checks[]
# Allows to force check scheduling without setting its status nor
# output. Useful for manual business rules rescheduling, for instance.
if exit_status is None:
return
#.........这里部分代码省略.........
开发者ID:adenir2202,项目名称:shinken,代码行数:101,代码来源:shinken_test.py
示例11: ShinkenTest
class ShinkenTest(unittest.TestCase):
def setUp(self):
self.setup_with_file('etc/nagios_1r_1h_1s.cfg')
def setup_with_file(self, path):
# i am arbiter-like
self.broks = {}
self.me = None
self.log = logger
self.log.load_obj(self)
self.config_files = [path]
self.conf = Config()
buf = self.conf.read_config(self.config_files)
raw_objects = self.conf.read_config_buf(buf)
self.conf.create_objects_for_type(raw_objects, 'arbiter')
self.conf.create_objects_for_type(raw_objects, 'module')
self.conf.early_arbiter_linking()
self.conf.create_objects(raw_objects)
self.conf.old_properties_names_to_new()
self.conf.instance_id = 0
self.conf.instance_name = 'test'
# Hack push_flavor, that is set by the dispatcher
self.conf.push_flavor = 0
self.conf.load_triggers()
self.conf.linkify_templates()
self.conf.apply_inheritance()
self.conf.explode()
#print "Aconf.services has %d elements" % len(self.conf.services)
self.conf.create_reversed_list()
self.conf.remove_twins()
self.conf.apply_implicit_inheritance()
self.conf.fill_default()
self.conf.remove_templates()
self.conf.compute_hash()
#print "conf.services has %d elements" % len(self.conf.services)
self.conf.create_reversed_list()
self.conf.pythonize()
self.conf.linkify()
self.conf.apply_dependencies()
self.conf.explode_global_conf()
self.conf.propagate_timezone_option()
self.conf.create_business_rules()
self.conf.create_business_rules_dependencies()
self.conf.is_correct()
if not self.conf.conf_is_correct:
print "The conf is not correct, I stop here"
return
self.confs = self.conf.cut_into_parts()
self.conf.prepare_for_sending()
self.conf.show_errors()
self.dispatcher = Dispatcher(self.conf, self.me)
scheddaemon = Shinken(None, False, False, False, None)
self.sched = Scheduler(scheddaemon)
scheddaemon.sched = self.sched
m = MacroResolver()
m.init(self.conf)
self.sched.load_conf(self.conf, in_test=True)
e = ExternalCommandManager(self.conf, 'applyer')
self.sched.external_command = e
e.load_scheduler(self.sched)
e2 = ExternalCommandManager(self.conf, 'dispatcher')
e2.load_arbiter(self)
self.external_command_dispatcher = e2
self.sched.schedule()
def add(self, b):
if isinstance(b, Brok):
self.broks[b.id] = b
return
if isinstance(b, ExternalCommand):
self.sched.run_external_command(b.cmd_line)
def fake_check(self, ref, exit_status, output="OK"):
#print "fake", ref
now = time.time()
ref.schedule(force=True)
# now checks are schedule and we get them in
# the action queue
check = ref.actions.pop()
self.sched.add(check) # check is now in sched.checks[]
# fake execution
check.check_time = now
# and lie about when we will launch it because
# if not, the schedule call for ref
# will not really reschedule it because there
# is a valid value in the future
ref.next_chk = now - 0.5
check.get_outputs(output, 9000)
check.exit_status = exit_status
check.execution_time = 0.001
check.status = 'waitconsume'
self.sched.waiting_results.append(check)
#.........这里部分代码省略.........
开发者ID:BaniaHP,项目名称:shinken,代码行数:101,代码来源:shinken_test.py
示例12: ShinkenTest
class ShinkenTest(unittest.TestCase):
def setUp(self):
self.setup_with_file('etc/nagios_1r_1h_1s.cfg')
def setup_with_file(self, path):
# i am arbiter-like
self.broks = {}
self.me = None
self.log = logger
self.log.load_obj(self)
self.config_files = [path]
self.conf = Config()
self.conf.read_config(self.config_files)
buf = self.conf.read_config(self.config_files)
raw_objects = self.conf.read_config_buf(buf)
self.conf.create_objects_for_type(raw_objects, 'arbiter')
self.conf.create_objects_for_type(raw_objects, 'module')
self.conf.early_arbiter_linking()
self.conf.create_objects(raw_objects)
self.conf.old_properties_names_to_new()
self.conf.instance_id = 0
self.conf.instance_name = 'test'
self.conf.linkify_templates()
self.conf.apply_inheritance()
self.conf.explode()
self.conf.create_reversed_list()
self.conf.remove_twins()
self.conf.apply_implicit_inheritance()
self.conf.fill_default()
self.conf.remove_templates()
self.conf.create_reversed_list()
self.conf.pythonize()
self.conf.linkify()
self.conf.apply_dependencies()
self.conf.explode_global_conf()
self.conf.propagate_timezone_option()
self.conf.create_business_rules()
self.conf.create_business_rules_dependencies()
self.conf.is_correct()
self.confs = self.conf.cut_into_parts()
self.conf.show_errors()
self.dispatcher = Dispatcher(self.conf, self.me)
scheddaemon = Shinken(None, False, False, False, None)
self.sched = Scheduler(scheddaemon)
scheddaemon.sched = self.sched
m = MacroResolver()
m.init(self.conf)
self.sched.load_conf(self.conf)
e = ExternalCommandManager(self.conf, 'applyer')
self.sched.external_command = e
e.load_scheduler(self.sched)
e2 = ExternalCommandManager(self.conf, 'dispatcher')
e2.load_arbiter(self)
self.external_command_dispatcher = e2
self.sched.schedule()
def add(self, b):
if isinstance(b, Brok):
self.broks[b.id] = b
return
if isinstance(b, ExternalCommand):
self.sched.run_external_command(b.cmd_line)
def fake_check(self, ref, exit_status, output="OK"):
#print "fake", ref
now = time.time()
ref.schedule(force=True)
#now checks are schedule and we get them in
#the action queue
check = ref.actions.pop()
self.sched.add(check) # check is now in sched.checks[]
# fake execution
check.check_time = now
# and lie about when we will launch it because
# if not, the schedule call for ref
# will not really reschedule it because there
# is a valid value in the future
ref.next_chk = now - 0.5
check.get_outputs(output, 9000)
check.exit_status = exit_status
check.execution_time = 0.001
check.status = 'waitconsume'
self.sched.waiting_results.append(check)
def scheduler_loop(self, count, reflist, do_sleep=False, sleep_time=61):
for ref in reflist:
(obj, exit_status, output) = ref
obj.checks_in_progress = []
for loop in range(1, count + 1):
print "processing check", loop
for ref in reflist:
(obj, exit_status, output) = ref
#.........这里部分代码省略.........
开发者ID:mleinart,项目名称:shinken,代码行数:101,代码来源:shinken_test.py
示例13: ShinkenTest
class ShinkenTest(unittest.TestCase):
def setUp(self):
self.setup_with_file('etc/nagios_1r_1h_1s.cfg')
def setup_with_file(self, path):
# i am arbiter-like
self.broks = {}
self.me = None
self.log = logger
self.log.load_obj(self)
self.config_files = [path]
self.conf = Config()
self.conf.read_config(self.config_files)
buf = self.conf.read_config(self.config_files)
raw_objects = self.conf.read_config_buf(buf)
self.conf.create_objects_for_type(raw_objects, 'arbiter')
self.conf.create_objects_for_type(raw_objects, 'module')
self.conf.early_arbiter_linking()
self.conf.create_objects(raw_objects)
self.conf.instance_id = 0
self.conf.instance_name = 'test'
self.conf.linkify_templates()
self.conf.apply_inheritance()
self.conf.explode()
self.conf.create_reversed_list()
self.conf.remove_twins()
self.conf.apply_implicit_inheritance()
self.conf.fill_default()
self.conf.clean_useless()
self.conf.pythonize()
self.conf.linkify()
self.conf.apply_dependancies()
self.conf.explode_global_conf()
self.conf.propagate_timezone_option()
self.conf.create_business_rules()
self.conf.create_business_rules_dependencies()
self.conf.is_correct()
self.confs = self.conf.cut_into_parts()
self.dispatcher = Dispatcher(self.conf, self.me)
scheddaemon = Shinken(None, False, False, False, None)
self.sched = Scheduler(scheddaemon)
scheddaemon.sched = self.sched
m = MacroResolver()
m.init(self.conf)
self.sched.load_conf(self.conf)
e = ExternalCommandManager(self.conf, 'applyer')
self.sched.external_command = e
e.load_scheduler(self.sched)
e2 = ExternalCommandManager(self.conf, 'dispatcher')
e2.load_arbiter(self)
self.external_command_dispatcher = e2
self.sched.schedule()
def add(self, b):
if isinstance(b, Brok):
self.broks[b.id] = b
return
if isinstance(b, ExternalCommand):
self.sched.run_external_command(b.cmd_line)
def fake_check(self, ref, exit_status, output="OK"):
#print "fake", ref
now = time.time()
ref.schedule(force=True)
#now checks are schedule and we get them in
#the action queue
check = ref.actions.pop()
self.sched.add(check) # check is now in sched.checks[]
# fake execution
check.check_time = now
elts_line1 = output.split('|')
#First line before | is output
check.output = elts_line1[0]
#After | is perfdata
if len(elts_line1) > 1:
check.perf_data = elts_line1[1]
else:
check.perf_data = ''
check.exit_status = exit_status
check.execution_time = 0.001
check.status = 'waitconsume'
self.sched.waiting_results.append(check)
def scheduler_loop(self, count, reflist, do_sleep=False, sleep_time=61):
for ref in reflist:
(obj, exit_status, output) = ref
obj.checks_in_progress = []
for loop in range(1, count + 1):
print "processing check", loop
for ref in reflist:
(obj, exit_status, output) = ref
obj.update_in_checking()
self.fake_check(obj, exit_status, output)
#.........这里部分代码省略.........
开发者ID:zoranzaric,项目名称:shinken,代码行数:101,代码来源:shinken_test.py
示例14: test_types
def test_types(self):
path = 'etc/shinken_1r_1h_1s.cfg'
time_hacker.set_my_time()
self.print_header()
# i am arbiter-like
self.broks = {}
self.me = None
self.log = logger
self.log.setLevel("INFO")
self.log.load_obj(self)
self.config_files = [path]
self.conf = Config()
buf = self.conf.read_config(self.config_files)
raw_objects = self.conf.read_config_buf(buf)
self.conf.create_objects_for_type(raw_objects, 'arbiter')
self.conf.create_objects_for_type(raw_objects, 'module')
self.conf.early_arbiter_linking()
self.conf.create_objects(raw_objects)
self.conf.instance_id = 0
self.conf.instance_name = 'test'
# Hack push_flavor, that is set by the dispatcher
self.conf.push_flavor = 0
self.conf.load_triggers()
self.conf.linkify_templates()
self.conf.apply_inheritance()
self.conf.explode()
self.conf.apply_implicit_inheritance()
self.conf.fill_default()
self.conf.remove_templates()
self.conf.compute_hash()
self.conf.override_properties()
self.conf.linkify()
self.conf.apply_dependencies()
self.conf.explode_global_conf()
self.conf.propagate_timezone_option()
self.conf.create_business_rules()
self.conf.create_business_rules_dependencies()
self.conf.is_correct()
# Cannot do it for all obj for now. We have to ensure unicode everywhere fist
for objs in [self.conf.arbiters]:
for obj in objs:
#print "=== obj : %s ===" % obj.__class__
for prop in obj.properties:
if hasattr(obj, prop):
value = getattr(obj, prop)
# We should get ride of None, maybe use the "neutral" value for type
if value is not None:
#print("TESTING %s with value %s" % (prop, value))
self.assertIsInstance(value, self.map_type(obj.properties[prop]))
else:
print("Skipping %s " % prop)
#print "==="
# Manual check of several attr for self.conf.contacts
# because contacts contains unicode attr
for contact in self.conf.contacts:
for prop in ["notificationways", "host_notification_commands", "service_notification_commands"]:
if hasattr(contact, prop):
value = getattr(contact, prop)
# We should get ride of None, maybe use the "neutral" value for type
if value is not None:
print("TESTING %s with value %s" % (prop, value))
self.assertIsInstance(value, self.map_type(contact.properties[prop]))
else:
print("Skipping %s " % prop)
# Same here
for notifway in self.conf.notificationways:
for prop in ["host_notification_commands", "service_notification_commands"]:
if hasattr(notifway, prop):
value = getattr(notifway, prop)
# We should get ride of None, maybe use the "neutral" value for type
if value is not None:
print("TESTING %s with value %s" % (prop, value))
self.assertIsInstance(value, self.map_type(notifway.properties[prop]))
else:
print("Skipping %s " % prop)
开发者ID:0pc0deFR,项目名称:shinken,代码行数:81,代码来源:test_end_parsing_types.py
示例15: TestEndParsingType
class TestEndParsingType(unittest.TestCase):
def map_type(self, obj):
# TODO: Replace all str with unicode when done in property.default attribute
# TODO: Fix ToGuessProp as it may be a list.
if isinstance(obj, ListProp):
return list
if isinstance(obj, StringProp):
return str
if isinstance(obj, UnusedProp):
return str
if isinstance(obj, BoolProp):
return bool
if isinstance(obj, IntegerProp):
return int
if isinstance(obj, FloatProp):
return float
if isinstance(obj, CharProp):
return str
if isinstance(obj, DictProp):
return dict
if isinstance(obj, AddrProp):
return str
if isinstance(obj, ToGuessProp):
return str
def print_header(self):
print "\n" + "#" * 80 + "\n" + "#" + " " * 78 + "#"
print "#" + string.center(self.id(), 78) + "#"
print "#" + " " * 78 + "#\n" + "#" * 80 + "\n"
def add(self, b):
if isinstance(b, Brok):
self.broks[b.id] = b
return
if isinstance(b, ExternalCommand):
self.sched.run_external_command(b.cmd_line)
def test_types(self):
path = 'etc/shinken_1r_1h_1s.cfg'
time_hacker.set_my_time()
self.print_header()
# i am arbiter-like
self.broks = {}
self.me = None
self.log = logger
self.log.setLevel("INFO")
self.log.load_obj(self)
self.config_files = [path]
self.conf = Config()
buf = self.conf.read_config(self.config_files)
raw_objects = self.conf.read_config_buf(buf)
self.conf.create_objects_for_type(raw_objects, 'arbiter')
self.conf.create_objects_for_type(raw_objects, 'module')
self.conf.early_arbiter_linking()
self.conf.create_objects(raw_objects)
self.conf.instance_id = 0
self.conf.instance_name = 'test'
# Hack push_flavor, that is set by the dispatcher
self.conf.push_flavor = 0
self.conf.load_triggers()
self.conf.linkify_templates()
self.conf.apply_inheritance()
self.conf.explode()
self.conf.apply_implicit_inheritance()
self.conf.fill_default()
self.conf.remove_templates()
self.conf.compute_hash()
self.conf.override_properties()
self.conf.linkify()
self.conf.apply_dependencies()
self.conf.explode_global_conf()
self.conf.propagate_timezone_option()
self.conf.create_business_rules()
self.conf.create_business_rules_dependencies()
self.conf.is_correct()
# Cannot do it for all obj for now. We have to ensure unicode everywhere fist
for objs in [self.conf.arbiters]:
for obj in objs:
#print "=== obj : %s ===" % obj.__class__
for prop in obj.properties:
if hasattr(obj, prop):
value = getattr(obj, prop)
# We should get ride of None, maybe use the "neutral" value for type
if value is not None:
#print("TESTING %s with value %s" % (prop, value))
#.........这里部分代码省略.........
开发者ID:0pc0deFR,项目名称:shinken,代码行数:101,代码来源:test_end_parsing_types.py
注:本文中的shinken.objects.config.Config类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论