Я пытаюсь использовать 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. Я также изменил предоставленный конфигурационный файл @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
Проверьте, включена ли у вас поддержка 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
Если это не так, вы должны убедиться, что вы скомпилировали syslog-ng с поддержкой python или, если вы установили из пакетов, установите пакет с именем syslog-ng-python
или похожие.