| 1 |
/* |
| 2 |
* Copyright (C) 2016 Red Hat, Inc. |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
import '../lib/patternfly/patternfly-6-cockpit.scss'; |
| 7 |
import cockpit from "cockpit"; |
| 8 |
|
| 9 |
import React, { useEffect, useState } from "react"; |
| 10 |
import { Alert } from "@patternfly/react-core/dist/esm/components/Alert/index.js"; |
| 11 |
import { Button } from "@patternfly/react-core/dist/esm/components/Button/index.js"; |
| 12 |
import { Checkbox } from "@patternfly/react-core/dist/esm/components/Checkbox/index.js"; |
| 13 |
import { Card, CardBody, CardTitle } from "@patternfly/react-core/dist/esm/components/Card/index.js"; |
| 14 |
import { HelperText, HelperTextItem } from "@patternfly/react-core/dist/esm/components/HelperText/index.js"; |
| 15 |
import { Flex, FlexItem } from "@patternfly/react-core/dist/esm/layouts/Flex/index.js"; |
| 16 |
import { Form, FormGroup, FormSection } from "@patternfly/react-core/dist/esm/components/Form/index.js"; |
| 17 |
import { FormSelect, FormSelectOption } from "@patternfly/react-core/dist/esm/components/FormSelect/index.js"; |
| 18 |
import { Page, PageSection } from "@patternfly/react-core/dist/esm/components/Page/index.js"; |
| 19 |
import { CodeBlockCode } from "@patternfly/react-core/dist/esm/components/CodeBlock/index.js"; |
| 20 |
import { DescriptionList, DescriptionListDescription, DescriptionListGroup, DescriptionListTerm } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js"; |
| 21 |
import { |
| 22 |
Modal, ModalBody, ModalFooter, ModalHeader |
| 23 |
} from '@patternfly/react-core/dist/esm/components/Modal/index.js'; |
| 24 |
import { Spinner } from "@patternfly/react-core/dist/esm/components/Spinner/index.js"; |
| 25 |
import { Switch } from "@patternfly/react-core/dist/esm/components/Switch/index.js"; |
| 26 |
import { Content, ContentVariants } from "@patternfly/react-core/dist/esm/components/Content/index.js"; |
| 27 |
import { TextInput } from "@patternfly/react-core/dist/esm/components/TextInput/index.js"; |
| 28 |
import { Title } from "@patternfly/react-core/dist/esm/components/Title/index.js"; |
| 29 |
import { Tooltip } from "@patternfly/react-core/dist/esm/components/Tooltip/index.js"; |
| 30 |
|
| 31 |
import { useDialogs, DialogsContext } from "dialogs.jsx"; |
| 32 |
import { read_os_release } from "os-release.js"; |
| 33 |
import { fmt_to_fragments } from 'utils.jsx'; |
| 34 |
import { FormHelper } from "cockpit-components-form-helper"; |
| 35 |
import { ModalError } from 'cockpit-components-inline-notification.jsx'; |
| 36 |
import { PrivilegedButton } from "cockpit-components-privileged"; |
| 37 |
import { ModificationsExportDialog } from "cockpit-components-modifications"; |
| 38 |
|
| 39 |
const _ = cockpit.gettext; |
| 40 |
const DEFAULT_KDUMP_PATH = "/var/crash"; |
| 41 |
|
| 42 |
const exportAnsibleTask = (settings, os_release) => { |
| 43 |
const target = Object.keys(settings.targets)[0]; |
| 44 |
const targetSettings = settings.targets[target]; |
| 45 |
const kdump_core_collector = settings.core_collector; |
| 46 |
|
| 47 |
let role_name = "linux-system-roles"; |
| 48 |
if (os_release?.PLATFORM_ID?.startsWith('platform:el') || os_release.ID_LIKE?.includes('rhel')) { |
| 49 |
role_name = "rhel-system-roles"; |
| 50 |
} |
| 51 |
|
| 52 |
let ansible = ` |
| 53 |
--- |
| 54 |
# Also available via https://galaxy.ansible.com/ui/standalone/roles/linux-system-roles/kdump/ |
| 55 |
- name: install ${role_name} |
| 56 |
package: |
| 57 |
name: ${role_name} |
| 58 |
state: present |
| 59 |
delegate_to: 127.0.0.1 |
| 60 |
become: true |
| 61 |
- name: run kdump system role |
| 62 |
include_role: |
| 63 |
name: ${role_name}.kdump |
| 64 |
vars: |
| 65 |
kdump_path: ${targetSettings.path || DEFAULT_KDUMP_PATH} |
| 66 |
kdump_core_collector: ${kdump_core_collector}`; |
| 67 |
|
| 68 |
if (target === "ssh") { |
| 69 |
// HACK: we should not have to specify kdump_ssh_user and kdump_ssh_user as it is in kdump_target.location |
| 70 |
// https://github.com/linux-system-roles/kdump/issues/184 |
| 71 |
let ssh_user; |
| 72 |
let ssh_server; |
| 73 |
const parts = targetSettings.server.split('@'); |
| 74 |
if (parts.length === 1) { |
| 75 |
ssh_user = "root"; |
| 76 |
ssh_server = parts[0]; |
| 77 |
} else if (parts.length === 2) { |
| 78 |
ssh_user = parts[0]; |
| 79 |
ssh_server = parts[1]; |
| 80 |
} else { |
| 81 |
throw new Error("ssh server contains two @ symbols"); |
| 82 |
} |
| 83 |
ansible += ` |
| 84 |
kdump_target: |
| 85 |
type: ssh |
| 86 |
kdump_sshkey: ${targetSettings.sshkey} |
| 87 |
kdump_ssh_server: ${ssh_server} |
| 88 |
kdump_ssh_user: ${ssh_user}`; |
| 89 |
} else if (target === "nfs") { |
| 90 |
ansible += ` |
| 91 |
kdump_target: |
| 92 |
type: nfs |
| 93 |
location: ${targetSettings.server}:${targetSettings.export} |
| 94 |
`; |
| 95 |
} else if (target !== "local") { |
| 96 |
// target is unsupported |
| 97 |
throw new Error("Unsupported kdump target"); // not-covered: assertion |
| 98 |
} |
| 99 |
|
| 100 |
return ansible; |
| 101 |
}; |
| 102 |
|
| 103 |
function getLocation(target, config) { |
| 104 |
let path = target.path || DEFAULT_KDUMP_PATH; |
| 105 |
|
| 106 |
if (target.type === "ssh") { |
| 107 |
path = `${target.server}:${path}`; |
| 108 |
} else if (target.type == "nfs") { |
| 109 |
if (!config.nfs_supports_directory) { |
| 110 |
path = ''; |
| 111 |
} |
| 112 |
path = path[0] !== '/' ? '/' + path : path; |
| 113 |
path = `${target.server}:${target.export + path}`; |
| 114 |
} |
| 115 |
|
| 116 |
return path; |
| 117 |
} |
| 118 |
|
| 119 |
const KdumpSettingsModal = ({ settings, initialTarget, handleSave }) => { |
| 120 |
const Dialogs = useDialogs(); |
| 121 |
const compressionAllowed = settings.compression?.allowed; |
| 122 |
const [isSaving, setIsSaving] = useState(false); |
| 123 |
const [error, setError] = useState(null); |
| 124 |
const [isFormValid, setFormValid] = useState(true); |
| 125 |
const [validationErrors, setValidationErrors] = useState({}); |
| 126 |
|
| 127 |
const [storageLocation, setStorageLocation] = useState(Object.keys(settings.targets)[0]); |
| 128 |
// common options |
| 129 |
const [compressionEnabled, setCompressionEnabled] = useState(settings.compression?.enabled); |
| 130 |
const [directory, setDirectory] = useState(initialTarget.path || DEFAULT_KDUMP_PATH); |
| 131 |
// nfs and ssh |
| 132 |
const [server, setServer] = useState(settings.targets.nfs?.server || settings.targets.ssh?.server); |
| 133 |
// nfs |
| 134 |
const [exportPath, setExportPath] = useState(settings.targets.nfs?.export || ""); |
| 135 |
// ssh |
| 136 |
const [sshkey, setSSHKey] = useState(settings.targets.ssh?.sshkey || ""); |
| 137 |
|
| 138 |
useEffect(() => { |
| 139 |
// We can't use a ref in a functional component |
| 140 |
const elem = document.querySelector("#kdump-settings-form"); |
| 141 |
if (elem) |
| 142 |
setFormValid(elem.checkValidity()); |
| 143 |
}, [storageLocation, directory, sshkey, server, exportPath]); |
| 144 |
|
| 145 |
const changeStorageLocation = target => { |
| 146 |
setError(null); |
| 147 |
setDirectory(DEFAULT_KDUMP_PATH); |
| 148 |
setServer(""); |
| 149 |
setStorageLocation(target); |
| 150 |
}; |
| 151 |
|
| 152 |
const changeSSHKey = value => { |
| 153 |
if (value.trim() && !value.match("/.+")) { |
| 154 |
setValidationErrors({ sshkey: _("SSH key isn't a path") }); |
| 155 |
} else { |
| 156 |
setValidationErrors({}); |
| 157 |
} |
| 158 |
setSSHKey(value); |
| 159 |
}; |
| 160 |
|
| 161 |
const saveSettings = () => { |
| 162 |
setError(null); |
| 163 |
setIsSaving(true); |
| 164 |
const newSettings = { |
| 165 |
compression: { |
| 166 |
allowed: compressionAllowed, |
| 167 |
enabled: compressionEnabled, |
| 168 |
}, |
| 169 |
targets: { |
| 170 |
[storageLocation]: { |
| 171 |
type: storageLocation, |
| 172 |
// HACK: to not needlessly write a path /var/crash as this is the default, |
| 173 |
// set an empty string. |
| 174 |
path: directory === DEFAULT_KDUMP_PATH ? "" : directory, |
| 175 |
} |
| 176 |
}, |
| 177 |
_internal: { |
| 178 |
...settings._internal |
| 179 |
} |
| 180 |
}; |
| 181 |
|
| 182 |
if (storageLocation === "ssh") { |
| 183 |
newSettings.targets.ssh.server = server; |
| 184 |
newSettings.targets.ssh.sshkey = sshkey; |
| 185 |
} |
| 186 |
|
| 187 |
if (storageLocation === "nfs") { |
| 188 |
newSettings.targets.nfs.server = server; |
| 189 |
newSettings.targets.nfs.export = exportPath; |
| 190 |
} |
| 191 |
|
| 192 |
handleSave(newSettings) |
| 193 |
.then(Dialogs.close) |
| 194 |
.finally(() => setIsSaving(false)) |
| 195 |
.catch(error => { |
| 196 |
if (error.details) { |
| 197 |
// avoid bad summary like "systemd job RestartUnit ["kdump.service","replace"] failed with result failed" |
| 198 |
// if we have a more concrete journal and trim journal's `kdump: ` prefix. |
| 199 |
error.message = _("Unable to save settings"); |
| 200 |
error.details = <CodeBlockCode>{ error.details.replaceAll(/\nkdump: /g, "\n") }</CodeBlockCode>; |
| 201 |
setError(error); |
| 202 |
} else { |
| 203 |
// without a journal, show the error as-is |
| 204 |
setError(new Error(cockpit.format(_("Unable to save settings: $0"), String(error)))); |
| 205 |
} |
| 206 |
}); |
| 207 |
}; |
| 208 |
|
| 209 |
return ( |
| 210 |
<Modal position="top" variant="small" id="kdump-settings-dialog" isOpen |
| 211 |
onClose={Dialogs.close}> |
| 212 |
<ModalHeader title={_("Crash dump location")} /> |
| 213 |
<ModalBody> |
| 214 |
{error && <ModalError isExpandable |
| 215 |
dialogError={error.message || error} |
| 216 |
dialogErrorDetail={error.details} />} |
| 217 |
<Form id="kdump-settings-form" isHorizontal> |
| 218 |
<FormGroup fieldId="kdump-settings-location" label={_("Location")}> |
| 219 |
<FormSelect key="location" onChange={(_, val) => changeStorageLocation(val)} |
| 220 |
id="kdump-settings-location" value={storageLocation}> |
| 221 |
<FormSelectOption value='local' |
| 222 |
label={_("Local filesystem")} /> |
| 223 |
<FormSelectOption value='ssh' |
| 224 |
label={_("Remote over SSH")} /> |
| 225 |
<FormSelectOption value='nfs' |
| 226 |
label={_("Remote over NFS")} /> |
| 227 |
</FormSelect> |
| 228 |
</FormGroup> |
| 229 |
|
| 230 |
{storageLocation === "local" && |
| 231 |
<FormGroup fieldId="kdump-settings-local-directory" label={_("Directory")} isRequired> |
| 232 |
<TextInput id="kdump-settings-local-directory" key="directory" |
| 233 |
placeholder={DEFAULT_KDUMP_PATH} value={directory} |
| 234 |
data-stored={directory} |
| 235 |
onChange={(_event, value) => setDirectory(value)} |
| 236 |
isRequired /> |
| 237 |
</FormGroup> |
| 238 |
} |
| 239 |
|
| 240 |
{storageLocation === "nfs" && |
| 241 |
<> |
| 242 |
<FormGroup fieldId="kdump-settings-nfs-server" label={_("Server")} isRequired> |
| 243 |
<TextInput id="kdump-settings-nfs-server" key="server" |
| 244 |
placeholder="penguin.example.com" value={server} |
| 245 |
onChange={(_event, value) => setServer(value)} isRequired /> |
| 246 |
</FormGroup> |
| 247 |
<FormGroup fieldId="kdump-settings-nfs-export" label={_("Export")} isRequired> |
| 248 |
<TextInput id="kdump-settings-nfs-export" key="export" |
| 249 |
placeholder="/export/cores" value={exportPath} |
| 250 |
onChange={(_event, value) => setExportPath(value)} isRequired /> |
| 251 |
</FormGroup> |
| 252 |
{settings.nfs_supports_directory && |
| 253 |
<FormGroup fieldId="kdump-settings-nfs-directory" label={_("Directory")} isRequired> |
| 254 |
<TextInput id="kdump-settings-nfs-directory" key="directory" |
| 255 |
placeholder={DEFAULT_KDUMP_PATH} value={directory} |
| 256 |
data-stored={directory} |
| 257 |
onChange={(_event, value) => setDirectory(value)} |
| 258 |
isRequired /> |
| 259 |
</FormGroup> |
| 260 |
} |
| 261 |
</> |
| 262 |
} |
| 263 |
|
| 264 |
{storageLocation === "ssh" && |
| 265 |
<> |
| 266 |
<FormGroup fieldId="kdump-settings-ssh-server" label={_("Server")} isRequired> |
| 267 |
<TextInput id="kdump-settings-ssh-server" key="server" |
| 268 |
placeholder="[email protected]" value={server} |
| 269 |
onChange={(_event, value) => setServer(value)} isRequired /> |
| 270 |
</FormGroup> |
| 271 |
|
| 272 |
<FormGroup fieldId="kdump-settings-ssh-key" label={_("SSH key")}> |
| 273 |
<TextInput id="kdump-settings-ssh-key" key="ssh" |
| 274 |
placeholder="/root/.ssh/kdump_id_rsa" value={sshkey} |
| 275 |
onChange={(_event, value) => changeSSHKey(value)} |
| 276 |
validated={validationErrors.sshkey ? "error" : "default"} /> |
| 277 |
<FormHelper helperTextInvalid={validationErrors.sshkey} /> |
| 278 |
</FormGroup> |
| 279 |
|
| 280 |
<FormGroup fieldId="kdump-settings-ssh-directory" label={_("Directory")} isRequired> |
| 281 |
<TextInput id="kdump-settings-ssh-directory" key="directory" |
| 282 |
placeholder={DEFAULT_KDUMP_PATH} value={directory} |
| 283 |
data-stored={directory} |
| 284 |
onChange={(_event, value) => setDirectory(value)} |
| 285 |
isRequired /> |
| 286 |
</FormGroup> |
| 287 |
</> |
| 288 |
} |
| 289 |
|
| 290 |
<FormSection> |
| 291 |
<FormGroup fieldId="kdump-settings-compression" label={_("Compression")} hasNoPaddingTop> |
| 292 |
<Checkbox id="kdump-settings-compression" |
| 293 |
isChecked={compressionEnabled} |
| 294 |
onChange={(_, c) => setCompressionEnabled(c)} |
| 295 |
isDisabled={!compressionAllowed} |
| 296 |
label={_("Compress crash dumps to save space")} /> |
| 297 |
</FormGroup> |
| 298 |
</FormSection> |
| 299 |
</Form> |
| 300 |
</ModalBody> |
| 301 |
<ModalFooter> |
| 302 |
<Button variant="primary" |
| 303 |
isLoading={isSaving} |
| 304 |
isDisabled={isSaving || !isFormValid || Object.keys(validationErrors).length !== 0} |
| 305 |
onClick={saveSettings}> |
| 306 |
{_("Save changes")} |
| 307 |
</Button> |
| 308 |
<Button variant="link" |
| 309 |
isDisabled={isSaving} |
| 310 |
className="cancel" |
| 311 |
onClick={Dialogs.close}> |
| 312 |
{_("Cancel")} |
| 313 |
</Button> |
| 314 |
</ModalFooter> |
| 315 |
</Modal>); |
| 316 |
}; |
| 317 |
|
| 318 |
const KdumpTestDialog = ({ verifyMessage, onCrashKernel }) => { |
| 319 |
const Dialogs = useDialogs(); |
| 320 |
const [task, setTask] = useState(null); |
| 321 |
const [error, setError] = useState(null); |
| 322 |
|
| 323 |
function crash() { |
| 324 |
setError(null); |
| 325 |
setTask(onCrashKernel() |
| 326 |
.then(Dialogs.close) |
| 327 |
.catch(error => { |
| 328 |
setTask(null); |
| 329 |
setError(error); |
| 330 |
})); |
| 331 |
} |
| 332 |
|
| 333 |
return ( |
| 334 |
<Modal position="top" variant="small" id="kdump-test-dialog" isOpen |
| 335 |
onClose={Dialogs.close}> |
| 336 |
<ModalHeader title={_("Test kdump settings")} titleIconVariant="warning" /> |
| 337 |
<ModalBody> |
| 338 |
{error && <ModalError dialogError={error.message || error} />} |
| 339 |
<Content> |
| 340 |
<Content component={ContentVariants.p}> |
| 341 |
{_("Test kdump settings by crashing the kernel. This may take a while and the system might not automatically reboot. Do not purposefully crash the system while any important task is running.")} |
| 342 |
</Content> |
| 343 |
{verifyMessage && <Content component={ContentVariants.p}> |
| 344 |
{verifyMessage} |
| 345 |
</Content>} |
| 346 |
</Content> |
| 347 |
</ModalBody> |
| 348 |
<ModalFooter> |
| 349 |
<Button variant="danger" |
| 350 |
isLoading={!!task} |
| 351 |
isDisabled={!!task} |
| 352 |
onClick={crash}> |
| 353 |
{_("Crash system")} |
| 354 |
</Button> |
| 355 |
<Button variant="link" |
| 356 |
isDisabled={!!task} |
| 357 |
onClick={Dialogs.close}> |
| 358 |
{_("Cancel")} |
| 359 |
</Button> |
| 360 |
</ModalFooter> |
| 361 |
</Modal>); |
| 362 |
}; |
| 363 |
|
| 364 |
/* Show kdump status of the system and offer options to change or test the state |
| 365 |
* Expected properties: |
| 366 |
* kdumpActive kdump service status |
| 367 |
* onSetServiceState called when the OnOff state is toggled (for kdumpActive), parameter: desired state |
| 368 |
* stateChanging whether we're currently waiting for our last change to take effect |
| 369 |
* onSaveSettings called with current dialog settings when the user clicks Save |
| 370 |
* kdumpStatus object as described in kdump-client |
| 371 |
* reservedMemory memory reserved at boot time for kdump use |
| 372 |
* onCrashKernel callback to crash the kernel via kdumpClient, expects a promise |
| 373 |
*/ |
| 374 |
export class KdumpPage extends React.Component { |
| 375 |
static contextType = DialogsContext; |
| 376 |
|
| 377 |
constructor(props) { |
| 378 |
super(props); |
| 379 |
this.state = { os_release: null }; |
| 380 |
|
| 381 |
this.handleTestSettingsClick = this.handleTestSettingsClick.bind(this); |
| 382 |
this.handleSettingsClick = this.handleSettingsClick.bind(this); |
| 383 |
this.handleAutomationClick = this.handleAutomationClick.bind(this); |
| 384 |
read_os_release().then(os_release => this.setState({ os_release })); |
| 385 |
} |
| 386 |
|
| 387 |
handleTestSettingsClick() { |
| 388 |
const Dialogs = this.context; |
| 389 |
// if we have multiple targets defined, the config is invalid |
| 390 |
const target = this.props.kdumpStatus.target; |
| 391 |
let verifyMessage; |
| 392 |
if (!target.multipleTargets) { |
| 393 |
const path = getLocation(target, this.props.kdumpStatus.config); |
| 394 |
if (target.type === "local") { |
| 395 |
verifyMessage = fmt_to_fragments( |
| 396 |
' ' + _("Results of the crash will be stored in $0 as $1, if kdump is properly configured."), |
| 397 |
<span className="pf-v6-u-font-family-monospace-vf">{path}</span>, |
| 398 |
<span className="pf-v6-u-font-family-monospace-vf">vmcore</span>); |
| 399 |
} else if (target.type === "ssh" || target.type == "nfs") { |
| 400 |
verifyMessage = fmt_to_fragments( |
| 401 |
' ' + _("Results of the crash will be copied through $0 to $1 as $2, if kdump is properly configured."), |
| 402 |
<span className="pf-v6-u-font-family-monospace-vf">{target.type === "ssh" ? "SSH" : "NFS"}</span>, |
| 403 |
<span className="pf-v6-u-font-family-monospace-vf">{path}</span>, |
| 404 |
<span className="pf-v6-u-font-family-monospace-vf">vmcore</span>); |
| 405 |
} |
| 406 |
} |
| 407 |
|
| 408 |
Dialogs.show(<KdumpTestDialog verifyMessage={verifyMessage} |
| 409 |
onCrashKernel={this.props.onCrashKernel} />); |
| 410 |
} |
| 411 |
|
| 412 |
handleServiceDetailsClick() { |
| 413 |
cockpit.jump("/system/services#/kdump.service", cockpit.transport.host); |
| 414 |
} |
| 415 |
|
| 416 |
handleSettingsClick() { |
| 417 |
const Dialogs = this.context; |
| 418 |
Dialogs.show(<KdumpSettingsModal settings={this.props.kdumpStatus.config} |
| 419 |
initialTarget={this.props.kdumpStatus.target} |
| 420 |
handleSave={this.props.onSaveSettings} />); |
| 421 |
} |
| 422 |
|
| 423 |
handleAutomationClick() { |
| 424 |
const Dialogs = this.context; |
| 425 |
let enableCrashKernel = ''; |
| 426 |
let kdumpconf = this.props.exportConfig(this.props.kdumpStatus.config); |
| 427 |
kdumpconf = kdumpconf.replaceAll('$', '\\$'); |
| 428 |
if (this.state.os_release.NAME?.includes('Fedora')) { |
| 429 |
enableCrashKernel = ` |
| 430 |
# A reboot will be required if crashkernel was not set before |
| 431 |
kdumpctl reset-crashkernel`; |
| 432 |
} |
| 433 |
let shell; |
| 434 |
if (this.state.os_release.NAME?.includes('MicroOS')) { |
| 435 |
enableCrashKernel = ` |
| 436 |
# A reboot will be required if crashkernel was not set before |
| 437 |
transactional-update setup-kdump`; |
| 438 |
shell = ` |
| 439 |
cat > /etc/kdump.conf << EOF |
| 440 |
${kdumpconf} |
| 441 |
EOF |
| 442 |
${enableCrashKernel} |
| 443 |
`; |
| 444 |
} else { |
| 445 |
shell = ` |
| 446 |
cat > /etc/kdump.conf << EOF |
| 447 |
${kdumpconf} |
| 448 |
EOF |
| 449 |
systemctl enable --now kdump.service |
| 450 |
${enableCrashKernel} |
| 451 |
`; |
| 452 |
} |
| 453 |
|
| 454 |
Dialogs.show( |
| 455 |
<ModificationsExportDialog |
| 456 |
ansible={ this.state.os_release.NAME?.includes('MicroOS') ? null : exportAnsibleTask(this.props.kdumpStatus.config, this.state.os_release)} |
| 457 |
shell={shell} |
| 458 |
onClose={Dialogs.close} |
| 459 |
/>); |
| 460 |
} |
| 461 |
|
| 462 |
render() { |
| 463 |
let kdumpLocation = ( |
| 464 |
<div className="dialog-wait-ct"> |
| 465 |
<Spinner size="md" /> |
| 466 |
<span>{ _("Loading...") }</span> |
| 467 |
</div> |
| 468 |
); |
| 469 |
let targetCanChange = false; |
| 470 |
if (this.props.kdumpStatus && this.props.kdumpStatus.target) { |
| 471 |
// if we have multiple targets defined, the config is invalid |
| 472 |
const target = this.props.kdumpStatus.target; |
| 473 |
if (target.multipleTargets) { |
| 474 |
kdumpLocation = _("invalid: multiple targets defined"); |
| 475 |
} else { |
| 476 |
const locationPath = getLocation(target, this.props.kdumpStatus.config); |
| 477 |
if (target.type == "local") { |
| 478 |
kdumpLocation = cockpit.format(_("Local, $0"), locationPath); |
| 479 |
targetCanChange = true; |
| 480 |
} else if (target.type == "ssh") { |
| 481 |
kdumpLocation = cockpit.format(_("Remote over SSH, $0"), locationPath); |
| 482 |
targetCanChange = true; |
| 483 |
} else if (target.type == "nfs") { |
| 484 |
kdumpLocation = cockpit.format(_("Remote over NFS, $0"), locationPath); |
| 485 |
targetCanChange = true; |
| 486 |
} else if (target.type == "raw") { |
| 487 |
kdumpLocation = _("Raw to a device"); |
| 488 |
} else if (target.type == "mount") { |
| 489 |
/* mount targets outside of nfs are too complex for the |
| 490 |
* current target dialog */ |
| 491 |
kdumpLocation = _("On a mounted device"); |
| 492 |
} else if (target.type == "ftp") { |
| 493 |
kdumpLocation = _("Remote over FTP"); |
| 494 |
} else if (target.type == "sftp") { |
| 495 |
kdumpLocation = _("Remote over SFTP"); |
| 496 |
} else if (target.type == "cifs") { |
| 497 |
kdumpLocation = _("Remote over CIFS/SMB"); |
| 498 |
} else { |
| 499 |
kdumpLocation = _("No configuration found"); |
| 500 |
} |
| 501 |
} |
| 502 |
} |
| 503 |
// this.storeLocation(this.props.kdumpStatus.config); |
| 504 |
const settingsLink = targetCanChange && <Button variant="link" isInline id="kdump-change-target" onClick={this.handleSettingsClick}>{_("Edit")}</Button>; |
| 505 |
let reservedMemory; |
| 506 |
if (this.props.reservedMemory === undefined) { |
| 507 |
// still waiting for result |
| 508 |
reservedMemory = ( |
| 509 |
<div className="dialog-wait-ct"> |
| 510 |
<Spinner size="md" /> |
| 511 |
<span>{ _("Reading...") }</span> |
| 512 |
</div> |
| 513 |
); |
| 514 |
} else if (this.props.reservedMemory === 0) { |
| 515 |
// nothing reserved |
| 516 |
reservedMemory = <span>{_("None")} </span>; |
| 517 |
} else if (Number.isInteger(this.props.reservedMemory)) { |
| 518 |
// TODO: hint at using debug_mem_level to identify actual memory required? |
| 519 |
reservedMemory = <span>{cockpit.format_bytes(this.props.reservedMemory, { base2: true })}</span>; |
| 520 |
} else { |
| 521 |
// error while reading |
| 522 |
reservedMemory = null; |
| 523 |
} |
| 524 |
|
| 525 |
const serviceRunning = this.props.kdumpStatus?.target && |
| 526 |
this.props.kdumpStatus?.installed && |
| 527 |
this.props.kdumpStatus?.state === "running"; |
| 528 |
|
| 529 |
let testButton; |
| 530 |
if (serviceRunning) { |
| 531 |
testButton = ( |
| 532 |
<PrivilegedButton variant="secondary" isDanger |
| 533 |
excuse={ _("The user $0 is not permitted to test crash the kernel") } |
| 534 |
onClick={this.handleTestSettingsClick}> |
| 535 |
{ _("Test configuration") } |
| 536 |
</PrivilegedButton> |
| 537 |
); |
| 538 |
} else { |
| 539 |
const tooltip = _("Test is only available while the kdump service is running."); |
| 540 |
testButton = ( |
| 541 |
<Tooltip id="tip-test" content={tooltip}> |
| 542 |
<Button variant="secondary" isDanger isAriaDisabled> |
| 543 |
{_("Test configuration")} |
| 544 |
</Button> |
| 545 |
</Tooltip> |
| 546 |
); |
| 547 |
} |
| 548 |
|
| 549 |
let automationButton = null; |
| 550 |
if (this.props.kdumpStatus && this.props.kdumpStatus.config !== null && this.state.os_release !== null && targetCanChange) { |
| 551 |
automationButton = ( |
| 552 |
<FlexItem align={{ md: 'alignRight' }}> |
| 553 |
<Button id="kdump-automation-script" variant="secondary" onClick={this.handleAutomationClick}> |
| 554 |
{_("View automation script")} |
| 555 |
</Button> |
| 556 |
</FlexItem> |
| 557 |
); |
| 558 |
} |
| 559 |
|
| 560 |
let kdumpSwitch; |
| 561 |
let kdumpSwitchHelper; |
| 562 |
if (!this.props.kdumpCmdlineEnabled) { |
| 563 |
kdumpSwitchHelper = _("Currently not supported"); |
| 564 |
} else { |
| 565 |
kdumpSwitch = (<Switch isChecked={!!serviceRunning} |
| 566 |
onChange={this.props.onSetServiceState} |
| 567 |
aria-label={_("kdump status")} |
| 568 |
label={serviceRunning ? _("Enabled") : _("Disabled")} |
| 569 |
isDisabled={this.props.stateChanging} />); |
| 570 |
} |
| 571 |
|
| 572 |
let alertMessage; |
| 573 |
let alertDetail; |
| 574 |
if (!this.props.stateChanging && this.props.kdumpStatus && this.props.kdumpStatus.installed !== undefined) { |
| 575 |
if (this.props.kdumpStatus.installed) { |
| 576 |
if (this.props.reservedMemory == 0) { |
| 577 |
alertMessage = fmt_to_fragments( |
| 578 |
_("Kernel did not boot with the $0 setting"), |
| 579 |
<span className="pf-v6-u-font-family-monospace-vf">crashkernel</span> |
| 580 |
); |
| 581 |
alertDetail = fmt_to_fragments( |
| 582 |
_("Reserve memory at boot time by setting a '$0' option on the kernel command line. For example, append '$1' to $2 in $3 or use your distribution's kernel argument editor."), |
| 583 |
<span className="pf-v6-u-font-family-monospace-vf">crashkernel</span>, |
| 584 |
<span className="pf-v6-u-font-family-monospace-vf">crashkernel=512M</span>, |
| 585 |
<span className="pf-v6-u-font-family-monospace-vf">GRUB_CMDLINE_LINUX</span>, |
| 586 |
<span className="pf-v6-u-font-family-monospace-vf">/etc/default/grub</span> |
| 587 |
); |
| 588 |
} else if (this.props.kdumpStatus.state == "failed") { |
| 589 |
alertMessage = ( |
| 590 |
<> |
| 591 |
{_("Service has an error")} |
| 592 |
<Button variant="link" isInline className="pf-v6-u-ml-sm" onClick={this.handleServiceDetailsClick}>{_("more details")}</Button> |
| 593 |
</> |
| 594 |
); |
| 595 |
} |
| 596 |
} else { |
| 597 |
alertMessage = _("Kdump service is not installed."); |
| 598 |
alertDetail = fmt_to_fragments( |
| 599 |
_("Install the $0 package."), |
| 600 |
<span className="pf-v6-u-font-family-monospace-vf">kexec-tools</span> |
| 601 |
); |
| 602 |
} |
| 603 |
} |
| 604 |
return ( |
| 605 |
<Page className="pf-m-no-sidebar"> |
| 606 |
<PageSection hasBodyWrapper={false}> |
| 607 |
<Flex spaceItems={{ default: 'spaceItemsMd' }} alignItems={{ default: 'alignItemsCenter' }}> |
| 608 |
<Title headingLevel="h2" size="3xl"> |
| 609 |
{_("Kernel crash dump")} |
| 610 |
</Title> |
| 611 |
{kdumpSwitch} |
| 612 |
{kdumpSwitchHelper && |
| 613 |
<HelperText className="subtle-helper-text"> |
| 614 |
<HelperTextItem>{kdumpSwitchHelper}</HelperTextItem> |
| 615 |
</HelperText>} |
| 616 |
{automationButton} |
| 617 |
</Flex> |
| 618 |
</PageSection> |
| 619 |
<PageSection hasBodyWrapper={false}> |
| 620 |
|
| 621 |
{alertMessage && |
| 622 |
<Alert variant='danger' |
| 623 |
className="pf-v6-u-mb-md" |
| 624 |
isLiveRegion={this.props.isLiveRegion} |
| 625 |
isInline |
| 626 |
title={alertMessage}> |
| 627 |
{alertDetail} |
| 628 |
</Alert> |
| 629 |
} |
| 630 |
<Card isPlain> |
| 631 |
<CardTitle> |
| 632 |
<Title headingLevel="h4" size="xl"> |
| 633 |
{_("Kdump settings")} |
| 634 |
</Title> |
| 635 |
</CardTitle> |
| 636 |
<CardBody> |
| 637 |
<DescriptionList className="pf-m-horizontal-on-sm"> |
| 638 |
<DescriptionListGroup> |
| 639 |
<DescriptionListTerm>{_("Reserved memory")}</DescriptionListTerm> |
| 640 |
<DescriptionListDescription> |
| 641 |
{reservedMemory} |
| 642 |
</DescriptionListDescription> |
| 643 |
</DescriptionListGroup> |
| 644 |
|
| 645 |
<DescriptionListGroup> |
| 646 |
<DescriptionListTerm>{_("Crash dump location")}</DescriptionListTerm> |
| 647 |
<DescriptionListDescription> |
| 648 |
<Flex spaceItems={{ default: 'spaceItemsSm' }}> |
| 649 |
<span id="kdump-target-info">{ kdumpLocation }</span> |
| 650 |
{settingsLink} |
| 651 |
</Flex> |
| 652 |
</DescriptionListDescription> |
| 653 |
</DescriptionListGroup> |
| 654 |
|
| 655 |
<DescriptionListGroup> |
| 656 |
<DescriptionListTerm /> |
| 657 |
<DescriptionListDescription> |
| 658 |
{testButton} |
| 659 |
</DescriptionListDescription> |
| 660 |
</DescriptionListGroup> |
| 661 |
</DescriptionList> |
| 662 |
</CardBody> |
| 663 |
</Card> |
| 664 |
</PageSection> |
| 665 |
</Page> |
| 666 |
); |
| 667 |
} |
| 668 |
} |