Guest User

Zabbix Bug Report - https://support.zabbix.com/browse/ZBX-3530

a guest
Feb 11th, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.88 KB | None | 0 0
  1. --- class.ctrigger.php.ori  2011-01-04 11:57:52.000000000 -0200
  2. +++ class.ctrigger.php  2011-02-11 16:15:32.195584051 -0200
  3. @@ -869,115 +869,8 @@ Copt::memoryPick();
  4.  
  5.  // expandDescription
  6.         if(!is_null($options['expandDescription'])){
  7. -// Function compare values {{{
  8.             foreach($result as $tnum => $trigger){
  9. -               preg_match_all('/\$([1-9])/u', $trigger['description'], $numbers);
  10. -               preg_match_all('~{[0-9]+}[+\-\*/<>=#]?[\(]*(?P<val>[+\-0-9]+)[\)]*~u', $trigger['expression'], $matches);
  11. -
  12. -               foreach($numbers[1] as $i){
  13. -                   $rep = isset($matches['val'][$i-1]) ? $matches['val'][$i-1] : '';
  14. -                   $result[$tnum]['description'] = str_replace('$'.($i), $rep, $result[$tnum]['description']);
  15. -               }
  16. -           }
  17. -// }}}
  18. -
  19. -           $functionids = array();
  20. -           $triggers_to_expand_hosts = array();
  21. -           $triggers_to_expand_items = array();
  22. -           $triggers_to_expand_items2 = array();
  23. -           foreach($result as $tnum => $trigger){
  24. -
  25. -               preg_match_all('/{HOSTNAME([1-9]?)}/u', $trigger['description'], $hnums);
  26. -               if(!empty($hnums[1])){
  27. -                   preg_match_all('/{([0-9]+)}/u', $trigger['expression'], $funcs);
  28. -                   $funcs = $funcs[1];
  29. -
  30. -                   foreach($hnums[1] as $fnum){
  31. -                       $fnum = $fnum ? $fnum : 1;
  32. -                       if(isset($funcs[$fnum-1])){
  33. -                           $functionid = $funcs[$fnum-1];
  34. -                           $functionids[$functionid] = $functionid;
  35. -                           $triggers_to_expand_hosts[$trigger['triggerid']][$functionid] = $fnum;
  36. -                       }
  37. -                   }
  38. -               }
  39. -
  40. -               preg_match_all('/{ITEM.LASTVALUE([1-9]?)}/u', $trigger['description'], $inums);
  41. -               if(!empty($inums[1])){
  42. -                   preg_match_all('/{([0-9]+)}/u', $trigger['expression'], $funcs);
  43. -                   $funcs = $funcs[1];
  44. -
  45. -                   foreach($inums[1] as $fnum){
  46. -                       $fnum = $fnum ? $fnum : 1;
  47. -                       if(isset($funcs[$fnum-1])){
  48. -                           $functionid = $funcs[$fnum-1];
  49. -                           $functionids[$functionid] = $functionid;
  50. -                           $triggers_to_expand_items[$trigger['triggerid']][$functionid] = $fnum;
  51. -                       }
  52. -                   }
  53. -               }
  54. -
  55. -               preg_match_all('/{ITEM.VALUE([1-9]?)}/u', $trigger['description'], $inums);
  56. -               if(!empty($inums[1])){
  57. -                   preg_match_all('/{([0-9]+)}/u', $trigger['expression'], $funcs);
  58. -                   $funcs = $funcs[1];
  59. -
  60. -                   foreach($inums[1] as $fnum){
  61. -                       $fnum = $fnum ? $fnum : 1;
  62. -                       if(isset($funcs[$fnum-1])){
  63. -                           $functionid = $funcs[$fnum-1];
  64. -                           $functionids[$functionid] = $functionid;
  65. -                           $triggers_to_expand_items2[$trigger['triggerid']][$functionid] = $fnum;
  66. -                       }
  67. -                   }
  68. -               }
  69. -           }
  70. -
  71. -           if(!empty($functionids)){
  72. -               $sql = 'SELECT DISTINCT f.triggerid, f.functionid, h.host, i.lastvalue'.
  73. -                       ' FROM functions f,items i,hosts h'.
  74. -                       ' WHERE f.itemid=i.itemid'.
  75. -                           ' AND i.hostid=h.hostid'.
  76. -                           ' AND h.status<>'.HOST_STATUS_TEMPLATE.
  77. -                           ' AND '.DBcondition('f.functionid', $functionids);
  78. -               $db_funcs = DBselect($sql);
  79. -               while($func = DBfetch($db_funcs)){
  80. -                   if(isset($triggers_to_expand_hosts[$func['triggerid']][$func['functionid']])){
  81. -
  82. -                       $fnum = $triggers_to_expand_hosts[$func['triggerid']][$func['functionid']];
  83. -                       if($fnum == 1)
  84. -                           $result[$func['triggerid']]['description'] = str_replace('{HOSTNAME}', $func['host'], $result[$func['triggerid']]['description']);
  85. -
  86. -                       $result[$func['triggerid']]['description'] = str_replace('{HOSTNAME'.$fnum.'}', $func['host'], $result[$func['triggerid']]['description']);
  87. -                   }
  88. -
  89. -                   if(isset($triggers_to_expand_items[$func['triggerid']][$func['functionid']])){
  90. -                       $fnum = $triggers_to_expand_items[$func['triggerid']][$func['functionid']];
  91. -                       if($fnum == 1)
  92. -                           $result[$func['triggerid']]['description'] = str_replace('{ITEM.LASTVALUE}', $func['lastvalue'], $result[$func['triggerid']]['description']);
  93. -
  94. -                       $result[$func['triggerid']]['description'] = str_replace('{ITEM.LASTVALUE'.$fnum.'}', $func['lastvalue'], $result[$func['triggerid']]['description']);
  95. -                   }
  96. -
  97. -                   if(isset($triggers_to_expand_items2[$func['triggerid']][$func['functionid']])){
  98. -                       $fnum = $triggers_to_expand_items2[$func['triggerid']][$func['functionid']];
  99. -                       if($fnum == 1)
  100. -                           $result[$func['triggerid']]['description'] = str_replace('{ITEM.VALUE}', $func['lastvalue'], $result[$func['triggerid']]['description']);
  101. -
  102. -                       $result[$func['triggerid']]['description'] = str_replace('{ITEM.VALUE'.$fnum.'}', $func['lastvalue'], $result[$func['triggerid']]['description']);
  103. -                   }
  104. -               }
  105. -           }
  106. -
  107. -           foreach($result as $tnum => $trigger){
  108. -               if($res = preg_match_all('/'.ZBX_PREG_EXPRESSION_USER_MACROS.'/', $trigger['description'], $arr)){
  109. -                   $macros = CUserMacro::getMacros($arr[1], array('triggerid' => $trigger['triggerid']));
  110. -
  111. -                   $search = array_keys($macros);
  112. -                   $values = array_values($macros);
  113. -
  114. -                   $result[$tnum]['description'] = str_replace($search, $values, $trigger['description']);
  115. -               }
  116. +               $result[$tnum]['description'] = expand_trigger_description($trigger['triggerid']);
  117.             }
  118.         }
Add Comment
Please, Sign In to add comment