Mark
Mark

Reputation: 368

Setting a variable path with syslog-ng python destination

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.

Upvotes: 1

Views: 374

Answers (1)

MrAnno
MrAnno

Reputation: 754

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

Upvotes: 1

Related Questions