【问题标题】:syslog-ng not run scriptsyslog-ng 不运行脚本
【发布时间】:2014-08-05 08:34:47
【问题描述】:

我想使用 syslog-ng 来接收 netgear 日志,并使用 python 脚本进程。

但是 syslog-ng 没有运行 python 脚本。

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);};

和这样的python脚本

#!/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()

脚本已经是 777 即使我将配置更改为使用'echo'直接管道到文件中,也没有写一个字......

那么……为什么?

【问题讨论】:

    标签: python syslog-ng


    【解决方案1】:

    愚蠢的问题,但是你有传入的日志吗?如果您使用简单的文件目标而不是程序,您会收到日志吗?如果不是,则问题不在程序目的地。

    另外,尝试更改 flush_lines (0);选择 1 看看是否有帮助。

    问候,

    罗伯特·费克特

    【讨论】:

      【解决方案2】:

      我可以向您展示我的代码以供参考:

      我的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);
          };
      

      我的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()
      

      当你输入 echo "something" >> /home/test/in.log 时,/home/test/out_from_python.log 中会出现一个新的日志

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-15
        • 2018-10-31
        • 2016-02-03
        • 2019-12-12
        相关资源
        最近更新 更多