【问题标题】:Powershell get Zabbix Hosts via APIPowershell 通过 API 获取 Zabbix Hosts
【发布时间】:2019-06-05 09:11:18
【问题描述】:

我正在尝试使用 powershell 从 Zabbix API 获取主机数据。

我想获取主机组 15、24、26 的以下列:

  • 主机标识
  • 主持人
  • 状态
  • interfaceid
  • ip
  • DNS
  • 使用ip

如果我使用 Postman 提交查询,我将提交以下内容:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": [
            "hostid",
            "host",
            "status"
        ],
        "groupids": [15, 24, 26],
        "selectInterfaces": [
            "interfaceid",
            "ip",
            "dns",
            "useip"
        ]
    },
    "id": 2,
    "auth": "xxxxxxxxxxxxx"
}

到目前为止,我有以下返回大量信息的 powershell

$params.body = @{
    "jsonrpc"= "2.0"
    "method"= "host.get"
    "params"= @{
        output = "extend"
        selectHosts = "extend"
    }
    auth= "xxxxxxxxxxxxx"
    id= 2
} | ConvertTo-Json

$result = Invoke-WebRequest @params

Write-Host $result

我无法理解如何仅请求我想要的信息,我以前没有做过这样的 powershell 脚本,所以希望得到任何指导。

【问题讨论】:

    标签: powershell zabbix


    【解决方案1】:

    您需要使用您在 Postman 中使用的相同字段和选项来构建您的 $params.body

    $params.body = @{
        "jsonrpc"= "2.0"
        "method"= "host.get"
        "params"= @{
            output = @( "host", "hostid", "status" )
            selectInterfaces = @( "interfaceid", "ip", "dns", "useip" )
            groupids = @( "15", "24", "26")
        }
        auth = xxxxxxxxxxxxx
        id = 2
    } | ConvertTo-Json
    

    你应该得到类似的东西:

    hostid host        status interfaces                                                                                          
    ------ ----        ------ ----------                                                                                          
    10017  somehost    0      {@{interfaceid=30251; ip=192.168.10.15; dns=; useip=1}}                                               
    10051  anotherone  0      {@{interfaceid=12353; ip=10.10.10.20; dns=tanotherone.mydomain.com; useip=1}}                       
    10054  whatisthis  0      {@{interfaceid=43262; ip=172.16.1.20; dns=; useip=1}}     
    

    【讨论】:

    • 在你回复之前我设法让它工作了,我做了同样的事情,不过那是为了帮助!!!
    猜你喜欢
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多