FreeBSD/swatch

swatch

ログの自動監視ツール

インストール

# cd /usr/ports/security/swatch
# make install clean

/etc/rc.conf

# swatch
swatch_enable="YES"  
swatch_rules="1"    
swatch_1_flags="--config-file=/usr/local/etc/swatch1.conf --awk-field-syntax --tail-file=/var/log/messages --daemon --pid-file=/var/run/swatch_1.pid"
swatch_1_pidfile="/var/run/swatch_1.pid"

swatchオプション

--awk-field-syntax     $0や$1の変数が使えるようになります。

/usr/local/etc/swatch.conf

Action解説
echo [modes]ウインドウにメッセージを表示
bell [N]ビープ音をN回鳴らす
exec command”command”を実行する
mail [address=xxx@xxx.jp:xxx@xx...]指定したアドレスにメールを送信する
pipe command [,keep_open]パイプで”command”に結果を返す
write [user:user:...]writeコマンドを使って指定したユーザに通知を行う
throtte hours:minites:seconds, [use=message or regex]同じメッセージが検出された場合、指定した時間まで通知を行わない
continue指定したパターンを見つけても処理を終了せず、続けて処理を行う
quitSwatchを終了させる

設定ファイルの書式

watchfor   /パターン/
       アクション1
       アクション2
       ……

パターンの後ろにiを付けると、パターンの大文字・小文字を区別しなくなります。(例:/ssh/i)

最近多いDosアタックを検知するとIPFでアクセス拒否にする例

watchfor /skin\/skin\/skin/
       exec "echo '@1 block in quick from $1 to any' | /sbin/ipf -f -"
       exec "echo $1 Access Stop."

/usr/local/etc/rc.d/swatch.shの編集

初期のシェルでstopをかけると下記のエラーでpidfileを認識してくれません。

# /usr/local/etc/rc.d/swatch.sh stop
swatch not running? (check /var/run/swatch_1.pid).

■procnameの個所をコメントアウトすると正常にsotpしてくれます。

# chmod 755 /usr/local/etc/rc.d/swatch.sh
# vi /usr/local/etc/rc.d/swatch.sh
command=/usr/local/bin/swatch
procname=/usr/local/bin/perl
        ↓
command=/usr/local/bin/swatch
#procname=/usr/local/bin/perl