diff --git a/sysutils/monit/Makefile b/sysutils/monit/Makefile index 97c89acb1..f4c825342 100644 --- a/sysutils/monit/Makefile +++ b/sysutils/monit/Makefile @@ -1,8 +1,7 @@ PLUGIN_NAME= monit -PLUGIN_VERSION= 0.1 +PLUGIN_VERSION= 1.0 PLUGIN_COMMENT= Proactive system monitoring PLUGIN_MAINTAINER= frank.brendel@eurolog.com PLUGIN_DEPENDS= monit -PLUGIN_DEVEL= yes .include "../../Mk/plugins.mk" diff --git a/sysutils/monit/src/etc/inc/plugins.inc.d/monit.inc b/sysutils/monit/src/etc/inc/plugins.inc.d/monit.inc index 179f4ff6d..b8f1a5382 100644 --- a/sysutils/monit/src/etc/inc/plugins.inc.d/monit.inc +++ b/sysutils/monit/src/etc/inc/plugins.inc.d/monit.inc @@ -1,4 +1,5 @@ gettext('Monit System Monitoring'), + 'section' => 'OPNsense.monit', + 'id' => 'monit', + ); + + return $result; +} diff --git a/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/ServiceController.php b/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/ServiceController.php index b84511268..7d77f14ae 100644 --- a/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/ServiceController.php +++ b/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/ServiceController.php @@ -94,17 +94,24 @@ class ServiceController extends ApiControllerBase */ public function statusAction() { - if ($this->request->isPost()) { - $this->sessionClose(); - } - $result['function'] = "status"; - $result['result'] = "failed"; - $result['status'] = 'stopped'; - $status = $this->callBackend('status'); - if (substr($status, 0, 16) == 'monit is running') { - $result['result'] = "ok"; + $mdlMonit = new Monit(); + $result = array(); + $result['function'] = 'status'; + $result['result'] = 'ok'; + $response = $this->callBackend('status'); + if (strpos($response, 'not running') > 0) { + if ($mdlMonit->general->enabled->__toString() == '1') { + $result['status'] = 'stopped'; + } else { + $result['status'] = 'disabled'; + } + } elseif (strpos($response, 'is running') > 0) { $result['status'] = 'running'; + } elseif ($mdlMonit->general->enabled->__toString() == '0') { + $result['status'] = 'disabled'; } else { + $result['result'] = 'failed'; + $result['status'] = 'unknown'; $result['error'] = $status; } return $result; diff --git a/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php b/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php index b45d6f395..fabc62de8 100644 --- a/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php +++ b/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php @@ -357,9 +357,6 @@ class SettingsController extends ApiControllerBase Config::getInstance()->save(); $svcMonit = new ServiceController(); $result = $svcMonit->configtestAction(); - if ($nodeType == 'general' && $node->enabled->__toString() == 0) { - $result['stop'] = $svcMonit->stopAction(); - } } } } diff --git a/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/forms/alerts.xml b/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/forms/alerts.xml index 30bee0535..643de6d59 100644 --- a/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/forms/alerts.xml +++ b/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/forms/alerts.xml @@ -37,8 +37,7 @@ monit.alert.reminder text - - Send a reminder after some cycles + monit.alert.description diff --git a/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/forms/general.xml b/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/forms/general.xml index 9c4c95825..31426bc4b 100644 --- a/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/forms/general.xml +++ b/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/forms/general.xml @@ -3,24 +3,48 @@ monit.general.enabled checkbox - Enable or disable monit. + monit.general.interval text - Polling interval in seconds + monit.general.startdelay text - On system boot wait before Monit starts checking services. + monit.general.mailserver text - Comma separated list of SMTP servers for alert delivery. + + + + monit.general.port + + text + + + + monit.general.username + + text + + + + monit.general.password + + password + + + + monit.general.ssl + + checkbox + diff --git a/sysutils/monit/src/opnsense/mvc/app/models/OPNsense/Monit/Monit.xml b/sysutils/monit/src/opnsense/mvc/app/models/OPNsense/Monit/Monit.xml index 2a45e9e3f..49af87c54 100644 --- a/sysutils/monit/src/opnsense/mvc/app/models/OPNsense/Monit/Monit.xml +++ b/sysutils/monit/src/opnsense/mvc/app/models/OPNsense/Monit/Monit.xml @@ -23,12 +23,28 @@ Start Delay needs to be an integer value between 0 and 86400 + 127.0.0.1 Y - 127.0.0.1 - Y - /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-4]|2[0-5][0-9]|[01]?[0-9][0-9]?)$/ + /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-4]|2[0-5][0-9]|[01]?[0-9][0-9]?)$/ Mail Server must be a valid IPv4 address + + Y + 25 + 0 + 65535 + Port needs to be an integer value between 0 and 65535 + + + N + + + N + + + 0 + Y + 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 %}