]> granicus.if.org Git - pdns/commitdiff
hook up several more ringbuffers to the recursor web API, support grouping by public...
authorbert hubert <bert.hubert@netherlabs.nl>
Sun, 11 Jan 2015 21:22:35 +0000 (22:22 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Sun, 11 Jan 2015 21:22:35 +0000 (22:22 +0100)
pdns/rec_channel.hh
pdns/rec_channel_rec.cc
pdns/ws-api.cc
pdns/ws-recursor.cc

index f220d292d70bacc9177800445f8dc798ae5bef37..7d320c02d974967a97d705da273df2edcc784953 100644 (file)
@@ -6,7 +6,7 @@
 #include <inttypes.h>
 #include <sys/un.h>
 #include <pthread.h>
-
+#include "iputils.hh"
 
 /** this class is used both to send and answer channel commands to the PowerDNS Recursor */
 class RecursorControlChannel
@@ -45,4 +45,8 @@ extern pthread_mutex_t g_carbon_config_lock;
 void sortPublicSuffixList();
 std::vector<std::pair<std::string, uint16_t> >* pleaseGetQueryRing();
 std::vector<std::pair<std::string, uint16_t> >* pleaseGetServfailQueryRing();
+std::vector<ComboAddress>* pleaseGetRemotes();
+std::vector<ComboAddress>* pleaseGetServfailRemotes();
+std::vector<ComboAddress>* pleaseGetLargeAnswerRemotes();
+std::string getRegisteredName(const std::string& dom);
 #endif 
index 0c5600e6d8cf017e6109a1a6610f626876bdb712..03a4a9823193dd14ea8a4d48d50b3b78bf5ebd12 100644 (file)
@@ -712,7 +712,7 @@ void sortPublicSuffixList()
 }
 
 
-static string getRegisteredName(const std::string& dom)
+string getRegisteredName(const std::string& dom)
 {
   vector<string> parts;
   stringtok(parts, dom, ".");
@@ -909,7 +909,6 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP
   if(cmd=="top-pub-queries")
     return doGenericTopQueries(pleaseGetQueryRing, getRegisteredName);
 
-
   if(cmd=="top-servfail-queries")
     return doGenericTopQueries(pleaseGetServfailQueryRing);
 
index 7628fb61b87015374c89ae6f7ec1f8bf4c35ebd7..faae37af0a4a3db0fca4610d05bdb2f19b1d8d8b 100644 (file)
@@ -21,7 +21,6 @@
 #include <boost/foreach.hpp>
 #include <boost/tokenizer.hpp>
 #include <boost/circular_buffer.hpp>
-#include "version_generated.h"
 #include "namespaces.hh"
 #include "ws-api.hh"
 #include "json.hh"
@@ -87,7 +86,8 @@ static void fillServerDetail(Value& out, Value::AllocatorType& allocator)
   out.AddMember("id", "localhost", allocator);
   out.AddMember("url", "/servers/localhost", allocator);
   out.AddMember("daemon_type", jdaemonType, allocator);
-  out.AddMember("version", PDNS_VERSION, allocator);
+  Value jversion(getPDNSVersion().c_str(), allocator);
+  out.AddMember("version", jversion, allocator);
   out.AddMember("config_url", "/servers/localhost/config{/config_setting}", allocator);
   out.AddMember("zones_url", "/servers/localhost/zones{/zone}", allocator);
 }
