-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add support for http hostname in nginx filebeat module #14505
Conversation
"service.type": "nginx", | ||
"source.address": "localhost, localhost", | ||
"source.address": "localhost", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was being incorrectly parsed, this is also fixed as part of this PR.
"lang": "painless", | ||
"source": "boolean isPrivate(def dot, def ip) { try { StringTokenizer tok = new StringTokenizer(ip, dot); int firstByte = Integer.parseInt(tok.nextToken()); int secondByte = Integer.parseInt(tok.nextToken()); if (firstByte == 10) { return true; } if (firstByte == 192 && secondByte == 168) { return true; } if (firstByte == 172 && secondByte >= 16 && secondByte <= 31) { return true; } if (firstByte == 127) { return true; } return false; } catch (Exception e) { return false; } } try { ctx.source.ip = null; if (ctx.nginx.access.remote_ip_list == null) { return; } def found = false; for (def item : ctx.nginx.access.remote_ip_list) { if (!isPrivate(params.dot, item)) { ctx.source.ip = item; found = true; break; } } if (!found) { ctx.source.ip = ctx.nginx.access.remote_ip_list[0]; }} catch (Exception e) { ctx.source.ip = null; }", | ||
"source": "boolean isPrivate(def dot, def ip) { try { StringTokenizer tok = new StringTokenizer(ip, dot); int firstByte = Integer.parseInt(tok.nextToken()); int secondByte = Integer.parseInt(tok.nextToken()); if (firstByte == 10) { return true; } if (firstByte == 192 && secondByte == 168) { return true; } if (firstByte == 172 && secondByte >= 16 && secondByte <= 31) { return true; } if (firstByte == 127) { return true; } return false; } catch (Exception e) { return false; } } try { ctx.source.address = null; if (ctx.nginx.access.remote_ip_list == null) { return; } def found = false; for (def item : ctx.nginx.access.remote_ip_list) { if (!isPrivate(params.dot, item)) { ctx.source.address = item; found = true; break; } } if (!found) { ctx.source.address = ctx.nginx.access.remote_ip_list[0]; }} catch (Exception e) { ctx.source.address = null; }", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change in this script is a replacement of source.ip
with source.address
.
LGTM |
@@ -286,8 +289,12 @@ | |||
"http.version": "1.1", | |||
"input.type": "log", | |||
"log.offset": 1398, | |||
"nginx.access.remote_ip_list": [ | |||
"localhost", | |||
"localhost" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is localhost repeated here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears twice in the example log line:
localhost, localhost - - [29/May/2017:19:02:48 +0000] "GET /test2 HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2" "-"
Not sure how this log was generated.
It is common to modify the default log format in nginx to include the http host used by the client to make the logged request. This is similar to what we already did for Apache in elastic#12778. It also fixes an issue found on source address parsing when source addresses are not IPs. For that, the pipeline works with addresses as strings instead of IPs, and it only tries to convert to IP to finally store the it in `source.ip` if it parses as an IP. Co-authored-by: poma <Semenov.Roman@mail.ru> (cherry picked from commit 1967bc9)
…ebeat module (#14654) It is common to modify the default log format in nginx to include the http host used by the client to make the logged request. This is similar to what we already did for Apache in #12778. It also fixes an issue found on source address parsing when source addresses are not IPs. For that, the pipeline works with addresses as strings instead of IPs, and it only tries to convert to IP to finally store the it in `source.ip` if it parses as an IP. (cherry picked from commit 1967bc9) Co-authored-by: poma <Semenov.Roman@mail.ru>
is it available on 7.x build? |
It is available starting on 7.6.0. |
It is common to modify the default log format in nginx to include
the http host used by the client to make the logged request.
This continues with #13223 to add support for that, and is
similar to what we already did for Apache in #12778.
Fixes #13223.
It also fixes an issue found on source address parsing when
source addresses are not IPs. For that, the pipeline works
with addresses as strings instead of IPs, and it only tries to
convert to IP to finally store the it in
source.ip
if it parsesas an IP.
Co-authored-by: poma Semenov.Roman@mail.ru