Powershell通过API获取Zabbix主机
我正在尝试使用powershell从Zabbix API获取主机数据 我想返回主机组15、24、26的以下列:Powershell通过API获取Zabbix主机,powershell,zabbix,Powershell,Zabbix,我正在尝试使用powershell从Zabbix API获取主机数据 我想返回主机组15、24、26的以下列: 霍斯蒂德 主人 地位 接口ID 知识产权 域名系统 乌西普 如果我使用Postman提交查询,我将提交以下内容: { "jsonrpc": "2.0", "method": "host.get", "params": { "output": [ "hostid", "host",
- 霍斯蒂德
- 主人
- 地位
- 接口ID
- 知识产权
- 域名系统
- 乌西普
{
"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脚本,因此希望您能提供指导。您需要使用与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}}
就在你回复之前,我设法让它工作了,我做了同样的事情,这是为了帮助你!!!