首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >apache中的apache规范

apache中的apache规范
EN

Stack Overflow用户
提问于 2022-10-12 15:53:10
回答 1查看 51关注 0票数 -2

投入:

代码语言:javascript
运行
复制
{
  "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"
    }
  ]
}

预期产出

代码语言:javascript
运行
复制
{
  "severity" : "0",
  "name" : "High memory utilization",
  "host" : "hostname",
  "parameter" : "memory"
}

应该将标记组件值分配给参数字段。请帮帮我。

EN

回答 1

Stack Overflow用户

发布于 2022-10-12 18:23:44

遍历数组的对象,因为您希望从标记数组的成员对象中获取value键的值,在将标记值作为每个嵌套对象的键名之后,具有与component相等的值的tag键。

然后使用这些移位转换规范从外部属性派生值。

代码语言:javascript
运行
复制
[
  {
    // 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"
    }
  }
]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74044734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档