diff --git a/sysutils/monit/src/opnsense/mvc/app/views/OPNsense/Monit/index.volt b/sysutils/monit/src/opnsense/mvc/app/views/OPNsense/Monit/index.volt
index c67c865cd..df1107c90 100644
--- a/sysutils/monit/src/opnsense/mvc/app/views/OPNsense/Monit/index.volt
+++ b/sysutils/monit/src/opnsense/mvc/app/views/OPNsense/Monit/index.volt
@@ -70,11 +70,35 @@ POSSIBILITY OF SUCH DAMAGE.
});
$('#btn_ApplyGeneralSettings').unbind('click').click(function(){
$("#frm_GeneralSettings_progress").addClass("fa fa-spinner fa-pulse");
- saveFormToEndpoint(
- url = "/api/monit/settings/setGeneral",
- formid = "frm_GeneralSettings"
+ var frm_id = 'frm_GeneralSettings';
+ saveFormToEndpoint(url = "/api/monit/settings/setGeneral",formid=frm_id,callback_ok=function(){
+ // on correct save, perform reconfigure. set progress animation when reloading
+ $("#"+frm_id+"_progress").addClass("fa fa-spinner fa-pulse");
+
+ //
+ ajaxCall(url="/api/monit/service/restart", sendData={}, callback=function(data,status){
+ // when done, disable progress animation.
+ $("#"+frm_id+"_progress").removeClass("fa fa-spinner fa-pulse");
+
+ if (status != "success" || data['result'] != 'OK' ) {
+ // fix error handling
+ BootstrapDialog.show({
+ type:BootstrapDialog.TYPE_WARNING,
+ title: 'Error',
+ message: JSON.stringify(data),
+ draggable: true
+ });
+ } else {
+ // request service status after successful save and update status box (wait a few seconds before update)
+ setTimeout(function(){
+ ajaxCall(url="/api/monit/service/status", sendData={}, callback=function(data,status) {
+ updateServiceStatusUI(data['status']);
+ });
+ },3000);
+ }
+ });
+ }
);
- $("#frm_GeneralSettings_progress").removeClass("fa fa-spinner fa-pulse");
$("#btn_ApplyGeneralSettings").blur();
});
@@ -311,8 +335,8 @@ POSSIBILITY OF SUCH DAMAGE.
-
-
+
+
diff --git a/sysutils/monit/src/opnsense/scripts/OPNsense/Monit/post-install.php b/sysutils/monit/src/opnsense/scripts/OPNsense/Monit/post-install.php
index b32b2a3d4..c448c622b 100755
--- a/sysutils/monit/src/opnsense/scripts/OPNsense/Monit/post-install.php
+++ b/sysutils/monit/src/opnsense/scripts/OPNsense/Monit/post-install.php
@@ -58,6 +58,30 @@ $LoadAvg15 = $nCPU[0];
$hostName = $cfgObj->system->hostname;
$domainName = $cfgObj->system->domain;
+// inherit SMTP settings from System->Settings->Notifications
+$generalSettings = array();
+if (!empty($cfgObj->notifications->smtp->ipaddress)) {
+ $generalSettings['mailserver'] = $cfgObj->notifications->smtp->ipaddress;
+}
+if (!empty($cfgObj->notifications->smtp->port)) {
+ $generalSettings['port'] = $cfgObj->notifications->smtp->port;
+}
+if (!empty($cfgObj->notifications->smtp->username)) {
+ $generalSettings['username'] = $cfgObj->notifications->smtp->username;
+}
+if (!empty($cfgObj->notifications->smtp->password)) {
+ $generalSettings['password'] = $cfgObj->notifications->smtp->password;
+}
+if ((!empty($cfgObj->notifications->smtp->tls) && $cfgObj->notifications->smtp->tls == 1) ||
+ (!empty($cfgObj->notifications->smtp->ssl) && $cfgObj->notifications->smtp->ssl == 1)) {
+ $generalSettings['ssl'] = 1;
+}
+
+$alertSettings = array();
+if (!empty($cfgObj->notifications->smtp->notifyemailaddress)) {
+ $alertSettings['recipient'] = $cfgObj->notifications->smtp->notifyemailaddress;
+}
+
// define some tests
$defaultTests = array(
array("name" => "Ping", "condition" => "failed ping", "action" => "alert"),
@@ -106,8 +130,13 @@ foreach ($defaultTests as $defaultTest) {
$systemService['tests'] = substr($systemService['tests'], 0, -1);
$rootFsService['tests'] = substr($rootFsService['tests'], 0, -1);
-// add an alert with default settings
-$mdlMonit->alert->Add();
+// set general properties
+$generalNode = $mdlMonit->getNodeByReference('general');
+$generalNode->setNodes($generalSettings);
+
+// add an alert with (almost) default settings
+$alertNode = $mdlMonit->alert->Add();
+$alertNode->setNodes($alertSettings);
// add system service
$serviceNode = $mdlMonit->service->Add();
diff --git a/sysutils/monit/src/opnsense/service/templates/OPNsense/Monit/monitrc b/sysutils/monit/src/opnsense/service/templates/OPNsense/Monit/monitrc
index 6fe124651..f98a69a18 100644
--- a/sysutils/monit/src/opnsense/service/templates/OPNsense/Monit/monitrc
+++ b/sysutils/monit/src/opnsense/service/templates/OPNsense/Monit/monitrc
@@ -9,7 +9,17 @@ set daemon {{ OPNsense.monit.general.interval }} with start delay {{ OPNsense.mo
set logfile syslog facility log_daemon
-set mailserver {{ OPNsense.monit.general.mailserver }}
+{% if helpers.exists('OPNsense.monit.general.mailserver') %}
+{% set port = "port " ~ OPNsense.monit.general.port if OPNsense.monit.general.port|default('') != '' %}
+{% set username = '' %}
+{% set password = '' %}
+{% if helpers.exists('OPNsense.monit.general.username') and helpers.exists('OPNsense.monit.general.password') %}
+{% set username = "username " ~ OPNsense.monit.general.username %}
+{% set password = "password " ~ OPNsense.monit.general.password %}
+{% endif %}
+{% set ssl = 'using ssl' if OPNsense.monit.general.ssl|default('0') == '1' %}
+set mailserver {{ OPNsense.monit.general.mailserver }} {{ port }} {{ username }} {{ password }} {{ ssl }}
+{% endif %}
{% if helpers.exists('OPNsense.monit.alert') %}
{% for alert in helpers.toList('OPNsense.monit.alert') %}
diff --git a/sysutils/monit/src/opnsense/service/templates/OPNsense/Monit/rc.conf.d b/sysutils/monit/src/opnsense/service/templates/OPNsense/Monit/rc.conf.d
index 3ca37dd5a..dab07c4ef 100644
--- a/sysutils/monit/src/opnsense/service/templates/OPNsense/Monit/rc.conf.d
+++ b/sysutils/monit/src/opnsense/service/templates/OPNsense/Monit/rc.conf.d
@@ -1,6 +1,7 @@
# DO NOT EDIT THIS FILE -- OPNsense auto-generated file
{% if helpers.exists('OPNsense.monit.general.enabled') and OPNsense.monit.general.enabled|default("0") == "1" %}
monit_enable="YES"
+monit_opnsense_bootup_run="/usr/local/opnsense/scripts/OPNsense/Monit/setup.sh"
{% else %}
monit_enable="NO"
{% endif %}