2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[RHEL7/CentOS7] ログ監視ツール swatch を入れてメール通知してみた

Last updated at Posted at 2020-01-07

インストール

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
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?