【问题标题】:Setting a variable path with syslog-ng python destination使用 syslog-ng python 目标设置变量路径
【发布时间】:2019-03-22 13:15:38
【问题描述】:

这可能吗?据我所见,将选项放入 python 类的唯一方法是将它们硬编码到 python 目的地的选项中。我需要根据 $HOST 之类的宏设置变量路径,但似乎没有插入 python 目标选项。我需要一种将 $HOST 等宏值传递给 init() 方法的方法。

【问题讨论】:

  • 如果您的问题以“我有:”部分描述您的设置、使用的软件和您已有的代码作为开始可能会更好。

标签: python syslog-ng


【解决方案1】:

$HOST 的值随每条消息而变化,因此您实际上需要它在 send() 中,而不是在 init() 中。你可能真正想要的是这样的:

class MyDestination(object):

# ...

  def send(self, msg):
    host = msg["HOST"]
    # ...
    return True

或者您可以使用从 v3.18 开始的模板:

import syslogng

class MyDestination(object):
  def init(self, options):
    self.log_template = syslogng.LogTemplate("$HOST")
    # ...
    return True

  def send(self, msg):
    formatted_string = self.log_template.format(msg, self.template_options)
    # ...
    return True

【讨论】:

    猜你喜欢
    • 2019-03-18
    • 2017-06-02
    • 1970-01-01
    • 2011-11-21
    • 1970-01-01
    • 1970-01-01
    • 2013-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多