Commit 72c3c8c4 authored by Ad Schellevis's avatar Ad Schellevis

(netflow) add some configd/api commands

parent 42dc887c
...@@ -33,6 +33,7 @@ namespace OPNsense\Diagnostics\Api; ...@@ -33,6 +33,7 @@ namespace OPNsense\Diagnostics\Api;
use \OPNsense\Base\ApiControllerBase; use \OPNsense\Base\ApiControllerBase;
use \OPNsense\Diagnostics\Netflow; use \OPNsense\Diagnostics\Netflow;
use \OPNsense\Core\Config; use \OPNsense\Core\Config;
use \OPNsense\Core\Backend;
/** /**
* Class NetflowController * Class NetflowController
...@@ -83,4 +84,45 @@ class NetflowController extends ApiControllerBase ...@@ -83,4 +84,45 @@ class NetflowController extends ApiControllerBase
} }
return $result; return $result;
} }
/**
* configure start/stop netflow
* @return array
*/
public function reconfigureAction()
{
if ($this->request->isPost()) {
// close session for long running action
$this->sessionClose();
// reconfigure netflow
$backend = new Backend();
$backend->configdRun("template reload OPNsense.Netflow");
// restart netflow, by calling stop (which will always stop the collectors) and start
// (which will only start if there are collectors configured)
$backend->configdRun("netflow stop");
$backend->configdRun("netflow start");
return array("status" => "ok");
} else {
return array("status" => "error");
}
}
/**
* request netflow status
* @return array
*/
public function statusAction()
{
$backend = new Backend();
$status = trim($backend->configdRun("netflow status"));
if (strpos($status, "netflow is active") !== false) {
// active, return status active + number of configured collectors
$collectors = trim(explode(')', explode(':', $status)[1])[0]);
return array("status" => "active", "collectors" => $collectors);
} else {
// inactive
return array("status" => "inactive");
}
}
} }
[stop]
command:/usr/local/etc/rc.d/netflow onestop
parameters:
type:script
message:stop netflow
[start]
command:/usr/local/etc/rc.d/netflow start
parameters:
type:script
message:start netflow
[restart]
command:/usr/local/etc/rc.d/netflow restart
parameters:
type:script
message:restart netflow
[status]
command:/usr/local/etc/rc.d/netflow status || exit 0
parameters:
type:script_output
message:get netflow status
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment