protected function calcTriggers() { $this->triggers = array(); if ($this->m_showTriggers != 1) { return; } $max = 3; $cnt = 0; foreach ($this->items as $inum => $item) { $sql = '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=' . $item['itemid'] . ' ORDER BY tr.priority'; $db_triggers = DBselect($sql); 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; } CUserMacro::resolveTrigger($trigger); if (!preg_match('/\\{([0-9]{1,})\\}([\\<\\>\\=]{1})([0-9\\.]{1,})([K|M|G]{0,1})/i', $trigger['expression'], $arr)) { continue; } $val = $arr[3]; if (strcasecmp($arr[4], 'K') == 0) { $val *= 1024; } else { if (strcasecmp($arr[4], 'M') == 0) { $val *= 1048576; } else { if (strcasecmp($arr[4], 'G') == 0) { $val *= 1073741824; } } } //1024*1024*1024; $minY = $this->m_minY[$this->items[$inum]['axisside']]; $maxY = $this->m_maxY[$this->items[$inum]['axisside']]; switch ($trigger['priority']) { case TRIGGER_SEVERITY_DISASTER: $color = 'Priority Disaster'; break; case TRIGGER_SEVERITY_HIGH: $color = 'Priority High'; break; case TRIGGER_SEVERITY_AVERAGE: $color = 'Priority Average'; break; case TRIGGER_SEVERITY_WARNING: $color = 'Priority Warning'; break; case TRIGGER_SEVERITY_INFORMATION: $color = 'Priority Information'; break; default: $color = 'Priority'; } array_push($this->triggers, array('skipdraw' => $val <= $minY || $val >= $maxY, 'y' => $this->sizeY - ($val - $minY) / ($maxY - $minY) * $this->sizeY + $this->shiftY, 'color' => $color, 'description' => S_TRIGGER . ': ' . expand_trigger_description_by_data($trigger), 'constant' => '[' . $arr[2] . ' ' . $arr[3] . $arr[4] . ']')); ++$cnt; } } }
function triggerExpression($trigger, $html, $template = false, $resolve_macro = false) { $expression = $trigger['expression']; // echo "EXPRESSION:",$expression,"<Br>"; $functionid = ''; $macros = ''; if (0 == $html) { $exp = ''; } else { $exp = array(); } $state = ''; for ($i = 0, $max = zbx_strlen($expression); $i < $max; $i++) { if ($expression[$i] == '{' && $expression[$i + 1] == '$') { $functionid = ''; $macros = ''; $state = 'MACROS'; } else { if ($expression[$i] == '{') { $functionid = ''; $state = 'FUNCTIONID'; continue; } } if ($expression[$i] == '}') { if ($state == 'MACROS') { $macros .= '}'; if ($resolve_macro) { $function_data['expression'] = $macros; CUserMacro::resolveTrigger($function_data); $macros = $function_data['expression']; } if (1 == $html) { array_push($exp, $macros); } else { $exp .= $macros; } $macros = ''; $state = ''; continue; } $state = ''; if ($functionid == 'TRIGGER.VALUE') { if (0 == $html) { $exp .= '{' . $functionid . '}'; } else { array_push($exp, '{' . $functionid . '}'); } } else { if (is_numeric($functionid) && isset($trigger['functions'][$functionid])) { $function_data = $trigger['functions'][$functionid]; $function_data += $trigger['items'][$function_data['itemid']]; $function_data += $trigger['hosts'][$function_data['hostid']]; if ($template) { $function_data['host'] = '{HOSTNAME}'; } if ($resolve_macro) { CUserMacro::resolveItem($function_data); $function_data['expression'] = $function_data['parameter']; CUserMacro::resolveTrigger($function_data); $function_data['parameter'] = $function_data['expression']; } //SDII($function_data); if ($html == 0) { $exp .= '{' . $function_data['host'] . ':' . $function_data['key_'] . '.' . $function_data['function'] . '(' . $function_data['parameter'] . ')}'; } else { $style = $function_data['status'] == ITEM_STATUS_DISABLED ? 'disabled' : 'unknown'; if ($function_data['status'] == ITEM_STATUS_ACTIVE) { $style = 'enabled'; } $link = new CLink($function_data['host'] . ':' . $function_data['key_'], 'items.php?form=update&itemid=' . $function_data['itemid'], $style); if ($function_data['type'] == ITEM_TYPE_HTTPTEST) { $link = new CSpan($function_data['host'] . ':' . $function_data['key_'], $style); } array_push($exp, array('{', $link, '.', bold($function_data['function'] . '('), $function_data['parameter'], bold(')'), '}')); } } else { if (1 == $html) { array_push($exp, new CSpan('*ERROR*', 'on')); } else { $exp .= '*ERROR*'; } } } continue; } if ($state == 'FUNCTIONID') { $functionid = $functionid . $expression[$i]; continue; } else { if ($state == 'MACROS') { $macros = $macros . $expression[$i]; continue; } } if (1 == $html) { array_push($exp, $expression[$i]); } else { $exp .= $expression[$i]; } } //SDII($exp); return $exp; }