アーカイブ

‘CentOS5’ タグのついている投稿

logwatchでfreshclamのUPDATEがうまくいかないと表示された場合

2015 年 7 月 1 日 Comments off

先日、clamAVをバージョンアップしたところ下記のようなログがLOGWATCHに表示されるようになった。

LOGWATCHメール内容

################### Logwatch 7.3.6 (05/19/07) ####################
Processing Initiated: Tue XXXXXXXXXXXXXXXXXX
Date Range Processed: yesterday
( 2015-XXX-XXX )
Period is day.
Detail Level of Output: 10
Type of Output: unformatted
Logfiles for Host: www16071ue.sakura.ne.jp
##################################################################

——————— clam-update Begin ————————
No updates detected in the log for the freshclam daemon (the
ClamAV update process). If the freshclam daemon is not running,
you may need to restart it. Other options:
A. If you no longer wish to run freshclam, deleting the log file
(default is freshclam.log) will suppress this error message.
B. If you use a different log file, update the appropriate
configuration file. For example:
echo “LogFile = log_file” >> /etc/logwatch/conf/logfiles/clam-update.conf
where log_file is the filename of the freshclam log file.
C. If you are logging using syslog, you need to indicate that your
log file uses the syslog format. For example:
echo “*OnlyService = freshclam” >> /etc/logwatch/conf/logfiles/clam-update.conf
echo “*RemoveHeaders” >> /etc/logwatch/conf/logfiles/clam-update.conf
———————- clam-update End ————————-

・・・・・・

こんな感じでfreshclam deamonが動いていないとかで表示されていない。

ちなみに正常な状態は、以下の通り

——————— clam-update Begin ————————

The ClamAV update process was started 1 time(s)

Last ClamAV update process started at Mon Jan 19 02:39:24 2015

Last Status:
    main.cld is up to date (version: 55, sigs: 2424225, f-level: 60, builder: neo)
    Downloading daily-19941.cdiff [100%]
    Downloading daily-19942.cdiff [100%]
    Downloading daily-19943.cdiff [100%]
    Downloading daily-19944.cdiff [100%]
    daily.cld updated (version: 19944, sigs: 1310564, f-level: 63, builder: neo)
    bytecode.cld is up to date (version: 245, sigs: 43, f-level: 63, builder: dgoddard)
    Database updated (3734832 signatures) from db.jp.clamav.net (IP: 203.178.137.175)

———————- clam-update End ————————-

ということでA~Cの可能性をひとつづつ調べてみる。

A. If you no longer wish to run freshclam, deleting the log file
(default is freshclam.log) will suppress this error message.

freshclam.logのエラーメッセージがあるかもということで確認してみる。

vi /etc/freshclam.confでログの場所を確認

##
## Example config file for freshclam
## Please read the freshclam.conf(5) manual before editing this file.
##


# Comment or remove the line below.
#Example

# Path to the database directory.
# WARNING: It must match clamd.conf's directive!
# Default: hardcoded (depends on installation options)
DatabaseDirectory /var/lib/clamav

# Path to the log file (make sure it has proper permissions)
# Default: disabled
UpdateLogFile /var/log/clamav/freshclam.log

# Maximum size of the log file.
# Value of 0 disables the limit.
# You may use 'M' or 'm' for megabytes (1M = 1m = 1048576 bytes)
# and 'K' or 'k' for kilobytes (1K = 1k = 10

vi /var/log/clamav/freshclam.logでログを確認

Tue Jun 30 03:12:26 2015 -> --------------------------------------
Tue Jun 30 03:12:26 2015 -> ClamAV update process started at Tue Jun 30 03:12:26 2015
Tue Jun 30 03:12:26 2015 -> main.cvd is up to date (version: 55, sigs: 2424225, f-level: 60, builder: neo)
Tue Jun 30 03:12:41 2015 -> Downloading daily-20617.cdiff [100%]
Tue Jun 30 03:12:41 2015 -> Downloading daily-20618.cdiff [100%]
Tue Jun 30 03:12:41 2015 -> Downloading daily-20619.cdiff [100%]
Tue Jun 30 03:12:49 2015 -> daily.cld updated (version: 20619, sigs: 1444349, f-level: 63, builder: jesler)
Tue Jun 30 03:12:50 2015 -> Downloading bytecode-261.cdiff [100%]
Tue Jun 30 03:12:50 2015 -> bytecode.cld updated (version: 261, sigs: 48, f-level: 63, builder: anvilleg)
Tue Jun 30 03:12:59 2015 -> Database updated (3868622 signatures) from db.jp.clamav.net (IP: 120.29.176.126)

毎日更新されているようだ。特に問題なし。

B. If you use a different log file, update the appropriate
configuration file. For example:
echo “LogFile = log_file” >> /etc/logwatch/conf/logfiles/clam-update.conf
where log_file is the filename of the freshclam log file.

B は、別のログファイル使用している場合は、適切な更新ファイルに設定するみたいな感じでしょうか?
特に、A で調べた限りclam-update更新は、行われているがlogwatchに表示されないだけらしい。

C. If you are logging using syslog, you need to indicate that your
log file uses the syslog format. For example:
echo “*OnlyService = freshclam” >> /etc/logwatch/conf/logfiles/clam-update.conf
echo “*RemoveHeaders” >> /etc/logwatch/conf/logfiles/clam-update.conf

