Skip to content

Commit

Permalink
updates per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
legoguy1000 committed Dec 22, 2021
1 parent 3f3295f commit cf4bcc8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add documentation for add_kubernetes_metadata processors `log_path` matcher. {pull}28868[28868]
- Add support for parsers on journald input {pull}29070[29070]
- Add support in httpjson input for oAuth2ProviderDefault of password grant_type. {pull}29087[29087]
- Update Cisco module to enable TCP input. {issue}26118[26118] {issue}28821[28821] {pull}26159[26159]
- Add new `userAgent` and `beatInfo` template functions for httpjson input {pull}29528[29528]

*Heartbeat*
Expand Down
13 changes: 7 additions & 6 deletions libbeat/common/useragent/useragent.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package useragent

import (
"fmt"
"runtime"
"strings"

Expand All @@ -27,22 +26,24 @@ import (

// UserAgent takes the capitalized name of the current beat and returns
// an RFC compliant user agent string for that beat.
func UserAgent(beatNameCapitalized string, additional_agents ...string) string {
func UserAgent(beatNameCapitalized string, additionalComments ...string) string {
var builder strings.Builder
fmt.Fprintf(&builder, "Elastic-%s/%s ", beatNameCapitalized, version.GetDefaultVersion())
builder.WriteString("Elastic-" + beatNameCapitalized + "/" + version.GetDefaultVersion() + " ")
uaValues := []string{
runtime.GOOS,
runtime.GOARCH,
version.Commit(),
version.BuildTime().String(),
}
if additional_agents != nil {
for _, val := range additional_agents {
if additionalComments != nil {
for _, val := range additionalComments {
if val != "" {
uaValues = append(uaValues, val)
}
}
}
fmt.Fprintf(&builder, "(%s)", strings.Join(uaValues, "; "))
builder.WriteByte('(')
builder.WriteString(strings.Join(uaValues, "; "))
builder.WriteByte(')')
return builder.String()
}
3 changes: 3 additions & 0 deletions libbeat/common/useragent/useragent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ import (
func TestUserAgent(t *testing.T) {
ua := UserAgent("FakeBeat")
assert.Regexp(t, regexp.MustCompile("^Elastic-FakeBeat"), ua)

ua2 := UserAgent("FakeBeat", "integration_name/1.2.3")
assert.Regexp(t, regexp.MustCompile("; integration_name\\/1\\.2\\.3\\)$"), ua2)
}
4 changes: 2 additions & 2 deletions x-pack/filebeat/docs/inputs/input-httpjson.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ Some built-in helper functions are provided to work with the input state inside
- `sprintf`: formats according to a format specifier and returns the resulting string. Refer to https://pkg.go.dev/fmt#Sprintf[the Go docs] for usage. Example: `[[sprintf "%d:%q" 34 "quote this"]]`
- `hmacBase64`: calculates the hmac signature of a list of strings concatenated together. Returns a base64 encoded signature. Supports sha1 or sha256. Example `[[hmac "sha256" "secret" "string1" "string2" (formatDate (now) "RFC1123")]]`
- `uuid`: returns a random UUID such as `a11e8780-e3e7-46d0-8e76-f66e75acf019`. Example: `[[ uuid ]]`
- `userAgent`: generates the User Agent with optional additional values. No arguments generate the default User Agent that is already used. Example: `[[ userAgent "integration/1.2.3" ]]` would generate `Elastic-Filebeat/8.1.0 (darwin; amd64; 9b893e88cfe109e64638d65c58fd75c2ff695402; 2021-12-15 13:20:00 +0000 UTC; integration_name/1.2.3)`
- `beatInfo`: returns a map containing information about the beat. Available keys in the map are `goos` (running operating system), `goarch` (running system architecture), `commit` (git commit of current build), `buildtime` (compile time of current build), `version` (version of current build). Example: `[[ beatInfo.version ]]` returns `8.1.0`.
- `userAgent`: generates the User Agent with optional additional values. If no arguments are provided, it will generate the default User Agent that is added to all requests by default. It is recommended to delete the existing User-Agent header before setting a new one. Example: `[[ userAgent "integration/1.2.3" ]]` would generate `Elastic-Filebeat/8.1.0 (darwin; amd64; 9b893e88cfe109e64638d65c58fd75c2ff695402; 2021-12-15 13:20:00 +0000 UTC; integration_name/1.2.3)`
- `beatInfo`: returns a map containing information about the Beat. Available keys in the map are `goos` (running operating system), `goarch` (running system architecture), `commit` (git commit of current build), `buildtime` (compile time of current build), `version` (version of current build). Example: `[[ beatInfo.version ]]` returns `{version}`.

In addition to the provided functions, any of the native functions for https://golang.org/pkg/time/#Time[`time.Time`], https://golang.org/pkg/net/http/#Header[`http.Header`], and https://golang.org/pkg/net/url/#Values[`url.Values`] types can be used on the corresponding objects. Examples: `[[(now).Day]]`, `[[.last_response.header.Get "key"]]`

Expand Down

0 comments on commit cf4bcc8

Please sign in to comment.