投入:
{
"eventid": "165",
"name": "High memory utilization",
"severity": "0",
"userid": "1",
"hosts": [
{
"hostid": "101",
"proxy_hostid": "0",
"host": "hostname",
"name": "name"
}
],
"relatedObject": {
"description": "High memory utilization",
"comments": "The system is running out of free memory.",
"uuid": ""
},
"tags": [
{
"tag": "component",
"value": "memory"
},
{
"tag": "class",
"value": "os"
},
{
"tag": "target",
"value": "linux"
}
]
}预期产出
{
"severity" : "0",
"name" : "High memory utilization",
"host" : "hostname",
"parameter" : "memory"
}应该将标记组件值分配给参数字段。请帮帮我。
发布于 2022-10-12 18:23:44
遍历数组的对象,因为您希望从标记数组的成员对象中获取value键的值,在将标记值作为每个嵌套对象的键名之后,具有与component相等的值的tag键。
然后使用这些移位转换规范从外部属性派生值。
[
{
// tag objects with the value of the tag keys
"operation": "shift",
"spec": {
"tags": {
"*": {
"@(2,severity)": "@(1,tag).severity", // go two levels up to grab the value from the attribute "severity"
"@(2,name)": "@(1,tag).name",
"@(2,hosts[0].host)": "@(1,tag).host", // go two levels up to grab the value from the array "hosts" and pick the first objects's "host" value among the objects nested within the array
"value": "@(1,tag).&"
}
}
}
},
{
// pick only the key-value pair from the object which's tagged "component"
"operation": "shift",
"spec": {
"component": ""
}
},
{
// replace the tag name of the attribute with "parameter"
"operation": "shift",
"spec": {
"*": "&", // "else" case (matches the attributes other than the below one)
"value": "parameter" // rename the attribute "value" to "parameter"
}
}
]https://stackoverflow.com/questions/74044734
复制相似问题