我正在尝试使用Syslog-ng,以便将消息转发到python目标。 但是,我不断收到“错误parsing目标,目标插件python找不到…”消息。
我完全按照这个教程。 https://syslog-ng.gitbooks.io/getting-started/content/chapters/chapter_5/section_1.html
从我可以收集的关键字“java”和“python”需要Syslog-ng 3.7+。 我已经从3.5.6升级到了。 我也将提供的configuration文件@version:3.7更改为@version:3.8,这是我从示例中更改的唯一一个。
任何想法为什么Syslog ng不能识别我的configuration文件中的关键字“python”?
这是提供的脚本。
@version: 3.7 @include "scl.conf" source s_local { system(); internal(); }; destination python_to_file { python( class("betterpythonexample.TextDestination") on-error("fallback-to-string") value-pairs(scope(everything)) ); }; log { source(s_local); destination(python_to_file); };
这是示例中的python代码。
class LogDestination(object): def open(self): """Open a connection to the target service""" return True def close(self): """Close the connection to the target service""" pass def is_opened(self): """Check if the connection to the target is able to receive messages""" return True def init(self): """This method is called at initialization time""" return True def deinit(self): """This method is called at deinitialization time""" pass def send(self, msg): """Send a message to the target service It should return True to indicate success, False will suspend the destination for a period specified by the time-reopen() option.""" pass class TextDestination(LogDestination): def __init__(self): self.outfile = None def init(self): self.outfile = open('/tmp/example.txt', 'a') self.outfile.write("initialized\n") self.outfile.flush() return True def open(self): self.outfile.write("opened\n") self.outfile.flush() return True def close(self): self.outfile.write("closed\n") self.outfile.flush() return True def deinit(self): self.outfile.write("deinit\n") self.outfile.flush() self.outfile.close(); return True def send(self, msg): self.outfile.write("Name Value Pairs are \n") for key,v in msg.items(): self.outfile.write(str(key)+" "+str(v)+"\n"); self.outfile.flush() return True
检查,如果你有使用syslog-ng -V启用python支持。 mod-python应该列在可用的模块中:
linux-utjy:~ # syslog-ng -V syslog-ng 3.7.3 Installer-Version: 3.7.3 Revision: Available-Modules: afamqp,affile,afmongodb,afprog,afsocket,afstomp,afuser,basicfuncs,confgen,cryptofuncs,csvparser,dbparser,graphite,json-plugin,kvformat,linux-kmsg-format,pseudofile,sdjournal,syslogformat,system-source,mod-python Enable-Debug: off Enable-GProf: off Enable-Memtrace: off Enable-IPv6: on Enable-Spoof-Source: on Enable-TCP-Wrapper: on Enable-Linux-Caps: off
如果不是的话,你应该确保你用python支持编译syslog-ng,或者如果你是从软件包安装的,安装一个名为syslog-ng-python或类似的软件包。