Syslog-ng 未触发 Python 脚本

Syslog-ng 未触发 Python 脚本

我目前正在尝试设置一个 Syslog 应用程序,以便在发现特定消息时触发特定的 Python 脚本,但是我无法调用该 Python 脚本。以下是当前的配置文件。

需要确认的是,我看到了日志进入日志目的地,但是程序目的地由于某种原因无法工作。

我一直在使用的信息https://syslog-ng.com/documents/html/syslog-ng-ose-latest-guides/en/syslog-ng-ose-guide-admin/html/reference-filters.html#filter-message

并且https://syslog-ng.com/documents/html/syslog-ng-ose-latest-guides/en/syslog-ng-ose-guide-admin/html/patterndb-actions-external.html

作为参考,配置有点混乱,但那是因为我还处于初始阶段。

@version: 3.5
@include "scl.conf"
@include "`scl-root`/system/tty10.conf"

# Syslog-ng configuration file, compatible with default Debian syslogd
# installation.

# First, set some global options.
options { chain_hostnames(off); flush_lines(1); use_dns(no); use_fqdn(no);
          owner("root"); group("adm"); perm(0640); stats_freq(0); keep-        
hostname(yes);
};


#destination dest_triggers{ program("/bin/echo 'haha' >> /tmp/test");};
destination dest_triggers{ program("python             
/home/jonathan/PycharmProjects/FYP/syslog.py >> /tmp/testfile");};
filter int_down_trigger {
        message(".*changed state to down");
};
source s_net { syslog(transport("udp"));};
destination d_network_local { file("/var/log/messages_${HOST}"); };
log{source(s_net); destination(d_network_local); };

#log{source(s_net); filter(int_down_trigger); destination(dest_triggers); };
log{source(s_net);  destination(dest_triggers); };

@include "/etc/syslog-ng/conf.d/*.conf"

Python脚本:

import time
    with open('downlog', 'a+') as f:
        f.write(time.strftime("%A, %d %B - %X" )+"A link went down\n")
        f.close()

相关内容