使用TCL抓取SYSlog(端口514)UDP/TCP?

Using TCL to capture SYSlog (port 514) UDP/TCP?

我正在寻找将端口 514 上网络生成的系统日志捕获到 TCL 变量列表(使用 lappend mysyslist $newsyslogentry 之类的东西)或仅附加到文件(即 open "syslog.txt" a)

我怀疑它需要通过每个新(端口 514)条目(即 fileevent $$ readable...)的事件触发,并且如果可能的话允许其他程序访问系统日志端口?

我相信网络系统日志流量是基于 UDP 的(不是 100% 确定),但我已经播种了 UDP + TCP 系统日志捕获应用程序。

有一些 SYSlog 客户端应用程序可用,但我需要一个简单的 TCL 端口 514 记录器。

我有一些想法,但如有任何建议,我们将不胜感激。

对于任何感兴趣的人,我在这里创建了一个 UDP 版本:

#!/usr/local/bin/tclsh
package require udp ; # load the required UDP Package

set port 514 ; # default SYSlog port
set logfile "udp_syslog.txt" ; # set the log filename to log data to

# Capture the UDP data here
proc udp_triggered {} {
    global dg logfile ; # ensure the global variables work in this procedure
    set rcdata [read $dg(udp)] ; # grab the UDP data within rcdata
    set udp_log [open $logfile a] ; # open the specified logfile to append to (auto-creates if does not exist)
    puts $udp_log $rcdata ; # place the UDP data line into the log file
    close $udp_log ; # close the log file
    return
}

set dg(udp) [udp_open $port] ; # setup the UDP capture port
fileevent $dg(udp) readable udp_triggered ; # setup the event trigger when the UDP port becomes readable and execute the procedure to capture the data
vwait forever ; # activates the (fileevent) trigger to wait for UDP data