mirror of
https://github.com/opnsense/plugins.git
synced 2026-05-28 04:34:15 -04:00
sysutils/monit: version 1.0 from master
This commit is contained in:
parent
752dd04fce
commit
cb61b7d3e2
11 changed files with 156 additions and 32 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
Copyright (C) 2017 EURO-LOG AG
|
||||
All rights reserved.
|
||||
|
|
@ -46,3 +47,20 @@ function monit_services()
|
|||
}
|
||||
return $services;
|
||||
}
|
||||
|
||||
/**
|
||||
* sync configuration via xmlrpc
|
||||
* @return array
|
||||
*/
|
||||
function monit_xmlrpc_sync()
|
||||
{
|
||||
$result = array();
|
||||
|
||||
$result[] = array(
|
||||
'description' => gettext('Monit System Monitoring'),
|
||||
'section' => 'OPNsense.monit',
|
||||
'id' => 'monit',
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,8 +37,7 @@
|
|||
<id>monit.alert.reminder</id>
|
||||
<label>Reminder</label>
|
||||
<type>text</type>
|
||||
<help><![CDATA[]]></help>
|
||||
<help>Send a reminder after some cycles</help>
|
||||
<help><![CDATA[Send a reminder after some cycles]]></help>
|
||||
</field>
|
||||
<field>
|
||||
<id>monit.alert.description</id>
|
||||
|
|
|
|||
|
|
@ -3,24 +3,48 @@
|
|||
<id>monit.general.enabled</id>
|
||||
<label>Enable monit</label>
|
||||
<type>checkbox</type>
|
||||
<help>Enable or disable monit.</help>
|
||||
<help><![CDATA[Enable or disable monit.]]></help>
|
||||
</field>
|
||||
<field>
|
||||
<id>monit.general.interval</id>
|
||||
<label>Polling Interval</label>
|
||||
<type>text</type>
|
||||
<help>Polling interval in seconds</help>
|
||||
<help><![CDATA[Polling interval in seconds]]></help>
|
||||
</field>
|
||||
<field>
|
||||
<id>monit.general.startdelay</id>
|
||||
<label>Start Delay</label>
|
||||
<type>text</type>
|
||||
<help>On system boot wait before Monit starts checking services.</help>
|
||||
<help><![CDATA[On system boot wait before Monit starts checking services.]]></help>
|
||||
</field>
|
||||
<field>
|
||||
<id>monit.general.mailserver</id>
|
||||
<label>Mail Server</label>
|
||||
<type>text</type>
|
||||
<help>Comma separated list of SMTP servers for alert delivery.</help>
|
||||
<help><![CDATA[Comma separated list of SMTP servers for alert delivery.]]></help>
|
||||
</field>
|
||||
<field>
|
||||
<id>monit.general.port</id>
|
||||
<label>Mail Server Port</label>
|
||||
<type>text</type>
|
||||
<help><![CDATA[The port of the mail server. Typically 465 for SSL or 25 for TLS and non secure connections.]]></help>
|
||||
</field>
|
||||
<field>
|
||||
<id>monit.general.username</id>
|
||||
<label>Username</label>
|
||||
<type>text</type>
|
||||
<help><![CDATA[The username for authentication.]]></help>
|
||||
</field>
|
||||
<field>
|
||||
<id>monit.general.password</id>
|
||||
<label>Password</label>
|
||||
<type>password</type>
|
||||
<help><![CDATA[The password for authentication.]]></help>
|
||||
</field>
|
||||
<field>
|
||||
<id>monit.general.ssl</id>
|
||||
<label>Secure Connection</label>
|
||||
<type>checkbox</type>
|
||||
<help><![CDATA[Enable encryption.]]></help>
|
||||
</field>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -23,12 +23,28 @@
|
|||
<ValidationMessage>Start Delay needs to be an integer value between 0 and 86400</ValidationMessage>
|
||||
</startdelay>
|
||||
<mailserver type="TextField">
|
||||
<default>127.0.0.1</default>
|
||||
<Required>Y</Required>
|
||||
<default>127.0.0.1</default>
|
||||
<Required>Y</Required>
|
||||
<mask>/^(?:(?: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]?)$/</mask>
|
||||
<mask>/^(?:(?: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]?)$/</mask>
|
||||
<ValidationMessage>Mail Server must be a valid IPv4 address</ValidationMessage>
|
||||
</mailserver>
|
||||
<port type="IntegerField">
|
||||
<Required>Y</Required>
|
||||
<default>25</default>
|
||||
<MinimumValue>0</MinimumValue>
|
||||
<MaximumValue>65535</MaximumValue>
|
||||
<ValidationMessage>Port needs to be an integer value between 0 and 65535</ValidationMessage>
|
||||
</port>
|
||||
<username type="TextField">
|
||||
<Required>N</Required>
|
||||
</username>
|
||||
<password type="TextField">
|
||||
<Required>N</Required>
|
||||
</password>
|
||||
<ssl type="BooleanField">
|
||||
<default>0</default>
|
||||
<Required>Y</Required>
|
||||
</ssl>
|
||||
</general>
|
||||
<alert type="ArrayField">
|
||||
<enabled type="BooleanField">
|
||||
|
|
|
|||
|
|
@ -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.
|
|||
</div>
|
||||
<div class="col-md-12">
|
||||
<hr/>
|
||||
<button class="btn btn-primary" id="btn_configtest" type="button"><b>{{ lang._('Test Configuration') }}</b><i id="configtest_progress" class=""></i></button>
|
||||
<button class="btn btn-primary" id="btn_reload" type="button"><b>{{ lang._('Reload Configuration') }}</b><i id="reload_progress" class=""></i></button>
|
||||
<button class="btn btn-primary" id="btn_configtest" type="button"><b>{{ lang._('Test Configuration') }}</b><i id="btn_configtest_progress" class=""></i></button>
|
||||
<button class="btn btn-primary" id="btn_reload" type="button"><b>{{ lang._('Reload Configuration') }}</b><i id="btn_reload_progress" class=""></i></button>
|
||||
<br/>
|
||||
<br/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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') %}
|
||||
|
|
|
|||
|
|
@ -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 %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue