ixfr.cc ixfr.hh \
ixfrdist.cc \
ixfrutils.cc ixfrutils.hh \
+ ixfrdist-stats.hh \
+ ixfrdist-web.hh ixfrdist-web.cc \
logger.cc logger.hh\
misc.cc misc.hh \
mplexer.hh \
statbag.cc \
threadname.hh threadname.cc \
tsigverifier.cc tsigverifier.hh \
- unix_utility.cc zoneparser-tng.cc
+ unix_utility.cc \
+ webserver.hh webserver.cc \
+ zoneparser-tng.cc
+
ixfrdist_LDADD = \
$(BOOST_PROGRAM_OPTIONS_LIBS) \
+ $(JSON11_LIBS) \
$(LIBCRYPTO_LIBS) \
+ $(YAHTTP_LIBS) \
$(YAML_LIBS)
ixfrdist_LDFLAGS = \
--- /dev/null
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#include "ixfrdist-web.hh"
+#include <thread>
+#include "threadname.hh"
+#include "ixfrdist-stats.hh"
+
+string doGetStats();
+
+IXFRDistWebServer::IXFRDistWebServer(const ComboAddress &listenAddress) {
+ // TODO wrap in smart pointer
+ d_ws = new WebServer(listenAddress.toString() , listenAddress.getPort());
+ d_ws->bind();
+}
+
+void IXFRDistWebServer::go() {
+ // std::thread wt(IXFRDistWebServer::webThread);
+ d_ws->registerWebHandler("/metrics", boost::bind(&IXFRDistWebServer::getMetrics, this, _1, _2));
+ d_ws->go();
+ // wt.detach();
+}
+
+void IXFRDistWebServer::webThread() {
+ setThreadName("ixfrdist/web");
+}
+
+void IXFRDistWebServer::getMetrics(HttpRequest* req, HttpResponse* resp) {
+ if(req->method != "GET")
+ throw HttpMethodNotAllowedException();
+
+ resp->body = doGetStats();
+ resp->status = 200;
+}
--- /dev/null
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#pragma once
+#include "webserver.hh"
+#include "iputils.hh"
+//#include "ixfrdist-stats.hh"
+
+class IXFRDistWebServer
+{
+ public:
+ explicit IXFRDistWebServer(const ComboAddress &listenAddress);
+ void go();
+
+ private:
+ WebServer *d_ws;
+ void webThread();
+
+ // All endpoints
+ void getMetrics(HttpRequest* req, HttpResponse* resp);
+};
#include "iputils.hh"
#include "logger.hh"
#include "ixfrdist-stats.hh"
+#include "ixfrdist-web.hh"
#include <yaml-cpp/yaml.h>
/* BEGIN Needed because of deeper dependencies */
static ixfrdistStats g_stats;
+// g_stats is static, so local to this file. But the webserver needs this info
+string doGetStats() {
+ return g_stats.getStats();
+}
+
static void handleSignal(int signum) {
g_log<<Logger::Notice<<"Got "<<strsignal(signum)<<" signal";
if (g_exiting) {
config["compress"] = false;
}
+ if (config["webserver-address"]) {
+ try {
+ config["webserver-address"].as<ComboAddress>();
+ }
+ catch (const runtime_error &e) {
+ g_log<<Logger::Error<<"Unable to read 'webserver-address' value: "<<e.what()<<endl;
+ retval = false;
+ }
+ }
+
return retval;
}
}
}
+ if (config["webserver-address"]) {
+ auto ws = IXFRDistWebServer(config["webserver-address"].as<ComboAddress>());
+ ws.go();
+ }
+
int newuid = 0;
if (config["uid"]) {
#
# gid: ixfrdist
+# The IP address and port where the webserver should listen
+#
+webserver-address: 127.0.0.1:8080
+
# The domains to redistribute, the 'master' and 'domains' keys are mandatory.
# When no port is specified, 53 is used. When specifying ports for IPv6, use the
# "bracket" notation: