From 8b59b3e9aabc8881022cd673bce975a11a055a21 Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Sun, 17 Mar 2019 22:17:11 +0100 Subject: [PATCH] net-mgmt/zabbix-agent: migrate to ApiMutableServiceController --- .../ZabbixAgent/Api/ServiceController.php | 127 +----------------- 1 file changed, 7 insertions(+), 120 deletions(-) diff --git a/net-mgmt/zabbix-agent/src/opnsense/mvc/app/controllers/OPNsense/ZabbixAgent/Api/ServiceController.php b/net-mgmt/zabbix-agent/src/opnsense/mvc/app/controllers/OPNsense/ZabbixAgent/Api/ServiceController.php index 008956b17..70545400b 100644 --- a/net-mgmt/zabbix-agent/src/opnsense/mvc/app/controllers/OPNsense/ZabbixAgent/Api/ServiceController.php +++ b/net-mgmt/zabbix-agent/src/opnsense/mvc/app/controllers/OPNsense/ZabbixAgent/Api/ServiceController.php @@ -1,6 +1,6 @@ request->isPost()) { - // close session for long running action - $this->sessionClose(); - $backend = new Backend(); - $response = $backend->configdRun("zabbixagent start"); - return array("response" => $response); - } else { - return array("response" => array()); - } - } - - /** - * stop zabbix agent service - * @return array - */ - public function stopAction() - { - if ($this->request->isPost()) { - // close session for long running action - $this->sessionClose(); - $backend = new Backend(); - $response = $backend->configdRun("zabbixagent stop"); - return array("response" => $response); - } else { - return array("response" => array()); - } - } - - /** - * restart zabbix agent service - * @return array - */ - public function restartAction() - { - if ($this->request->isPost()) { - // close session for long running action - $this->sessionClose(); - $backend = new Backend(); - $response = $backend->configdRun("zabbixagent restart"); - return array("response" => $response); - } else { - return array("response" => array()); - } - } - - /** - * retrieve status of zabbix agent service - * @return array - * @throws \Exception - */ - public function statusAction() - { - $backend = new Backend(); - $mdlAgent = new ZabbixAgent(); - $response = $backend->configdRun("zabbixagent status"); - - if (strpos($response, "not running") > 0) { - if ($mdlAgent->settings->main->enabled->__toString() == "1") { - $status = "stopped"; - } else { - $status = "disabled"; - } - } elseif (strpos($response, "is running") > 0) { - $status = "running"; - } elseif ($mdlAgent->settings->main->enabled->__toString() == "0") { - $status = "disabled"; - } else { - $status = "unkown"; - } - - return array("status" => $status); - } - - /** - * reconfigure zabbix agent, generate config and reload - */ - public function reconfigureAction() - { - if ($this->request->isPost()) { - $force_restart = false; - // close session for long running action - $this->sessionClose(); - - $mdlAgent = new ZabbixAgent(); - $backend = new Backend(); - - $runStatus = $this->statusAction(); - - // stop zabbix agent when disabled - if ($runStatus['status'] == "running" && - ($mdlAgent->settings->main->enabled->__toString() == "0" || $force_restart)) { - $this->stopAction(); - } - - // generate template - $backend->configdRun('template reload OPNsense/ZabbixAgent'); - - // (res)start daemon - if ($mdlAgent->settings->main->enabled->__toString() == "1") { - if ($runStatus['status'] == "running" && !$force_restart) { - $backend->configdRun("zabbixagent reconfigure"); - } else { - $this->startAction(); - } - } - - return array("status" => "ok"); - } else { - return array("status" => "failed"); - } - } + protected static $internalServiceClass = '\OPNsense\ZabbixAgent\ZabbixAgent'; + protected static $internalServiceTemplate = 'OPNsense/ZabbixAgent'; + protected static $internalServiceEnabled = 'settings.main.enabled'; + protected static $internalServiceName = 'zabbixagent'; }