【问题标题】:Regex on Zabbix API?Zabbix API 上的正则表达式?
【发布时间】:2016-05-26 14:12:18
【问题描述】:

花了几个小时阅读 Zabbix Api 的文档后,我还没有找到一种方法来通过键执行 search 并具有多个可能的值。

因此,使用以下代码:

{
"jsonrpc": "2.0",
"method": "item.get",
"params": {
    "output": "extend",
    "hostids": " 10355",
    "search": {
        "key_": "[in_*|out_*]"
     },

"sortfield": "name"
},
"auth": "15729708df1f5936f6ea840ae1b41cb6",
"id": 0
}

我试图获取每个item 哪个键是in_<anything> OR out_<anything> 所以,输出将是与接口相关的所有项目的组合。相反,我得到了这个:

{"jsonrpc":"2.0","result":[],"id":0}

我知道可以使用 filter 而不是 search,但是根据我的阅读,当您想要完全匹配时使用它,但事实并非如此。

【问题讨论】:

  • 如果这里完全支持正则表达式,请尝试"key_": "(in|out)_.*"。
  • 不,没什么。并且支持正则表达式,因为它适用于 json。

标签: json regex zabbix


【解决方案1】:

Zabbix API(以及其他地方的过滤)不支持正则表达式。在某些版本中,您可以传递通配符,但这不会解决您当前的问题。您必须执行两个单独的 API 查询。

要在此处回答评论中的问题,可以使用 excludeSearch 参数来否定搜索 - 有关更多详细信息,请参阅 API documentation。

【讨论】:

  • 好的,感谢您的信息,您知道是否有任何方法可以通过不匹配进行过滤吗?
  • 编辑了答案以包含该信息,但最好将一个问题保留在一个主题中。
【解决方案2】:

为了这项工作,你需要把这个键searchWildcardsEnabled

{
"jsonrpc": "2.0",
"method": "item.get",
"params": {
    "output": "extend",
    "hostids": " 10355",
    "searchWildcardsEnabled": "true",
    "search": {
        "key_": "[in_*|out_*]"
     },

"sortfield": "name"
},
"auth": "15729708df1f5936f6ea840ae1b41cb6",
"id": 0
}

【讨论】:

    【解决方案3】:

    我认为您应该考虑使用searchByAnyparameter,它可以让您找到符合任何search 条件的项目。这是您应该尝试的正确 json:

    {
        "jsonrpc": "2.0",
        "method": "item.get",
        "params": {
            "output": "extend",
            "hostids": " 10355",
            "searchWildcardsEnabled": "true",
            "search": {
                "key_": [
                    "in_*",
                    "out_*"
                ]
            },
            "sortfield": "name"
        },
        "auth": "15729708df1f5936f6ea840ae1b41cb6",
        "id": 1
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-17
      • 2015-12-29
      相关资源
      最近更新 更多