Compare commits

..

2 commits

Author SHA1 Message Date
dv
a322b612f8 фикс карточки устройства 2 2026-04-14 13:49:56 +03:00
dv
1e9592f013 фикс страницы объекта 2026-04-14 13:44:47 +03:00
3 changed files with 99 additions and 94 deletions

View file

@ -111,8 +111,8 @@ def _parse(output: str) -> dict:
disk_lines = sections.get("DISK", [])
disks = []
for line in disk_lines:
# Skip header lines
if line.startswith("Filesystem") or line.startswith("target"):
# Skip header lines ("Filesystem ...", "target ...", "Mounted on ...")
if line.startswith(("Filesystem", "target", "Mounted")):
continue
parts = line.split()
if len(parts) >= 5:

View file

@ -38,7 +38,7 @@ import dayjs from 'dayjs'
import { useState } from 'react'
import { useNavigate, useParams } from 'react-router-dom'
import { useAlerts, useAcknowledgeAlert, useResolveAlert, type AlertItem } from '../api/alerts'
import { useDevice, useDeleteDevice, useObject, useDeviceCredentials, type DeviceItem } from '../api/objects'
import { useDevice, useDeleteDevice, useObject, useDeviceCredentials, type DeviceItem, type ObjectItem } from '../api/objects'
import { getDeviceWebUrl } from '../utils/deviceUrl'
import { elapsedAgo } from '../utils/time'
import { useSnapshots, useSnapshotDiff } from '../api/snapshots'
@ -101,13 +101,29 @@ function getSnapshotConfig(device: DeviceItem) {
// ─── SSH / Credentials block ──────────────────────────────────────────────────
function SshBlock({ device, objId }: { device: DeviceItem; objId: number }) {
function SshBlock({ device, objId, obj }: { device: DeviceItem; objId: number; obj: ObjectItem | undefined }) {
const [showPassword, setShowPassword] = useState(false)
const { data: creds, isFetching: credsFetching } = useDeviceCredentials(objId, device.id, showPassword)
const hasOverride = !!(device.ssh_user_override || device.ssh_port_override || device.ssh_key_id_override)
const lastAuth = device.ssh_last_auth
// Resolve effective values: device override → object default → fallback
const effectiveUser =
lastAuth?.username
? String(lastAuth.username)
: device.ssh_user_override ?? obj?.ssh_user ?? null
const effectivePort = device.ssh_port_override ?? 22
// Determine auth method from last_auth
const authType = lastAuth?.type ? String(lastAuth.type) : null
const usesKey = authType === 'key' || device.ssh_key_id_override != null
const credSource: 'device' | 'object' | 'unknown' =
lastAuth?.cred_id != null ? 'object'
: lastAuth?.key_id != null || device.ssh_key_id_override != null ? 'device'
: device.ssh_user_override ? 'device'
: 'object'
return (
<Descriptions
bordered
@ -117,63 +133,80 @@ function SshBlock({ device, objId }: { device: DeviceItem; objId: number }) {
style={{ marginTop: 16 }}
title={<Typography.Text strong style={{ fontSize: 13 }}>SSH / Авторизация</Typography.Text>}
>
{/* Effective login */}
<Descriptions.Item label="Логин">
{device.ssh_user_override
? <><Typography.Text code>{device.ssh_user_override}</Typography.Text> <Tag color="blue" style={{ fontSize: 10 }}>override</Tag></>
: <Typography.Text type="secondary">С объекта</Typography.Text>}
<Space size={6}>
{effectiveUser
? <Typography.Text code>{effectiveUser}</Typography.Text>
: <Typography.Text type="secondary">Не задан</Typography.Text>}
{device.ssh_user_override
? <Tag color="blue" style={{ fontSize: 10 }}>device</Tag>
: obj?.ssh_user
? <Tag style={{ fontSize: 10 }}>объект</Tag>
: null}
</Space>
</Descriptions.Item>
<Descriptions.Item label="Пароль">
{device.ssh_key_id_override != null ? (
<Typography.Text type="secondary"> (используется ключ)</Typography.Text>
{/* Effective auth method + password */}
<Descriptions.Item label="Авторизация">
{usesKey ? (
<Space size={6}>
<Tag color="purple">SSH ключ</Tag>
{(lastAuth?.key_id != null || device.ssh_key_id_override != null) && (
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
key_id={String(lastAuth?.key_id ?? device.ssh_key_id_override)}
</Typography.Text>
)}
</Space>
) : (
<Space size={8}>
{showPassword ? (
credsFetching
? <Spin size="small" />
: creds?.ssh_password
? <Typography.Text code>{creds.ssh_password}</Typography.Text>
: <Typography.Text type="secondary">Не задан (используется с объекта)</Typography.Text>
<Tag color="orange">Пароль</Tag>
{credSource === 'object' ? (
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
с объекта{lastAuth?.cred_id != null ? ` (cred_id=${String(lastAuth.cred_id)})` : ''}
</Typography.Text>
) : (
<Typography.Text type="secondary"></Typography.Text>
<>
{showPassword ? (
credsFetching
? <Spin size="small" />
: creds?.ssh_password
? <Typography.Text code copyable>{creds.ssh_password}</Typography.Text>
: <Typography.Text type="secondary">Не задан</Typography.Text>
) : (
<Typography.Text type="secondary"></Typography.Text>
)}
<Button
size="small"
type="text"
icon={showPassword ? <EyeInvisibleOutlined /> : <EyeOutlined />}
onClick={() => setShowPassword((v) => !v)}
>
{showPassword ? 'Скрыть' : 'Показать'}
</Button>
</>
)}
<Button
size="small"
type="text"
icon={showPassword ? <EyeInvisibleOutlined /> : <EyeOutlined />}
onClick={() => setShowPassword((v) => !v)}
>
{showPassword ? 'Скрыть' : 'Показать'}
</Button>
</Space>
)}
</Descriptions.Item>
{/* Port */}
<Descriptions.Item label="Порт">
{device.ssh_port_override
? <><Typography.Text code>{device.ssh_port_override}</Typography.Text> <Tag color="blue" style={{ fontSize: 10 }}>override</Tag></>
: <Typography.Text type="secondary">22 (по умолчанию)</Typography.Text>}
<Space size={6}>
<Typography.Text code>{effectivePort}</Typography.Text>
{device.ssh_port_override && <Tag color="blue" style={{ fontSize: 10 }}>device</Tag>}
</Space>
</Descriptions.Item>
{device.ssh_key_id_override != null && (
<Descriptions.Item label="SSH ключ (override)">
<Typography.Text code>key_id={device.ssh_key_id_override}</Typography.Text>
</Descriptions.Item>
)}
{!hasOverride && (
<Descriptions.Item label="Кредиалы">
<Typography.Text type="secondary">Используются настройки объекта</Typography.Text>
</Descriptions.Item>
)}
{/* Last successful connection */}
{lastAuth && (
<Descriptions.Item label="Последний успешный SSH">
<Descriptions.Item label="Последнее подключение">
<Space size={4} wrap>
<Tag color="green">{String(lastAuth.type ?? '—')}</Tag>
{lastAuth.username && <Typography.Text code>{String(lastAuth.username)}</Typography.Text>}
{lastAuth.key_id != null && <Typography.Text type="secondary">key_id={String(lastAuth.key_id)}</Typography.Text>}
{lastAuth.cred_id != null && <Typography.Text type="secondary">cred_id={String(lastAuth.cred_id)}</Typography.Text>}
<Tag color="green">успешно</Tag>
{authType && <Tag>{authType === 'key' ? 'ключ' : 'пароль'}</Tag>}
{lastAuth.username && (
<Typography.Text code style={{ fontSize: 12 }}>{String(lastAuth.username)}</Typography.Text>
)}
</Space>
</Descriptions.Item>
)}
@ -372,7 +405,7 @@ function SystemInfoRender({ data }: { data: Record<string, unknown> }) {
{disks && disks.length > 0 && (
<div>
<Typography.Text type="secondary" style={{ fontSize: 12, display: 'block', marginBottom: 4 }}>Диски:</Typography.Text>
{disks.map((d) => {
{disks.filter((d) => !isNaN(parseInt(d.pct))).map((d) => {
const pctNum = parseInt(d.pct)
return (
<div key={d.mount} style={{ marginBottom: 6 }}>
@ -1021,7 +1054,7 @@ export function DeviceDetailPage() {
</Descriptions>
{/* SSH block — always shown */}
<SshBlock device={device} objId={objId} />
<SshBlock device={device} objId={objId} obj={obj} />
{/* System info (Linux-like devices) */}
{isLinuxLike && <SystemInfoBlock device={device} tasks={tasks} />}

View file

@ -25,7 +25,6 @@ import {
Select,
Space,
Spin,
Switch,
Table,
Tag,
Tooltip,
@ -72,9 +71,9 @@ type GroupRow = {
type DeviceRow = DeviceItem & { _type: 'device' }
type TableRow = GroupRow | DeviceRow
// Inventory cols: IP, Hostname, Rack, Category, Ping+Status, Source, Actions = 7
// Work cols: IP, Hostname, Category, Ping+Status, Actions = 5
const COL_SPAN: Record<Mode, number> = { inventory: 7, work: 5 }
// Inventory cols: IP, Hostname, Category, Ping+Status, Source, Actions = 6
// Work cols: IP, Hostname, Category, Ping+Status, Actions = 5
const COL_SPAN: Record<Mode, number> = { inventory: 6, work: 5 }
function PingButton({
scope,
@ -127,7 +126,6 @@ export function ObjectDetailPage({ defaultMode = 'inventory' }: { defaultMode?:
const queryClient = useQueryClient()
const [mode, setMode] = useState<Mode>(defaultMode)
const [editMode, setEditMode] = useState(false)
const toggleMode = () => setMode((m) => (m === 'inventory' ? 'work' : 'inventory'))
@ -397,19 +395,6 @@ export function ObjectDetailPage({ defaultMode = 'inventory' }: { defaultMode?:
)
},
},
...(mode === 'inventory' ? [{
title: 'Стойка / локация',
key: 'location',
onCell: (row: TableRow) => row._type === 'group' ? { colSpan: 0 } : {},
render: (_: unknown, row: TableRow) => {
if (row._type === 'group') return null
const d = row as DeviceRow
if (d.rack_name) return <Tag color="blue">{rackLabel(d.rack_name, d.rack_type)}</Tag>
if (d.location === 'server_room') return <Tag color="purple">Серверная</Tag>
if (d.location === 'street') return <Tag color="orange">Улица</Tag>
return <Typography.Text type="secondary"></Typography.Text>
},
}] : []),
{
title: 'Категория',
dataIndex: 'category',
@ -509,7 +494,6 @@ export function ObjectDetailPage({ defaultMode = 'inventory' }: { defaultMode?:
</Button>
)
}
if (!editMode) return null
return (
<Space>
<Button size="small" icon={<EditOutlined />} onClick={() => { setEditDevice(d); setDeviceModal(true) }} />
@ -622,16 +606,14 @@ export function ObjectDetailPage({ defaultMode = 'inventory' }: { defaultMode?:
<Row justify="space-between" align="middle" style={{ marginBottom: 16 }}>
<Col><Breadcrumb items={breadcrumbItems} /></Col>
<Col>
<div onClick={toggleMode} style={{ cursor: 'pointer' }}>
<Segmented
value={mode}
options={[
{ label: 'Инвентарь', value: 'inventory', icon: <DatabaseOutlined /> },
{ label: 'Работа', value: 'work', icon: <ControlOutlined /> },
]}
onChange={() => {}}
/>
</div>
<Segmented
value={mode}
options={[
{ label: 'Инвентарь', value: 'inventory', icon: <DatabaseOutlined /> },
{ label: 'Работа', value: 'work', icon: <ControlOutlined /> },
]}
onChange={(v) => setMode(v as Mode)}
/>
</Col>
</Row>
@ -703,25 +685,15 @@ export function ObjectDetailPage({ defaultMode = 'inventory' }: { defaultMode?:
</Col>
</Row>
{/* Search + edit toggle + delete all */}
{/* Search */}
<Row justify="space-between" align="middle" style={{ marginBottom: 12 }}>
<Col>
<Space>
<Input.Search
placeholder="Поиск по IP или hostname..."
allowClear
style={{ width: 360 }}
onChange={(e) => setSearchText(e.target.value)}
/>
{mode === 'inventory' && (
<Space size={6}>
<Switch size="small" checked={editMode} onChange={setEditMode} />
<Typography.Text type="secondary" style={{ fontSize: 13 }}>
Режим редактирования
</Typography.Text>
</Space>
)}
</Space>
<Input.Search
placeholder="Поиск по IP или hostname..."
allowClear
style={{ width: 360 }}
onChange={(e) => setSearchText(e.target.value)}
/>
</Col>
</Row>