Coverage Report

Created: 2026-06-09 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/haproxy/src/mailers.c
Line
Count
Source
1
/*
2
 * Mailer management.
3
 *
4
 * Copyright 2015 Horms Solutions Ltd, Simon Horman <horms@verge.net.au>
5
 * Copyright 2020 Willy Tarreau <w@1wt.eu>
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version
10
 * 2 of the License, or (at your option) any later version.
11
 *
12
 */
13
14
#include <stdlib.h>
15
16
#include <haproxy/action-t.h>
17
#include <haproxy/api.h>
18
#include <haproxy/errors.h>
19
#include <haproxy/mailers.h>
20
#include <haproxy/proxy.h>
21
#include <haproxy/server-t.h>
22
#include <haproxy/task.h>
23
#include <haproxy/time.h>
24
#include <haproxy/tools.h>
25
26
int mailers_used_from_lua = 0;
27
28
struct mailers *mailers = NULL;
29
30
/* Initializes mailer alerts for the proxy <p> using <mls> parameters.
31
 *
32
 * The function returns 1 in success case, otherwise, it returns 0 and err is
33
 * filled.
34
 */
35
int init_email_alert(struct mailers *mls, struct proxy *p, char **err)
36
0
{
37
0
  mls->users++;
38
0
  free(p->email_alert.mailers.name);
39
0
  p->email_alert.mailers.m = mls;
40
0
  p->email_alert.flags |= PR_EMAIL_ALERT_RESOLVED;
41
0
  return 0;
42
0
}
43
44
void free_email_alert(struct proxy *p)
45
0
{
46
0
  if (!(p->email_alert.flags & PR_EMAIL_ALERT_RESOLVED))
47
0
    ha_free(&p->email_alert.mailers.name);
48
0
  ha_free(&p->email_alert.from);
49
0
  ha_free(&p->email_alert.to);
50
0
  ha_free(&p->email_alert.myhostname);
51
0
}
52
53
static int mailers_post_check(void)
54
0
{
55
0
  struct mailers *cur;
56
57
0
  for (cur = mailers; cur != NULL; cur = cur->next) {
58
0
    if (cur->users && !mailers_used_from_lua) {
59
0
      ha_warning("mailers '%s' is referenced on at least one proxy but Lua "
60
0
                 "mailers are not configured so the setting will be ignored. "
61
0
                 "Use 'examples/lua/mailers.lua' file for basic mailers support.\n", cur->id);
62
0
      return ERR_WARN;
63
0
    }
64
0
  }
65
0
  return ERR_NONE;
66
0
}
67
REGISTER_POST_CHECK(mailers_post_check);