fix: validate advanced snmp oid json rows
This commit is contained in:
@@ -355,12 +355,21 @@ const hasSnmpOidTableUnsupportedFields = (raw: string) => {
|
||||
const rows = parseSnmpOidJsonArray(raw)
|
||||
return rows.some((item) => {
|
||||
if (!item || typeof item !== 'object' || Array.isArray(item)) {
|
||||
return Boolean(item)
|
||||
return true
|
||||
}
|
||||
return Object.keys(item).some((key) => !snmpOidTableFields.includes(key))
|
||||
})
|
||||
}
|
||||
|
||||
const findInvalidSnmpOidJsonRowIndex = (rows: unknown[]) =>
|
||||
rows.findIndex((item) => {
|
||||
if (!item || typeof item !== 'object' || Array.isArray(item)) {
|
||||
return true
|
||||
}
|
||||
const row = item as Record<string, unknown>
|
||||
return !String(row.oid ?? '').trim() || !String(row.metric_name ?? '').trim()
|
||||
})
|
||||
|
||||
const stringifySnmpOidRows = (rows: SnmpOidRow[]) => {
|
||||
const normalizedRows = normalizeSnmpOidRows(rows)
|
||||
return normalizedRows.length ? JSON.stringify(normalizedRows, null, 2) : ''
|
||||
@@ -552,12 +561,12 @@ const validateSnmpOidConfigBeforeSubmit = () => {
|
||||
|
||||
try {
|
||||
const parsedRows = parseSnmpOidJsonArray(formData.snmp_oids)
|
||||
const rows = parseSnmpOidRows(formData.snmp_oids)
|
||||
const invalidIndex = findIncompleteSnmpOidRowIndex(rows)
|
||||
if (invalidIndex >= 0) {
|
||||
Message.warning(`SNMP OID 第 ${invalidIndex + 1} 行请填写 OID 和指标名称`)
|
||||
const invalidJsonIndex = findInvalidSnmpOidJsonRowIndex(parsedRows)
|
||||
if (invalidJsonIndex >= 0) {
|
||||
Message.warning(`SNMP OID 第 ${invalidJsonIndex + 1} 行请填写 OID 和指标名称`)
|
||||
return false
|
||||
}
|
||||
const rows = parseSnmpOidRows(formData.snmp_oids)
|
||||
const normalizedRows = normalizeSnmpOidRows(rows)
|
||||
snmpOidRows.value = normalizedRows
|
||||
formData.snmp_oids = JSON.stringify(parsedRows, null, 2)
|
||||
|
||||
Reference in New Issue
Block a user