C については、syslogを使用していれば・・・なので上記のfreshclam.logを使用しているのでこのログをlogwatchが取り込めないだけらしい。

 

yumでclamAVをバージョンアップしたのですがログを見てみるとログの出力方法が変わっていた。

今までのログ

————————————–
ClamAV update process started at Sun Jun  7 03:19:28 2015
main.cld is up to date (version: 55, sigs: 2424225, f-level: 60, builder: neo)
Downloading daily-20552.cdiff [100%]
daily.cld updated (version: 20552, sigs: 1413781, f-level: 63, builder: neo)
bytecode.cld is up to date (version: 256, sigs: 45, f-level: 63, builder: dgoddard)
Database updated (3838051 signatures) from db.jp.clamav.net (IP: 203.178.137.175)
————————————–

バージョンアップ後のログ

Sun Jun 28 02:40:11 2015 -> ————————————–
Sun Jun 28 02:40:11 2015 -> ClamAV update process started at Sun Jun 28 02:40:11 2015
Sun Jun 28 02:40:12 2015 -> main.cvd is up to date (version: 55, sigs: 2424225, f-level: 60, builder: neo)
Sun Jun 28 02:41:02 2015 -> WARNING: getfile: Unknown response from remote server (IP: 219.94.128.99)
Sun Jun 28 02:41:02 2015 -> WARNING: getpatch: Can’t download daily-20615.cdiff from db.jp.clamav.net
Sun Jun 28 02:41:03 2015 -> Downloading daily-20615.cdiff [100%]
Sun Jun 28 02:41:25 2015 -> daily.cld updated (version: 20615, sigs: 1443395, f-level: 63, builder: jesler)
Sun Jun 28 02:41:25 2015 -> bytecode.cvd is up to date (version: 260, sigs: 47, f-level: 63, builder: shurley)
Sun Jun 28 02:41:41 2015 -> Database updated (3867667 signatures) from db.jp.clamav.net (IP: 27.96.54.66)

 

freshclamがはき出すログは日付等(Sun Jun 28 02:40:11 2015 ->)が入っているのでここがLOGWATCHで取り込む際の障壁になっているようだ。

ということで、ググって見ると結構同じような障害に見舞われているいるかたがいるらしい。

Adriano’s Place
logwatchでfreshclamのログがうまく読めない場合がある
 

などです。

LOGWATCHの各ファイルを取り込むスクリプトファイルを変更すればいいらしい。

vi  /usr/share/logwatch/scripts/services/clam-update

:set nuで行番号を表示

私のLogwatch 7.3.6 (05/19/07)のバージョンだと89行目に

$ThisLine = substr($ThisLine, 28);

を追記すればいいらしい。

(perlで書かれているので見てみると要は、1行取り込んだ$ThisLineにsubstrで28文字目から取り込むだけ

最初の文字から -> までを読み込まないようにするだけのこと)

 

     81 my %Warnings;
     82
     83
     84 $SearchDate = TimeFilter("%b %e");
     85
     86 while (defined(my $ThisLine = <STDIN>)) {
     87    # Freshclam ends log messages with a newline.  If using the LogSyslog option, this is
     88    # turned into a space.  So we remove a space from every line, if it exists.
     89    $ThisLine =~ s/ $//;
      $ThisLine = substr($ThisLine, 28);
     90    if (
     91        # separator of 38 dashes
     92        ($ThisLine =~ /^\-{38}$/) or
     93        # the following failure is also recorded with ERROR later on
     94        ($ThisLine =~ /^Giving up/) or
     95        # SIGALRM, SIGUSR1, and SIGHIP signals
     96        ($ThisLine =~ /^Received signal \d*, wake up$/) or
     97        ($ThisLine =~ /^Received signal \d*, re-opening log file$/) or

これでLOGWATCHで正しく読み込めるはず。
下記コマンドで標準出力で確認してみる。
# logwatch –print

[root@www16071ue]# logwatch --print

 ################### Logwatch 7.3.6 (05/19/07) ####################
        Processing Initiated: Tue Jun 30 20:39:22 2015
        Date Range Processed: yesterday
                              ( 2015-Jun-29 )
                              Period is day.
      Detail Level of Output: 10
              Type of Output: unformatted
           Logfiles for Host: www16071ue.sakura.ne.jp
  ##################################################################

 --------------------- clam-update Begin ------------------------

 The ClamAV update process was started 1 time(s)

 Last ClamAV update process started at Mon Jun 29 03:17:36 2015

 Last Status:
    main.cvd is up to date (version: 55, sigs: 2424225, f-level: 60, builder: neo)
    Downloading daily-20616.cdiff [100%]
    daily.cld updated (version: 20616, sigs: 1443371, f-level: 63, builder: shurley)
    bytecode.cvd is up to date (version: 260, sigs: 47, f-level: 63, builder: shurley)
    Database updated (3867643 signatures) from db.jp.clamav.net (IP: 120.29.176.126)

 ---------------------- clam-update End -------------------------

うまく出来たようです。

ただこの方法だとログの出力形式が変わった場合また対処しなければいけない。

ということで備忘録的に記述しておきます。