]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: Add an extended status report in the bind backend 8682/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 8 Jan 2020 16:46:10 +0000 (17:46 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 29 Jan 2020 08:46:12 +0000 (09:46 +0100)
docs/backends/bind.rst
docs/manpages/pdns_control.1.rst
modules/bindbackend/bindbackend2.cc
modules/bindbackend/bindbackend2.hh

index 1e20a167003fcb638ff023c4ac2ec7fcac41b905..8ea0d0a260e054135f41bf5d15b39cd3b71e6767 100644 (file)
@@ -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> [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:
index fa28d9b15788cffa4fdae2cb4899856a57e76dba..04fc888261f8ad9491471e744e2246e130a3a98a 100644 (file)
@@ -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*...]
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
index cd1ddbfe0f132a2349b16390e2b7f1d2114b9b29..fe383aa8b956aa36debeae73663c295c417dcf06 100644 (file)
@@ -567,16 +567,17 @@ string Bind2Backend::DLReloadNowHandler(const vector<string>&parts, Utility::pid
 string Bind2Backend::DLDomStatusHandler(const vector<string>&parts, Utility::pid_t ppid)
 {
   ostringstream ret;
-      
+
   if(parts.size() > 1) {
     for(vector<string>::const_iterator i=parts.begin()+1;i<parts.end();++i) {
       BB2DomainInfo bbd;
-      if(safeGetBBDomainInfo(DNSName(*i), &bbd)) {     
+      if(safeGetBBDomainInfo(DNSName(*i), &bbd)) {
         ret<< *i << ": "<< (bbd.d_loaded ? "": "[rejected]") <<"\t"<<bbd.d_status<<"\n";
-    }
-      else
+      }
+      else {
         ret<< *i << " no such domain\n";
-    }    
+      }
+    }
   }
   else {
     ReadLock rl(&s_state_lock);
@@ -591,6 +592,69 @@ string Bind2Backend::DLDomStatusHandler(const vector<string>&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<string>&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<string>&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", "<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", "<domain> <filename>");
 }
index 4140b0aa0ba2927370c3f4b8f1e137890398c102..dfb16198503f14f3cf71cc146a38e7cc25a7cf76 100644 (file)
@@ -121,6 +121,12 @@ public:
     return ret;
   }
 
+  size_t getEntriesCount() const
+  {
+    std::lock_guard<std::mutex> lock(s_lock);
+    return d_records->size();
+  }
+
 private:
   static std::mutex s_lock;
   shared_ptr<T> 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<recordstorage_t>& 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<string>&parts, Utility::pid_t ppid);
+  static string DLDomExtendedStatusHandler(const vector<string>&parts, Utility::pid_t ppid);
   static string DLListRejectsHandler(const vector<string>&parts, Utility::pid_t ppid);
   static string DLReloadNowHandler(const vector<string>&parts, Utility::pid_t ppid);
   static string DLAddDomainHandler(const vector<string>&parts, Utility::pid_t ppid);