require_once dirname(__FILE__).'/../../include/triggers.inc.php';
class CControllerPopupTestTriggerExpr extends CController {
private $defined_error_phrases = [];
private $expression = '';
private $macros_data = [];
private $data_table_rows = [];
private $allowed_testing = true;
private $supported_token_types = [
CExpressionParserResult::TOKEN_TYPE_HIST_FUNCTION,
CExpressionParserResult::TOKEN_TYPE_MACRO,
CExpressionParserResult::TOKEN_TYPE_USER_MACRO,
CExpressionParserResult::TOKEN_TYPE_LLD_MACRO,
CExpressionParserResult::TOKEN_TYPE_STRING
protected function init() {
$this->disableCsrfValidation();
define('ZBX_PAGE_NO_MENU', true);
define('NO_LINK_IN_TESTING', true);
$this->defined_error_phrases = [
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'),
EXPRESSION_UNSUPPORTED_VALUE_TYPE => _('Incorrect item value type')
if (array_key_exists('expression', $_REQUEST)) {
$this->expression = $_REQUEST['expression'];
$expression_parser = new CExpressionParser(['usermacros' => true, 'lldmacros' => true]);
if ($expression_parser->parse($this->expression) == CParser::PARSE_SUCCESS) {
foreach ($expression_parser->getResult()->getTokensOfTypes($this->supported_token_types) as $token) {
if ($token['type'] == CExpressionParserResult::TOKEN_TYPE_STRING) {
$matched_macros = CMacrosResolverGeneral::extractMacros(
[CExpressionParser::unquoteString($token['match'])],
'trigger' => ['{TRIGGER.VALUE}']
$macros = array_merge(array_keys($matched_macros['usermacros'] + $matched_macros['lldmacros']),
$matched_macros['macros']['trigger']
$macros = [$token['match']];
foreach ($macros as $macro) {
if (array_key_exists($macro, $this->macros_data)) {
$row = (new CRow())->addItem(
->addClass(ZBX_STYLE_OVERFLOW_ELLIPSIS)
->addStyle('max-width: '.ZBX_TEXTAREA_BIG_WIDTH.'px;')
$fname = 'test_data_'.md5($macro);
$this->macros_data[$macro] = array_key_exists($fname, $_REQUEST) ? $_REQUEST[$fname] : '';
$info = get_item_function_info($macro);