Esempio n. 1
0
function trigger_get_func_value($expression, $flag, $function, $param)
{
    $result = NULL;
    $functionid = trigger_get_N_functionid($expression, $function);
    if (isset($functionid)) {
        $row = DBfetch(DBselect('select i.* from items i, functions f ' . ' where i.itemid=f.itemid and f.functionid=' . $functionid));
        if ($row) {
            $result = $flag == ZBX_FLAG_TRIGGER ? item_get_history($row, $param) : item_get_history($row, 0, $param);
        }
    }
    return $result;
}
 protected function resolveItemValueMacro(array $item, array $trigger)
 {
     $item['lastvalue'] = item_get_history($item, 0, $trigger['clock'], $trigger['ns']);
     return formatItemValue($item, UNRESOLVED_MACRO_STRING);
 }
 /**
  * Get {ITEM.VALUE} macro.
  * For triggers macro is resolved in same way as {ITEM.LASTVALUE} macro. Separate methods are created for event description,
  * where {ITEM.VALUE} macro resolves in different way.
  *
  * @param mixed $lastValue
  * @param array $item
  * @param array $trigger
  *
  * @return string
  */
 protected function getItemValueMacro($lastValue, array $item, array $trigger)
 {
     if ($this->config === 'eventDescription') {
         $value = item_get_history($item, $trigger['clock'], $trigger['ns']);
         return $value === null ? UNRESOLVED_MACRO_STRING : formatHistoryValue($value, $item);
     } else {
         return $this->getItemLastValueMacro($lastValue, $item);
     }
 }
 /**
  * Get item macros.
  *
  * @param array $macros
  * @param array $triggers
  * @param array $macroValues
  * @param bool  $events			resolve {ITEM.VALUE} macro using 'clock' and 'ns' fields
  *
  * @return array
  */
 protected function getItemMacros(array $macros, array $triggers, array $macroValues, $events)
 {
     if ($macros) {
         $functions = DbFetchArray(DBselect('SELECT f.triggerid,f.functionid,i.itemid,i.value_type,i.units,i.valuemapid' . ' FROM functions f' . ' JOIN items i ON f.itemid=i.itemid' . ' JOIN hosts h ON i.hostid=h.hostid' . ' WHERE ' . dbConditionInt('f.functionid', array_keys($macros))));
         $history = Manager::History()->getLast($functions, 1, ZBX_HISTORY_PERIOD);
         // False passed to DBfetch to get data without null converted to 0, which is done by default.
         foreach ($functions as $func) {
             foreach ($macros[$func['functionid']] as $macro => $fNums) {
                 $lastValue = isset($history[$func['itemid']]) ? $history[$func['itemid']][0]['value'] : null;
                 switch ($macro) {
                     case 'ITEM.LASTVALUE':
                         $replace = $this->getItemLastValueMacro($lastValue, $func);
                         break;
                     case 'ITEM.VALUE':
                         if ($events) {
                             $trigger = $triggers[$func['triggerid']];
                             $value = item_get_history($func, $trigger['clock'], $trigger['ns']);
                             $replace = $value === null ? UNRESOLVED_MACRO_STRING : formatHistoryValue($value, $func);
                         } else {
                             $replace = $this->getItemLastValueMacro($lastValue, $func);
                         }
                         break;
                 }
                 $macroValues = $this->getFunctionMacroValues($macroValues, $fNums, $func['triggerid'], $macro, $replace);
             }
         }
     }
     return $macroValues;
 }