From e640604f3a36ebf642fc32a8d33bce14c0aae44e Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 8 Jan 2020 17:46:10 +0100 Subject: [PATCH] auth: Add an extended status report in the bind backend --- docs/backends/bind.rst | 11 ++++- docs/manpages/pdns_control.1.rst | 8 +++ modules/bindbackend/bindbackend2.cc | 75 +++++++++++++++++++++++++++-- modules/bindbackend/bindbackend2.hh | 11 +++++ 4 files changed, 99 insertions(+), 6 deletions(-) diff --git a/docs/backends/bind.rst b/docs/backends/bind.rst index 1e20a16700..8ea0d0a260 100644 --- a/docs/backends/bind.rst +++ b/docs/backends/bind.rst @@ -144,7 +144,16 @@ will be loaded at first request. .. note:: This does not add the zone to the :ref:`setting-bind-config` file. -``bind-domain-status [domain]`` +``bind-domain-extended-status [domain ...]`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. versionadded:: 4.3.0 + +Output an extended status of a domain or domains, containing much more information than +the simple domain status, like the number of records currently loaded, whether pdns +is master or slave for the domain, the list of masters, various timers, etc + +``bind-domain-status [domain ...]`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Output status of domain or domains. Can be one of: diff --git a/docs/manpages/pdns_control.1.rst b/docs/manpages/pdns_control.1.rst index fa28d9b157..04fc888261 100644 --- a/docs/manpages/pdns_control.1.rst +++ b/docs/manpages/pdns_control.1.rst @@ -34,6 +34,14 @@ When using the BIND backend, add a zone. This zone is added in-memory and served immediately. Note that this does not add the zone to the bind-config file. *FILENAME* must be an absolute path. +bind-domain-extended-status [*DOMAIN*...] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Output an extended status of all domains, containing much more information than +the simple domain status, like the number of records currently loaded, whether pdns +is master or slave for the domain, the list of masters, various timers, etc +Optionally, append *DOMAIN*\ s to get the status of specific zones. + bind-domain-status [*DOMAIN*...] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/modules/bindbackend/bindbackend2.cc b/modules/bindbackend/bindbackend2.cc index cd1ddbfe0f..fe383aa8b9 100644 --- a/modules/bindbackend/bindbackend2.cc +++ b/modules/bindbackend/bindbackend2.cc @@ -567,16 +567,17 @@ string Bind2Backend::DLReloadNowHandler(const vector&parts, Utility::pid string Bind2Backend::DLDomStatusHandler(const vector&parts, Utility::pid_t ppid) { ostringstream ret; - + if(parts.size() > 1) { for(vector::const_iterator i=parts.begin()+1;i&parts, Utility::pid return ret.str(); } +static void printDomainExtendedStatus(ostringstream& ret, const BB2DomainInfo& info) +{ + ret << info.d_name << ": " << std::endl; + ret << "\t Status: " << info.d_status << std::endl; + ret << "\t Internal ID: " << info.d_id << std::endl; + ret << "\t On-disk file: " << info.d_filename << " (" << info.d_ctime << ")" << std::endl; + ret << "\t Kind: "; + switch (info.d_kind) { + case DomainInfo::Master: + ret << "Master"; + break; + case DomainInfo::Slave: + ret << "Slave"; + break; + default: + ret << "Native"; + } + ret << std::endl; + ret << "\t Masters: " << std::endl; + for (const auto& master : info.d_masters) { + ret << "\t\t - " << master.toStringWithPort() << std::endl; + } + ret << "\t Also Notify: " << std::endl; + for (const auto& also : info.d_also_notify) { + ret << "\t\t - " << also << std::endl; + } + ret << "\t Number of records: " << info.d_records.getEntriesCount() << std::endl; + ret << "\t Loaded: " << info.d_loaded << std::endl; + ret << "\t Check now: " << info.d_checknow << std::endl; + ret << "\t Check interval: " << info.getCheckInterval() << std::endl; + ret << "\t Last check: " << info.d_lastcheck << std::endl; + ret << "\t Last notified: " << info.d_lastnotified << std::endl; +} + +string Bind2Backend::DLDomExtendedStatusHandler(const vector&parts, Utility::pid_t ppid) +{ + ostringstream ret; + + if (parts.size() > 1) { + for (const auto& part : parts) { + BB2DomainInfo bbd; + if (safeGetBBDomainInfo(DNSName(part), &bbd)) { + printDomainExtendedStatus(ret, bbd); + } + else { + ret << part << " no such domain" << std::endl; + } + } + } + else { + ReadLock rl(&s_state_lock); + for (const auto& state : s_state) { + printDomainExtendedStatus(ret, state); + } + } + + if (ret.str().empty()) { + ret << "no domains passed" << std::endl; + } + + return ret.str(); +} + string Bind2Backend::DLListRejectsHandler(const vector&parts, Utility::pid_t ppid) { ostringstream ret; @@ -676,6 +740,7 @@ Bind2Backend::Bind2Backend(const string &suffix, bool loadZones) extern DynListener *dl; dl->registerFunc("BIND-RELOAD-NOW", &DLReloadNowHandler, "bindbackend: reload domains", ""); dl->registerFunc("BIND-DOMAIN-STATUS", &DLDomStatusHandler, "bindbackend: list status of all domains", "[domains]"); + dl->registerFunc("BIND-DOMAIN-EXTENDED-STATUS", &DLDomExtendedStatusHandler, "bindbackend: list the extended status of all domains", "[domains]"); dl->registerFunc("BIND-LIST-REJECTS", &DLListRejectsHandler, "bindbackend: list rejected domains"); dl->registerFunc("BIND-ADD-ZONE", &DLAddDomainHandler, "bindbackend: add zone", " "); } diff --git a/modules/bindbackend/bindbackend2.hh b/modules/bindbackend/bindbackend2.hh index 4140b0aa0b..dfb1619850 100644 --- a/modules/bindbackend/bindbackend2.hh +++ b/modules/bindbackend/bindbackend2.hh @@ -121,6 +121,12 @@ public: return ret; } + size_t getEntriesCount() const + { + std::lock_guard lock(s_lock); + return d_records->size(); + } + private: static std::mutex s_lock; shared_ptr d_records; @@ -136,6 +142,10 @@ public: bool current(); //! configure how often this domain should be checked for changes (on disk) void setCheckInterval(time_t seconds); + time_t getCheckInterval() const + { + return d_checkinterval; + } DNSName d_name; //!< actual name of the domain DomainInfo::DomainKind d_kind; //!< the kind of domain @@ -299,6 +309,7 @@ private: static void insertRecord(std::shared_ptr& records, const DNSName& zoneName, const DNSName &qname, const QType &qtype, const string &content, int ttl, const std::string& hashed=string(), bool *auth=nullptr); void reload() override; static string DLDomStatusHandler(const vector&parts, Utility::pid_t ppid); + static string DLDomExtendedStatusHandler(const vector&parts, Utility::pid_t ppid); static string DLListRejectsHandler(const vector&parts, Utility::pid_t ppid); static string DLReloadNowHandler(const vector&parts, Utility::pid_t ppid); static string DLAddDomainHandler(const vector&parts, Utility::pid_t ppid); -- 2.47.2