本文整理汇总了PHP中CMacrosResolverHelper::resolveTriggerExpressionUserMacro方法的典型用法代码示例。如果您正苦于以下问题:PHP CMacrosResolverHelper::resolveTriggerExpressionUserMacro方法的具体用法?PHP CMacrosResolverHelper::resolveTriggerExpressionUserMacro怎么用?PHP CMacrosResolverHelper::resolveTriggerExpressionUserMacro使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMacrosResolverHelper
的用法示例。
在下文中一共展示了CMacrosResolverHelper::resolveTriggerExpressionUserMacro方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: calcTriggers
protected function calcTriggers()
{
$this->triggers = array();
if ($this->m_showTriggers != 1) {
return;
}
$max = 3;
$cnt = 0;
foreach ($this->items as $inum => $item) {
$db_triggers = DBselect('SELECT DISTINCT h.host,tr.description,tr.triggerid,tr.expression,tr.priority,tr.value' . ' FROM triggers tr,functions f,items i,hosts h' . ' WHERE tr.triggerid=f.triggerid' . " AND f.function IN ('last','min','avg','max')" . ' AND tr.status=' . TRIGGER_STATUS_ENABLED . ' AND i.itemid=f.itemid' . ' AND h.hostid=i.hostid' . ' AND f.itemid=' . zbx_dbstr($item['itemid']) . ' ORDER BY tr.priority');
while (($trigger = DBfetch($db_triggers)) && $cnt < $max) {
$db_fnc_cnt = DBselect('SELECT COUNT(*) AS cnt FROM functions f WHERE f.triggerid=' . $trigger['triggerid']);
$fnc_cnt = DBfetch($db_fnc_cnt);
if ($fnc_cnt['cnt'] != 1) {
continue;
}
$trigger['expression'] = CMacrosResolverHelper::resolveTriggerExpressionUserMacro($trigger);
if (!preg_match('/^\\{([0-9]+)\\}\\s*?([\\<\\>\\=]{1})\\s*?([\\-0-9\\.]+)([TGMKsmhdw]?)$/', $trigger['expression'], $arr)) {
continue;
}
$val = convert($arr[3] . $arr[4]);
$minY = $this->m_minY[$this->items[$inum]['axisside']];
$maxY = $this->m_maxY[$this->items[$inum]['axisside']];
$this->triggers[] = array('skipdraw' => $val <= $minY || $val >= $maxY, 'y' => $this->sizeY - ($val - $minY) / ($maxY - $minY) * $this->sizeY + $this->shiftY, 'color' => getSeverityColor($trigger['priority']), 'description' => _('Trigger') . NAME_DELIMITER . CMacrosResolverHelper::resolveTriggerName($trigger), 'constant' => '[' . $arr[2] . ' ' . $arr[3] . $arr[4] . ']');
++$cnt;
}
}
}
示例2: explode_exp
function explode_exp($expressionCompressed, $html = false, $resolveMacro = false, $sourceHost = null, $destinationHost = null)
{
$expressionExpanded = $html ? array() : '';
$trigger = array();
for ($i = 0, $state = '', $max = zbx_strlen($expressionCompressed); $i < $max; $i++) {
if ($expressionCompressed[$i] == '{') {
if ($expressionCompressed[$i + 1] == '$') {
$state = 'USERMACRO';
$userMacro = '';
} elseif ($expressionCompressed[$i + 1] == '#') {
$state = 'LLDMACRO';
$lldMacro = '';
} else {
$state = 'FUNCTIONID';
$functionId = '';
continue;
}
} elseif ($expressionCompressed[$i] == '}') {
if ($state == 'USERMACRO') {
$state = '';
$userMacro .= '}';
if ($resolveMacro) {
$functionData['expression'] = $userMacro;
$userMacro = CMacrosResolverHelper::resolveTriggerExpressionUserMacro($functionData);
}
if ($html) {
$expressionExpanded[] = $userMacro;
} else {
$expressionExpanded .= $userMacro;
}
continue;
} elseif ($state == 'LLDMACRO') {
$state = '';
$lldMacro .= '}';
if ($html) {
$expressionExpanded[] = $lldMacro;
} else {
$expressionExpanded .= $lldMacro;
}
continue;
} elseif ($functionId == 'TRIGGER.VALUE') {
$state = '';
if ($html) {
$expressionExpanded[] = '{' . $functionId . '}';
} else {
$expressionExpanded .= '{' . $functionId . '}';
}
continue;
}
$state = '';
$error = true;
if (is_numeric($functionId)) {
$functionData = DBfetch(DBselect('SELECT h.host,h.hostid,i.itemid,i.key_,f.function,f.triggerid,f.parameter,i.itemid,i.status,i.type,i.flags' . ' FROM items i,functions f,hosts h' . ' WHERE f.functionid=' . zbx_dbstr($functionId) . ' AND i.itemid=f.itemid' . ' AND h.hostid=i.hostid'));
if ($functionData) {
$error = false;
if ($resolveMacro) {
$trigger = $functionData;
// expand macros in item key
$items = CMacrosResolverHelper::resolveItemKeys(array($functionData));
$item = reset($items);
$functionData['key_'] = $item['key_expanded'];
// expand macros in function parameter
$functionParameters = CMacrosResolverHelper::resolveFunctionParameters(array($functionData));
$functionParameter = reset($functionParameters);
$functionData['parameter'] = $functionParameter['parameter_expanded'];
}
if ($sourceHost !== null && $destinationHost !== null && $sourceHost === $functionData['host']) {
$functionData['host'] = $destinationHost;
}
if ($html) {
if ($functionData['status'] == ITEM_STATUS_DISABLED) {
$style = 'disabled';
} elseif ($functionData['status'] == ITEM_STATUS_ACTIVE) {
$style = 'enabled';
} else {
$style = 'unknown';
}
if ($functionData['flags'] == ZBX_FLAG_DISCOVERY_CREATED || $functionData['type'] == ITEM_TYPE_HTTPTEST) {
$link = new CSpan($functionData['host'] . ':' . $functionData['key_'], $style);
} elseif ($functionData['flags'] == ZBX_FLAG_DISCOVERY_PROTOTYPE) {
$link = new CLink($functionData['host'] . ':' . $functionData['key_'], 'disc_prototypes.php?form=update&itemid=' . $functionData['itemid'] . '&parent_discoveryid=' . $trigger['discoveryRuleid'] . '&switch_node=' . id2nodeid($functionData['itemid']), $style);
} else {
$link = new CLink($functionData['host'] . ':' . $functionData['key_'], 'items.php?form=update&itemid=' . $functionData['itemid'] . '&switch_node=' . id2nodeid($functionData['itemid']), $style);
}
$expressionExpanded[] = array('{', $link, '.', bold($functionData['function'] . '('), $functionData['parameter'], bold(')'), '}');
} else {
$expressionExpanded .= '{' . $functionData['host'] . ':' . $functionData['key_'] . '.' . $functionData['function'] . '(' . $functionData['parameter'] . ')}';
}
}
}
if ($error) {
if ($html) {
$expressionExpanded[] = new CSpan('*ERROR*', 'on');
} else {
$expressionExpanded .= '*ERROR*';
}
}
continue;
}
switch ($state) {
//.........这里部分代码省略.........