当使用apache托pipe多个域时,查看包含虚拟主机名的logwatch apache输出是有用的,但是我只能得到:
--------------------- httpd Begin ------------------------ Requests with error response codes 400 Bad Request /: 1 Time(s) /robots.txt: 1 Time(s)
而我想要的东西
--------------------- httpd Begin ------------------------ Requests with error response codes 400 Bad Request example.com/: 1 Time(s) example.org/robots.txt: 1 Time(s)
我怎样才能达到这个logging?
试试这个(适用于我):在你的httpd.conf定义LogFormat
LogFormat“%h%t [%V] \”%r \“%> s \”%{Referer} i \“”
在这种情况下,您将拥有remote_address,date/时间, [根据UseCanonicalName设置的服务器名称] ,请求,satus代码和Referer(这是我所需的格式),然后把
$ LogFormat“%h%t%V \”%r \“%> s \”%{Referer} i \“”
在你的services / http.conf中的LogWatch文件中。 那将会
下面是这个特定的一组指令在日志输出中的一个例子:
172.3.20.11 [01 / Jun / 2011:21:00:52 +0200] joomla.local“GET /images/tabs_back.png HTTP / 1.1”404“ http://joomla.local/templates/beez_20/css/personal .css “
如果我们关注错误代码,以及它们如何在LogWatch中处理,则可以对/ usr / share / logwatch / scripts / services / http进行一些更改:Add:
my $ my_host =“”; my $ my_url =“”;
然后,关于第462行,添加这一行来保存我们的第四列(HOST):
$ field {my_host} = $ field {$ log_fields [3]};
在560行,缩短fmt_url后( if (length($field{url}) > 60) {...} )add:
$my_host = $field{$log_fields[3]}; $my_host = substr($my_host,1); $my_url=$my_host . $fmt_url;
最后,改变:
$needs_exam{$field{http_rc}}{$fmt_url}++;
通过
$needs_exam{$field{http_rc}}{$my_url}++;
这样做,你会在你的Logwatch中有这个:
Requests with error response codes 404 Not Found joomla.local/images/tabs_back.png: 3 Time(s)
我希望它能帮助你
我有同样的问题,并通过更改apache.conf的LogFormat解决了它( http://httpd.apache.org/docs/2.2/mod/mod_log_config.html )
# LogFormat "%h %l %u %t \"%r\" %>s %O" common # The default output has no info about the server name (%v). # %m %U%q %H is strictly equivalent to %r. LogFormat "%h %l %u %t \"%m %v%U%q %H\" %>s %O" common
这将生成与默认相同的输出,将规范服务器名称添加为前缀。 例如:
... "GET www.example.com/apache_pb.gif HTTP/1.0" 200 2326 ...
亲是你不需要任何其他的定制(例如在日志的一面)。 结论是,你会得到一些额外的字符为每个日志行。
如果将所有虚拟域logging到同一个日志文件中,我不认为这是可能的。apache日志不会区分它们。
我也build议你看一下开源的OSSEC 。 我们从logwatch移动到它,因为它是实时的,并允许集中关联(关联像ssh失败的login与Apache 400错误的东西)。
我发现一篇博客文章详细说明了这个问题,以及如何解决这个问题 。 不知道这将如何影响日志分析,但在这里注意到,因为我发现它有用。
您可以在apacheconfiguration中使用LogFormat指令来获取主机名。 您可以使用以下选项
%{Host}i
我在这个链接中find了这个信息。 Logwatch应该能够parsing自定义信息。
非常感谢@Syquus,他让我正确的修改了/usr/share/logwatch/scripts/services/http文件。
我的文件和解决scheme是不同的,但我想我会分享所有相同的。
我使用Apache提供的标准vhost_combined LogFormat,如下所示:
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
其输出如下所示:
example.org:80 1.1.1.1 - - [08/Oct/2013:16:55:01 +0000] "GET / HTTP/1.1" 200 6094 "-" "Opera/9.80 (X11; Linux x86_64; Edition Linux Mint) Presto/2.12.388 Version/12.16"
我把它放在/etc/logwatch/conf/services/http.conf的服务configuration覆盖中:
$logformat = "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\""
在/usr/share/logwatch/scripts/services/httpfind@ Syquus解决scheme的更改大致正确的位置后,我认为只需将索引从[3]更改为[0]就可以工作 – 事实并非如此。 我得到了不正确的path段,甚至遍历整个散列/数组后,我没有find主机名。 debugging是令人沮丧的,因为我是Perl的新手,但是我的解决scheme是添加匹配的%v被丢弃,然后修改url进一步包括域名。
比较我的解决scheme(我也删除了url截断),YMMV:
--- __http.2013-10-09 2013-10-09 13:11:48.000000000 +0000 +++ http 2013-10-09 14:36:59.000000000 +0000 @@ -132,6 +132,8 @@ # Build tables of the log format to parse it and determine whats what # +my $my_url = ""; + my $detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0; my $ignoreURLs = $ENV{'http_ignore_urls'}; my $ignoreIPs = $ENV{'http_ignore_ips'}; @@ -379,7 +381,10 @@ $logformat =~ s/%[\d,!]*/%/g; while ($end_loop) { - if ($logformat =~ /\G%h/gc) { + if ($logformat =~ /\G%v/gc) { + $parse_string[$parse_index] .= "(\\S*?)"; + $parse_field[$parse_index][$parse_subindex++] = "my_host"; + } elsif ($logformat =~ /\G%h/gc) { $parse_string[$parse_index] .= "(\\S*?)"; $parse_field[$parse_index][$parse_subindex++] = "client_ip"; } elsif ($logformat =~ /\G%l/gc) { @@ -437,7 +442,6 @@ # # Process log file on stdin # - while (my $line = <STDIN>) { chomp($line); @@ -580,11 +584,12 @@ !((defined $ignoreURLs) && ($field{url} =~ /$ignoreURLs/)) && !((defined $ignoreIPs) && ($field{client_ip} =~ /$ignoreIPs/)) ) { my $fmt_url = $field{url}; - if (length($field{url}) > 60) { - $fmt_url = substr($field{url},0,42) . " ... " . - substr($field{url},-15,15); - } - $needs_exam{$field{http_rc}}{$fmt_url}++; + #if (length($field{url}) > 60) { + # $fmt_url = substr($field{url},0,42) . " ... " . + # substr($field{url},-15,15); + #} + $my_url = $field{my_host} . $fmt_url; + $needs_exam{$field{http_rc}}{$my_url}++; } if (defined $field{userid} && $field{userid} ne "-" && (eval $user_display) &&
我是否应该决定在以外的端口上提供安全的内容或内容:80我可能会在将来包括它。 现在应该是显而易见的。
希望这可以帮助!
做了一些更改,修复了一个错误。 而不是继续编辑这个答案,你可以在这里find我的修改: https : //bitbucket.org/ubiquitypress/logwatch