setPostContentType(self::POST_CONTENT_TYPE_JSON); } protected function checkInput(): bool { $fields = [ 'proxyids' => 'required|array_id' ]; $ret = $this->validateInput($fields); if (!$ret) { $this->setResponse( new CControllerResponseData(['main_block' => json_encode([ 'error' => [ 'messages' => array_column(get_and_clear_messages(), 'message') ] ])]) ); } return $ret; } protected function checkPermissions(): bool { if (!$this->checkAccess(CRoleHelper::UI_ADMINISTRATION_PROXIES)) { return false; } $num_proxies = API::Proxy()->get([ 'proxyids' => $this->getInput('proxyids'), 'countOutput' => true, 'editable' => true ]); return $num_proxies == count($this->getInput('proxyids')); } protected function doAction() { $result = (bool) API::Task()->create([ 'type' => ZBX_TM_DATA_TYPE_PROXYIDS, 'request' => [ 'proxyids' => $this->getInput('proxyids') ] ]); if ($result) { $output['success']['title'] = _('Request created successfully'); if ($messages = get_and_clear_messages()) { $output['success']['messages'] = array_column($messages, 'message'); } } else { $output['error'] = [ 'title' => _('Cannot create request'), 'messages' => array_column(get_and_clear_messages(), 'message') ]; } $this->setResponse(new CControllerResponseData(['main_block' => json_encode($output)])); } }