mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-20 13:21:29 +02:00
Now that native mailers configuration is only usable with Lua mailers, Willy noticed that we lack a way to warn the user if mailers were previously configured on an older version but Lua mailers were not loaded, which could trick the user into thinking mailers keep working when transitionning to 3.2 while it is not. In this patch we add the 'core.use_native_mailers_config()' Lua function which should be called in Lua script body before making use of 'Proxy:get_mailers()' function to retrieve legacy mailers configuration from haproxy main config. This way haproxy effectively knows that the native mailers config is actually being used from Lua (which indicates user correctly migrated from native mailers to Lua mailers), else if mailers are configured but not used from Lua then haproxy warns the user about the fact that they will be ignored unless they are used from Lua. (e.g.: using the provided 'examples/lua/mailers.lua' to ease transition)
68 lines
1.8 KiB
C
68 lines
1.8 KiB
C
/*
|
|
* Mailer management.
|
|
*
|
|
* Copyright 2015 Horms Solutions Ltd, Simon Horman <horms@verge.net.au>
|
|
* Copyright 2020 Willy Tarreau <w@1wt.eu>
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version
|
|
* 2 of the License, or (at your option) any later version.
|
|
*
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <haproxy/action-t.h>
|
|
#include <haproxy/api.h>
|
|
#include <haproxy/errors.h>
|
|
#include <haproxy/mailers.h>
|
|
#include <haproxy/proxy.h>
|
|
#include <haproxy/server-t.h>
|
|
#include <haproxy/task.h>
|
|
#include <haproxy/time.h>
|
|
#include <haproxy/tools.h>
|
|
|
|
int mailers_used_from_lua = 0;
|
|
|
|
struct mailers *mailers = NULL;
|
|
|
|
/* Initializes mailer alerts for the proxy <p> using <mls> parameters.
|
|
*
|
|
* The function returns 1 in success case, otherwise, it returns 0 and err is
|
|
* filled.
|
|
*/
|
|
int init_email_alert(struct mailers *mls, struct proxy *p, char **err)
|
|
{
|
|
mls->users++;
|
|
free(p->email_alert.mailers.name);
|
|
p->email_alert.mailers.m = mls;
|
|
p->email_alert.flags |= PR_EMAIL_ALERT_RESOLVED;
|
|
return 0;
|
|
}
|
|
|
|
void free_email_alert(struct proxy *p)
|
|
{
|
|
if (!(p->email_alert.flags & PR_EMAIL_ALERT_RESOLVED))
|
|
ha_free(&p->email_alert.mailers.name);
|
|
ha_free(&p->email_alert.from);
|
|
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);
|