diff --git a/net/haproxy/pkg-descr b/net/haproxy/pkg-descr index 3c0d71c5f..dab4836e5 100644 --- a/net/haproxy/pkg-descr +++ b/net/haproxy/pkg-descr @@ -17,6 +17,7 @@ Added: * add config diff * guard against broken config by using a staging config file * add basic OCSP stapling support (#1430) +* add support for e-mail alerts and mailers (#1669) Fixed: * fix maintenance page (python error: 'list' object has no attribute 'strip') diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/SettingsController.php b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/SettingsController.php index ef5f8f65d..0cd365dc4 100644 --- a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/SettingsController.php +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/Api/SettingsController.php @@ -409,4 +409,34 @@ class SettingsController extends ApiMutableModelControllerBase { return $this->searchBase('resolvers.resolver', array('enabled', 'name', 'nameservers'), 'name'); } + + public function getmailerAction($uuid = null) + { + return $this->getBase('mailer', 'mailers.mailer', $uuid); + } + + public function setmailerAction($uuid) + { + return $this->setBase('mailer', 'mailers.mailer', $uuid); + } + + public function addmailerAction() + { + return $this->addBase('mailer', 'mailers.mailer'); + } + + public function delmailerAction($uuid) + { + return $this->delBase('mailers.mailer', $uuid); + } + + public function togglemailerAction($uuid, $enabled = null) + { + return $this->toggleBase('mailers.mailer', $uuid); + } + + public function searchmailersAction() + { + return $this->searchBase('mailers.mailer', array('enabled', 'name', 'mailservers', 'sender', 'recipient'), 'name'); + } } diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/IndexController.php b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/IndexController.php index 141fac3e5..8e2b52f65 100644 --- a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/IndexController.php +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/IndexController.php @@ -53,6 +53,7 @@ class IndexController extends \OPNsense\Base\IndexController $this->view->formDialogGroup = $this->getForm("dialogGroup"); $this->view->formDialogHealthcheck = $this->getForm("dialogHealthcheck"); $this->view->formDialogLua = $this->getForm("dialogLua"); + $this->view->formDialogMailer = $this->getForm("dialogMailer"); $this->view->formDialogMapfile = $this->getForm("dialogMapfile"); $this->view->formDialogResolver = $this->getForm("dialogResolver"); $this->view->formDialogServer = $this->getForm("dialogServer"); diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogBackend.xml b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogBackend.xml index 4744fb03c..a17a99b86 100644 --- a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogBackend.xml +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogBackend.xml @@ -119,6 +119,12 @@ true + + backend.linkedMailer + + dropdown + + header diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogMailer.xml b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogMailer.xml new file mode 100644 index 000000000..cbede5c7c --- /dev/null +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogMailer.xml @@ -0,0 +1,61 @@ +
+ + mailer.enabled + + checkbox + Enable this mailer configuration. + + + mailer.name + + text + Choose a name for this mailer configuration. + + + mailer.description + + text + Choose a optional description for this mailer configuration. + + + mailer.mailservers + + select_multiple + + true + true + + Enter ip:port here. Finish with TAB. + + + mailer.sender + + text + + + + mailer.recipient + + text + + + + mailer.loglevel + + dropdown + + + + mailer.timeout + + text + + + + mailer.hostname + + text + + true + +
diff --git a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml index 89d711a03..7e2086bd9 100644 --- a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml +++ b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml @@ -928,6 +928,18 @@ Please specify a value between 1 and 100. N + + + + + Related mailer not found + N + N + 0 N @@ -2623,5 +2635,64 @@ + + + + Y + + + 1 + Y + + + /^[^\t^,^;^\.^\[^\]^\{^\}]{1,255}$/u + Should be a string between 1 and 255 characters. + Y + + + N + /^.{1,255}$/u + Should be a string between 1 and 255 characters. + + + Y + Y + Y + /^((([0-9a-zA-Z._\-\*:\[\]]+:[0-9]+(-[0-9]+)?)([,]){0,1}))*/u + lower + Please provide mailserver addresses, i.e. 192.168.1.1:25. + + + Y + + + Y + + + Y + alert + + emerg + alert + crit + err + warning + notice + info + debug + + + + 30 + 4 + 10000 + Please specify a value between 4 and 10000 seconds. + Y + + + N + + + diff --git a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Menu/Menu.xml b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Menu/Menu.xml index 520fcc7c3..0d78bf3eb 100644 --- a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Menu/Menu.xml +++ b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Menu/Menu.xml @@ -21,6 +21,7 @@ + diff --git a/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/index.volt b/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/index.volt index e9fa6c2e0..bbb658680 100644 --- a/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/index.volt +++ b/net/haproxy/src/opnsense/mvc/app/views/OPNsense/HAProxy/index.volt @@ -212,6 +212,19 @@ POSSIBILITY OF SUCH DAMAGE. } ); + $("#grid-mailers").UIBootgrid( + { search:'/api/haproxy/settings/searchMailers', + get:'/api/haproxy/settings/getMailer/', + set:'/api/haproxy/settings/setMailer/', + add:'/api/haproxy/settings/addMailer/', + del:'/api/haproxy/settings/delMailer/', + toggle:'/api/haproxy/settings/toggleMailer/', + options: { + rowCount:[10,25,50,100,500,1000] + } + } + ); + // hook into on-show event for dialog to extend layout. $('#DialogAcl').on('shown.bs.modal', function (e) { $("#acl\\.expression").change(function(){ @@ -608,6 +621,7 @@ POSSIBILITY OF SUCH DAMAGE.
  • {{ lang._('Map Files') }}
  • {{ lang._('CPU Affinity Rules') }}
  • {{ lang._('Resolvers') }}
  • +
  • {{ lang._('E-Mail Alerts') }}
  • @@ -715,6 +729,7 @@ POSSIBILITY OF SUCH DAMAGE.
  • {{ lang._("%sMap Files:%s A map allows to map a data in input to an other one on output. For example, this makes it possible to map a large number of domains to backend pools without using the GUI. Map files need to be used in %sRules%s, otherwise they are ignored.") | format('', '', '', '') }}
  • {{ lang._("%sCPU Affinity Rules:%s This feature makes it possible to bind HAProxy's processes/threads to a specific CPU (or a CPU set). Furthermore it is possible to select CPU Affinity Rules in %sPublic Services%s to restrict them to a certain set of processes/threads/CPUs.") | format('', '', '', '') }}
  • {{ lang._("%sResolvers:%s This feature allows in-depth configuration of how HAProxy handles name resolution and interacts with name resolvers (DNS). Each resolver configuration can be used in %sBackend Pools%s to apply individual name resolution configurations.") | format('', '', '', '') }}
  • +
  • {{ lang._("%sE-Mail Alerts:%s It is possible to send email alerts when the state of servers changes. Each configuration can be used in %sBackend Pools%s to send e-mail alerts to the configured recipient.") | format('', '', '', '') }}
  • {{ lang._("For more details visit HAProxy's official documentation regarding the %sError Messages%s, %sLua Script%s and the %sMap Files%s features. More information on HAProxy's CPU Affinity is also available %shere%s, %shere%s and %shere%s. A detailed explanation of the resolvers feature can be found %shere%s.") | format('', '', '', '', '', '' ,'', '' ,'', '' ,'', '','', '') }}


    @@ -1149,6 +1164,40 @@ POSSIBILITY OF SUCH DAMAGE. +
    + + + + + + + + + + + + + + + + + + + + +
    {{ lang._('Mailer ID') }}{{ lang._('Enabled') }}{{ lang._('Name') }}{{ lang._('Sender') }}{{ lang._('Recipient') }}{{ lang._('Commands') }}{{ lang._('ID') }}
    + + +
    +
    +
    + + +
    +
    +
    +
    +
    @@ -1242,3 +1291,4 @@ POSSIBILITY OF SUCH DAMAGE. {{ partial("layout_partials/base_dialog",['fields':formDialogMapfile,'id':'DialogMapfile','label':lang._('Edit Map File')])}} {{ partial("layout_partials/base_dialog",['fields':formDialogCpu,'id':'DialogCpu','label':lang._('Edit CPU Affinity Rule')])}} {{ partial("layout_partials/base_dialog",['fields':formDialogResolver,'id':'DialogResolver','label':lang._('Edit Resolver')])}} +{{ partial("layout_partials/base_dialog",['fields':formDialogMailer,'id':'DialogMailer','label':lang._('Edit E-Mail Alert')])}} diff --git a/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf b/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf index 8f3ce54f1..64f07b7cb 100644 --- a/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf +++ b/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf @@ -1049,6 +1049,29 @@ resolvers {{resolver.id}} {% endfor %} {%- endif -%} +{# ############################### #} +{# MAILERS #} +{# ############################### #} + +{% if helpers.exists('OPNsense.HAProxy.mailers') %} +{% for mailer in helpers.toList('OPNsense.HAProxy.mailers.mailer') %} +{% if mailer.enabled == '1' %} +# Mailer: {{mailer.name}} +mailers {{mailer.id}} + timeout mail {{mailer.timeout}}s +{% if mailer.mailservers|default("") != "" %} +{% for mailserver in mailer.mailservers.split(",") %} + mailer {{mailserver}} {{mailserver}} +{% endfor %} +{% endif %} + +{% else %} +# Mailer (DISABLED): {{mailer.name}} + +{% endif %} +{% endfor %} +{%- endif -%} + {# ############################### #} {# FRONTENDS #} {# ############################### #} @@ -1353,6 +1376,23 @@ backend {{backend.name}} # health checking is DISABLED {% set healthcheck_enabled = '0' %} {% endif %} +{# # mailer #} +{% if backend.linkedMailer|default("") != "" %} +{% set mailer_data = helpers.getUUID(backend.linkedMailer) %} +{% if mailer_data == {} %} +# ERROR: mailer data not found ({{backend.linkedMailer}}) +{% elif mailer_data.enabled == '0' %} +# NOTE: specified mailer is disabled ({{mailer_data.name}}) +{% else %} + email-alert mailers {{mailer_data.id}} + email-alert from {{mailer_data.sender}} + email-alert to {{mailer_data.recipient}} + email-alert level {{mailer_data.loglevel}} +{% if mailer_data.hostname|default("") != "" %} + email-alert myhostname {{mailer_data.hostname}} +{% endif %} +{% endif %} +{% endif %} {# # NOTE: Usually the frontend and the backend are in the same mode, #} {# # but we have no way to know what frontend uses this backend. #} {# # Hence we can't automatically set the mode and thus need a #}