Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Email Notification haproxy

    Scheduled Pinned Locked Moved pfSense Packages
    10 Posts 2 Posters 3.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kiekar
      last edited by

      Hello,

      I have currently haproxy-devel v 0.59_14 and pfSense 2.4.4. Occasionally i have a backend for a website showing status down. Is it possible to get an email notification to an email address when the backend status goes down? In the settings page for haproxy I added the information in the Global Email Notification section but i never got notified when i deliberately set the backend status to down. Do i need to select a specific dropdown choice the mail level? Any help would be much appreciated.

      Thanks,

      Karl

      P 2 Replies Last reply Reply Quote 0
      • P
        PiBa @kiekar
        last edited by

        @kiekar
        You do have a mailserver configured for haproxy to use that accepts incoming mails without authentication nor encryption? As haproxy just tries to send few plain text smtp commands when for example a health-check fails..

        K 1 Reply Last reply Reply Quote 0
        • P
          PiBa @kiekar
          last edited by

          @kiekar
          p.s. you might want to checkout some of these lua scripts i made, they produce less 'bulk mail' when something happens than haproxy's own mail notification method.. https://github.com/PiBa-NL/MyPublicProjects/tree/master/haproxy/lua-scripts
          Though still should get a bit of tweaking to become truly 'beautiful' ;)..

          1 Reply Last reply Reply Quote 0
          • K
            kiekar @PiBa
            last edited by

            @piba

            Thanks for your reply. I do have a mail server and I do currently have it setup with pfsense through Sysytem>Advanced>Notification which works. As for the setup in haproxy, i'm not sure if this is correct.

            0_1542457501892_haproxy_mail.jpg

            P 1 Reply Last reply Reply Quote 0
            • P
              PiBa @kiekar
              last edited by

              @kiekar
              It looks like it 'should' work like that.. (Though the 'Mail myhostname' could probably be something like pfsense.yourdomain.com)

              Perhaps you can perform a packetcapture from between haproxy and the mailserver and watch if it tries to connect and mail something on startup? The smtp traffic is 'readable' if you capture the content, it should be possible to see why it isn't working.. I presume the backends dont have the level set to 'don't mail' setting?

              Can you check haproxy.cfg contains a reference to the 'globalmailer' in each backend?

              K 1 Reply Last reply Reply Quote 0
              • K
                kiekar @PiBa
                last edited by

                @piba

                Will the lua script work if the backend goes down? If so what files do i need in order for the email notification to work as I saw files and folders at the link you provided.

                0_1543620494876_backend.jpg

                P 1 Reply Last reply Reply Quote 0
                • P
                  PiBa @kiekar
                  last edited by

                  @kiekar
                  You would need 3 scripts:

                  /smtpmailqueue/smtpmailqueue.lua
                  /serverhealthchecker/serverhealthchecker.lua
                  /serverhealth_smtpmail.lua
                  

                  And edit the 3rd to use proper mailserver and email address for at least the destination. Just putting their content into the haproxy files tab and mark them as type lua, it should work and send a mail if the backend go's down or comes back up. Also after startup it always sends 1 mail.

                  K 1 Reply Last reply Reply Quote 0
                  • K
                    kiekar @PiBa
                    last edited by

                    @piba

                    Thanks for you help up to now, much appreciated.

                    I added 3 separate entries to haproxy based on the 3 files you indicated. When saving the entries i received an Error shown below.

                    Does the passed variable "lumamailer" in Smtpmailqueue("lumamailer",5) need to replaced by mailer servers table name "mailer1" from the Global email notifications in settings tab I had setup?

                    haproxy: startup error output!: [ALERT] 335/102935 (32469) : parsing [/var/etc/haproxy/haproxy.cfg:16] : lua runtime error: /var/etc/haproxy/luascript_serverhealth_smtpmail:6: attempt to call a nil value (global 'Smtpmailqueue')[ALERT] 335/102935 (32469) : Error(s) found in configuration file : /var/etc/haproxy/haproxy.cfg[ALERT] 335/102935 (32469) : Fatal errors found in configuration. 
                    
                    P 1 Reply Last reply Reply Quote 0
                    • P
                      PiBa @kiekar
                      last edited by

                      @kiekar
                      I think the order is important, can you move the serverhealth_smtpmail.lua as the last script.?

                      K 1 Reply Last reply Reply Quote 0
                      • K
                        kiekar @PiBa
                        last edited by

                        @piba

                        "I think the order is important, can you move the serverhealth_smtpmail.lua as the last script"

                        That did the trick.

                        Tested by deliberately shutting down the site, all worked perfectly.

                        Thanks again!!

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.