sysutils/monit: merge version 1.5 from master

This commit is contained in:
Franco Fichtner 2018-02-28 22:38:17 +01:00
parent ffa156ca76
commit da33638d2a
10 changed files with 276 additions and 529 deletions

View file

@ -1,5 +1,5 @@
PLUGIN_NAME= monit
PLUGIN_VERSION= 1.4
PLUGIN_VERSION= 1.5
PLUGIN_COMMENT= Proactive system monitoring
PLUGIN_MAINTAINER= frank.brendel@eurolog.com
PLUGIN_DEPENDS= monit

View file

@ -1,7 +1,7 @@
<?php
/**
* Copyright (C) 2017 EURO-LOG AG
* Copyright (C) 2017-2018 EURO-LOG AG
*
* All rights reserved.
*
@ -30,7 +30,7 @@
namespace OPNsense\Monit\Api;
use \OPNsense\Base\ApiControllerBase;
use \OPNsense\Base\ApiMutableServiceControllerBase;
use \OPNsense\Core\Backend;
use \OPNsense\Monit\Monit;
@ -38,8 +38,13 @@ use \OPNsense\Monit\Monit;
* Class ServiceController
* @package OPNsense\Monit
*/
class ServiceController extends ApiControllerBase
class ServiceController extends ApiMutableServiceControllerBase
{
static protected $internalServiceClass = '\OPNsense\Monit\Monit';
static protected $internalServiceEnabled = 'general.enabled';
static protected $internalServiceTemplate = 'OPNsense/Monit';
static protected $internalServiceName = 'monit';
/**
* test monit configuration
* @return array
@ -48,129 +53,27 @@ class ServiceController extends ApiControllerBase
{
if ($this->request->isPost()) {
$this->sessionClose();
}
$result['function'] = "configtest";
$result['template'] = $this->callBackend('template');
if ($result['template'] != 'OK') {
$result['result'] = "Template error: " . $result['template'];
return $result;
}
$backend = new Backend();
$result['result'] = $this->callBackend('configtest');
return $result;
}
/**
* reload monit with new configuration
* @return array
*/
public function reloadAction()
{
if ($this->request->isPost()) {
$this->sessionClose();
}
$result['function'] = "reload";
$result['template'] = $this->callBackend('template');
if ($result['template'] != 'OK') {
$result['result'] = "Template error: " . $result['template'];
return $result;
}
$status = $this->callBackend('status');
if (substr($status, 0, 16) != 'monit is running') {
$result['result'] = "Monit is not running";
return $result;
}
$result['result'] = $this->callBackend('reload');
return $result;
}
/**
* get status of monit process
* @return array
*/
public function statusAction()
{
$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';
$result['function'] = "configtest";
$result['template'] = trim($backend->configdRun('template reload OPNsense/Monit'));
if ($result['template'] != 'OK') {
$result['result'] = "Template error: " . $result['template'];
return $result;
}
} elseif (strpos($response, 'is running') > 0) {
$result['status'] = 'running';
} elseif ($mdlMonit->general->enabled->__toString() == '0') {
$result['status'] = 'disabled';
$result['result'] = trim($backend->configdRun('monit configtest'));
return $result;
} else {
$result['result'] = 'failed';
$result['status'] = 'unknown';
$result['error'] = $status;
return array('status' => 'failed');
}
return $result;
}
/**
* start monit service
* @return array
*/
public function startAction()
/**
* avoid restarting Relayd on reconfigure
*/
protected function reconfigureForceRestart()
{
$result = array("result" => "failed", "function" => "start");
if ($this->request->isPost()) {
$this->sessionClose();
$result['result'] = $this->callBackend('start');
}
return $result;
}
/**
* stop monit service
* @return array
*/
public function stopAction()
{
$result = array("result" => "failed", "function" => "stop");
if ($this->request->isPost()) {
$this->sessionClose();
$result['result'] = $this->callBackend('stop');
}
return $result;
}
/**
* restart monit service
* @return array
*/
public function restartAction()
{
$result = array("result" => "failed", "function" => "restart");
if ($this->request->isPost()) {
$this->sessionClose();
$result['result'] = $this->callBackend('restart');
}
return $result;
}
/**
* call backend functions
* @param action
* @return string
*/
protected function callBackend($action)
{
$backend = new Backend();
if ($action == 'template') {
return trim($backend->configdRun('template reload OPNsense/Monit'));
} else {
return trim($backend->configdRun('monit ' . $action));
}
return 0;
}
}

View file

@ -1,7 +1,7 @@
<?php
/**
* Copyright (C) 2017 EURO-LOG AG
* Copyright (C) 2017-2018 EURO-LOG AG
*
* All rights reserved.
*
@ -42,241 +42,28 @@ use \OPNsense\Base\UIModelGrid;
class SettingsController extends ApiControllerBase
{
//// GENRAL SETTINGS ////
/**
* retrieve monit general settings or return defaults
* @return array
*/
public function getGeneralAction()
{
return $this->get('general');
}
/**
* update monit general settings with given properties
* @return array
* list with valid model node types
*/
public function setGeneralAction()
{
return $this->set('general');
}
//// ALERT SETTINGS ////
private $nodeTypes = array('general', 'alert', 'service', 'test');
/**
* search alert
* @return array
*/
public function searchAlertAction()
{
$fields = array("enabled", "recipient", "noton", "events", "description");
return $this->search('alert', $fields);
}
/**
* retrieve monit alert settings or return defaults
* @param $uuid item unique id
* @return array
*/
public function getAlertAction($uuid = null)
{
return $this->get('alert', $uuid);
}
/**
* set monit alert parameter
* @param $uuid item unique id
* @return array
*/
public function setAlertAction($uuid = null)
{
if ($uuid != null) {
return $this->set('alert', $uuid);
}
return array("result" => "failed");
}
/**
* add monit alert parameter
* @return array
*/
public function addAlertAction()
{
return $this->set('alert', null, true);
}
/**
* delete monit alert parameter
* @param $uuid item unique id
* @return array
*/
public function delAlertAction($uuid = null)
{
if ($uuid != null) {
return $this->del('alert', $uuid);
}
return array("result" => "failed");
}
/**
* toggle monit alert by uuid (enable/disable)
* @param $uuid item unique id
* @return array
*/
public function toggleAlertAction($uuid)
{
if ($uuid != null) {
return $this->toggle('alert', $uuid);
}
return array("result" => "failed");
}
//// SERVICE SETTINGS ////
/**
* search service
* @return array
*/
public function searchServiceAction()
{
$fields = array("enabled", "name", "type", "description");
return $this->search('service', $fields);
}
/**
* retrieve monit service settings or return defaults
* @param $uuid item unique id
* @return array
*/
public function getServiceAction($uuid = null)
{
return $this->get('service', $uuid);
}
/**
* set monit service parameter
* @param $uuid item unique id
* @return array
*/
public function setServiceAction($uuid = null)
{
if ($uuid != null) {
return $this->set('service', $uuid);
}
return array("result" => "failed");
}
/**
* add monit service parameter
* @return array
*/
public function addServiceAction()
{
return $this->set('service', null, true);
}
/**
* delete monit service parameter
* @param $uuid item unique id
* @return array
*/
public function delServiceAction($uuid = null)
{
if ($uuid != null) {
return $this->del('service', $uuid);
}
return array("result" => "failed");
}
/**
* toggle monit service by uuid (enable/disable)
* @param $uuid item unique id
* @return array
*/
public function toggleServiceAction($uuid)
{
if ($uuid != null) {
return $this->toggle('service', $uuid);
}
return array("result" => "failed");
}
//// SERVICE TEST SETTINGS ////
/**
* search test
* @return array
*/
public function searchTestAction()
{
$fields = array("name", "condition", "action");
return $this->search('test', $fields);
}
/**
* retrieve monit service test settings or return defaults
* @param $uuid item unique id
* @return array
*/
public function getTestAction($uuid = null)
{
return $this->get('test', $uuid);
}
/**
* set monit service test parameter
* @param $uuid item unique id
* @return array
*/
public function setTestAction($uuid = null)
{
if ($uuid != null) {
return $this->set('test', $uuid);
}
return array("result" => "failed");
}
/**
* add monit service test parameter
* @return array
*/
public function addTestAction()
{
return $this->set('test', null, true);
}
/**
* delete monit service test parameter
* @param $uuid item unique id
* @return array
*/
public function delTestAction($uuid = null)
{
if ($uuid != null) {
return $this->del('test', $uuid);
}
return array("result" => "failed");
}
//// ABSTRACT FUNCTIONS ////
/**
* retrieve monit settings
* query monit settings
* @param $nodeType
* @param $uuid
* @return result array
*/
private function get($nodeType = null, $uuid = null)
public function getAction($nodeType = null, $uuid = null)
{
$result = array("result" => "failed");
if ($this->request->isGet() && $nodeType != null) {
$this->validateNodeType($nodeType);
$mdlMonit = new Monit();
if ($uuid != null) {
$node = $mdlMonit->getNodeByReference($nodeType . '.' . $uuid);
if ($nodeType == 'general') {
$node = $mdlMonit->getNodeByReference($nodeType);
} else {
if ($nodeType == 'general') {
$node = $mdlMonit->getNodeByReference($nodeType);
if ($uuid != null) {
$node = $mdlMonit->getNodeByReference($nodeType . '.' . $uuid);
} else {
$node = $mdlMonit->$nodeType->Add();
}
@ -293,26 +80,22 @@ class SettingsController extends ApiControllerBase
* set monit properties
* @param $nodeType
* @param $uuid
* @parm $action set or add node
* @return result array
* @return status array
*/
private function set($nodeType = null, $uuid = null, $add = false)
public function setAction($nodeType = null, $uuid = null)
{
$result = array("result" => "failed");
$result = array("result" => "failed", "validations" => array());
if ($this->request->isPost() && $this->request->hasPost("monit") && $nodeType != null) {
$this->validateNodeType($nodeType);
$mdlMonit = new Monit();
if ($add == false) { // set node
if ($nodeType == 'general') {
$node = $mdlMonit->getNodeByReference($nodeType);
} else {
if ($uuid != null) {
$node = $mdlMonit->getNodeByReference($nodeType . '.' . $uuid);
} else {
if ($nodeType == 'general') {
$node = $mdlMonit->getNodeByReference($nodeType);
} else {
$node = $mdlMonit->$nodeType->Add();
}
$node = $mdlMonit->$nodeType->Add();
}
} else {
$node = $mdlMonit->$nodeType->Add();
}
if ($node != null) {
$monitInfo = $this->request->getPost("monit");
@ -352,11 +135,15 @@ class SettingsController extends ApiControllerBase
$fieldnm = str_replace($node->__reference, "monit." . $nodeType, $msg->getField());
$result["validations"][$fieldnm] = $msg->getMessage();
}
if ($valMsgs->count() == 0) {
if (empty($result["validations"])) {
unset($result["validations"]);
$result['result'] = 'ok';
$mdlMonit->serializeToConfig();
Config::getInstance()->save();
$svcMonit = new ServiceController();
$result = $svcMonit->configtestAction();
if ($nodeType == 'general' && $monitInfo['general']['enabled'] == '0') {
$svcMonit = new ServiceController();
$result = $svcMonit->stopAction();
}
}
}
}
@ -364,50 +151,34 @@ class SettingsController extends ApiControllerBase
}
/**
* delete monit properties
* delete monit settings
* @param $nodeType
* @param $uuid
* @return result array
* @return status array
*/
private function del($nodeType = null, $uuid = null)
public function delAction($nodeType = null, $uuid = null)
{
$result = array("result" => "failed");
if ($this->request->isPost() && $nodeType != null) {
$mdlMonit = new Monit();
if ($nodeType != null) {
$this->validateNodeType($nodeType);
if ($uuid != null) {
$mdlMonit = new Monit();
$node = $mdlMonit->getNodeByReference($nodeType . '.' . $uuid);
if ($node != null) {
if ($mdlMonit->$nodeType->del($uuid) == true) {
// remove test from services
// delete relations
if ($nodeType == 'test') {
// get a list of all services
$services = $mdlMonit->service->getNodes();
foreach ($services as $serviceUuid => $service) {
foreach ($service['tests'] as $testUuid => $test) {
// service has a reference to a test
if ($testUuid == $uuid) {
// get service model and remove $uuid from tests
$ref = 'service.' . $serviceUuid . '.tests';
$tstNode = $mdlMonit->getNodeByReference($ref);
$svcTests = str_replace($uuid, '', $tstNode->__toString());
$svcTests = str_replace(',,', ',', $svcTests);
$svcTests = rtrim($svcTests, ',');
$svcTests = ltrim($svcTests, ',');
$mdlMonit->setNodeByReference($ref, $svcTests);
}
}
$nodeName = $mdlMonit->getNodeByReference($nodeType . '.' . $uuid . '.name');
if ($nodeName != null) {
$nodeName = $nodeName->__toString();
$this->deleteRelations('service', 'tests', $uuid, 'test', $nodeName, $mdlMonit);
}
}
$mdlMonit->serializeToConfig();
Config::getInstance()->save();
$svcMonit = new ServiceController();
$result = $svcMonit->reloadAction();
$result["result"] = "ok";
}
} else {
$result['result'] = "not found";
}
} else {
$result['result'] = "uuid not given";
}
}
return $result;
@ -419,7 +190,7 @@ class SettingsController extends ApiControllerBase
* @param $uuid
* @return result array
*/
private function toggle($nodeType = null, $uuid = null)
public function toggleAction($nodeType = null, $uuid = null)
{
$result = array("result" => "failed");
if ($this->request->isPost() && $nodeType != null) {
@ -449,16 +220,122 @@ class SettingsController extends ApiControllerBase
/**
* search monit settings
* @param $nodeType
* @param requested field list
* @return array
* @return result array
*/
private function search($nodeType = null, &$fields = null)
public function searchAction($nodeType = null)
{
$this->sessionClose();
if ($nodeType != null) {
if ($this->request->isPost() && $nodeType != null) {
$this->validateNodeType($nodeType);
$mdlMonit = new Monit();
$grid = new UIModelGrid($mdlMonit->$nodeType);
$fields = array();
switch ($nodeType) {
case 'alert':
$fields = array("enabled", "recipient", "noton", "events", "description");
break;
case 'service':
$fields = array("enabled", "name", "type", "description");
break;
case 'test':
$fields = array("name", "condition", "action");
break;
}
return $grid->fetchBindRequest($this->request, $fields);
}
}
/**
* import system notification settings
* @return result array
*/
public function notificationAction()
{
$result = array("result" => "failed");
if ($this->request->isPost()) {
$this->sessionClose();
$cfg = Config::getInstance();
$cfgObj = $cfg->object();
$mdlMonit = new Monit();
$node = $mdlMonit->getNodeByReference('general');
$generalSettings = array();
// inherit SMTP settings from System->Settings->Notifications
if (!empty($cfgObj->notifications->smtp->ipaddress)) {
$generalSettings['mailserver'] = $cfgObj->notifications->smtp->ipaddress;
}
if (!empty($cfgObj->notifications->smtp->port)) {
$generalSettings['port'] = $cfgObj->notifications->smtp->port;
}
$generalSettings['username'] = $cfgObj->notifications->smtp->username;
$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;
} else {
$generalSettings['ssl'] = 0;
}
// apply them
$node->setNodes($generalSettings);
$valMsgs = $mdlMonit->performValidation();
foreach ($valMsgs as $field => $msg) {
$fieldnm = str_replace($node->__reference, "monit.general.", $msg->getField());
$result["validations"][$fieldnm] = $msg->getMessage();
}
if (empty($result["validations"])) {
unset($result["validations"]);
$result['result'] = 'ok';
$mdlMonit->serializeToConfig();
Config::getInstance()->save();
}
}
return $result;
}
/**
* validate nodeType
* @param $nodeType
* @throws \Exception
*/
private function validateNodeType($nodeType = null)
{
if (array_search($nodeType, $this->nodeTypes) === false) {
throw new \Exception('unknown nodeType: ' . $nodeType);
}
}
/**
* delete relations
* @param $nodeType
* @param $uuid
* @param $relNodeType
* @param &$mdlMonit
* @throws \Exception
*/
private function deleteRelations($nodeType = null, $nodeField = null, $relUuid = null, $relNodeType = null, $relNodeName = null, &$mdlMonit = null)
{
$nodes = $mdlMonit->$nodeType->getNodes();
// get nodes with relations
foreach ($nodes as $nodeUuid => $node) {
// get relation uuids
foreach ($node[$nodeField] as $fieldUuid => $field) {
// remove uuid from field
if ($fieldUuid == $relUuid) {
$refField = $nodeType . '.' . $nodeUuid . '.' . $nodeField;
$relNode = $mdlMonit->getNodeByReference($refField);
$nodeRels = str_replace($relUuid, '', $relNode->__toString());
$nodeRels = str_replace(',,', ',', $nodeRels);
$nodeRels = rtrim($nodeRels, ',');
$nodeRels = ltrim($nodeRels, ',');
$mdlMonit->setNodeByReference($refField, $nodeRels);
if ($relNode->isEmptyAndRequired()) {
$nodeName = $mdlMonit->getNodeByReference($nodeType . '.' . $nodeUuid . '.name')->__toString();
throw new \Exception("Cannot delete $relNodeType '$relNodeName' from $nodeType '$nodeName'");
}
}
}
}
}
}

View file

@ -1,7 +1,7 @@
<?php
/**
* Copyright (C) 2017 EURO-LOG AG
* Copyright (C) 2017-2018 EURO-LOG AG
*
* All rights reserved.
*
@ -44,57 +44,59 @@ class StatusController extends ApiControllerBase
* see monit(1)
* @return array
*/
public function getAction()
public function getAction($format = 'xml')
{
$result = array("result" => "failed", "function" => "getStatus");
$result = array("result" => "failed");
// connect monit httpd socket defined in monitrc by 'set httpd ...'
if (file_exists("/var/run/monit.sock") && filetype("/var/run/monit.sock") == "socket") {
// throws an exception therefore no error handling
$socket = stream_socket_client("unix:///var/run/monit.sock", $errno, $errstr);
$socketPath = "/var/run/monit.sock";
// get monit status page
$request = "GET /_status?format=text HTTP/1.0\r\n";
// map the requested html format from the status page to the Monit text format
$format = $format == 'html' ? 'text' : $format;
// check monit httpd socket defined in monitrc by 'set httpd ...'
if (file_exists($socketPath) && filetype($socketPath) == "socket") {
// set curl options
$ch = curl_init("http://127.0.0.1/_status?format=" . $format);
curl_setopt($ch, CURLOPT_UNIX_SOCKET_PATH, $socketPath);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// get credentials if configured
$mdlMonit = new Monit();
if ($mdlMonit->general->httpdUsername->__toString() != null && trim($mdlMonit->general->httpdUsername->__toString()) !== "" &&
$mdlMonit->general->httpdPassword->__toString() != null && trim($mdlMonit->general->httpdPassword->__toString()) !== "") {
$request .= "Authorization: Basic " . base64_encode($mdlMonit->general->httpdUsername->__toString() . ":" . $mdlMonit->general->httpdPassword->__toString()) . "\r\n";
curl_setopt($ch, CURLOPT_USERPWD, $mdlMonit->general->httpdUsername->__toString() . ":" . $mdlMonit->general->httpdPassword->__toString());
}
$request .= "\r\n";
$count = fwrite($socket, $request);
$result['count'] = $count;
$result['status'] = '';
$result['orig'] = '';
$result['httpstatus'] = preg_replace("/\r|\n/", "", fgets($socket));
$ignorelines = 1;
if ($result['httpstatus'] == 'HTTP/1.0 200 OK') {
while (!feof($socket)) {
$line = fgets($socket);
$result['orig'] .= $line;
// ignore lines (mostly HTTP headers) until a line starts with 'Monit' e.g. 'Monit 5.20.0 uptime: 2d 23h 2m'
if (substr($line, 0, 5) == 'Monit') {
$ignorelines = 0;
}
if ($ignorelines) {
continue;
}
$result['status'] .= $line;
}
// send request
if (!$response = curl_exec($ch)) {
$result['status'] = curl_error($ch);
return $result;
}
$HTTPCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($HTTPCode != 200) {
$result['status'] = 'Monit returns with code ' . $HTTPCode;
} else {
$result['result'] = "ok";
}
fclose($socket);
// response contains shell color escape codes; convert them to CSS
$result['status'] = '<pre style="color:WhiteSmoke;background-color:DimGrey">' . $this->bashColorToCSS($result['status']) . '</pre>';
// format the response
if ($format == 'xml') {
$result['status'] = simplexml_load_string($response);
} elseif ($format === 'text') {
$result['status'] = '<pre style="color:WhiteSmoke;background-color:DimGrey">' . $this->bashColorToCSS($response) . '</pre>';
}
}
} else {
$result['status'] = '<pre style="color:WhiteSmoke;background-color:DimGrey">
Either the file /var/run/monit.sock does not exists or it is not a unix socket.
$msg = "
Either the file " . $socketPath . " does not exists or it is not a unix socket.
Please check if the Monit service is running.
If you have started Monit recently, wait for StartDelay seconds and refresh this page.</pre>';
If you have started Monit recently, wait for StartDelay seconds and refresh this page.";
if ($format == 'xml') {
$result['status'] = $msg;
} elseif ($format === 'text') {
$result['status'] = '<pre style="color:WhiteSmoke;background-color:DimGrey">' . $msg . '</pre>';
}
}
return $result;
}

View file

@ -1,40 +0,0 @@
<?php
/**
* Copyright (C) 2016 EURO-LOG AG
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
namespace OPNsense\Monit;
/**
* Class ItemController
* @package OPNsense\Monit
*/
class ItemController extends \OPNsense\Base\IndexController
{
}

View file

@ -1,6 +1,6 @@
<model>
<mount>//OPNsense/monit</mount>
<version>1.0.1</version>
<version>1.0.2</version>
<description>Monit settings</description>
<items>
<general>
@ -26,8 +26,9 @@
<default>127.0.0.1</default>
<Required>Y</Required>
<multiple>Y</multiple>
<mask>/^((?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]),?)+$/</mask>
<ValidationMessage>Mail Server must be a valid IPv4 address</ValidationMessage>
<mask>/^([0-9a-zA-Z\.,_\-:]){0,1024}$/u</mask>
<ChangeCase>lower</ChangeCase>
<ValidationMessage>Please specify a valid servername or IP address.</ValidationMessage>
</mailserver>
<port type="IntegerField">
<Required>Y</Required>

View file

@ -1,6 +1,6 @@
{#
Copyright © 2017 by EURO-LOG AG
Copyright © 2017-2018 by EURO-LOG AG
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
@ -30,6 +30,15 @@ POSSIBILITY OF SUCH DAMAGE.
$( document ).ready(function() {
/**
* add button 'Import System Notification'
* can't do it via base_dialog
*/
$('<button class="btn btn-primary" id="btn_ImportSystemNotification" type="button" style="margin-left: 3px;">' +
'<b> {{ lang._('Import System Notification')}} </b>' +
'<i id="frm_ImportSystemNotification_progress"></i>' +
'</button>').insertAfter('#btn_ApplyGeneralSettings');
/**
* UI functions
*/
@ -45,23 +54,37 @@ POSSIBILITY OF SUCH DAMAGE.
$('#btn_reload').unbind('click').click(function(){
$('#btn_reload_progress').addClass("fa fa-spinner fa-pulse");
ajaxCall(url="/api/monit/service/reload", sendData={}, callback=function(data,status) {
ajaxCall(url="/api/monit/service/reconfigure", sendData={}, callback=function(data,status) {
$('#btn_reload_progress').removeClass("fa fa-spinner fa-pulse");
$('#btn_reload').blur();
$("#responseMsg").removeClass("hidden");
$("#responseMsg").html(data['result']);
ajaxCall(url="/api/monit/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
});
});
$('#btn_ImportSystemNotification').unbind('click').click(function(){
$('#frm_ImportSystemNotification_progress').addClass("fa fa-spinner fa-pulse");
ajaxCall(url="/api/monit/settings/notification", sendData={}, callback=function(data,status) {
$('#frm_ImportSystemNotification_progress').removeClass("fa fa-spinner fa-pulse");
$('#btn_ImportSystemNotification').blur();
ajaxCall(url="/api/monit/service/status", sendData={}, callback=function(data,status) {
mapDataToFormUI({'frm_GeneralSettings':"/api/monit/settings/get/general/"}).done(function(){
formatTokenizersUI();
$('.selectpicker').selectpicker('refresh');
ajaxCall(url="/api/monit/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
});
});
});
});
/**
* general settings
*/
// load data
mapDataToFormUI({'frm_GeneralSettings':"/api/monit/settings/getGeneral"}).done(function(){
mapDataToFormUI({'frm_GeneralSettings':"/api/monit/settings/get/general/"}).done(function(){
formatTokenizersUI();
$('.selectpicker').selectpicker('refresh');
ajaxCall(url="/api/monit/service/status", sendData={}, callback=function(data,status) {
@ -93,33 +116,14 @@ POSSIBILITY OF SUCH DAMAGE.
});
$('#btn_ApplyGeneralSettings').unbind('click').click(function(){
$("#frm_GeneralSettings_progress").addClass("fa fa-spinner fa-pulse");
$("#frm_GeneralSettings_progress").addClass("fa fa-spinner fa-pulse");
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 {
ajaxCall(url="/api/monit/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
}
});
}
);
saveFormToEndpoint(url = "/api/monit/settings/set/general/",formid=frm_id,callback_ok=function(){
ajaxCall(url="/api/monit/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
});
$("#"+frm_id+"_progress").removeClass("fa fa-spinner fa-pulse");
$("#btn_ApplyGeneralSettings").blur();
});
@ -128,8 +132,8 @@ POSSIBILITY OF SUCH DAMAGE.
*/
function openAlertDialog(uuid) {
var editDlg = "DialogEditAlert";
var setUrl = "/api/monit/settings/setAlert/";
var getUrl = "/api/monit/settings/getAlert/";
var setUrl = "/api/monit/settings/set/alert/";
var getUrl = "/api/monit/settings/get/alert/";
var urlMap = {};
urlMap['frm_' + editDlg] = getUrl + uuid;
mapDataToFormUI(urlMap).done(function () {
@ -143,12 +147,12 @@ POSSIBILITY OF SUCH DAMAGE.
};
$("#grid-alerts").UIBootgrid({
'search':'/api/monit/settings/searchAlert',
'get':'/api/monit/settings/getAlert/',
'set':'/api/monit/settings/setAlert/',
'add':'/api/monit/settings/addAlert/',
'del':'/api/monit/settings/delAlert/',
'toggle':'/api/monit/settings/toggleAlert/'
'search':'/api/monit/settings/search/alert/',
'get':'/api/monit/settings/get/alert/',
'set':'/api/monit/settings/set/alert/',
'add':'/api/monit/settings/set/alert/',
'del':'/api/monit/settings/del/alert/',
'toggle':'/api/monit/settings/toggle/alert/'
});
/**
@ -215,12 +219,12 @@ POSSIBILITY OF SUCH DAMAGE.
$('#monit\\.service\\.interface').on('changed.bs.select', function(e) {ShowHideFields();});
$("#grid-services").UIBootgrid({
'search':'/api/monit/settings/searchService',
'get':'/api/monit/settings/getService/',
'set':'/api/monit/settings/setService/',
'add':'/api/monit/settings/addService/',
'del':'/api/monit/settings/delService/',
'toggle':'/api/monit/settings/toggleService/'
'search':'/api/monit/settings/search/service/',
'get':'/api/monit/settings/get/service/',
'set':'/api/monit/settings/set/service/',
'add':'/api/monit/settings/set/service/',
'del':'/api/monit/settings/del/service/',
'toggle':'/api/monit/settings/toggle/service/'
});
@ -241,8 +245,8 @@ POSSIBILITY OF SUCH DAMAGE.
function openTestDialog(uuid) {
var editDlg = "TestEditAlert";
var setUrl = "/api/monit/settings/setTest/";
var getUrl = "/api/monit/settings/getTest/";
var setUrl = "/api/monit/settings/set/test/";
var getUrl = "/api/monit/settings/get/test/";
var urlMap = {};
urlMap['frm_' + editDlg] = getUrl + uuid;
mapDataToFormUI(urlMap).done(function () {
@ -256,11 +260,11 @@ POSSIBILITY OF SUCH DAMAGE.
};
$("#grid-tests").UIBootgrid({
'search':'/api/monit/settings/searchTest',
'get':'/api/monit/settings/getTest/',
'set':'/api/monit/settings/setTest/',
'add':'/api/monit/settings/addTest/',
'del':'/api/monit/settings/delTest/'
'search':'/api/monit/settings/search/test/',
'get':'/api/monit/settings/get/test/',
'set':'/api/monit/settings/set/test/',
'add':'/api/monit/settings/set/test/',
'del':'/api/monit/settings/del/test/'
});
});

View file

@ -1,6 +1,6 @@
{#
Copyright © 2017 by EURO-LOG AG
Copyright © 2017-2018 by EURO-LOG AG
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
textArea.innerHTML = encodedString;
return textArea.value;
}
ajaxCall(url="/api/monit/status/get", sendData={}, callback=function(data,status) {
ajaxCall(url="/api/monit/status/get/html", sendData={}, callback=function(data,status) {
$("#status").html(decodeEntities(data['status']));
});
});

View file

@ -35,15 +35,15 @@ use OPNsense\Core\Config;
use OPNsense\Core\Shell;
use OPNsense\Monit\Monit;
$mdlMonit = new OPNsense\Monit\Monit;
$mdlMonit = new Monit();
$cfg = Config::getInstance();
$cfgObj = $cfg->object();
$shellObj = new OPNsense\Core\Shell;
$generalNode = $mdlMonit->getNodeByReference('general');
// generate password for local Monit plugin user
if (empty($cfgObj->general->httpdUsername) && empty($cfgObj->general->httpdPassword)) {
if (empty($cfgObj->OPNsense->monit->general->httpdUsername) && empty($cfgObj->OPNsense->monit->general->httpdPassword)) {
print "Generate Monit httpd username and password\n";
srand();
$generalNode->setNodes(array(
"httpdUsername" => "root",

View file

@ -9,7 +9,7 @@ type:script
message:stopping monit
[status]
command:/usr/local/etc/rc.d/monit status || exit 0
command:/usr/local/etc/rc.d/monit status; exit 0
type:script_output
message:get monit status