インストール
EPELリポジトリ追加
# rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
swatch インストール
# yum install swatch --enablerepo=epel
設定ファイル
ログファイルに「action="tunnel-up"」という文字を検出したときに
- 画面表示する → echo
- メール通知する → mail=
# vi /root/swatch_fwlog.conf
watchfor /action=\"tunnel-up\"/
echo
mail=fukuchan-senpai@sample.org,subject="[SSLVPN] tunnel-up"
手動起動
テストなどで一時的に動作させる場合は、コマンドの引数に設定ファイルと対象ログファイルを指定し、perl から実行します。
# /usr/bin/perl /bin/swatch -c /root/swatch_fwlog.conf -t /var/log/fwlog &
手動停止
普通に kill して止めます
# kill プロセス番号
Systemdへの登録
ユニットファイルの作成
systemd でサービス管理するために手動でユニットファイルを作成します。
# vi /lib/systemd/system/swatch_fwlog.service
[Unit]
Description=swatch for firewall log
After=syslog.target network.target postfix.service
[Service]
ExecStart=/usr/bin/swatch -c /root/swatch_fwlog.conf -t /var/log/fwlog --pid-file /var/run/swatch_fwlog.pid --daemon > /dev/null 2>&1
Type=forking
PIDFile=/var/run/swatch_fwlog.pid
[Install]
WantedBy=multi-user.target
反映
作成したユニットファイルを systemd に認識させます。
# systemctl daemon-reload
自動起動化
# systemctl enable swatch_fwlog
起動
# systemctl start swatch_fwlog
ステータス確認
# systemctl status swatch_fwlog
停止
# systemctl stop swatch_fwlog