]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hlua_fcn: add Server.tracking()
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 29 Mar 2023 09:30:36 +0000 (11:30 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 5 May 2023 14:28:32 +0000 (16:28 +0200)
This function returns the currently tracked server, if any.

doc/lua-api/index.rst
src/hlua_fcn.c

index 5c05871aa1077dc327b36a2b518b8c2db80bd7e9..4055ac24d4917fcd5451d878cbd59cffb5229bd8 100644 (file)
@@ -1337,6 +1337,15 @@ Server class
   :param class_server sv: A :ref:`server_class` which indicates the manipulated
    server.
 
+.. js:function:: Server.tracking(sv)
+
+  Check if the current server is tracking another server.
+
+  :param class_server sv: A :ref:`server_class` which indicates the manipulated
+   server.
+  :returns: A :ref:`server_class` which indicates the tracked server or nil if
+   the server doesn't track another one.
+
 .. js:function:: Server.event_sub(sv, event_types, func)
 
   Register a function that will be called on specific server events.
index 61eb580f35402b43738a6976cdfe77702d3ddbfd..931b6097062de13af9ac02dd56d529eb12cbcc1a 100644 (file)
@@ -1410,6 +1410,26 @@ int hlua_server_agent_force_down(lua_State *L)
        return 0;
 }
 
+/* returns the tracked server, if any */
+int hlua_server_tracking(lua_State *L)
+{
+       struct server *sv;
+       struct server *tracked;
+
+       sv = hlua_check_server(L, 1);
+       if (sv == NULL) {
+               return 0;
+       }
+
+       tracked = sv->track;
+       if (tracked == NULL)
+               lua_pushnil(L);
+       else
+               hlua_fcn_new_server(L, tracked);
+
+       return 1;
+}
+
 /* hlua_event_sub wrapper for per-server subscription:
  *
  * hlua_event_sub() is called with sv->e_subs subscription list and
@@ -1472,6 +1492,7 @@ int hlua_fcn_new_server(lua_State *L, struct server *srv)
        hlua_class_function(L, "agent_disable", hlua_server_agent_disable);
        hlua_class_function(L, "agent_force_up", hlua_server_agent_force_up);
        hlua_class_function(L, "agent_force_down", hlua_server_agent_force_down);
+       hlua_class_function(L, "tracking", hlua_server_tracking);
        hlua_class_function(L, "event_sub", hlua_server_event_sub);
 
        return 1;