When hosting multiple domains with apache it's useful to see the logwatch apache output with the virtual host name included, but I only get:
--------------------- httpd Begin ------------------------
Requests with error response codes
400 Bad Request
/: 1 Time(s)
/robots.txt: 1 Time(s)
whereas I would like something like
--------------------- httpd Begin ------------------------
Requests with error response codes
400 Bad Request
example.com/: 1 Time(s)
example.org/robots.txt: 1 Time(s)
How can I achieve this with logwatch?
Try this (works for me): Define LogFormat in your
httpd.conf
asWith this particular case, you'll have remote_address, date/time, [The server name according to the UseCanonicalName setting], request, satus code and Referer (that's my desired format) and then put
in your services/http.conf LogWatch file. That will
Here is an example of the a line in the log output with this particular set of directives:
If we FOCUS ON ERROR CODES, and how are they treated in LogWatch, here are some changes you can made to /usr/share/logwatch/scripts/services/http: Add:
Then, about line 462, add this line to save our 4th column (HOST):
And in line 560, after
fmt_url
is shorten (if (length($field{url}) > 60) {...}
) add:Finally, change:
$needs_exam{$field{http_rc}}{$fmt_url}++;
by
$needs_exam{$field{http_rc}}{$my_url}++;
doing so, you'll have this in your Logwatch:
I Hope it helps all you out
I had the same issue and solved it by changing the
LogFormat
inapache.conf
(http://httpd.apache.org/docs/2.2/mod/mod_log_config.html)This generates the same output as the default, adding the canonical server name as a prefix. Eg:
The pro is that you don't need any other customization (eg. on the logwatch side). The con is that you get a few extra characters for each logged line.
I don't think it is possible if you are logging all virtual domains into the same log file... The apache log will not differentiate between them.
I would also suggest that you take a look at the open source OSSEC. We moved from logwatch to it, because it is in real time and allow centralized correlation (correlating things like ssh failed login with apache 400 errors).
I found a blog post detailing this problem and how someone resolved it. Don't know how this will affect log analysis, but noting it here as I found it useful.
You can get the hostname using the LogFormat directive in the apache configuration. You can use the following option
I found this information in this link. Logwatch should be able to parse custom information.
Many thanks to @Syquus who put me on the right path to modifying the
/usr/share/logwatch/scripts/services/http
file.My file and solution was different but I thought I would share all the same.
I use the standard
vhost_combined
LogFormat that Apache provides that looks like:LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
which outputs something like:
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"
I put this in the service configuration override at
/etc/logwatch/conf/services/http.conf
:After finding the approximately correct places to make the changes for @Syquus's solution in
/usr/share/logwatch/scripts/services/http
, I thought simply changing the index from [3] to [0] would work - it didn't. I got incorrect segments of the path and even after traversing the whole hash/array, I didn't find the hostname. Debugging was frustrating because I'm new to Perl, but my solution was to add in matching for the%v
which was being discarded and then modifying the url further down to include the domain name.Diff for my solution (I also removed the url truncation), YMMV:
Should I decide to serve up secured content or content on a port other than :80 I might include it in the future. It should be obvious now how.
Hope this helps!
UPDATE
Made some more changes, fixed a bug. Rather than keep editing this answer you can find my modifications here: https://bitbucket.org/ubiquitypress/logwatch