本文整理汇总了Python中shinken.macroresolver.MacroResolver.resolve_simple_macros_in_string方法的典型用法代码示例。如果您正苦于以下问题:Python MacroResolver.resolve_simple_macros_in_string方法的具体用法?Python MacroResolver.resolve_simple_macros_in_string怎么用?Python MacroResolver.resolve_simple_macros_in_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shinken.macroresolver.MacroResolver
的用法示例。
在下文中一共展示了MacroResolver.resolve_simple_macros_in_string方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bprule_expand_template_macros
# 需要导入模块: from shinken.macroresolver import MacroResolver [as 别名]
# 或者: from shinken.macroresolver.MacroResolver import resolve_simple_macros_in_string [as 别名]
def test_bprule_expand_template_macros(self):
svc_cor = self.sched.services.find_srv_by_name_and_hostname("dummy", "formatted_bp_rule_output")
self.assert_(svc_cor.got_business_rule is True)
self.assert_(svc_cor.business_rule is not None)
svc1 = self.sched.services.find_srv_by_name_and_hostname("test_host_01", "srv1")
svc2 = self.sched.services.find_srv_by_name_and_hostname("test_host_02", "srv2")
svc3 = self.sched.services.find_srv_by_name_and_hostname("test_host_03", "srv3")
hst4 = self.sched.hosts.find_by_name("test_host_04")
for i in range(2):
self.scheduler_loop(
1,
[
[svc1, 0, "OK test_host_01/srv1"],
[svc2, 1, "WARNING test_host_02/srv2"],
[svc3, 2, "CRITICAL test_host_03/srv3"],
[hst4, 2, "DOWN test_host_04"],
],
)
time.sleep(61)
self.sched.manage_internal_checks()
self.sched.consume_results()
# Performs checks
m = MacroResolver()
template = "$STATUS$,$SHORTSTATUS$,$HOSTNAME$,$SERVICEDESC$,$FULLNAME$"
data = svc1.get_data_for_checks()
output = m.resolve_simple_macros_in_string(template, data)
self.assert_(output == "OK,O,test_host_01,srv1,test_host_01/srv1")
data = svc2.get_data_for_checks()
output = m.resolve_simple_macros_in_string(template, data)
self.assert_(output == "WARNING,W,test_host_02,srv2,test_host_02/srv2")
data = svc3.get_data_for_checks()
output = m.resolve_simple_macros_in_string(template, data)
self.assert_(output == "CRITICAL,C,test_host_03,srv3,test_host_03/srv3")
data = hst4.get_data_for_checks()
output = m.resolve_simple_macros_in_string(template, data)
self.assert_(output == "DOWN,D,test_host_04,,test_host_04")
data = svc_cor.get_data_for_checks()
output = m.resolve_simple_macros_in_string(template, data)
self.assert_(output == "CRITICAL,C,dummy,formatted_bp_rule_output,dummy/formatted_bp_rule_output")