From 197a509ac6dc21644b667c2b0caacf35d6422128 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Thu, 20 Apr 2017 13:34:31 +0200 Subject: [PATCH] sysutils/monit: version 0.2 by @fbrendel --- sysutils/monit/Makefile | 2 +- .../OPNsense/Monit/forms/alerts.xml | 3 +- .../OPNsense/Monit/forms/general.xml | 32 +++++++++++++++--- .../mvc/app/models/OPNsense/Monit/Monit.xml | 22 +++++++++++-- .../mvc/app/views/OPNsense/Monit/index.volt | 10 +++--- .../scripts/OPNsense/Monit/post-install.php | 33 +++++++++++++++++-- .../service/templates/OPNsense/Monit/monitrc | 12 ++++++- .../templates/OPNsense/Monit/rc.conf.d | 1 + 8 files changed, 98 insertions(+), 17 deletions(-) diff --git a/sysutils/monit/Makefile b/sysutils/monit/Makefile index 97c89acb1..bccf0192d 100644 --- a/sysutils/monit/Makefile +++ b/sysutils/monit/Makefile @@ -1,5 +1,5 @@ PLUGIN_NAME= monit -PLUGIN_VERSION= 0.1 +PLUGIN_VERSION= 0.2 PLUGIN_COMMENT= Proactive system monitoring PLUGIN_MAINTAINER= frank.brendel@eurolog.com PLUGIN_DEPENDS= monit 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..2dffaf7f2 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 @@ -72,9 +72,11 @@ POSSIBILITY OF SUCH DAMAGE. $("#frm_GeneralSettings_progress").addClass("fa fa-spinner fa-pulse"); saveFormToEndpoint( url = "/api/monit/settings/setGeneral", - formid = "frm_GeneralSettings" + formid = "frm_GeneralSettings", + callback_ok=function(){ + $("#frm_GeneralSettings_progress").removeClass("fa fa-spinner fa-pulse"); + } ); - $("#frm_GeneralSettings_progress").removeClass("fa fa-spinner fa-pulse"); $("#btn_ApplyGeneralSettings").blur(); }); @@ -311,8 +313,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..a2a05ee57 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 %}