[RHEL7/CentOS7] ログ監視ツール swatch を入れてメール通知してみた
インストール
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=[email protected],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
Author And Source
この問題について([RHEL7/CentOS7] ログ監視ツール swatch を入れてメール通知してみた), 我々は、より多くの情報をここで見つけました https://qiita.com/fukuchan-senpai/items/ad5beb22baa657733d9b著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .