]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Add simple 'ping' endpoint for healthchecks
authorOlliver Schinagl <oliver@schinagl.nl>
Sat, 10 Jun 2023 15:16:06 +0000 (17:16 +0200)
committerFlole998 <Flole998@users.noreply.github.com>
Sun, 11 Jun 2023 18:19:44 +0000 (20:19 +0200)
To determine if the server is online, we want to be able to 'ping' it
with as little configuration and access possibilities as possible. The
only available option for this today, is anonymous access.

Let us thus add a new endpoint, that replies with 'PONG' when queried.

This will need anonymous access enabled, but can be restricted to:
a) localhost
b) without any access permissions

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
src/webui/simpleui.c

index 3443029cfe7fb6782757b8ea8d98f4e248b7c49a..16b808f7523427291fbbdefa1e2960ee675b0cd7 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include "tvheadend.h"
+#include "htsbuf.h"
 #include "http.h"
 #include "webui.h"
 #include "access.h"
@@ -398,6 +399,19 @@ page_einfo(http_connection_t *hc, const char *remain, void *opaque)
   return 0;
 }
 
+/**
+ * Simple ping 'page', for healthcheck purposes
+ */
+static int page_ping(http_connection_t *hc, const char *remain, void *opaque)
+{
+  htsbuf_queue_t *hq = &hc->hc_reply;
+
+  htsbuf_qprintf(hq, "PONG\n");
+  http_output_content(hc, "text/plain");
+
+  return 0;
+}
+
 /**
  * PVR info, deliver info about the given PVR entry
  */
@@ -620,6 +634,7 @@ simpleui_start(void)
 {
   http_path_add("/simple.html", NULL, page_simple,  ACCESS_SIMPLE);
   http_path_add("/eventinfo",   NULL, page_einfo,   ACCESS_SIMPLE);
+  http_path_add("/ping",        NULL, page_ping,  ACCESS_ANONYMOUS);
   http_path_add("/pvrinfo",     NULL, page_pvrinfo, ACCESS_SIMPLE);
   http_path_add("/status.xml",  NULL, page_status,  ACCESS_SIMPLE);
   http_path_add("/epgsave",    NULL, page_epgsave,     ACCESS_SIMPLE);