当前位置: 首页>>代码示例>>PHP>>正文


PHP CMacrosResolverHelper::resolve方法代码示例

本文整理汇总了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;
 }
开发者ID:omidmt,项目名称:zabbix-greenplum,代码行数:52,代码来源:CScript.php

示例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;
}
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:31,代码来源:scripts_exec.php


注:本文中的CMacrosResolverHelper::resolve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。