From: Pieter Lexis Date: Thu, 22 Mar 2018 16:53:00 +0000 (+0100) Subject: Expose rpz stats in the web-interface X-Git-Tag: rec-4.1.2~1^2~4^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a70228157ae00e18f66676e6ca0d039ae59d0c69;p=pdns Expose rpz stats in the web-interface (cherry picked from commit 2278ffdab2c5a3ff47c56021892926d7b47a811c) --- diff --git a/pdns/rpzloader.cc b/pdns/rpzloader.cc index 0326befee..55adb452c 100644 --- a/pdns/rpzloader.cc +++ b/pdns/rpzloader.cc @@ -250,16 +250,6 @@ void loadRPZFromFile(const std::string& fname, std::shared_ptr d_failedTransfers; - std::atomic d_successfulTransfers; - std::atomic d_fullTransfers; - std::atomic d_numberOfRecords; - std::atomic d_lastUpdate; - std::atomic d_serial; -}; - static std::unordered_map s_rpzStats; static std::mutex s_rpzStatsMutex; diff --git a/pdns/rpzloader.hh b/pdns/rpzloader.hh index 900ea23b0..71e4de0b4 100644 --- a/pdns/rpzloader.hh +++ b/pdns/rpzloader.hh @@ -30,3 +30,15 @@ void loadRPZFromFile(const std::string& fname, std::shared_ptr loadRPZFromServer(const ComboAddress& master, const DNSName& zoneName, std::shared_ptr zone, boost::optional defpol, uint32_t maxTTL, const TSIGTriplet& tt, size_t maxReceivedBytes, const ComboAddress& localAddress, const uint16_t axfrTimeout); void RPZRecordToPolicy(const DNSRecord& dr, std::shared_ptr zone, bool addOrRemove, boost::optional defpol, uint32_t maxTTL); void RPZIXFRTracker(const ComboAddress& master, boost::optional defpol, uint32_t maxTTL, size_t polZone, const TSIGTriplet &tt, size_t maxReceivedBytes, const ComboAddress& localAddress, std::shared_ptr zone, const uint16_t axfrTimeout); + +struct rpzStats +{ + std::atomic d_failedTransfers; + std::atomic d_successfulTransfers; + std::atomic d_fullTransfers; + std::atomic d_numberOfRecords; + std::atomic d_lastUpdate; + std::atomic d_serial; +}; + +rpzStats& getRPZZoneStats(const std::string& zone); diff --git a/pdns/ws-recursor.cc b/pdns/ws-recursor.cc index 1701e6c10..74d74d9d5 100644 --- a/pdns/ws-recursor.cc +++ b/pdns/ws-recursor.cc @@ -39,6 +39,8 @@ #include "ws-api.hh" #include "logger.hh" #include "ext/incbin/incbin.h" +#include "rec-lua-conf.hh" +#include "rpzloader.hh" extern thread_local FDMultiplexer* t_fdm; @@ -381,6 +383,34 @@ static void apiServerCacheFlush(HttpRequest* req, HttpResponse* resp) { }); } +static void apiServerRPZ(HttpRequest* req, HttpResponse* resp) { + if(req->method != "GET") + throw HttpMethodNotAllowedException(); + + auto luaconf = g_luaconfs.getLocal(); + auto numZones = luaconf->dfe.size(); + + Json::object ret; + + for (size_t i=0; i < numZones; i++) { + auto zone = luaconf->dfe.getZone(i); + if (zone == nullptr) + continue; + auto name = zone->getName(); + auto& stats = getRPZZoneStats(*name); + Json::object zoneInfo = { + {"transfers_failed", (double)stats.d_failedTransfers}, + {"transfers_success", (double)stats.d_successfulTransfers}, + {"transfers_full", (double)stats.d_fullTransfers}, + {"records", (double)stats.d_numberOfRecords}, + {"last_update", (double)stats.d_lastUpdate}, + {"serial", (double)stats.d_serial}, + }; + ret[*name] = zoneInfo; + } + resp->setBody(ret); +} + #include "htmlfiles.h" static void serveStuff(HttpRequest* req, HttpResponse* resp)