<?php declare(strict_types = 0);
class CControllerHostCreate extends CControllerHostUpdateGeneral {
protected function checkInput(): bool {
$ret = $this->validateInput(self::getValidationFields());
new CControllerResponseData(['main_block' => json_encode([
'title' => _('Cannot add host'),
'messages' => array_column(get_and_clear_messages(), 'message')
protected function checkPermissions(): bool {
if (!$this->checkAccess(CRoleHelper::UI_CONFIGURATION_HOSTS)) {
if ($this->hasInput('clone_hostid') && $this->hasInput('clone')) {
$hosts = API::Host()->get([
'hostids' => $this->getInput('clone_hostid')
protected function doAction(): void {
'status' => $this->getInput('status', HOST_STATUS_NOT_MONITORED),
'monitored_by' => $this->getInput('monitored_by', ZBX_MONITORED_BY_SERVER),
'groups' => $this->processHostGroups($this->getInput('groups', [])),
'interfaces' => $this->processHostInterfaces($this->getInput('interfaces', [])),
'tags' => $this->processTags($this->getInput('tags', [])),
'templates' => $this->processTemplates([
$this->getInput('add_templates', []), $this->getInput('templates', [])
'macros' => $this->processUserMacros($this->getInput('macros', [])),
'inventory' => ($this->getInput('inventory_mode', HOST_INVENTORY_DISABLED) != HOST_INVENTORY_DISABLED)
? $this->getInput('host_inventory', [])
'tls_connect' => $this->getInput('tls_connect', HOST_ENCRYPTION_NONE),
'tls_accept' => $this->getInput('tls_accept', HOST_ENCRYPTION_NONE)
if ($host['monitored_by'] == ZBX_MONITORED_BY_PROXY) {
$host['proxyid'] = $this->getInput('proxyid', 0);
elseif ($host['monitored_by'] == ZBX_MONITORED_BY_PROXY_GROUP) {
$host['proxy_groupid'] = $this->getInput('proxy_groupid', 0);
$this->getInputs($host, [
'host', 'visiblename', 'description', 'ipmi_authtype', 'ipmi_privilege', 'ipmi_username',
'ipmi_password', 'tls_subject', 'tls_issuer', 'tls_psk_identity', 'tls_psk', 'inventory_mode'