public function getHosts() { $hostsData = array(); if (!empty($this->data['hosts'])) { foreach ($this->data['hosts'] as $host) { $host = $this->renameData($host, array('proxyid' => 'proxy_hostid')); CArrayHelper::convertFieldToArray($host, 'interfaces'); if (!empty($host['interfaces'])) { foreach ($host['interfaces'] as $inum => $interface) { $host['interfaces'][$inum] = $this->renameData($interface, array('default' => 'main')); } } CArrayHelper::convertFieldToArray($host, 'templates'); if (empty($host['templates'])) { unset($host['templates']); } CArrayHelper::convertFieldToArray($host, 'macros'); CArrayHelper::convertFieldToArray($host, 'groups'); if (!empty($host['inventory']) && isset($host['inventory']['inventory_mode'])) { $host['inventory_mode'] = $host['inventory']['inventory_mode']; unset($host['inventory']['inventory_mode']); } else { $host['inventory_mode'] = HOST_INVENTORY_DISABLED; } $hostsData[] = CArrayHelper::getByKeys($host, array('inventory', 'proxy', 'groups', 'templates', 'macros', 'interfaces', 'host', 'status', 'ipmi_authtype', 'ipmi_privilege', 'ipmi_username', 'ipmi_password', 'name', 'inventory_mode')); } } return $hostsData; }
/** * Get hosts from the imported data. * * @return array */ public function getHosts() { $hosts = []; if (array_key_exists('hosts', $this->data)) { foreach ($this->data['hosts'] as $host) { $host = CArrayHelper::renameKeys($host, ['proxyid' => 'proxy_hostid']); if (array_key_exists('interfaces', $host)) { foreach ($host['interfaces'] as $inum => $interface) { $host['interfaces'][$inum] = CArrayHelper::renameKeys($interface, ['default' => 'main']); } } if (array_key_exists('inventory', $host)) { if (array_key_exists('inventory_mode', $host['inventory'])) { $host['inventory_mode'] = $host['inventory']['inventory_mode']; unset($host['inventory']['inventory_mode']); } else { $host['inventory_mode'] = HOST_INVENTORY_DISABLED; } } $hosts[] = CArrayHelper::getByKeys($host, ['inventory', 'proxy', 'groups', 'templates', 'macros', 'interfaces', 'host', 'status', 'description', 'ipmi_authtype', 'ipmi_privilege', 'ipmi_username', 'ipmi_password', 'name', 'inventory_mode', 'tls_connect', 'tls_accept', 'tls_issuer', 'tls_subject', 'tls_psk_identity', 'tls_psk']); } } return $hosts; }