1

I have a simple requirement. I want to receive all syslog messages coming from user facility and store them in a file. If the syslog message contains a specific pattern, I want to execute a script.

I have the following configuration,

destination d_logfile { file("/var/log/logile.log"); }; destination d_start_script { program("/home/ubuntu/start-script.sh"); }; destination d_stop_script { program("/home/ubuntu/stop-script.sh"); }; filter f_logfile { facility(user) and not filter(f_debug); }; filter f_filter_start { facility(user) and message("start"); }; filter f_filter_stop { facility(user) and message("stop"); }; log { source(s_network_tcp); filter(f_logfile); destination(d_logfile); }; log { source(s_network_tcp); filter(f_filter_start); destination(d_start_script; }; log { source(s_network_tcp); filter(f_filter_stop; destination(d_stop_script); }; 

when I start syslog-ng it seems to loop and execute both start and stop scripts on and off.

am I missing something?

2 Answers 2

0

If I understand correctly, then instead of a start/stop script, you really want to have one script that processes a sequence of messages, and a way to create this sequence. Check if you can create this sequence using the grouping-by() parser, for example using the ${HOST}${PROGRAM}${PID} scope. If it's not adequate, in newer syslog-ng versions you can write your own syslog-ng destination in Python, that probably gives you enough flexibility to get the job done (but you can also write parsers in Python if needed).

2
  • Is there a simpler way to comply with the requirement? Commented May 7, 2019 at 20:34
  • I guess it depends on what your incoming log messages that you want to group look like. Can you post some examples? Commented May 9, 2019 at 8:06
0

As I know syslog-ng calls the program destination after it has been started and sends a stream to them. I use it a similar way, but in the script have:
if grep -qE "start" ; then <do all you needs>

So the script runs with syslog and wait a message.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.