]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add getPoolNames() function 12621/head
authorChristof Chen <christof@chen.de>
Fri, 7 Oct 2022 18:32:37 +0000 (20:32 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 6 Mar 2023 13:38:21 +0000 (14:38 +0100)
(cherry picked from commit 377c12005b8548a3431ccce4be1dcf5e5b01956f)

pdns/dnsdist-console.cc
pdns/dnsdist-lua.cc

index a052779e3801e228c432b786f0de35d9ffc1d853..e00cdc7f9a844a49c8610bc84e4fd2f7e3c5086f 100644 (file)
@@ -460,6 +460,7 @@ const std::vector<ConsoleKeyword> g_consoleKeywords{
   { "getOutgoingTLSSessionCacheSize", true, "", "returns the number of TLS sessions (for outgoing connections) currently cached" },
   { "getPool", true, "name", "return the pool named `name`, or \"\" for the default pool" },
   { "getPoolServers", true, "pool", "return servers part of this pool" },
+  { "getPoolNames", true, "", "returns a table with all the pool names" },
   { "getQueryCounters", true, "[max=10]", "show current buffer of query counters, limited by 'max' if provided" },
   { "getResponseRing", true, "", "return the current content of the response ring" },
   { "getRespRing", true, "", "return the qname/rcode content of the response ring" },
index 641464cd2181f44a4664d947b8c9e4caa820a3da..653cbd5e531fd3d914f897a839f3261858866157 100644 (file)
@@ -1741,6 +1741,18 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
     }
   });
 
+  luaCtx.writeFunction("getPoolNames", []() {
+    setLuaNoSideEffect();
+    std::vector<std::pair<int, std::string>> ret;
+    int count = 1;
+    const auto localPools = g_pools.getCopy();
+    for (const auto& entry : localPools) {
+      const string& name = entry.first;
+      ret.push_back(make_pair(count++, name));
+    }
+    return ret;
+  });
+
   luaCtx.writeFunction("getPool", [client](const string& poolName) {
     if (client) {
       return std::make_shared<ServerPool>();