$octet = false;
$datas = array();
$fields = array();
$rplcts = array();
$allowedTesting = true;
$expressionData = new CTriggerExpression();
if ($expressionData->parse($expression)) {
    $macrosData = array();
    $expressions = array_merge($expressionData->expressions, $expressionData->macros, $expressionData->usermacros);
    foreach ($expressions as $exprPart) {
        if (isset($macrosData[$exprPart['expression']])) {
            continue;
        }
        $fname = 'test_data_' . md5($exprPart['expression']);
        $macrosData[$exprPart['expression']] = get_request($fname, '');
        $info = get_item_function_info($exprPart['expression']);
        if (!is_array($info) && isset($definedErrorPhrases[$info])) {
            $allowedTesting = false;
            $control = new CTextBox($fname, $macrosData[$exprPart['expression']], 30);
            $control->setAttribute('disabled', 'disabled');
        } else {
            $octet = $info['value_type'] == 'HHMMSS';
            $validation = $info['validation'];
            if (substr($validation, 0, COMBO_PATTERN_LENGTH) == COMBO_PATTERN) {
                $vals = explode(',', substr($validation, COMBO_PATTERN_LENGTH, zbx_strlen($validation) - COMBO_PATTERN_LENGTH - 4));
                $control = new CComboBox($fname, $macrosData[$exprPart['expression']]);
                foreach ($vals as $v) {
                    $control->addItem($v, $v);
                }
            } else {
                $control = new CTextBox($fname, $macrosData[$exprPart['expression']], 30);
Example #2
0
$fields = [];
$rplcts = [];
$allowedTesting = true;
$expressionData = new CTriggerExpression();
$result = $expressionData->parse($expression);
if ($result) {
    $macrosData = [];
    $supportedTokenTypes = [CTriggerExpressionParserResult::TOKEN_TYPE_FUNCTION_MACRO => 1, CTriggerExpressionParserResult::TOKEN_TYPE_MACRO => 1, CTriggerExpressionParserResult::TOKEN_TYPE_USER_MACRO => 1, CTriggerExpressionParserResult::TOKEN_TYPE_LLD_MACRO => 1];
    foreach ($result->getTokens() as $token) {
        if (!isset($supportedTokenTypes[$token['type']]) || isset($macrosData[$token['value']])) {
            continue;
        }
        $row = (new CRow())->addItem($token['value']);
        $fname = 'test_data_' . md5($token['value']);
        $macrosData[$token['value']] = getRequest($fname, '');
        $info = get_item_function_info($token['value']);
        if (!is_array($info) && isset($definedErrorPhrases[$info])) {
            $allowedTesting = false;
            $row->addItem((new CCol($definedErrorPhrases[$info]))->addClass(ZBX_STYLE_RED)->setColspan(2));
        } else {
            $validation = $info['validation'];
            if (substr($validation, 0, COMBO_PATTERN_LENGTH) == COMBO_PATTERN) {
                $end = strlen($validation) - COMBO_PATTERN_LENGTH - 4;
                $vals = explode(',', substr($validation, COMBO_PATTERN_LENGTH, $end));
                $control = new CComboBox($fname, $macrosData[$token['value']]);
                foreach ($vals as $v) {
                    $control->addItem($v, $v);
                }
            } else {
                $control = (new CTextBox($fname, $macrosData[$token['value']]))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH);
            }
Example #3
0
function expressionHighLevelErrors($expression)
{
    static $errors, $definedErrorPhrases;
    if (!isset($errors)) {
        $definedErrorPhrases = array(EXPRESSION_HOST_UNKNOWN => _('Unknown host, no such host present in system'), EXPRESSION_HOST_ITEM_UNKNOWN => _('Unknown host item, no such item in selected host'), EXPRESSION_NOT_A_MACRO_ERROR => _('Given expression is not a macro'), EXPRESSION_FUNCTION_UNKNOWN => _('Incorrect function is used'));
        $errors = array();
    }
    if (!isset($errors[$expression])) {
        $errors[$expression] = array();
        $expressionData = new CTriggerExpression();
        if ($expressionData->parse($expression)) {
            foreach ($expressionData->expressions as $exprPart) {
                $info = get_item_function_info($exprPart['expression']);
                if (!is_array($info) && isset($definedErrorPhrases[$info])) {
                    if (!isset($errors[$expression][$exprPart['expression']])) {
                        $errors[$expression][$exprPart['expression']] = $definedErrorPhrases[$info];
                    }
                }
            }
        }
    }
    $ret = array();
    if (count($errors[$expression]) == 0) {
        return $ret;
    }
    $expressionData = new CTriggerExpression();
    if ($expressionData->parse($expression)) {
        foreach ($expressionData->expressions as $exprPart) {
            if (isset($errors[$expression][$exprPart['expression']])) {
                $ret[$exprPart['expression']] = $errors[$expression][$exprPart['expression']];
            }
        }
    }
    return $ret;
}
function expressionHighLevelErrors($expression, $start, $end)
{
    static $errors, $definedErrorPhrases;
    if (!isset($errors)) {
        $definedErrorPhrases = array(EXPRESSION_VALUE_TYPE_UNKNOWN => S_EXPRESSION_VALUE_TYPE_UNKNOWN, EXPRESSION_HOST_UNKNOWN => S_EXPRESSION_HOST_UNKNOWN, EXPRESSION_HOST_ITEM_UNKNOWN => S_EXPRESSION_HOST_ITEM_UNKNOWN, EXPRESSION_NOT_A_MACRO_ERROR => S_EXPRESSION_NOT_A_MACRO_ERROR);
        $errors = array();
    }
    if (!isset($errors[$expression])) {
        $errors[$expression] = array();
        $expressionData = parseTriggerExpressions($expression, true);
        if (isset($expressionData[$expression]['expressions']) && is_array($expressionData[$expression]['expressions'])) {
            foreach ($expressionData[$expression]['expressions'] as $expPart) {
                $expValue = zbx_substr($expression, $expPart['openSymbolNum'], $expPart['closeSymbolNum'] - $expPart['openSymbolNum'] + 1);
                $info = get_item_function_info($expValue);
                if (!is_array($info) && isset($definedErrorPhrases[$info])) {
                    if (!isset($errors[$expression][$expValue])) {
                        $errors[$expression][$expValue] = array();
                    }
                    $errors[$expression][$expValue][] = array('start' => $expPart['openSymbolNum'], 'end' => $expPart['closeSymbolNum'], 'error' => &$definedErrorPhrases[$info]);
                }
            }
        }
    }
    $ret = array();
    if (count($errors[$expression]) > 0) {
        foreach ($errors[$expression] as $expValue => $errsPos) {
            foreach ($errsPos as $errData) {
                if ($errData['start'] >= $start && $errData['end'] <= $end && !isset($ret[$expValue])) {
                    $ret[$expValue] =& $errData['error'];
                }
            }
        }
    }
    return $ret;
}