perform the heavy job in a dedicated task and allow remaining events to be
processed more quickly.
+.. js:function:: core.use_native_mailers_config()
+
+ **context**: body
+
+ Inform haproxy that the script will make use of the native "mailers"
+ config section (although legacy). In other words, inform haproxy that
+ :js:func:`Proxy.get_mailers()` will be used later in the program.
+
.. _proxy_class:
Proxy class
**LEGACY**
- Returns a table containing mailers config for the current proxy or nil
- if mailers are not available for the proxy.
+ Returns a table containing legacy mailers config (from haproxy configuration
+ file) for the current proxy or nil if mailers are not available for the proxy.
+
+ .. warning::
+ When relying on :js:func:`Proxy.get_mailers()` to retrieve mailers
+ configuration, :js:func:`core.use_native_mailers_config()` must be called
+ first from body or init context to inform haproxy that Lua makes use of the
+ legacy mailers config.
:param class_proxy px: A :ref:`proxy_class` which indicates the manipulated
proxy.
mailers_track_server_events(data.reference)
end
+-- tell haproxy that we do use the legacy native "mailers" config section
+-- which allows us to retrieve mailers configuration using Proxy:get_mailers()
+core.use_native_mailers_config()
+
-- event subscriptions are purposely performed in an init function to prevent
-- email alerts from being generated too early (when process is starting up)
core.register_init(function()
#include <haproxy/proxy-t.h>
#include <haproxy/server-t.h>
+extern int mailers_used_from_lua;
extern struct mailers *mailers;
int init_email_alert(struct mailers *mailers, struct proxy *p, char **err);
/* set to 1 once some lua was loaded already */
static uint8_t hlua_loaded = 0;
+/* set to 1 during body evaluation (very early lua file loading), then 0 */
+static uint8_t hlua_body = 1;
#define HLUA_BOOL_SAMPLE_CONVERSION_UNK 0x0
#define HLUA_BOOL_SAMPLE_CONVERSION_NORMAL 0x1
return MAY_LJMP(hlua_smp2lua(L, &smp));
}
+/* This function informs haproxy that native mailers config section is
+ * actually being used from Lua.
+ *
+ * It may not be used outside of body context.
+ */
+__LJMP static int hlua_use_native_mailers_config(lua_State *L)
+{
+ if (!hlua_body)
+ WILL_LJMP(luaL_error(L, "use_native_mailers_config: "
+ "not available outside of body context"));
+ mailers_used_from_lua = 1;
+ return 0;
+}
+
/* A class is a lot of memory that contain data. This data can be a table,
* an integer or user data. This data is associated with a metatable. This
* metatable have an original version registered in the global context with
struct hlua_function *fcn;
struct hlua_reg_filter *reg_flt;
+ hlua_body = 0;
+
#if defined(USE_OPENSSL)
/* Initialize SSL server. */
if (socket_ssl->xprt->prepare_srv) {
hlua_class_function(L, "Warning", hlua_log_warning);
hlua_class_function(L, "Alert", hlua_log_alert);
hlua_class_function(L, "done", hlua_done);
+ hlua_class_function(L, "use_native_mailers_config", hlua_use_native_mailers_config);
hlua_fcn_reg_core_fcn(L);
lua_setglobal(L, "core");
#include <haproxy/time.h>
#include <haproxy/tools.h>
+int mailers_used_from_lua = 0;
struct mailers *mailers = NULL;
ha_free(&p->email_alert.to);
ha_free(&p->email_alert.myhostname);
}
+
+static int mailers_post_check(void)
+{
+ struct mailers *cur;
+
+ for (cur = mailers; cur != NULL; cur = cur->next) {
+ if (cur->users && !mailers_used_from_lua) {
+ ha_warning("mailers '%s' is referenced on at least one proxy but Lua "
+ "mailers are not configured so the setting will be ignored. "
+ "Use 'examples/lua/mailers.lua' file for basic mailers support.\n", cur->id);
+ return ERR_WARN;
+ }
+ }
+ return ERR_NONE;
+}
+REGISTER_POST_CHECK(mailers_post_check);