setPostContentType(self::POST_CONTENT_TYPE_JSON); $this->disableCsrfValidation(); } protected function checkInput(): bool { $fields = [ 'conditiontype' => 'db corr_condition.type|in '.implode(',', [ZBX_CORR_CONDITION_OLD_EVENT_TAG, ZBX_CORR_CONDITION_NEW_EVENT_TAG, ZBX_CORR_CONDITION_NEW_EVENT_HOSTGROUP, ZBX_CORR_CONDITION_EVENT_TAG_PAIR, ZBX_CORR_CONDITION_OLD_EVENT_TAG_VALUE, ZBX_CORR_CONDITION_NEW_EVENT_TAG_VALUE ]), 'operator' => 'in '.implode(',', [CONDITION_OPERATOR_EQUAL, CONDITION_OPERATOR_NOT_EQUAL, CONDITION_OPERATOR_LIKE, CONDITION_OPERATOR_NOT_LIKE ]), 'tag' => 'db corr_condition_tagvalue.tag|string', 'oldtag' => 'db corr_condition_tagpair.oldtag|string', 'newtag' => 'db corr_condition_tagpair.newtag|string', 'value' => 'db corr_condition_tagvalue.value|string', 'groupids' => 'array_id' ]; $ret = $this->validateInput($fields); if ($ret) { $validator = new CEventCorrCondValidator(); $is_valid = $validator->validate([ 'type' => $this->getInput('conditiontype'), 'operator' => $this->getInput('operator'), 'tag' => $this->getInput('tag', ''), 'oldtag' => $this->getInput('oldtag', ''), 'newtag' => $this->getInput('newtag', ''), 'value' => $this->getInput('value', ''), 'groupids' => $this->getInput('groupids', '') ]); if (!$is_valid) { error($validator->getError()); $ret = false; } } if (!$ret) { $this->setResponse( (new CControllerResponseData(['main_block' => json_encode([ 'error' => [ 'messages' => array_column(get_and_clear_messages(), 'message') ] ])]))->disableView() ); } return $ret; } protected function checkPermissions(): bool { return $this->checkAccess(CRoleHelper::UI_CONFIGURATION_EVENT_CORRELATION); } protected function doAction(): void { $output = [ 'conditiontype' => $this->getInput('conditiontype'), 'operator' => $this->getInput('operator'), 'tag' => $this->getInput('tag', ''), 'oldtag' => $this->getInput('oldtag', ''), 'newtag' => $this->getInput('newtag', ''), 'value' => $this->getInput('value', ''), 'groupids' => $this->hasInput('groupids') ? $this->getGroups($this->getInput('groupids')) : '', 'operator_name' => CCorrelationHelper::getLabelByOperator($this->getInput('operator')), 'user' => [ 'debug_mode' => $this->getDebugMode() ] ]; $this->setResponse(new CControllerResponseData(['main_block' => json_encode($output, JSON_THROW_ON_ERROR)])); } /** * Returns host group ID and name as key and value pair. * * @param array $groupids An array of groups IDs. * * @return array */ protected function getGroups(array $groupids): array { $groups = API::HostGroup()->get([ 'output' => ['groupid','name'], 'groupids' => $groupids, 'preservekeys' => true ]); return array_combine(array_keys($groups), array_column($groups, 'name')); } }