fix(inputs.jolokia2): add optional origin header (#11692)

This commit is contained in:
Joshua Powers 2022-09-07 13:08:21 -06:00 committed by GitHub
parent 38fd172ed1
commit dc9abf3f04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 13 deletions

View File

@ -23,6 +23,7 @@ type ClientConfig struct {
ResponseTimeout time.Duration
Username string
Password string
Origin string
ProxyConfig *ProxyConfig
tls.ClientConfig
}
@ -137,6 +138,9 @@ func (c *Client) read(requests []ReadRequest) ([]ReadResponse, error) {
}
req.Header.Add("Content-type", "application/json")
if c.config.Origin != "" {
req.Header.Add("Origin", c.config.Origin)
}
resp, err := c.client.Do(req)
if err != nil {

View File

@ -18,6 +18,10 @@ The `jolokia2_agent` input plugin reads JMX metrics from one or more
# password = ""
# response_timeout = "5s"
## Optional origin URL to include as a header in the request. Some endpoints
## may reject an empty origin.
# origin = ""
## Optional TLS config
# tls_ca = "/var/private/ca.pem"
# tls_cert = "/var/private/client.pem"

View File

@ -15,6 +15,7 @@ import (
)
// DO NOT REMOVE THE NEXT TWO LINES! This is required to embed the sampleConfig data.
//
//go:embed sample.conf
var sampleConfig string
@ -23,9 +24,10 @@ type JolokiaAgent struct {
DefaultFieldSeparator string
DefaultTagPrefix string
URLs []string `toml:"urls"`
Username string
Password string
URLs []string `toml:"urls"`
Username string `toml:"username"`
Password string `toml:"password"`
Origin string `toml:"origin"`
ResponseTimeout config.Duration `toml:"response_timeout"`
tls.ClientConfig
@ -91,6 +93,7 @@ func (ja *JolokiaAgent) createClient(url string) (*common.Client, error) {
return common.NewClient(url, &common.ClientConfig{
Username: ja.Username,
Password: ja.Password,
Origin: ja.Origin,
ResponseTimeout: time.Duration(ja.ResponseTimeout),
ClientConfig: ja.ClientConfig,
})

View File

@ -10,6 +10,10 @@
# password = ""
# response_timeout = "5s"
## Optional origin URL to include as a header in the request. Some endpoints
## may reject an empty origin.
# origin = ""
## Optional TLS config
# tls_ca = "/var/private/ca.pem"
# tls_cert = "/var/private/client.pem"

View File

@ -19,6 +19,10 @@ REST endpoint.
# password = ""
# response_timeout = "5s"
## Optional origin URL to include as a header in the request. Some endpoints
## may reject an empty origin.
# origin = ""
## Optional TLS config
# tls_ca = "/var/private/ca.pem"
# tls_cert = "/var/private/client.pem"

View File

@ -12,21 +12,23 @@ import (
)
// DO NOT REMOVE THE NEXT TWO LINES! This is required to embed the sampleConfig data.
//
//go:embed sample.conf
var sampleConfig string
type JolokiaProxy struct {
DefaultFieldPrefix string
DefaultFieldSeparator string
DefaultTagPrefix string
DefaultFieldPrefix string `toml:"default_field_prefix"`
DefaultFieldSeparator string `toml:"default_field_separator"`
DefaultTagPrefix string `toml:"default_tag_prefix"`
URL string `toml:"url"`
DefaultTargetPassword string
DefaultTargetUsername string
URL string `toml:"url"`
DefaultTargetPassword string `toml:"default_target_password"`
DefaultTargetUsername string `toml:"default_target_username"`
Targets []JolokiaProxyTargetConfig `toml:"target"`
Username string
Password string
Username string `toml:"username"`
Password string `toml:"password"`
Origin string `toml:"origin"`
ResponseTimeout config.Duration `toml:"response_timeout"`
tls.ClientConfig
@ -37,8 +39,8 @@ type JolokiaProxy struct {
type JolokiaProxyTargetConfig struct {
URL string `toml:"url"`
Username string
Password string
Username string `toml:"username"`
Password string `toml:"password"`
}
func (*JolokiaProxy) SampleConfig() string {

View File

@ -10,6 +10,10 @@
# password = ""
# response_timeout = "5s"
## Optional origin URL to include as a header in the request. Some endpoints
## may reject an empty origin.
# origin = ""
## Optional TLS config
# tls_ca = "/var/private/ca.pem"
# tls_cert = "/var/private/client.pem"