LogWatchでApacheのバーチャルホストを監視する

Last-modified: Sun, 09 Apr 2017 14:03:36 JST (2575d)
Top > LogWatchでApacheのバーチャルホストを監視する
  • Apacheでバーチャルホストを設定するとき、ログファイルをバーチャルホスト別に出力先を分けていると、LogWatchは監視してくれませんので、設定します。
  • 動作環境はubuntu 16.04で確認しました。
  1. デフォルトの設定を変更する方法もあるのですが、アップデート時に面倒なことになりそうなので、
    別名でApacheのデフォルト設定、スクリプトを持ってきます。
    cp /usr/share/logwatch/default.conf/services/http-error.conf /etc/logwatch/conf/services/apache-vhost-error.conf
    cp /usr/share/logwatch/default.conf/services/http.conf /etc/logwatch/conf/services/apache-vhost.conf
    
    cp /usr/share/logwatch/default.conf/logfiles/http-error.conf /etc/logwatch/conf/logfiles/apache-vhost-error.conf
    cp /usr/share/logwatch/default.conf/logfiles/http.conf /etc/logwatch/conf/logfiles/apache-vhost.conf
    
    cp /usr/share/logwatch/scripts/services/http-error  /etc/logwatch/scripts/services/apache-vhost-error
    cp /usr/share/logwatch/scripts/services/http /etc/logwatch/scripts/services/apache-vhost
  2. 参照するログファイルの場所を設定します。
    ここでは、/var/log/apache2/example.com/にログが出力されているとします。
    vi /etc/logwatch/conf/logfiles/apache-vhost.conf
    
    # What actual file?  Defaults to LogPath if not absolute path....
    LogFile = apache2/example.com/*access.log.1
    LogFile = apache2/example.com/*access.log
    LogFile = apache2/example.com/*access_log
    
    
    # If the archives are searched, here is one or more line
    # (optionally containing wildcards) that tell where they are...
    #If you use a "-" in naming add that as well -mgt
    Archive = apache2/example.com/*access.log.*.gz
    Archive = apache2/example.com/*access_log.*.gz
    Archive = apache2/example.com/*access.log-*.gz
  3. エラーログも同様に設定します。
    vi /etc/logwatch/conf/logfiles/apache-vhost-error.conf
    # What actual file?  Defaults to LogPath if not absolute path....
    LogFile = apache2/example.com/*error.log.1
    LogFile = apache2/example.com/*error.log
    LogFile = apache2/example.com/*error_log
    
    
    # If the archives are searched, here is one or more line
    # (optionally containing wildcards) that tell where they are...
    #If you use a "-" in naming add that as well -mgt
    Archive = apache2/example.com/*error.log.*.gz
    Archive = apache2/example.com/*error_log.*.gz
    Archive = apache2/example.com/*error.log-*.gz
  4. 参照するサービスの設定をします。
    vi /etc/logwatch/conf/services/apache-vhost-error.conf
    
    Title = example.com errors
    
    # Which logfile group...
    LogFile = apache-vhost-error
  5. 同様に設定します。
    vi /etc/logwatch/conf/services/apache-vhost.conf
    
    
    Title = "example.com"
    
    # Which logfile group...
    LogFile = apache-vhost
  6. 動作確認をします。
logwatch --output stdout --service apache-custom  --range today

こんなのが出ればOKです。(もちろんパーズすべきログがないとダメですが・・)

 ################### Logwatch 7.4.2 (02/27/16) ####################
        Processing Initiated: Sun Apr  9 13:55:00 2017
        Date Range Processed: today
                              ( 2017-Apr-09 )
                              Period is day.
        Detail Level of Output: 0
        Type of Output/Format: stdout / text
        Logfiles for Host: example.com
 ##################################################################

 --------------------- example.com Begin ------------------------

 Requests with error response codes
    404 Not Found
       /cgi-bin/php?-d+allow_url_include%3Don+-d+ ... atus_env%3D0+-n: 1 Time(s)

 ---------------------- example.com End -------------------------


 ###################### Logwatch End #########################

Counter: 798, today: 1, yesterday: 2

このページの参照回数は、798です。