Difference between revisions of "Blackbox exporter header host"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
− | + | # Custom Headers | |
To pass an HTTPS IP address and a Host header value dynamically as targets in Blackbox Exporter configuration, you can use the http_custom_headers module with Prometheus relabeling to achieve this. Here's how you can set it up: | To pass an HTTPS IP address and a Host header value dynamically as targets in Blackbox Exporter configuration, you can use the http_custom_headers module with Prometheus relabeling to achieve this. Here's how you can set it up: | ||
− | + | ``` | |
− | |||
modules: | modules: | ||
http_custom_headers: | http_custom_headers: | ||
Line 13: | Line 12: | ||
Host: '${host}' | Host: '${host}' | ||
valid_http_versions: ["HTTP/1.1", "HTTP/2"] | valid_http_versions: ["HTTP/1.1", "HTTP/2"] | ||
− | valid_status_codes: | + | valid_status_codes: '${valid_status_codes}' |
target: '${target}' | target: '${target}' | ||
tls_config: | tls_config: | ||
Line 26: | Line 25: | ||
- source_labels: [__param_target] | - source_labels: [__param_target] | ||
target_label: target | target_label: target | ||
− | + | - source_labels: [__param_valid_status_codes] | |
+ | target_label: valid_status_codes | ||
+ | ``` | ||
+ | /blackbox/probe?target=https://10.1.1.2/api/test&module=http_custom_headers&host=api.example.com&valid_status_codes=200,201,204 | ||
+ | |||
+ | |||
+ | # Explanation: | ||
+ | ``` | ||
prober: Specifies the probe type, which is HTTP in this case. | prober: Specifies the probe type, which is HTTP in this case. | ||
timeout: Sets the timeout for the probe. | timeout: Sets the timeout for the probe. |
Latest revision as of 21:38, 26 March 2024
Custom Headers
To pass an HTTPS IP address and a Host header value dynamically as targets in Blackbox Exporter configuration, you can use the http_custom_headers module with Prometheus relabeling to achieve this. Here's how you can set it up:
modules: http_custom_headers: prober: http timeout: 5s http: method: GET headers: Host: '${host}' valid_http_versions: ["HTTP/1.1", "HTTP/2"] valid_status_codes: '${valid_status_codes}' target: '${target}' tls_config: insecure_skip_verify: true # You may need to adjust this based on your environment relabel_configs: - source_labels: [__address__] target_label: target - source_labels: [__address__] target_label: host - source_labels: [__param_host] target_label: host - source_labels: [__param_target] target_label: target - source_labels: [__param_valid_status_codes] target_label: valid_status_codes
/blackbox/probe?target=https://10.1.1.2/api/test&module=http_custom_headers&host=api.example.com&valid_status_codes=200,201,204
Explanation:
prober: Specifies the probe type, which is HTTP in this case. timeout: Sets the timeout for the probe. method: Specifies the HTTP method (GET by default). headers: Defines the custom headers. Here, the Host header is set to ${host}, which will be dynamically replaced. target: Defines the target URL for the probe. This will be dynamically replaced with the value from the __param_target label. tls_config: Configures TLS settings. In this example, insecure_skip_verify is set to true for simplicity. Adjust this based on your security requirements. relabel_configs: Specifies the relabeling rules for modifying target URL and headers based on labels. When using this configuration, you need to pass the target IP address and the Host header value as parameters when querying the Blackbox Exporter's probe endpoint. For example, to probe https://10.1.1.2/api/test with the Host header set to api.example.com, you would query: bash Copy code /blackbox/probe?target=https://10.1.1.2/api/test&module=http_custom_headers&host=api.example.com This configuration allows for dynamic substitution of the target URL and Host header value based on parameters passed in the query. Adjust the configuration as needed for your specific use case and environment.