haproxyhigh-availabilityrhel7rsyslog

HAPROXY: Display log messages from external check script to rsyslog


I would like to print some log messages from the external check script of HAPROXY to rsyslog. For now, I use “echo” in my external-check.sh script but it does not show up the echo messages. It only shows the haproxy log messages. Is that possible?

The content of haproxy.cfg:

global
    log 127.0.0.1 local0
    external-check
    insecure-fork-wanted

defaults
    mode                    http
    log                     global
    option                  httplog
    timeout queue           1m
    timeout connect         10m
    timeout client          1m
    timeout server          10m
    timeout http-keep-alive 10s
    timeout check           10m
    timeout tunnel          10m
    maxconn                 2048

frontend pa
    bind *:443
    use_backend back-servers

backend back-servers
    option external-check
    option log-health-checks
    external-check command /etc/haproxy/external-check.sh
    server PA-A xxx check inter 30s fall 6 rise 1 ssl verify none
    server PA-B xxx backup check inter 30s fall 6 rise 1 ssl verify none

the content of /etc/rsyslog.d/haproxy.conf

$ModLoad imudp
$UDPServerRun 514 
$template Haproxy,"%msg%\n"
local0.* -/var/log/haproxy.log

example of log output:

 Health check for server back-servers/PA-A failed, reason: External check timeout, code: 1, check duration: 30009ms, status: 0/1 DOWN.
 Health check for server back-servers/PA-A failed, reason: External check error, code: 1, check duration: 738ms, status: 0/1 DOWN.
 Health check for backup server back-servers/PA-B failed, reason: External check timeout, code: 1, check duration: 30022ms, status: 0/1 DOWN.
 Health check for backup server back-servers/PA-B failed, reason: External check error, code: 1, check duration: 1590ms, status: 0/1 DOWN

As you can see there are no printed messages of my "echo"(s) that I have added to the external check script


Solution

  • I got the answer:

    Currently, I am using echo but I should use logger to log messages from the external script to the rsyslog socket via 127.0.0.1. By default, HAPROXY does not do it for us. It only redirects the log messages of the haproxy.cfg events, but not the external script messages. The trick is to replace all echo messages by:

    logger -p local0.info -t external-script -n 127.0.0.1 "My message"