LoginSignup
2
2

More than 3 years have passed since last update.

tenshiでログ監視

Last updated at Posted at 2014-07-04

インストール

apt install tenshi

# sshのログを監視してみる
cd /etc/tenshi/includes-active/
ls ../includes-available/
ln -s  ../includes-available/ssh .

/etc/init.d/tenshi restart

書き方

  1. 監視したいログ
  2. filter名と、時刻、宛先を設定。即時送ってもらいたい場合は[now]と記述。
  3. ログ中の監視したい文字列を記述。
/etc/tenshi/tenshi.conf
+ set logfile /var/log/mail.log
+ set logfile /var/log/monit.log

+ set queue custom   tenshi@localhost root@localhost [55 * * * *]
+ custom ^(?:sudo|su|sshd):
+ custom .*
動作テスト
$ sudo -u tenshi /usr/sbin/tenshi -f -d 2 -c /etc/tenshi/tenshi.conf

テキスト監視だけしたいtenshi.conf

tenshi.conf
set uid tenshi
set gid tenshi

set pidfile /var/lib/tenshi/tenshi.pid
set logfile /var/log/kininaru.log

set tail_multiple off

set sleep 5
set limit 800
set pager_limit 2
set mask ___
set mailserver localhost
set subject tenshi report
set hidepid on

set queue misc from@localhost to@localhost [*/10 * * * *]

misc .*
  • /var/log/kininaru.log を10分おきに監視し、追記されたら to@localhost にメール送信してくれる

特定のメールが送られた場合の監視

critical ^postfix/smtp:.*spam
critical ^postfix/smtp:.*user1@localhost.localdomain

RPMパッケージの作成

yum groupinstall "Development Tools" rpm-build
cd
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
curl --insecure -O https://dev.inversepath.com/download/tenshi/tenshi-0.15.tar.gz
tar xzf tenshi-0.15.tar.gz 
mv tenshi-0.15.tar.gz /usr/src/redhat/SOURCES/
cd tenshi-0.15
rpmbuild -bb tenshi.redhat-spec
  • /usr/src/redhat/RPMS/i386/tenshi-0.15-1.i386.rpm
  • /usr/src/redhat/RPMS/x86_64/tenshi-0.15-1.x86_64.rpm が生成される

もしくは

systemd

/usr/lib/systemd/system/tenshi.service
[Unit]
Description=real-time log monitor

[Service]
ExecStart=/opt/tenshi/usr/sbin/tenshi -c /etc/tenshi/tenshi.conf -f
ExecReload=/usr/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
2
2
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
2