Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python destination with python3, can not process msg.MSG #1363

Closed
mitzkia opened this issue Mar 6, 2017 · 2 comments
Closed

python destination with python3, can not process msg.MSG #1363

mitzkia opened this issue Mar 6, 2017 · 2 comments
Assignees
Labels

Comments

@mitzkia
Copy link
Collaborator

mitzkia commented Mar 6, 2017

I got python exception when I wanted to use msg.MSG from python script with python3 interpreter

Reproduction:

  • configure syslog-ng with "with-python=3" option
  • create separate python script file with the following content
  • sngexample.py
class DummyPythonDest(object):
    def init(self, options):
        return True

    def send(self, msg):
        print("send: %s\n" % msg.MSG)
        return True
  • start syslog-ng with the given config
@version: 3.9
source s_net {tcp( ip("127.0.0.1") port(6666) );};
destination d_python {
  python(
    class("sngexample.DummyPythonDest")
  );
};
log {
  source(s_net);
  destination(d_python);
};
  • send message to syslog-ng with loggen
  • got following exception
[2017-03-06T15:08:32.136246] Incoming log entry; line='<38>2017-03-06T15:08:32 localhost prg00000[1234]: seq: 0000000000, thread: 0000, runid: 1488809312, stamp: 2017-03-06T15:08:32 PADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADDPADD'
[2017-03-06T15:08:32.136638] EOF occurred while reading; fd='15'
[2017-03-06T15:08:32.141016] Syslog connection closed; fd='15', client='AF_INET(127.0.0.1:52600)', local='AF_INET(127.0.0.1:6666)'
[2017-03-06T15:08:32.141118] Closing log transport fd; fd='15'
Traceback (most recent call last):
  File "/home/micek/micek_work/micek_syslog_ng_python_scripts/sngexample.py", line 8, in send
    print(msg.MSG)
SystemError: error return without exception set
[2017-03-06T15:08:32.211917] g_strlcpy: assertion 'src != NULL' failed
TypeError: expected bytes, str found
[2017-03-06T15:08:32.212136] Exception while calling a Python function; module='d_python#0', script='sngexample.DummyPythonDest', function='P\xa8\x0e\xd0r', exception='None'
@furiel
Copy link
Collaborator

furiel commented Aug 1, 2017

Instead of
print("send: %s\n" % msg.MSG)
this needs to be used:
print("send: %s\n" % msg["MESSAGE"])

@lbudai
Copy link
Collaborator

lbudai commented Aug 3, 2017

From #1371 only msg['MSG'] form is supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants