From 9316c216314b55da3a90bbe58340b6aabcf87f52 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Thu, 27 Apr 2023 08:24:40 -0700 Subject: [PATCH] add a /health health-check endpoint only shows online and version information --- service/OneService.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/service/OneService.cpp b/service/OneService.cpp index 67a39defc..ad7a38090 100644 --- a/service/OneService.cpp +++ b/service/OneService.cpp @@ -1444,7 +1444,7 @@ public: // Internal HTTP Control Plane void startHTTPControlPlane() { - std::vector noAuthEndpoints { "/sso" }; + std::vector noAuthEndpoints { "/sso", "/health" }; auto authCheck = [=] (const httplib::Request &req, httplib::Response &res) { std::string r = req.remote_addr + "/32"; @@ -1590,6 +1590,26 @@ public: _controlPlane.Post("/config/settings", configPost); _controlPlane.Put("/config/settings", configPost); + _controlPlane.Get("/health", [this](const httplib::Request &req, httplib::Response &res) { + json out = json::object(); + + char tmp[256]; + + ZT_NodeStatus status; + _node->status(&status); + + out["online"] = (bool)(status.online != 0); + out["versionMajor"] = ZEROTIER_ONE_VERSION_MAJOR; + out["versionMinor"] = ZEROTIER_ONE_VERSION_MINOR; + out["versionRev"] = ZEROTIER_ONE_VERSION_REVISION; + out["versionBuild"] = ZEROTIER_ONE_VERSION_BUILD; + OSUtils::ztsnprintf(tmp,sizeof(tmp),"%d.%d.%d",ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION); + out["version"] = tmp; + out["clock"] = OSUtils::now(); + + res.set_content(out.dump(), "application/json"); + }); + _controlPlane.Get("/moon", [this](const httplib::Request &req, httplib::Response &res) { std::vector moons(_node->moons());