diff --git a/sysutils/monit/Makefile b/sysutils/monit/Makefile index ef727c4a7..a2b702303 100644 --- a/sysutils/monit/Makefile +++ b/sysutils/monit/Makefile @@ -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 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 7d77f14ae..0b1a73522 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 @@ -1,7 +1,7 @@ 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; } } 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 fabc62de8..621aaaf45 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 @@ -1,7 +1,7 @@ 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'"); + } + } + } + } + } } diff --git a/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/StatusController.php b/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/StatusController.php index a9bf4c1ee..65646590a 100644 --- a/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/StatusController.php +++ b/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/StatusController.php @@ -1,7 +1,7 @@ "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'] = '
' . $this->bashColorToCSS($result['status']) . '
'; + // format the response + if ($format == 'xml') { + $result['status'] = simplexml_load_string($response); + } elseif ($format === 'text') { + $result['status'] = '
' . $this->bashColorToCSS($response) . '
'; + } + } } else { - $result['status'] = '
-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.
'; +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'] = '
' . $msg . '
'; + } } return $result; } diff --git a/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/ItemController.php b/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/ItemController.php deleted file mode 100644 index f2e397071..000000000 --- a/sysutils/monit/src/opnsense/mvc/app/controllers/OPNsense/Monit/ItemController.php +++ /dev/null @@ -1,40 +0,0 @@ - //OPNsense/monit - 1.0.1 + 1.0.2 Monit settings @@ -26,8 +26,9 @@ 127.0.0.1 Y Y - /^((?:(?: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]),?)+$/ - Mail Server must be a valid IPv4 address + /^([0-9a-zA-Z\.,_\-:]){0,1024}$/u + lower + Please specify a valid servername or IP address. 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 097d8a80d..5649844b3 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 @@ -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 + */ + $('').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/' }); }); diff --git a/sysutils/monit/src/opnsense/mvc/app/views/OPNsense/Monit/status.volt b/sysutils/monit/src/opnsense/mvc/app/views/OPNsense/Monit/status.volt index f4a63e62d..e9c279c01 100644 --- a/sysutils/monit/src/opnsense/mvc/app/views/OPNsense/Monit/status.volt +++ b/sysutils/monit/src/opnsense/mvc/app/views/OPNsense/Monit/status.volt @@ -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'])); }); }); 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 e898107fd..b46f04aba 100755 --- a/sysutils/monit/src/opnsense/scripts/OPNsense/Monit/post-install.php +++ b/sysutils/monit/src/opnsense/scripts/OPNsense/Monit/post-install.php @@ -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", diff --git a/sysutils/monit/src/opnsense/service/conf/actions.d/actions_monit.conf b/sysutils/monit/src/opnsense/service/conf/actions.d/actions_monit.conf index 1bf973bbc..025e0185d 100644 --- a/sysutils/monit/src/opnsense/service/conf/actions.d/actions_monit.conf +++ b/sysutils/monit/src/opnsense/service/conf/actions.d/actions_monit.conf @@ -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