]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hlua/event_hdl: expose SERVER_CHECK event
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 30 Mar 2023 13:53:33 +0000 (15:53 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 5 May 2023 14:28:32 +0000 (16:28 +0200)
Exposing SERVER_CHECK event through the lua API.

New lua class named ServerEventCheck was added to provide additional
data for SERVER_CHECK event.

Lua documentation was updated accordingly.

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

index 8a82a1685580031626b1ac3a2535d4b38a6098dd..d790c6b6d990357c83907f027c89041b4788cd77 100644 (file)
@@ -948,6 +948,9 @@ Core class
     * **SERVER_UP**: when a server state goes from DOWN to UP
     * **SERVER_STATE**: when a server state changes
     * **SERVER_ADMIN**: when a server administrative state changes
+    * **SERVER_CHECK**: when a server's check status change is reported.
+      Be careful when subscribing to this type since many events might be
+      generated.
 
    .. Note::
      Use **SERVER** in **event_types** to subscribe to all server events types
@@ -1541,6 +1544,13 @@ See :js:func:`core.event_sub()` for more info.
   .. Note::
      Only available for SERVER_ADMIN event
 
+.. js:attribute:: ServerEvent.check
+
+  A :ref:`server_event_checkres_class`
+
+  .. Note::
+     Only available for SERVER_CHECK event
+
 .. _server_event_checkres_class:
 
 ServerEventCheckRes class
index e3d6efd22057b67f5610abcc713fd95588ddafb4..f8dc9bb023a80187ec550c97ce41a039f8adbfa7 100644 (file)
@@ -9259,6 +9259,21 @@ __LJMP static void hlua_event_hdl_cb_push_args(struct hlua_event_sub *hlua_sub,
 
                        lua_settable(hlua->T, -3); /* admin table */
                }
+               else if (event_hdl_sub_type_equal(EVENT_HDL_SUB_SERVER_CHECK, event)) {
+                       struct event_hdl_cb_data_server_check *check = data;
+
+                       if (!lua_checkstack(hlua->T, 20))
+                               WILL_LJMP(luaL_error(hlua->T, "Lua out of memory error."));
+
+                       /* check subclass */
+                       lua_pushstring(hlua->T, "check");
+                       lua_newtable(hlua->T);
+
+                       /* check result snapshot */
+                       hlua_event_hdl_cb_push_event_checkres(hlua->T, &check->safe.res);
+
+                       lua_settable(hlua->T, -3); /* check table */
+               }
 
                /* attempt to provide reference server object
                 * (if it wasn't removed yet, SERVER_DEL will never succeed here)