From 46e8b49e13dcfe86dc6cecbf5dbae24dce9e225a Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 4 Aug 2016 16:14:27 +0200 Subject: [PATCH] dnsdist: Add response rules to the API and Web status page --- pdns/dnsdist-web.cc | 13 +++++++++++++ pdns/dnsdistdist/html/index.html | 3 +++ pdns/dnsdistdist/html/local.js | 12 ++++++++++++ regression-tests.dnsdist/test_API.py | 8 +++++++- 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/pdns/dnsdist-web.cc b/pdns/dnsdist-web.cc index e5a6e9939..b0ba8aa7f 100644 --- a/pdns/dnsdist-web.cc +++ b/pdns/dnsdist-web.cc @@ -275,6 +275,18 @@ static void connectionThread(int sock, ComboAddress remote, string password, str rules.push_back(rule); } + Json::array responseRules; + auto localResponseRules = g_resprulactions.getCopy(); + num=0; + for(const auto& a : localResponseRules) { + Json::object rule{ + {"id", num++}, + {"matches", (int)a.first->d_matches}, + {"rule", a.first->toString()}, + {"action", a.second->toString()}, + }; + responseRules.push_back(rule); + } string acl; @@ -298,6 +310,7 @@ static void connectionThread(int sock, ComboAddress remote, string password, str { "servers", servers}, { "frontends", frontends }, { "rules", rules}, + { "response-rules", responseRules}, { "acl", acl}, { "local", localaddresses} }; diff --git a/pdns/dnsdistdist/html/index.html b/pdns/dnsdistdist/html/index.html index 1417c212a..0897a7c6b 100644 --- a/pdns/dnsdistdist/html/index.html +++ b/pdns/dnsdistdist/html/index.html @@ -83,6 +83,9 @@
+ +
+
diff --git a/pdns/dnsdistdist/html/local.js b/pdns/dnsdistdist/html/local.js index 4b20cd074..dd6bd844d 100644 --- a/pdns/dnsdistdist/html/local.js +++ b/pdns/dnsdistdist/html/local.js @@ -211,6 +211,18 @@ $(document).ready(function() { bouw = bouw + 'No rules defined'; bouw = bouw + ""; $("#rules").html(bouw); + + bouw=''; + if(data["response-rules"].length) { + $.each(data["response-rules"], function(a,b) { + bouw = bouw + (""); + bouw = bouw + (""); + }); + } + else + bouw = bouw + ''; + bouw = bouw + "
#Response RuleActionMatches
"+b["id"]+""+b["rule"]+""+b["action"]+""+b["matches"]+"
No response rules defined
"; + $("#response-rules").html(bouw); } }); diff --git a/regression-tests.dnsdist/test_API.py b/regression-tests.dnsdist/test_API.py index 58163a604..a0e628faf 100644 --- a/regression-tests.dnsdist/test_API.py +++ b/regression-tests.dnsdist/test_API.py @@ -64,7 +64,7 @@ class TestBasics(DNSDistTest): self.assertEquals(content['daemon_type'], 'dnsdist') - for key in ['version', 'acl', 'local', 'rules', 'servers', 'frontends']: + for key in ['version', 'acl', 'local', 'rules', 'response-rules', 'servers', 'frontends']: self.assertIn(key, content) for rule in content['rules']: @@ -73,6 +73,12 @@ class TestBasics(DNSDistTest): for key in ['id', 'matches']: self.assertTrue(rule[key] >= 0) + for rule in content['response-rules']: + for key in ['id', 'matches', 'rule', 'action']: + self.assertIn(key, rule) + for key in ['id', 'matches']: + self.assertTrue(rule[key] >= 0) + for server in content['servers']: for key in ['id', 'latency', 'name', 'weight', 'outstanding', 'qpsLimit', 'reuseds', 'state', 'address', 'pools', 'qps', 'queries', 'order']: -- 2.40.0