0

I want to use syslog-ng to receive netgear log, and use python script process.

But syslog-ng didn't run the python script.

syslog-ng.config

@version:3.2

options {
    flush_lines (0);
    time_reopen (10);
    log_fifo_size (1000);
    long_hostnames (off);
    use_dns (no);
    use_fqdn (no);
    create_dirs (no);
    keep_hostname (yes);
};

source s_sys {
    udp(ip(0.0.0.0) port(514));
    };

destination d_python{
    program("/usr/local/bin/python /opt/syslog.py");    
    #program("/bin/echo 'haha' >> /tmp/test");
    };

log { source(s_sys); destination(d_python);};

and python script like this

#!/usr/local/bin/python
#coding:utf8

import os
import sys
import datetime

f = open('/var/log/pnet.log', 'a')

f.write('\nstart\n')
f.write('args\n')
f.write('%s\n' % sys.argv)
if not sys.stdin.isatty():
    f.write('stdin\n')
    f.write('%s\n' % date.date.now().isoformat() )
    tty_read = sys.stdin.read()
    f.write("'''\n")
    f.write(tty_read)
    f.write("\n'''\n")
f.write('end\n')
f.close()

The script is already 777 Even I change my config to use 'echo' directly pipe into a file, didn't write a word too...

So...why?

2 Answers2

0

silly question, but do you have incoming logs? If you use a simple file destination instead of the program, do you receive logs? If not, the problem is not in the program destination.

Also, try changing the flush_lines (0); option to 1 to see if it helps.

Regards,

Robert Fekete

Robert Fekete
  • 557
  • 3
  • 5
0

I could show you my code for reference:

my syslog-ng.conf :

source s_test{
    file("/home/test/in.log" follow-freq(1) flags(no-parse));
    };  
destination d_test{
    program ("/home/test/out.py" flush_lines(1) flags(no_multi_line));                                                                                                        
    };  
log {
    source(s_test);
    destination(d_test);
    flags(flow-control);
    };

my out.py:

#!/usr/bin/env python
# encoding: utf-8

import sys 
while True:
    line = sys.stdin.readline()
    file = open("/home/test/out_from_python.log","a")
    file.write(line)
    file.close()

when you type echo "something" >> /home/test/in.log , there would be a new log lie in /home/test/out_from_python.log

touchstone
  • 1,055
  • 1
  • 10
  • 14