|
29 | 29 | dnsProbe = lib.mkOption {
|
30 | 30 | type = with lib.types; attrsOf (submodule {
|
31 | 31 | options = {
|
32 |
| - names = lib.mkOption { |
| 32 | + domains = lib.mkOption { |
33 | 33 | type = with lib.types; listOf str;
|
34 | 34 | example = [ "example.com" ];
|
35 | 35 | description = "Query name to query";
|
|
109 | 109 | exporters.blackbox = {
|
110 | 110 | config.modules = lib.mkMerge (
|
111 | 111 | (lib.mapAttrsToList (probeName: opts:
|
112 |
| - (lib.foldl (x: name: x // { |
113 |
| - "dns_${probeName}_${name}" = { |
| 112 | + (lib.foldl (x: domain: x // { |
| 113 | + "dns_${probeName}_${domain}" = { |
114 | 114 | dns = {
|
115 |
| - query_name = name; |
| 115 | + query_name = domain; |
116 | 116 | query_type = opts.type;
|
117 | 117 | valid_rcodes = [ "NOERROR" ];
|
118 | 118 | };
|
119 | 119 | prober = "dns";
|
120 | 120 | timeout = "5s";
|
121 | 121 | };
|
122 |
| - }) { } opts.names) |
| 122 | + }) { } opts.domains) |
123 | 123 | ) cfgb.dnsProbe)
|
124 | 124 |
|
125 | 125 | ++ lib.mapAttrsToList (name: opts: let
|
|
162 | 162 | metrics_path = "/probe";
|
163 | 163 | relabel_configs = [ {
|
164 | 164 | source_labels = [ "__address__" ];
|
165 |
| - target_label = "__param_target"; |
| 165 | + target_label = "__param_target"; # __param_* will be rewritten as query string |
166 | 166 | } {
|
167 | 167 | source_labels = [ "__param_target" ];
|
168 | 168 | target_label = "instance";
|
169 | 169 | } {
|
| 170 | + # needed because blackbox exporter (ab)uses targets for its targets but we actually need to ask the exporter about the target state |
170 | 171 | target_label = "__address__";
|
171 | 172 | replacement = cfgb.blackboxExporterURL;
|
172 | 173 | } ];
|
173 | 174 | };
|
| 175 | + |
174 | 176 | genHttpProbeScrapeConfig = { name, opts }: commonProbeScrapeConfig // {
|
175 | 177 | job_name = "blackbox_http_${name}";
|
176 | 178 | params.module = [ "http_${name}" ];
|
177 |
| - inherit (commonProbeScrapeConfig) relabel_configs; |
| 179 | + relabel_configs = commonProbeScrapeConfig.relabel_configs ++ [ { |
| 180 | + source_labels = [ "__param_target" ]; |
| 181 | + regex = "https?://(.*)"; |
| 182 | + target_label = "domain"; |
| 183 | + } ]; |
178 | 184 | static_configs = [ {
|
179 | 185 | targets = opts.urls;
|
180 | 186 | } ];
|
181 | 187 | };
|
182 | 188 | in lib.flatten (lib.foldl (x: probe: x ++ [
|
183 |
| - (lib.foldl (x: name: x ++ [ |
| 189 | + (lib.foldl (x: domain: x ++ [ |
184 | 190 | (commonProbeScrapeConfig // {
|
185 |
| - job_name = "blackbox_dns_${probe.name}_${name}"; |
186 |
| - params.module = [ "dns_${probe.name}_${name}" ]; |
| 191 | + job_name = "blackbox_dns_${probe.name}_${domain}"; |
| 192 | + params.module = [ "dns_${probe.name}_${domain}" ]; |
187 | 193 | static_configs = [ {
|
| 194 | + labels = { inherit domain; }; |
188 | 195 | inherit (probe.value) targets;
|
189 | 196 | } ];
|
190 | 197 | })
|
191 |
| - ]) [ ] probe.value.names) |
| 198 | + ]) [ ] probe.value.domains) |
192 | 199 | ]) [ ] (lib.attrsToList cfgb.dnsProbe))
|
| 200 | + |
193 | 201 | ++ lib.filter (v: v != null) (lib.mapAttrsToList (name: opts:
|
194 | 202 | if (opts.ip == "both" || opts.ip == "ip4") then (genHttpProbeScrapeConfig { inherit name opts; }) else null
|
195 | 203 | ) cfgb.httpProbe
|
|
0 commit comments