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

View File

@ -18,6 +18,10 @@ The `jolokia2_agent` input plugin reads JMX metrics from one or more
# password = "" # password = ""
# response_timeout = "5s" # 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 ## Optional TLS config
# tls_ca = "/var/private/ca.pem" # tls_ca = "/var/private/ca.pem"
# tls_cert = "/var/private/client.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. // DO NOT REMOVE THE NEXT TWO LINES! This is required to embed the sampleConfig data.
//
//go:embed sample.conf //go:embed sample.conf
var sampleConfig string var sampleConfig string
@ -23,9 +24,10 @@ type JolokiaAgent struct {
DefaultFieldSeparator string DefaultFieldSeparator string
DefaultTagPrefix string DefaultTagPrefix string
URLs []string `toml:"urls"` URLs []string `toml:"urls"`
Username string Username string `toml:"username"`
Password string Password string `toml:"password"`
Origin string `toml:"origin"`
ResponseTimeout config.Duration `toml:"response_timeout"` ResponseTimeout config.Duration `toml:"response_timeout"`
tls.ClientConfig tls.ClientConfig
@ -91,6 +93,7 @@ func (ja *JolokiaAgent) createClient(url string) (*common.Client, error) {
return common.NewClient(url, &common.ClientConfig{ return common.NewClient(url, &common.ClientConfig{
Username: ja.Username, Username: ja.Username,
Password: ja.Password, Password: ja.Password,
Origin: ja.Origin,
ResponseTimeout: time.Duration(ja.ResponseTimeout), ResponseTimeout: time.Duration(ja.ResponseTimeout),
ClientConfig: ja.ClientConfig, ClientConfig: ja.ClientConfig,
}) })

View File

@ -10,6 +10,10 @@
# password = "" # password = ""
# response_timeout = "5s" # 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 ## Optional TLS config
# tls_ca = "/var/private/ca.pem" # tls_ca = "/var/private/ca.pem"
# tls_cert = "/var/private/client.pem" # tls_cert = "/var/private/client.pem"

View File

@ -19,6 +19,10 @@ REST endpoint.
# password = "" # password = ""
# response_timeout = "5s" # 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 ## Optional TLS config
# tls_ca = "/var/private/ca.pem" # tls_ca = "/var/private/ca.pem"
# tls_cert = "/var/private/client.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. // DO NOT REMOVE THE NEXT TWO LINES! This is required to embed the sampleConfig data.
//
//go:embed sample.conf //go:embed sample.conf
var sampleConfig string var sampleConfig string
type JolokiaProxy struct { type JolokiaProxy struct {
DefaultFieldPrefix string DefaultFieldPrefix string `toml:"default_field_prefix"`
DefaultFieldSeparator string DefaultFieldSeparator string `toml:"default_field_separator"`
DefaultTagPrefix string DefaultTagPrefix string `toml:"default_tag_prefix"`
URL string `toml:"url"` URL string `toml:"url"`
DefaultTargetPassword string DefaultTargetPassword string `toml:"default_target_password"`
DefaultTargetUsername string DefaultTargetUsername string `toml:"default_target_username"`
Targets []JolokiaProxyTargetConfig `toml:"target"` Targets []JolokiaProxyTargetConfig `toml:"target"`
Username string Username string `toml:"username"`
Password string Password string `toml:"password"`
Origin string `toml:"origin"`
ResponseTimeout config.Duration `toml:"response_timeout"` ResponseTimeout config.Duration `toml:"response_timeout"`
tls.ClientConfig tls.ClientConfig
@ -37,8 +39,8 @@ type JolokiaProxy struct {
type JolokiaProxyTargetConfig struct { type JolokiaProxyTargetConfig struct {
URL string `toml:"url"` URL string `toml:"url"`
Username string Username string `toml:"username"`
Password string Password string `toml:"password"`
} }
func (*JolokiaProxy) SampleConfig() string { func (*JolokiaProxy) SampleConfig() string {

View File

@ -10,6 +10,10 @@
# password = "" # password = ""
# response_timeout = "5s" # 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 ## Optional TLS config
# tls_ca = "/var/private/ca.pem" # tls_ca = "/var/private/ca.pem"
# tls_cert = "/var/private/client.pem" # tls_cert = "/var/private/client.pem"