Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for vhost:port in common/combined log formats #2688

Merged
merged 5 commits into from
Apr 29, 2019

Conversation

nambrosch
Copy link
Contributor

This patch will add support for vhost & port in common & combined apache logs as discussed @ #2670. Here is that format -

foo.com:443 1.2.3.4 - - [15/Apr/2019:14:30:16 -0400] "GET /bar.html HTTP/2.0" 500 - "https://foo.com/referer.html" "Mozilla/5.0 ..."

Below is my use case that I'm using on a test server, using the ${.apache.vhost} macro to create a directory then logging using combined format -

apache:

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" vcombined
CustomLog "|/usr/bin/logger -S 65536 -t apache -p info -d -n 127.0.0.1 -P 5141" vcombined

syslog-ng:

source s_apache_access {
  network(ip(127.0.0.1) port(5141) transport(udp) flags(syslog-protocol));
};

destination d_apache_access {
  file (
    "/var/log/httpd/${.apache.vhost}/access_log_${YEAR}${MONTH}${DAY}"
    template("${.apache.clientip} ${.apache.ident} ${.apache.auth} [${.apache.timestamp}] \"${.apache.rawrequest}\" ${.apache.response} ${.apache.bytes} \"${.apache.referrer}\" \"${.apache.agent}\"\n")
  );
};

log {
  source(s_apache_access);
  parser { apache-accesslog-parser(); };
  destination(d_apache_access);
};

@kira-syslogng
Copy link
Contributor

This user does not have permission to start the build. Can one of the admins verify this patch and start the build?
(admin: you have the next options (make sure you checked the code):
"ok to test" to accept this pull request (and further changes) for testing
"test this please" for a one time test run
"add to whitelist" add author of a Pull Request to whitelist (globally, be careful, it means this user can trigger kira for any PR)
do nothing -> CI won't start)

1 similar comment
@kira-syslogng
Copy link
Contributor

This user does not have permission to start the build. Can one of the admins verify this patch and start the build?
(admin: you have the next options (make sure you checked the code):
"ok to test" to accept this pull request (and further changes) for testing
"test this please" for a one time test run
"add to whitelist" add author of a Pull Request to whitelist (globally, be careful, it means this user can trigger kira for any PR)
do nothing -> CI won't start)

@Kokan
Copy link
Collaborator

Kokan commented Apr 19, 2019

@kira-syslogng ok to test

@kira-syslogng
Copy link
Contributor

Build SUCCESS

bazsi
bazsi previously approved these changes Apr 20, 2019
Copy link
Collaborator

@bazsi bazsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. There are some white space only changes, maybe tab to space conversion, that could perhaps be removed, but it's ok this way, as that's only a few lines.

I didn't exlicitly check that this is indeed the Apache combined format but i trust you it is.

@nambrosch
Copy link
Contributor Author

i used four spaces for indenting instead of tabs, what is your convention?

@bazsi
Copy link
Collaborator

bazsi commented Apr 21, 2019 via email

Signed-off-by: Nik Ambrosch <nik@ambrosch.com>
@kira-syslogng
Copy link
Contributor

Build SUCCESS

@furiel
Copy link
Collaborator

furiel commented Apr 21, 2019

The patch itself looks good to me. I just have one question for clarification.

Would it be possible to add support for the unofficial vcommon & vcombined formats to the apache parser?

Could you explain what do you mean by unofficial format? I tried to investigate, and here is what I found. According to the documentation, the official combined log format is

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined

which is different than the introduced version.

I fired up an apache server on centos:7 in docker, and they use the official format above.
However, with ubuntu:bionic, they go with your version, except they call it vhost_combined instead of vcombined.

So what is happening here is that some distributions deviate from the official log format? And the goal here is to support those distributions too? Out of curiosity, which distribution do you use?

Btw, I do not have problem with that. I like the idea that syslog-ng should work out of the box, and support the deviations of major distributions.


# if traditional log format
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From clean code point of view, instead of this comment, you could give a name to these parser blocks. Analogously to

block parser apache-accesslog-parser(prefix(".apache.") template("${MESSAGE}"))

you could extract these branches into apache-access-log-traditional-part and apache-access-log-combined-part. That would make the scl a little more readable. As maybe there are other distributions with different format, it would be easier to extend later on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware that ubuntu has this LogFormat already available, thanks for pointing it out. Fedora/CentOS does not include this format. It might make more sense to reference the name as vhost_combined instead of vcombined.

Shifting from 1 -> 3 blocks is a good idea, I'll explore that tonight.

Using one block for each log format makes extending easier.

Signed-off-by: Nik Ambrosch <nik@ambrosch.com>
Copy link
Contributor Author

@nambrosch nambrosch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@furiel split the blocks per your suggestion.

@kira-syslogng
Copy link
Contributor

Build SUCCESS

@bazsi
Copy link
Collaborator

bazsi commented Apr 23, 2019 via email

@bazsi
Copy link
Collaborator

bazsi commented Apr 23, 2019

Here's that last branch as a git branch, feel free to integrate it into yours.

https://github.com/bazsi/syslog-ng/tree/apache-access-log-parser-improvements

@nambrosch
Copy link
Contributor Author

nambrosch commented Apr 23, 2019

@bazsi i'm still using $1 two more times in block parser apache-accesslog-parser so removing set("`template`" value("1")); causes it to break.

moving the filter and changing $1 -> template in block parser apache-accesslog-parser-combined is logical though.

Signed-off-by: Balazs Scheidler <balazs.scheidler@oneidentity.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@oneidentity.com>
@bazsi
Copy link
Collaborator

bazsi commented Apr 28, 2019

I have just added a few more patches on top of the initial patch and sent a PR to @nambrosch With those patches this has my approval and I think it would be great if we could merge them by 3.21

Alternatively, we could my branch directly, it contains both this patch and my improvements
https://github.com/bazsi/syslog-ng/tree/apache-access-log-parser-improvements

@nambrosch
Copy link
Contributor Author

@bazsi Thanks, I'm happy with those changes - confirmed it works on a fedora host and merged the PR.

@kira-syslogng
Copy link
Contributor

Build SUCCESS

@bazsi
Copy link
Collaborator

bazsi commented Apr 29, 2019 via email

bazsi
bazsi previously approved these changes Apr 29, 2019
Copy link
Collaborator

@bazsi bazsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. It would be nice if you could get rid off the merge commit within the branch, just make sure its a set of linear patches.

@nambrosch
Copy link
Contributor Author

Approved. It would be nice if you could get rid off the merge commit within the branch, just make sure its a set of linear patches.

Thanks. Is it possible to remove that? I think trying to revert the merge commit in nambrosch/syslog-ng creates an additional PR, no?

@Kokan
Copy link
Collaborator

Kokan commented Apr 29, 2019

@nambrosch you should be fine to hard reset to @bazsi patch and force push it. (it should not create new PR)

Something like this: https://asciinema.org/a/zRtDlGZjId1VheJeiMoqP4qr9

@nambrosch
Copy link
Contributor Author

ah ha, perfect, all set.

@kira-syslogng
Copy link
Contributor

Build SUCCESS

@Kokan Kokan merged commit 7e3b683 into syslog-ng:master Apr 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants