фикс пинга 3
This commit is contained in:
parent
b170df43b8
commit
974d31a1c4
2 changed files with 23 additions and 35 deletions
|
|
@ -172,6 +172,7 @@ async def _run_on_device(
|
|||
device_row = await db.get(Device, device.id)
|
||||
if device_row:
|
||||
device_row.status = new_status
|
||||
device_row.last_ping_at = finished_at
|
||||
if action_result_success:
|
||||
device_row.last_seen = finished_at
|
||||
ping_ms = (action_data or {}).get("ping_ms")
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ import {
|
|||
import { useRacks, useCreateRack, useUpdateRack, useDeleteRack, type RackItem } from '../api/racks'
|
||||
import { useZones, useCreateZone, useDeleteZone, type ZoneItem } from '../api/zones'
|
||||
import { useActions, useCreateTask, useTask } from '../api/tasks'
|
||||
import { CategoryTag, DeviceStatusBadge } from '../components/StatusBadge'
|
||||
import { CategoryTag } from '../components/StatusBadge'
|
||||
import { DeviceEditModal } from '../components/DeviceEditModal'
|
||||
import { DiscoveryDrawer } from '../components/DiscoveryDrawer'
|
||||
import { stripEmpty } from '../utils/form'
|
||||
|
|
@ -72,9 +72,9 @@ type GroupRow = {
|
|||
type DeviceRow = DeviceItem & { _type: 'device' }
|
||||
type TableRow = GroupRow | DeviceRow
|
||||
|
||||
// Inventory cols: IP, Hostname, Rack, Category, Status, Ping, Source, Actions = 8
|
||||
// Work cols: IP, Hostname, Category, Status, Ping, Actions = 6
|
||||
const COL_SPAN: Record<Mode, number> = { inventory: 8, work: 6 }
|
||||
// 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 }
|
||||
|
||||
function PingButton({
|
||||
scope,
|
||||
|
|
@ -419,56 +419,43 @@ export function ObjectDetailPage({ defaultMode = 'inventory' }: { defaultMode?:
|
|||
row._type === 'group' ? null : <CategoryTag category={(row as DeviceRow).category} />,
|
||||
},
|
||||
{
|
||||
title: 'Статус',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
onCell: (row: TableRow) => row._type === 'group' ? { colSpan: 0 } : {},
|
||||
render: (_: unknown, row: TableRow) =>
|
||||
row._type === 'group' ? null : <DeviceStatusBadge status={(row as DeviceRow).status} />,
|
||||
},
|
||||
{
|
||||
title: 'Мониторинг',
|
||||
title: 'Последний пинг',
|
||||
key: 'monitoring',
|
||||
onCell: (row: TableRow) => row._type === 'group' ? { colSpan: 0 } : {},
|
||||
onCell: (row: TableRow) => {
|
||||
if (row._type === 'group') return { colSpan: 0 }
|
||||
const d = row as DeviceRow
|
||||
const bg =
|
||||
d.status === 'online' ? '#f6ffed' :
|
||||
d.status === 'offline' ? '#fff2f0' : undefined
|
||||
return bg ? { style: { background: bg } } : {}
|
||||
},
|
||||
render: (_: unknown, row: TableRow) => {
|
||||
if (row._type === 'group') return null
|
||||
const d = row as DeviceRow
|
||||
|
||||
// Нет никаких данных о пинге
|
||||
const pingTime = d.last_ping_at ?? d.last_seen
|
||||
if (!pingTime) {
|
||||
if (!d.monitor_enabled) return <Typography.Text type="secondary">выключен</Typography.Text>
|
||||
return <Typography.Text type="secondary">ожидание...</Typography.Text>
|
||||
return (
|
||||
<Typography.Text type="secondary">
|
||||
{d.monitor_enabled ? 'ожидание...' : 'нет данных'}
|
||||
</Typography.Text>
|
||||
)
|
||||
}
|
||||
|
||||
const pauseIcon = !d.monitor_enabled
|
||||
? <Tooltip title="Мониторинг выключен"><span style={{ color: '#faad14', marginLeft: 4 }}>⏸</span></Tooltip>
|
||||
: null
|
||||
|
||||
// Устройство online
|
||||
if (d.status === 'online') {
|
||||
return (
|
||||
<Space size={2}>
|
||||
<Tooltip title={elapsedAgo(pingTime)}>
|
||||
<span style={{ color: '#52c41a', cursor: 'default' }}>
|
||||
{dayjs(pingTime).format('DD.MM.YYYY HH:mm')}
|
||||
</span>
|
||||
</Tooltip>
|
||||
{pauseIcon}
|
||||
</Space>
|
||||
)
|
||||
}
|
||||
|
||||
// Устройство offline или unknown
|
||||
// pingTime = последняя попытка (last_ping_at) или последний онлайн (last_seen как fallback)
|
||||
const lastSeenHint = d.last_seen && d.last_ping_at && d.last_ping_at !== d.last_seen
|
||||
? `онлайн был: ${dayjs(d.last_seen).format('DD.MM.YYYY HH:mm')}`
|
||||
: null
|
||||
|
||||
const tooltipText = [elapsedAgo(pingTime), lastSeenHint].filter(Boolean).join(' · ')
|
||||
|
||||
return (
|
||||
<Space size={2}>
|
||||
<Tooltip title={[elapsedAgo(pingTime), lastSeenHint].filter(Boolean).join(' · ')}>
|
||||
<span style={{ color: '#ff4d4f', cursor: 'default' }}>
|
||||
<Tooltip title={tooltipText}>
|
||||
<span style={{ cursor: 'default' }}>
|
||||
{dayjs(pingTime).format('DD.MM.YYYY HH:mm')}
|
||||
</span>
|
||||
</Tooltip>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue