Skip to content

Instantly share code, notes, and snippets.

@hamletmun
Last active May 26, 2022 20:42
Show Gist options
  • Save hamletmun/ad48ccca28f0c02562037e44e6a34c9a to your computer and use it in GitHub Desktop.
Save hamletmun/ad48ccca28f0c02562037e44e6a34c9a to your computer and use it in GitHub Desktop.
Zabbix API (JSON RPC) with Powershell

Zabbix API (JSON RPC) with Powershell

method apiinfo.version

Invoke-RestMethod -Method POST -Uri https://my.org/zabbix/api_jsonrpc.php -ContentType application/json -Body (@{jsonrpc="2.0";method="apiinfo.version";params=@{};id=1} | ConvertTo-Json)

method user.login

(Invoke-RestMethod -Method POST -Uri https://my.org/zabbix/api_jsonrpc.php -ContentType application/json -Body (@{jsonrpc="2.0";method="user.login";params=@{user="UserName";password="Password"};id=1} | ConvertTo-Json)).result

method host.get

Search by name

(Invoke-RestMethod -Method POST -Uri https://my.org/zabbix/api_jsonrpc.php -ContentType application/json -Body (@{jsonrpc="2.0";id=1;auth="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";method="host.get";params=@{search=@{name="myhost"};output=@("hostid","name","status")}} | ConvertTo-Json)).result

Filter by name

(Invoke-RestMethod -Method POST -Uri https://my.org/zabbix/api_jsonrpc.php -ContentType application/json -Body (@{jsonrpc="2.0";id=1;auth="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";method="host.get";params=@{filter=@{name="myhostname"};output=@("hostid","name","status")}} | ConvertTo-Json)).result

List hosts' items

(Invoke-RestMethod -Method POST -Uri https://my.org/zabbix/api_jsonrpc.php -ContentType application/json -Body (@{jsonrpc="2.0";id=1;auth="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";method="host.get";params=@{search=@{name="myhost"};output=@("name");selectItems="extend"}} | ConvertTo-Json)).result.items | Select-Object name,key_

method item.get

List items which "key_" includes "sensor.status" from 5 hosts

(Invoke-RestMethod -Method POST -Uri https://my.org/zabbix/api_jsonrpc.php -ContentType application/json -Body (@{jsonrpc="2.0";id=1;auth="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";method="item.get";params=@{hostids=@(200200000000001;200200000000002;200200000000003;200200000000004;200200000000005);search=@{key_="sensor.status"}}} | ConvertTo-Json)).result | Select-Object hostid,name,lastvalue

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment