Harden the telemetry manager against unset Telemetry::metrics_address

We populate that address from the ZEEK_DEFAULT_LISTEN_ADDRESS environment
variable, but weren't prepared for that not being set. We now fall back to
0.0.0.0. This may have the same IPv6 issues that we've encountered elsewhere
when doing so before (v6 interfaces need "::") -- but this is still more likely
to work than not having any string at all.
This commit is contained in:
Christian Kreibich 2024-07-05 17:15:33 -07:00
parent 3ecacf4f50
commit 8eb74c04de

View file

@ -36,6 +36,8 @@ void Manager::InitPostScript() {
std::string prometheus_url;
auto metrics_port = id::find_val("Telemetry::metrics_port")->AsPortVal();
auto metrics_address = id::find_val("Telemetry::metrics_address")->AsStringVal()->ToStdString();
if ( metrics_address.empty() )
metrics_address = "0.0.0.0";
if ( metrics_port->Port() != 0 )
prometheus_url = util::fmt("%s:%u", metrics_address.data(), metrics_port->Port());