plugins: plugins_run() has no workers concept

"Workers" are chains of commands, but with run we want defined
output from the plugin itself so only one function/endpoint
returning the data.
This commit is contained in:
Franco Fichtner 2019-04-22 20:18:50 +02:00
parent 715ad3f253
commit 05622d5a93
2 changed files with 15 additions and 17 deletions

View File

@ -227,23 +227,21 @@ function plugins_run($hook, $verbose = false, $args = array())
try { include_once $path; } catch (ParseError $e) { error_log($e); }
$func = sprintf('%s_run', $name);
if (function_exists($func)) {
foreach ($func() as $when => $worker) {
if ($hook == $when && is_array($worker)) {
foreach ($worker as $task) {
/*
* An optional argument count parameter can be
* given by the plugin, which allows to securely
* pull more info from the configure call spot.
*/
list($argf, $argc) = explode(':', $task);
if (empty($argc) || !is_numeric($argc)) {
$argc = 1;
}
if ($argc > count($args)) {
$argc = count($args);
}
$ret[$name] = call_user_func_array($argf, array_slice($args, 0, $argc));
foreach ($func() as $when => $task) {
if ($hook == $when) {
/*
* An optional argument count parameter can be
* given by the plugin, which allows to securely
* pull more info from the configure call spot.
*/
list($argf, $argc) = explode(':', $task);
if (empty($argc) || !is_numeric($argc)) {
$argc = 1;
}
if ($argc > count($args)) {
$argc = count($args);
}
$ret[$name] = call_user_func_array($argf, array_slice($args, 0, $argc));
}
}
}

View File

@ -301,7 +301,7 @@ function dpinger_configure_do($verbose = false, $gwname = null)
function dpinger_run()
{
return array(
'return_gateways_status' => array('dpinger_status'),
'return_gateways_status' => 'dpinger_status',
);
}