我正在尝试使用 Syslog-ng,以便它将消息转发到 Python 目标。但是,我不断收到“解析目标时出错,未找到目标插件 Python...”消息。
我正在严格遵循本教程。https://syslog-ng.gitbooks.io/getting-started/content/chapters/chapter_5/section_1.html
据我所知,关键字“java”和“python”需要 Syslog-ng 3.7+。我已将其从 3.5.6 升级到 3.7+。我还将提供的配置文件 @version: 3.7 更改为 @version: 3.8,这是我对示例所做的唯一更改。
为什么 Syslog-ng 无法识别我的配置文件中的关键字“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
答案1
检查一下,如果你启用了 Python 支持syslog-ng -V
,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
或类似的包。