2021年10月7日 星期四

Rsyslog to PHP

以 PHP 為例,把 syslog 的資料即時 pipe 給程式分析

/etc/rsyslog.conf 加入
module(load="omprog")
*.* action(type="omprog" binary="/usr/local/bin/syslog-parser.php")

syslog-parser.php 內容

#!/usr/bin/php
<?php
while ($line=trim(fgets(STDIN))) {
  file_put_contents("/tmp/syslog-parser.log",$line."\n",FILE_APPEND);
}
?>

不要忘了 chmod +x syslog-parser.php,它需要有執行權限
本範例中的 $line 就是 syslog 會傳進來的每一行
當然這個方法不限於 PHP,可以讀取 STDIN 的程式都可以

沒有留言:

Using wgcf to export WARP WireGuard config

Cloudflare WARP 的底層是用 WireGuard tunnel wgcf 工具可以把它匯出成 WireGuard config curl -sL https://github.com/ViRb3/wgcf/releases/download/v2.2.29/w...