Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- class.ctrigger.php.ori 2011-01-04 11:57:52.000000000 -0200
- +++ class.ctrigger.php 2011-02-11 16:15:32.195584051 -0200
- @@ -869,115 +869,8 @@ Copt::memoryPick();
- // expandDescription
- if(!is_null($options['expandDescription'])){
- -// Function compare values {{{
- foreach($result as $tnum => $trigger){
- - preg_match_all('/\$([1-9])/u', $trigger['description'], $numbers);
- - preg_match_all('~{[0-9]+}[+\-\*/<>=#]?[\(]*(?P<val>[+\-0-9]+)[\)]*~u', $trigger['expression'], $matches);
- -
- - foreach($numbers[1] as $i){
- - $rep = isset($matches['val'][$i-1]) ? $matches['val'][$i-1] : '';
- - $result[$tnum]['description'] = str_replace('$'.($i), $rep, $result[$tnum]['description']);
- - }
- - }
- -// }}}
- -
- - $functionids = array();
- - $triggers_to_expand_hosts = array();
- - $triggers_to_expand_items = array();
- - $triggers_to_expand_items2 = array();
- - foreach($result as $tnum => $trigger){
- -
- - preg_match_all('/{HOSTNAME([1-9]?)}/u', $trigger['description'], $hnums);
- - if(!empty($hnums[1])){
- - preg_match_all('/{([0-9]+)}/u', $trigger['expression'], $funcs);
- - $funcs = $funcs[1];
- -
- - foreach($hnums[1] as $fnum){
- - $fnum = $fnum ? $fnum : 1;
- - if(isset($funcs[$fnum-1])){
- - $functionid = $funcs[$fnum-1];
- - $functionids[$functionid] = $functionid;
- - $triggers_to_expand_hosts[$trigger['triggerid']][$functionid] = $fnum;
- - }
- - }
- - }
- -
- - preg_match_all('/{ITEM.LASTVALUE([1-9]?)}/u', $trigger['description'], $inums);
- - if(!empty($inums[1])){
- - preg_match_all('/{([0-9]+)}/u', $trigger['expression'], $funcs);
- - $funcs = $funcs[1];
- -
- - foreach($inums[1] as $fnum){
- - $fnum = $fnum ? $fnum : 1;
- - if(isset($funcs[$fnum-1])){
- - $functionid = $funcs[$fnum-1];
- - $functionids[$functionid] = $functionid;
- - $triggers_to_expand_items[$trigger['triggerid']][$functionid] = $fnum;
- - }
- - }
- - }
- -
- - preg_match_all('/{ITEM.VALUE([1-9]?)}/u', $trigger['description'], $inums);
- - if(!empty($inums[1])){
- - preg_match_all('/{([0-9]+)}/u', $trigger['expression'], $funcs);
- - $funcs = $funcs[1];
- -
- - foreach($inums[1] as $fnum){
- - $fnum = $fnum ? $fnum : 1;
- - if(isset($funcs[$fnum-1])){
- - $functionid = $funcs[$fnum-1];
- - $functionids[$functionid] = $functionid;
- - $triggers_to_expand_items2[$trigger['triggerid']][$functionid] = $fnum;
- - }
- - }
- - }
- - }
- -
- - if(!empty($functionids)){
- - $sql = 'SELECT DISTINCT f.triggerid, f.functionid, h.host, i.lastvalue'.
- - ' FROM functions f,items i,hosts h'.
- - ' WHERE f.itemid=i.itemid'.
- - ' AND i.hostid=h.hostid'.
- - ' AND h.status<>'.HOST_STATUS_TEMPLATE.
- - ' AND '.DBcondition('f.functionid', $functionids);
- - $db_funcs = DBselect($sql);
- - while($func = DBfetch($db_funcs)){
- - if(isset($triggers_to_expand_hosts[$func['triggerid']][$func['functionid']])){
- -
- - $fnum = $triggers_to_expand_hosts[$func['triggerid']][$func['functionid']];
- - if($fnum == 1)
- - $result[$func['triggerid']]['description'] = str_replace('{HOSTNAME}', $func['host'], $result[$func['triggerid']]['description']);
- -
- - $result[$func['triggerid']]['description'] = str_replace('{HOSTNAME'.$fnum.'}', $func['host'], $result[$func['triggerid']]['description']);
- - }
- -
- - if(isset($triggers_to_expand_items[$func['triggerid']][$func['functionid']])){
- - $fnum = $triggers_to_expand_items[$func['triggerid']][$func['functionid']];
- - if($fnum == 1)
- - $result[$func['triggerid']]['description'] = str_replace('{ITEM.LASTVALUE}', $func['lastvalue'], $result[$func['triggerid']]['description']);
- -
- - $result[$func['triggerid']]['description'] = str_replace('{ITEM.LASTVALUE'.$fnum.'}', $func['lastvalue'], $result[$func['triggerid']]['description']);
- - }
- -
- - if(isset($triggers_to_expand_items2[$func['triggerid']][$func['functionid']])){
- - $fnum = $triggers_to_expand_items2[$func['triggerid']][$func['functionid']];
- - if($fnum == 1)
- - $result[$func['triggerid']]['description'] = str_replace('{ITEM.VALUE}', $func['lastvalue'], $result[$func['triggerid']]['description']);
- -
- - $result[$func['triggerid']]['description'] = str_replace('{ITEM.VALUE'.$fnum.'}', $func['lastvalue'], $result[$func['triggerid']]['description']);
- - }
- - }
- - }
- -
- - foreach($result as $tnum => $trigger){
- - if($res = preg_match_all('/'.ZBX_PREG_EXPRESSION_USER_MACROS.'/', $trigger['description'], $arr)){
- - $macros = CUserMacro::getMacros($arr[1], array('triggerid' => $trigger['triggerid']));
- -
- - $search = array_keys($macros);
- - $values = array_values($macros);
- -
- - $result[$tnum]['description'] = str_replace($search, $values, $trigger['description']);
- - }
- + $result[$tnum]['description'] = expand_trigger_description($trigger['triggerid']);
- }
- }
Add Comment
Please, Sign In to add comment