本文整理汇总了PHP中CMacrosResolverHelper::resolve方法的典型用法代码示例。如果您正苦于以下问题:PHP CMacrosResolverHelper::resolve方法的具体用法?PHP CMacrosResolverHelper::resolve怎么用?PHP CMacrosResolverHelper::resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMacrosResolverHelper
的用法示例。
在下文中一共展示了CMacrosResolverHelper::resolve方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getScriptsByHosts
/**
* Returns all the scripts that are available on each given host.
*
* @param $hostIds
*
* @return array (an array of scripts in the form of array($hostId => array($script1, $script2, ...), ...) )
*/
public function getScriptsByHosts($hostIds)
{
zbx_value2array($hostIds);
$scriptsByHost = array();
if (!$hostIds) {
return $scriptsByHost;
}
foreach ($hostIds as $hostId) {
$scriptsByHost[$hostId] = array();
}
$scripts = $this->get(array('output' => API_OUTPUT_EXTEND, 'selectHosts' => array('hostid'), 'hostids' => $hostIds, 'sortfield' => 'name', 'preservekeys' => true));
if ($scripts) {
// resolve macros
$macrosData = array();
foreach ($scripts as $scriptId => $script) {
if (!empty($script['confirmation'])) {
foreach ($script['hosts'] as $host) {
if (isset($scriptsByHost[$host['hostid']])) {
$macrosData[$host['hostid']][$scriptId] = $script['confirmation'];
}
}
}
}
if ($macrosData) {
$macrosData = CMacrosResolverHelper::resolve(array('config' => 'scriptConfirmation', 'data' => $macrosData));
}
foreach ($scripts as $scriptId => $script) {
$hosts = $script['hosts'];
unset($script['hosts']);
// set script to host
foreach ($hosts as $host) {
$hostId = $host['hostid'];
if (isset($scriptsByHost[$hostId])) {
$size = count($scriptsByHost[$hostId]);
$scriptsByHost[$hostId][$size] = $script;
// set confirmation text with resolved macros
if (isset($macrosData[$hostId][$scriptId]) && $script['confirmation']) {
$scriptsByHost[$hostId][$size]['confirmation'] = $macrosData[$hostId][$scriptId];
}
}
}
}
}
return $scriptsByHost;
}
示例2: define
$page['file'] = 'scripts_exec.php';
define('ZBX_PAGE_NO_MENU', 1);
ob_start();
require_once dirname(__FILE__) . '/include/page_header.php';
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$fields = ['hostid' => [T_ZBX_INT, O_MAND, P_SYS, DB_ID, null], 'scriptid' => [T_ZBX_INT, O_MAND, P_SYS, DB_ID, null]];
check_fields($fields);
ob_end_flush();
$scriptid = getRequest('scriptid');
$hostid = getRequest('hostid');
$data = ['name' => '', 'command' => '', 'message' => ''];
$scripts = API::Script()->get(['scriptids' => $scriptid, 'output' => ['name', 'command']]);
$error_exist = false;
if ($scripts) {
$script = $scripts[0];
$macros_data = CMacrosResolverHelper::resolve(['config' => 'scriptConfirmation', 'data' => [$hostid => [$scriptid => $script['command']]]]);
$data['name'] = $script['name'];
$data['command'] = $macros_data[$hostid][$scriptid];
$result = API::Script()->execute(['hostid' => $hostid, 'scriptid' => $scriptid]);
if (!$result) {
$error_exist = true;
} elseif ($result['response'] == 'failed') {
error($result['value']);
$error_exist = true;
} else {
$data['message'] = $result['value'];
}
} else {
error(_('No permissions to referred object or it does not exist!'));
$error_exist = true;
}