[syslog-ng] runtime definition of a constant
Evan Rempel
erempel at uvic.ca
Thu Apr 24 17:25:38 CEST 2014
I thought about a config snippet but in my case, I am reading log files from an application that is administered by
another group in our organization. It becomes the responsibility of this other group to define the instance name.
If it is an actual configuration snippet then if they get it wrong, syslog-ng won't start.
I have come up with a working solution, although it is a little indirect.
1. Make a small script that takes as its arguments a name and a path-to-file and produces the
code snippet
@define name "first-word-of-file"
If the file does not exist, or as multiple words or other things, then return nothing.
2. Add these two lines to syslog-ng.conf
@module confgen context(root) name(myinstance) exec("/path/to/script instance /path/to/instance/file")
myinstance()
3. Use the defined value of `instance` in the template
template t_my_template { template("<$pri>$parsedate $parsehost ldap: `instance`: $parsemessage\n"); template_escape(no); };
All of the validation/checking is done in the script to ensure that syslog-ng can restart, and it only needs to be invoked at startup/reload.
Evan.
On 04/23/2014 05:00 PM, Jakub Jankowski wrote:
> On 24.04.2014 00:57, Evan Rempel wrote:
>>
>> I have a use case where I want to preface every message from a source with some kind of instance name.
>> It would be easy to create a static template, but I would like to be able to use the same configuration include
>> on all of the hosts and provide the "instance" name from a local configuration space.
>>
>> Is there any way to do this kind of thing
>>
>> @module confgen context(root) name(myinstance) exec("/bin/cat /path/to/instance/file")
>> @define instance "myinstance()"
>> template t_mytemplate { template("<$pri>$parsedate $parsehost ldap: `instance`: $parsemessage\n"); template_escape(no); };
>>
>> or if the confgen could have a template context
>>
>> @module confgen context(template) name(myinstance) exec("/bin/cat /path/to/instance/file")
>> template t_mytemplate { template("<$pri>$parsedate $parsehost ldap: $(myinstance): $parsemessage\n"); template_escape(no); };
>
> Hm, why don't you just include a syslog-ng configuration snippet (that
> sets what you want) from a file that is local to your instance?
>
>
> Jakub
>
--
Evan Rempel erempel at uvic.ca
Senior Systems Administrator 250.721.7691
Data Centre Services, University Systems, University of Victoria
More information about the syslog-ng
mailing list