"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DiscoveryTroubleshootingModal = exports.HostsNotShowingLink = exports.DiscoveryTroubleshootingModalContent = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_core_1 = require("@patternfly/react-core");
const info_circle_icon_1 = require("@patternfly/react-icons/dist/js/icons/info-circle-icon");
const ui_1 = require("../ui");
const use_translation_wrapper_1 = require("../../hooks/use-translation-wrapper");
const react_i18next_1 = require("react-i18next");
const file_saver_1 = require("file-saver");
const docs_links_1 = require("../../config/docs_links");
const Sentry = tslib_1.__importStar(require("@sentry/browser"));
const DiscoveryTroubleshootingModalContent = () => {
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const downloadIsoPasswordScript = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
        try {
            const response = yield fetch(docs_links_1.CHANGE_ISO_PASSWORD_FILE_LINK);
            const fileContent = yield response.text();
            const blob = new Blob([fileContent], { type: 'text/plain;charset=utf-8' });
            (0, file_saver_1.saveAs)(blob, 'change-iso-password.sh');
        }
        catch (error) {
            Sentry.captureException(error);
        }
    });
    return (react_1.default.createElement(react_core_1.List, { component: react_core_1.ListComponent.ol, type: react_core_1.OrderType.number },
        react_1.default.createElement(react_core_1.ListItem, null,
            react_1.default.createElement(react_core_1.Content, { component: "p" }, t('ai:The host machine is powered on')),
            react_1.default.createElement(react_core_1.HelperText, null,
                react_1.default.createElement(react_core_1.HelperTextItem, { "data-testid": "discovery-troubleshooting-boot-time-helper" }, t('ai:Boot time depends on several factors such as your hardware and network configuration, and if you are booting from an ISO.')))),
        react_1.default.createElement(react_core_1.ListItem, null,
            react_1.default.createElement(react_core_1.Content, { component: "p" }, t('ai:If you used DHCP networking, verify that your DHCP server is enabled'))),
        react_1.default.createElement(react_core_1.ListItem, null,
            react_1.default.createElement(react_core_1.Content, { component: "p" }, t('ai:If you used static IP, bridges, and bonds networking, verify that your configurations are correct'))),
        react_1.default.createElement(react_core_1.ListItem, null,
            react_1.default.createElement(react_core_1.Content, { component: "p" }, t('ai:SSH into your machine')),
            react_1.default.createElement(react_core_1.HelperText, null,
                react_1.default.createElement(react_core_1.HelperTextItem, { "data-testid": "discovery-troubleshooting-ssh-access-helper" }, t('ai:Verify that you can access your host machine using SSH, or a console such as BMC or virtual machine console. In the CLI, enter the following command:'))),
            react_1.default.createElement(ui_1.PrismCode, { code: "ssh -i <identity_file> core@<machine-ip>" }),
            react_1.default.createElement(react_core_1.HelperText, null,
                react_1.default.createElement(react_core_1.HelperTextItem, { "data-testid": "discovery-troubleshooting-ssh-auth-helper" }, t('ai:Authentication is provided by the discovery ISO, therefore when you access your host using SSH, a password is not required. Optional -i parameter can be used to specify the private key that matches the public key provided when generating Discovery ISO.')))),
        react_1.default.createElement(react_core_1.ListItem, null,
            react_1.default.createElement(react_core_1.Content, { component: "p" }, t('ai:Unable to SSH into your hosts through the network?')),
            react_1.default.createElement(react_core_1.HelperText, null,
                react_1.default.createElement(react_core_1.HelperTextItem, { "data-testid": "discovery-troubleshooting-ssh-alternative-helper" },
                    t('ai:Try logging into the machine directly through physical access, out-of-band management, or a virtual machine console. To generate a new bootable image file with password-based login enabled, download the full image file and patch it locally with a login password of your choice using'),
                    ' ',
                    react_1.default.createElement(react_core_1.Button, { variant: react_core_1.ButtonVariant.link, onClick: () => {
                            void downloadIsoPasswordScript();
                        }, "data-testid": "download-script-btn", isInline: true }, t('ai:this script.')))),
            react_1.default.createElement(react_core_1.HelperText, null,
                react_1.default.createElement(react_core_1.HelperTextItem, { "data-testid": "discovery-troubleshooting-script-usage-helper" }, t('ai:Run these commands to use the script:'))),
            react_1.default.createElement(ui_1.PrismCode, { code: `chmod +x ./change-iso-password.sh
./change-iso-password.sh <path_to_your_iso_file>` })),
        react_1.default.createElement(react_core_1.ListItem, null,
            react_1.default.createElement(react_core_1.Content, { component: "p" }, t('ai:The discovery agent is running with the correct parameters')),
            react_1.default.createElement(ui_1.PrismCode, { code: `ps -ef | grep agent` }),
            react_1.default.createElement(react_core_1.HelperText, null,
                react_1.default.createElement(react_core_1.HelperTextItem, { "data-testid": "discovery-troubleshooting-agent-output-helper" }, t('ai:The output displays the following:'))),
            react_1.default.createElement(ui_1.PrismCode, { code: `root        1786       1  0 08:03 ?        00:00:00 /usr/local/bin/agent --url https://api.openshift.com --cluster-id e4c85fbe-77c7-411e-b107-5120f615c4fb --agent-version registry.redhat.io/openshift4/assisted-installer-agent-rhel8:v4.6.0-17 --insecure=false
core        2362    2311  0 08:04 pts/0    00:00:00 grep --color=auto agent` })),
        react_1.default.createElement(react_core_1.ListItem, null,
            react_1.default.createElement(react_core_1.Content, { component: "p" }, t('ai:The agent ran successfully')),
            react_1.default.createElement(react_core_1.HelperText, null,
                react_1.default.createElement(react_core_1.HelperTextItem, { "data-testid": "discovery-troubleshooting-agent-logs-helper" }, t('ai:To verify that the agent ran successfully, check the logs:'))),
            react_1.default.createElement(ui_1.PrismCode, { code: "sudo journalctl -u agent.service" }),
            react_1.default.createElement(react_core_1.HelperText, null,
                react_1.default.createElement(react_core_1.HelperTextItem, { "data-testid": "discovery-troubleshooting-network-error-helper" }, t('ai:In the following example, the errors indicate there is a network issue:'))),
            react_1.default.createElement(ui_1.PrismCode, { styles: [], code: `Oct 15 11:26:35 localhost systemd[1]: agent.service: Service RestartSec=3s expired, scheduling restart.
Oct 15 11:26:35 localhost systemd[1]: agent.service: Scheduled restart job, restart counter is at 9.
Oct 15 11:26:35 localhost systemd[1]: Stopped agent.service.
Oct 15 11:26:35 localhost systemd[1]: Starting agent.service...
Oct 15 11:26:35 localhost podman[1834]: Trying to pull quay.io/ocpmetal/assisted-installer-agent:latest...
Oct 15 11:26:35 localhost podman[1834]:   Get "https://quay.io/v2/": dial tcp: lookup quay.io on [::1]:53: read udp [::1]:58297->[::1]:53: read: connection refused
Oct 15 11:26:35 localhost podman[1834]: Error: unable to pull quay.io/ocpmetal/assisted-installer-agent:latest: unable to pull image: Error initializing source docker://quay.io/ocpmetal/assisted-installer-agent:latest: error pinging dock>
Oct 15 11:26:35 localhost systemd[1]: agent.service: Control process exited, code=exited status=125
Oct 15 11:26:35 localhost systemd[1]: agent.service: Failed with result 'exit-code'.
Oct 15 11:26:35 localhost systemd[1]: Failed to start agent.service.` }),
            react_1.default.createElement(react_core_1.HelperText, null,
                react_1.default.createElement(react_core_1.HelperTextItem, { "data-testid": "discovery-troubleshooting-proxy-network-helper" },
                    react_1.default.createElement(react_i18next_1.Trans, { t: t, components: { code: react_1.default.createElement("code", null) }, i18nKey: "ai:Check the proxy settings and verify that the assisted installer service is connected to a network. You can use <code>nmcli</code> to get additional information about your network configuration." })))),
        react_1.default.createElement(react_core_1.ListItem, null,
            react_1.default.createElement(react_core_1.Content, { component: "p" }, t('ai:Check agent logs')),
            react_1.default.createElement(react_core_1.HelperText, null,
                react_1.default.createElement(react_core_1.HelperTextItem, { "data-testid": "discovery-troubleshooting-detailed-logs-helper" }, t('ai:To view detailed agent logs and communication use following command:'))),
            react_1.default.createElement(ui_1.PrismCode, { code: "sudo journalctl TAG=agent | less" })),
        react_1.default.createElement(react_core_1.ListItem, null,
            react_1.default.createElement(react_core_1.Content, { component: "p" }, t('ai:Check assisted-installer logs')),
            react_1.default.createElement(ui_1.PrismCode, { code: `sudo su
podman ps -a | grep assisted-installer
podman logs <container id>` })),
        react_1.default.createElement(react_core_1.ListItem, null,
            react_1.default.createElement(react_core_1.Content, { component: "p" }, t('ai:Check bootkube logs')),
            react_1.default.createElement(ui_1.PrismCode, { code: `sudo journalctl -u bootkube` }))));
};
exports.DiscoveryTroubleshootingModalContent = DiscoveryTroubleshootingModalContent;
const HostsNotShowingLink = ({ setDiscoveryHintModalOpen, isSNO = false, isInline = false, }) => {
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    return (react_1.default.createElement(react_core_1.Button, { variant: react_core_1.ButtonVariant.link, onClick: () => setDiscoveryHintModalOpen(true), isInline: true },
        !isInline && (react_1.default.createElement(react_1.default.Fragment, null,
            react_1.default.createElement(react_core_1.Icon, { size: "sm" },
                react_1.default.createElement(info_circle_icon_1.InfoCircleIcon, null)),
            "\u00A0")),
        t('ai:Host not showing up?', { count: +isSNO })));
};
exports.HostsNotShowingLink = HostsNotShowingLink;
const DiscoveryTroubleshootingModal = ({ setDiscoveryHintModalOpen, isOpen, }) => {
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const onClose = react_1.default.useCallback(() => setDiscoveryHintModalOpen(false), [setDiscoveryHintModalOpen]);
    return (react_1.default.createElement(react_core_1.Modal, { isOpen: isOpen, onClose: onClose, variant: react_core_1.ModalVariant.large },
        react_1.default.createElement(react_core_1.ModalHeader, { title: t('ai:Hosts not showing up troubleshooter') }),
        react_1.default.createElement(react_core_1.ModalBody, null,
            react_1.default.createElement(exports.DiscoveryTroubleshootingModalContent, null)),
        react_1.default.createElement(react_core_1.ModalFooter, null,
            react_1.default.createElement(react_core_1.Button, { key: "close", variant: react_core_1.ButtonVariant.primary, onClick: onClose }, t('ai:Close')))));
};
exports.DiscoveryTroubleshootingModal = DiscoveryTroubleshootingModal;
//# sourceMappingURL=DiscoveryTroubleshootingModal.js.map