Index: include/classes/macros/CMacrosResolver.php =================================================================== --- include/classes/macros/CMacrosResolver.php (revision 33611) +++ include/classes/macros/CMacrosResolver.php (working copy) @@ -26,6 +26,7 @@ const PATTERN_IP = '{(IPADDRESS|HOST\.IP|HOST\.DNS|HOST\.CONN)}'; const PATTERN_IP_FUNCTION = '{(IPADDRESS|HOST\.IP|HOST\.DNS|HOST\.CONN)([1-9]?)}'; const PATTERN_ITEM_FUNCTION = '{(ITEM\.LASTVALUE|ITEM\.VALUE)([1-9]?)}'; + const PATTERN_PROFILE_FUNCTION = '{(PROFILE\.[A-Z\.]+)([1-9]?)}'; /** * Interface priorities. @@ -61,17 +62,17 @@ 'method' => 'resolveTexts' ), 'triggerName' => array( - 'types' => array('host', 'ip', 'user', 'item', 'reference'), + 'types' => array('host', 'ip', 'user', 'item', 'reference', 'profile'), 'source' => 'description', 'method' => 'resolveTrigger' ), 'triggerDescription' => array( - 'types' => array('host', 'ip', 'user', 'item'), + 'types' => array('host', 'ip', 'user', 'item', 'profile'), 'source' => 'comments', 'method' => 'resolveTrigger' ), 'eventDescription' => array( - 'types' => array('host', 'ip', 'user', 'item', 'reference'), + 'types' => array('host', 'ip', 'user', 'item', 'reference', 'profile'), 'source' => 'description', 'method' => 'resolveTrigger' ) @@ -266,7 +267,7 @@ * @return array */ private function resolveTrigger(array $data) { - $macros = array('host' => array(), 'ip' => array(), 'item' => array()); + $macros = array('host' => array(), 'ip' => array(), 'item' => array(), 'profile' => array()); $macroValues = array(); // get source field @@ -278,6 +279,7 @@ $isItemMacrosAvailable = $this->isTypeAvailable('item'); $isUserMacrosAvailable = $this->isTypeAvailable('user'); $isReferenceMacrosAvailable = $this->isTypeAvailable('reference'); + $isProfileMacrosAvailable = $this->isTypeAvailable('profile'); // find macros foreach ($data as $triggerId => $trigger) { @@ -328,6 +330,17 @@ $macroValues[$triggerId][$macro] = $value; } } + + if ($isProfileMacrosAvailable) { + foreach ($this->findFunctionMacros(self::PATTERN_PROFILE_FUNCTION, $trigger[$source]) as $macro => $fNums) { + foreach ($fNums as $fNum) { + $macroValues[$triggerId][$this->getFunctionMacroName($macro, $fNum)] = UNRESOLVED_MACRO_STRING; + if (isset($functions[$fNum])) { + $macros['profile'][$functions[$fNum]][$macro][] = $fNum; + } + } + } + } } // get macro value @@ -340,12 +353,16 @@ if ($isItemMacrosAvailable) { $macroValues = $this->resolveItemMacros($macros['item'], $data, $macroValues); } + if ($isProfileMacrosAvailable) { + $macroValues = $this->resolveProfileMacros($macros['profile'], $macroValues); + } // replace macros to value foreach ($data as $triggerId => $trigger) { preg_match_all('/'.self::PATTERN_HOST_FUNCTION. '|'.self::PATTERN_IP_FUNCTION. '|'.self::PATTERN_ITEM_FUNCTION. + '|'.self::PATTERN_PROFILE_FUNCTION. '|'.ZBX_PREG_EXPRESSION_USER_MACROS. '|\$([1-9])/', $trigger[$source], $matches, PREG_OFFSET_CAPTURE); @@ -629,6 +646,43 @@ return $macroValues; } + + /** + * Resolve profile macros. + * + * @param array $macros + * @param array $triggers + * @param array $macroValues + * + * @return bool + */ + private function resolveProfileMacros(array $macros, array $macroValues) { + if (!empty($macros)) { + $dbFuncs = DBselect( + 'SELECT f.triggerid,f.functionid,hi.*'. + ' FROM functions f'. + ' JOIN items i ON f.itemid=i.itemid'. + ' JOIN host_inventory hi ON i.hostid=hi.hostid'. + ' WHERE '.dbConditionInt('f.functionid', array_keys($macros)) + ); + // false passed to DBfetch to get data without null converted to 0, which is done by default + while ($func = DBfetch($dbFuncs, false)) { + foreach ($macros[$func['functionid']] as $macro => $fNums) { + $macro_name = $macro; + $macro_name = substr($macro_name,8); + $macro_name = strtolower($macro_name); + $macro_name = str_replace('.', '_', $macro_name); + $replace = $func[$macro_name]; + + $macroValues = $this->prepareFunctionMacroValues($macroValues, $fNums, $func['triggerid'], $macro, $replace); + } + } + } + + return $macroValues; + } + + /** * Resolve {ITEM.LASTVALUE} macro. *