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