これまで syslog やログのローテート、そして C 言語からの出力について紹介してきましたが、syslog
にはさまざまな問題があります。
- sender は UDP で送信するため、信頼性がない
- sender と receiver 間での認証がなく、IP アドレスの制限くらいしか掛けられない
- TIMESTAMP に年やタイムゾーンの情報がない
- ホスト名がFQDNではない
歴史が長い分だけ広く普及していますので、簡単に仕様も変えられないのでしょう。
データ形式の仕様は仕方ありませんが、送受信やフィルタ(振り分け)については改善の余地があるということで、syslogd の代替ツールが開発されてきています。
ports からインストールできるものをいくつか紹介します。この中では msyslog や syslog-ng はなかなか良さそうです。
● metalog
ports/sysutils/metalog
http://metalog.sourceforge.net
ログを振り分けるための条件として、facility や priority、そしてプログラム名の他に、Perl 互換の正規表現で設定することもできるようになったものです。
ログのローテートも設定できますし、外部コマンドを実行することも可能です。
設定ファイルのサンプルを リスト8 に挙げます。見れば意味はわかるほど単純なものになっています。
# Sample Metalog configuration file
maxsize = 100000
maxtime = 86400
maxfiles = 5
Kernel messages :
facility = "kern"
logdir = "/var/log/kernel"
Crond :
program = "crond"
logdir = "/var/log/crond"
Dudes firewalled by IPTrap :
program = "iptrap"
logdir = "/var/log/iptrap"
Password failures :
regex = "(password|login|authentication)\s+(fail|invalid)"
regex = "(failed|invalid)\s+(password|login|authentication)"
regex = "ILLEGAL ROOT LOGIN"
logdir = "/var/log/pwdfail"
# command = "/usr/local/sbin/mail_pwd_failures.sh"
FTP Server :
program = "pure-ftpd"
logdir = "/var/log/ftpd"
SSH Server :
program = "sshd"
logdir = "/var/log/sshd"
Telnet :
program = "login"
logdir = "/var/log/telnet"
Imap :
program = "/usr/sbin/imapd"
logdir = "/var/log/imap"
POP Toaster :
program = "/usr/sbin/ipop3d"
logdir = "/var/log/pop"
#Add authenticated IP addresses for SMTP relaying :
# program = "/usr/sbin/ipop3d"
# regex = "Login.+nmsgs="
# command = "/usr/local/sbin/add_pop_address.sh"
Mail :
facility = "mail"
logdir = "/var/log/mail"
Everything important :
facility = "*"
minimum = 6
logdir = "/var/log/everything"
Everything very important :
facility = "*"
minimum = 1
logdir = "/var/log/critical" |
|
|
● msyslog
ports/sysutils/msyslog
http://sourceforge.net/projects/msyslog/
Modular Syslog というものです。OpenBSD のものが元になっているそうです。表5
のようなさまざまなモジュールがあります。DB にも書き込めるのが面白いです。
| Output
Module |
動作 |
| Classic |
旧来の BSD syslogd
と同じような機能を提供します。 |
| MySQL |
MySQL にログを出力します。 |
| PostgreSQL |
PostgreSQL
にログを出力します。 |
| Regular
Expression |
正規表現によってログを指定し、フィルタとして機能します。 |
| Peo |
ログにハッシュ関数を掛けることで、改ざんされたことがわかるようにします。 |
| TCP |
ログを TCP で送ります。 |
| Input Module |
動作 |
| BSD |
BSD のカーネルログデバイス
(/dev/klog) からログを取得します。 |
| Linux |
Linux のカーネルログデバイスからログを取得します。/proc/ksyms
や /proc/kmsg を使うようです。 |
| UDP |
UDP からログを受信します。 |
| TCP |
TCP からログを受信します。 |
| Unix |
UNIX domain
socket からログを受信します。/dev/log です。(表1参照) |
| Streams |
Solaris などの
SYSV 系の stream デバイスからログを受信します。Doors Input Module
を使います。 |
| Doors |
他の Input Module
から呼び出されます。
Solaris 2.6 以降に存在するマルチスレッド化 IPC だそうです。 |
|
|
設定方法は syslogd とほとんど変わりません。
SELECTOR と ACTION との間にモジュール名を入れるくらいです。リスト9
に挙げます。
#This lines are equivalent we recommend the latter for msyslog
*.* /var/log/all
*.* %classic /var/log/all
#This lines are equivalent we recommend the latter for msyslog
#This sends a WALL message. A message to all logged users
*.emerg *
*.emerg %classic *
#This lines are equivalent we recommend the latter for msyslog
#This sends syslog output to a logging host through UDP transport
*.notice @loghost.domain.com
*.notice %classic @loghost.domain.com
#This lines are equivalent we recommend the latter for msyslog
#This sends all alert and higher messages to root
*.alert root
*.alert %classic root |
|
|
● socklog
ports/sysutils/socklog
http://smarden.org/socklog/
djb の daemontools のために開発された、小さくてセキュアな syslogd だそうです。syslogd を置き換えるというよりは、daemontools
の svscan, supervise, multilog に syslogd の機能を追加するというものです。
筆者は使ったことがないためによくわかっていないのですが、daemontools を利用している方には良いのではないでしょうか。
● syslog-ng
ports/sysutils/syslog-ng
http://www.balabit.hu/en/downloads/syslog-ng/
Syslog New Generation (新世代 Syslog) です。従来の facility/priority に加えて、メッセージの内容もフィルタの条件に加えたいというのが目的だそうです。
もちろん入出力の種類も充実しており、設定も比較的簡単でわかりやすいです。
ログの流れを制御するため、表6 のような4つの概念があります。細かいパラメータやオプションは省略します。
[Sources] ログの入力
source <identifier> {
source-driver(params); ...
}; |
| 名前 |
概要 |
| internal |
syslog-ng 内部 |
| unix-stream |
SOCK_STREAM
モードの unix socket |
| unix-dgram |
SOCK_DGRAM
モードの unix socket |
| file |
ファイル |
| pipe,
fifo |
名前付きパイプ |
| udp |
UDP |
| tcp |
TCP |
| sun-streams |
Solaris の STREAMS
デバイス |
 |
[Filters] フィルタ
filter <identifier> {
expression;
};
# 条件の組み合わせには and, or, not が使えます。 |
| 名前 |
概要 |
| facility(f1,
f2, ...) |
指定した facility |
level(p1,
p2, ...)
priority(p1, p2, ...) |
指定した priority |
| program(regexp) |
syslog のタグ部分の正規表現 |
| host(regexp) |
ホスト名の正規表現 |
| match(regexp) |
メッセージの正規表現 |
| filter() |
他のフィルタを呼ぶ |
 |
[Destinations] ログの出力
destination <identifier> {
destination-driver(params); ...
}; |
| 名前 |
概要 |
| file |
ファイル |
| fifo,
pipe |
名前付きパイプ |
| unix-stream |
SOCK_STREAM
モードの unix socket (Linux方式) |
| unix-dgram |
SOCK_DGRAM
モードの unix socket (BSD方式) |
| udp |
指定したホストとポート番号に
UDP で送信 |
| tcp |
指定したホストとポート番号に
TCP で送信 |
| usertty |
指定したユーザがログインしていれば、その画面に表示 |
| program |
指定したプログラムを起動し、標準入力に渡す |
 |
[Log paths] ログの制御
log {
source(); filter(); destination();
}; |
| 名前 |
概要 |
| source |
Source を指定 |
| filter |
Filter を指定
(複数記述可能) |
| destination |
Source を指定 |
|
|
これも実際の設定ファイルを見るのがわかりやすいでしょう。
Debian GNU/Linux では標準で採用されているそうで、その設定ファイルを リスト10
に挙げます。
少々記述量は多いですが、source 〜 filter 〜 destination の流れがわかりやすいものとなっています。
| リスト10 |
syslog-ng の設定ファイルの例 |
options { long_hostnames(off); sync(0); };
source src { unix-stream("/dev/log"); internal(); };
source net { udp(); };
destination authlog { file("/var/log/auth.log"); };
destination syslog { file("/var/log/syslog"); };
destination cron { file("/var/log/cron.log"); };
destination daemon { file("/var/log/daemon.log"); };
destination kern { file("/var/log/kern.log"); };
destination lpr { file("/var/log/lpr.log"); };
destination user { file("/var/log/user.log"); };
destination uucp { file("/var/log/uucp.log"); };
destination ppp { file("/var/log/ppp.log"); };
destination mail { file("/var/log/mail.log"); };
destination mailinfo { file("/var/log/mail.info"); };
destination mailwarn { file("/var/log/mail.warn"); };
destination mailerr { file("/var/log/mail.err"); };
destination newscrit { file("/var/log/news/news.crit"); };
destination newserr { file("/var/log/news/news.err"); };
destination newsnotice { file("/var/log/news/news.notice"); };
destination debug { file("/var/log/debug"); };
destination messages { file("/var/log/messages"); };
destination console { usertty("root"); };
destination console_all { file("/dev/tty12"); };
#destination loghost { udp("loghost" port(999)); };
destination xconsole { pipe("/dev/xconsole"); };
filter f_auth { facility(auth); };
filter f_authpriv { facility(auth, authpriv); };
filter f_syslog { not facility(authpriv, mail); };
filter f_cron { facility(cron); };
filter f_daemon { facility(daemon); };
filter f_kern { facility(kern); };
filter f_lpr { facility(lpr); };
filter f_mail { facility(mail); };
filter f_user { facility(user); };
filter f_uucp { facility(cron); };
filter f_ppp { facility(ppp); };
filter f_news { facility(news); };
filter f_debug { not facility(auth, authpriv, news, mail); };
filter f_messages { level(info..warn)
and not facility(auth, authpriv, mail, news); };
filter f_emergency { level(emerg); };
filter f_info { level(info); };
filter f_notice { level(notice); };
filter f_warn { level(warn); };
filter f_crit { level(crit); };
filter f_err { level(err); };
log { source(src); filter(f_authpriv); destination(authlog); };
log { source(src); filter(f_syslog); destination(syslog); };
log { source(src); filter(f_cron); destination(cron); };
log { source(src); filter(f_daemon); destination(daemon); };
log { source(src); filter(f_kern); destination(kern); };
log { source(src); filter(f_lpr); destination(lpr); };
log { source(src); filter(f_mail); destination(mail); };
log { source(src); filter(f_user); destination(user); };
log { source(src); filter(f_uucp); destination(uucp); };
log { source(src); filter(f_mail); filter(f_info); destination(mailinfo); };
log { source(src); filter(f_mail); filter(f_warn); destination(mailwarn); };
log { source(src); filter(f_mail); filter(f_err); destination(mailerr); };
log { source(src); filter(f_news); filter(f_crit); destination(newscrit); };
log { source(src); filter(f_news); filter(f_err); destination(newserr); };
log { source(src); filter(f_news); filter(f_notice); destination(newsnotice); };
log { source(src); filter(f_debug); destination(debug); };
log { source(src); filter(f_messages); destination(messages); };
log { source(src); filter(f_emergency); destination(console); };
log { source(src); filter(f_ppp); destination(ppp); };
log { source(src); destination(console_all); }; |
|
|
|