index ff45004dc5af05bd19d1fe1614884d197f9fd691..51bf165f48f305c90a400dc30436632a66838319 100644 (file)
@@ -535,6 +535,8 @@ void RecursorWebServer::jsonstat(HttpRequest* req, HttpResponse *resp)
   else if(command == "get-query-ring") {
     typedef pair<string,uint16_t> query_t;
     vector<query_t> queries;
+    bool filter=!req->getvars["public-filtered"].empty();
+      
     if(req->getvars["name"]=="servfail-queries")
       queries=broadcastAccFunction<vector<query_t> >(pleaseGetServfailQueryRing);
     else if(req->getvars["name"]=="queries")
@@ -545,7 +547,10 @@ void RecursorWebServer::jsonstat(HttpRequest* req, HttpResponse *resp)
     unsigned int total=0;
     BOOST_FOREACH(const query_t& q, queries) {
       total++;
-      counts[make_pair(toLower(q.first), q.second)]++;
+      if(filter)
+       counts[make_pair(getRegisteredName(toLower(q.first)), q.second)]++;
+      else 
+       counts[make_pair(toLower(q.first), q.second)]++;
     }
     
     typedef std::multimap<int, query_t> rcounts_t;
@@ -554,16 +559,16 @@ void RecursorWebServer::jsonstat(HttpRequest* req, HttpResponse *resp)
     for(counts_t::const_iterator i=counts.begin(); i != counts.end(); ++i)
       rcounts.insert(make_pair(-i->second, i->first));
 
-    
     Document doc;
     doc.SetObject();
     Value entries;
     entries.SetArray();
-    int tot=0;
+    unsigned int tot=0, totIncluded=0;
     BOOST_FOREACH(const rcounts_t::value_type& q, rcounts) {
       Value arr;
       
       arr.SetArray();
+      totIncluded-=q.first;
       arr.PushBack(-q.first, doc.GetAllocator());
       arr.PushBack(q.second.first.c_str(), doc.GetAllocator());
       arr.PushBack(DNSRecordContent::NumberToType(q.second.second).c_str(), doc.GetAllocator());
@@ -571,6 +576,67 @@ void RecursorWebServer::jsonstat(HttpRequest* req, HttpResponse *resp)
       if(tot++>=100)
        break;
     }
+    if(queries.size() != totIncluded) {
+      Value arr;
+      arr.SetArray();
+      arr.PushBack(queries.size()-totIncluded, doc.GetAllocator());
+      arr.PushBack("", doc.GetAllocator());
+      arr.PushBack("", doc.GetAllocator());
+      entries.PushBack(arr, doc.GetAllocator());
+    }
+    doc.AddMember("entries", entries, doc.GetAllocator());  
+    resp->setBody(doc);
+    return;
+  }
+  else if(command == "get-remote-ring") {
+    vector<ComboAddress> queries;
+    if(req->getvars["name"]=="remotes")
+      queries=broadcastAccFunction<vector<ComboAddress> >(pleaseGetRemotes);
+    else if(req->getvars["name"]=="servfail-remotes")
+      queries=broadcastAccFunction<vector<ComboAddress> >(pleaseGetServfailRemotes);
+    else if(req->getvars["name"]=="large-answer-remotes")
+      queries=broadcastAccFunction<vector<ComboAddress> >(pleaseGetLargeAnswerRemotes);
+    
+    typedef map<ComboAddress,unsigned int,ComboAddress::addressOnlyLessThan> counts_t;
+    counts_t counts;
+    unsigned int total=0;
+    BOOST_FOREACH(const ComboAddress& q, queries) {
+      total++;
+      counts[q]++;
+    }
+    
+    typedef std::multimap<int, ComboAddress> rcounts_t;
+    rcounts_t rcounts;
+  
+    for(counts_t::const_iterator i=counts.begin(); i != counts.end(); ++i)
+      rcounts.insert(make_pair(-i->second, i->first));
+
+    
+    Document doc;
+    doc.SetObject();
+    Value entries;
+    entries.SetArray();
+    unsigned int tot=0, totIncluded=0;
+    BOOST_FOREACH(const rcounts_t::value_type& q, rcounts) {
+      totIncluded-=q.first;
+      Value arr;
+      
+      arr.SetArray();
+      arr.PushBack(-q.first, doc.GetAllocator());
+      Value jname(q.second.toString().c_str(), doc.GetAllocator()); // copy 
+      arr.PushBack(jname, doc.GetAllocator());
+      entries.PushBack(arr, doc.GetAllocator());
+      if(tot++>=100)
+       break;
+    }
+    if(queries.size() != totIncluded) {
+      Value arr;
+      arr.SetArray();
+      arr.PushBack(queries.size()-totIncluded, doc.GetAllocator());
+      arr.PushBack("", doc.GetAllocator());
+      entries.PushBack(arr, doc.GetAllocator());
+    }
+
     doc.AddMember("entries", entries, doc.GetAllocator());  
     resp->setBody(doc);
     return;