コード例 #1
0
 /**
  * Resolve macros in screen element URL.
  *
  * @static
  *
  * @param array $screenElement
  *
  * @return string
  */
 public static function resolveScreenElementURL(array $screenElement)
 {
     self::init();
     $macros = self::$macrosResolver->resolve(array('config' => $screenElement['config'], 'data' => array($screenElement['hostid'] => array('url' => $screenElement['url']))));
     $macros = reset($macros);
     return $macros['url'];
 }
コード例 #2
0
 /**
  * Resolve positional macros and functional item macros, for example, {{HOST.HOST1}:key.func(param)}.
  *
  *  ! if same graph will be passed more than once only name for first entry will be resolved.
  *
  * @param array  $data					list or hashmap of graphs
  * @param int    $data[n]['graphid']	id of graph
  * @param string $data[n]['name']		name of graph
  *
  * @return array	inputted data with resolved names
  */
 public static function resolveGraphNameByIds($data)
 {
     self::init();
     $graphIds = array();
     $graphMap = array();
     foreach ($data as $graph) {
         // skip graphs without macros
         if (strpos($graph['name'], '{') !== false) {
             $graphMap[$graph['graphid']] = array('graphid' => $graph['graphid'], 'name' => $graph['name'], 'items' => array());
             $graphIds[$graph['graphid']] = $graph['graphid'];
         }
     }
     $items = DBfetchArray(DBselect('SELECT i.hostid,gi.graphid,h.host' . ' FROM graphs_items gi,items i,hosts h' . ' WHERE gi.itemid=i.itemid' . ' AND i.hostid=h.hostid' . ' AND ' . dbConditionInt('gi.graphid', $graphIds) . ' ORDER BY gi.sortorder'));
     foreach ($items as $item) {
         $graphMap[$item['graphid']]['items'][] = array('hostid' => $item['hostid'], 'host' => $item['host']);
     }
     $graphMap = self::$macrosResolver->resolve(array('config' => 'graphName', 'data' => $graphMap));
     $resolvedGraph = reset($graphMap);
     foreach ($data as &$graph) {
         if ($graph['graphid'] === $resolvedGraph['graphid']) {
             $graph['name'] = $resolvedGraph['name'];
             $resolvedGraph = next($graphMap);
         }
     }
     unset($graph);
     return $data;
 }
コード例 #3
0
ファイル: httptest.inc.php プロジェクト: itnihao/Zabbix_
/**
 * Resolve http tests macros.
 *
 * @param array $httpTests
 * @param bool  $resolveName
 * @param bool  $resolveStepName
 *
 * @return array
 */
function resolveHttpTestMacros(array $httpTests, $resolveName = true, $resolveStepName = true)
{
    $names = array();
    $i = 0;
    foreach ($httpTests as $test) {
        if ($resolveName) {
            $names[$test['hostid']][$i++] = $test['name'];
        }
        if ($resolveStepName) {
            foreach ($test['steps'] as $step) {
                $names[$test['hostid']][$i++] = $step['name'];
            }
        }
    }
    $macrosResolver = new CMacrosResolver();
    $names = $macrosResolver->resolve(array('config' => 'httpTestName', 'data' => $names));
    $i = 0;
    foreach ($httpTests as $tnum => $test) {
        if ($resolveName) {
            $httpTests[$tnum]['name'] = $names[$test['hostid']][$i++];
        }
        if ($resolveStepName) {
            foreach ($httpTests[$tnum]['steps'] as $snum => $step) {
                $httpTests[$tnum]['steps'][$snum]['name'] = $names[$test['hostid']][$i++];
            }
        }
    }
    return $httpTests;
}
コード例 #4
0
 /**
  * Resolve function parameter macros to "parameter_expanded" field.
  *
  * @static
  *
  * @param array  $data
  * @param string $data[n]['hostid']
  * @param string $data[n]['parameter']
  *
  * @return array
  */
 public static function resolveFunctionParameters(array $data)
 {
     self::init();
     return self::$macrosResolver->resolveFunctionParameters($data);
 }