1

Is this possible? From what I'm seeing, the only way to get options into the the python class is to hard code them in the python destination's options. I need to set a variable path based on macros like $HOST but python destination options don't seem to be interpolated. I need a way to pass in macro values like $HOST to the init() method.

Mark
  • 348
  • 4
  • 15
  • It might be better if you start your question with a "I have:" section describing your setup, used software and code you already have. – Klaus D. Mar 22 '19 at 13:22

1 Answers1

1

The value of $HOST changes for every message, so you actually need it in send(), not in init(). What you might really want is something like this:

class MyDestination(object):

# ...

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

Or you can use templates starting from 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
MrAnno
  • 754
  • 5
  • 17