curl -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"user.login","params":{"user":"admin","password":"zabbix"},"auth":null,"id":0}' http://192.168.74.133/api_jsonrpc.php
``` 返回值
{
"jsonrpc": "2.0",
"result": "4f4a647dbb6d2d31a345fce2977425c5",
"id": 0
}php
## 獲取全部主機信息,關於selectInterfaces的回參能夠在https://www.zabbix.com/documentation/3.4/manual/api/reference/hostinterface/get中查找
curl -H "Content-Type: application/json-rpc" -d '{"jsonrpc":"2.0","method":"host.get","params":{"output":["hostid","host"],"selectInterfaces":["interfaceid","ip"]},"id":0,"auth":"4f4a647dbb6d2d31a345fce2977425c5"}' http://192.168.74.133/api_jsonrpc.phpjson
``` 返回值 { "jsonrpc": "2.0", "result": [{ "hostid": "10084", "host": "Zabbix server", "interfaces": [{ "interfaceid": "1", "ip": "127.0.0.1" }] }, { "hostid": "10261", "host": "zabbix-agent_134", "interfaces": [{ "interfaceid": "2", "ip": "172.18.0.134" }] }], "id": 0 }
curl -H "Content-Type: application/json-rpc" -d '{"jsonrpc": "2.0","method": "item.get","params": {"output": "extend","host":"Zabbix server"},"id":0,"auth":"4f4a647dbb6d2d31a345fce2977425c5"}' http://192.168.74.133/api_jsonrpc.php
``` 返回值,直截取部分,由於太多
{
"jsonrpc": "2.0",
"result": [{
"itemid": "23327",
"type": "0",
"snmp_community": "",
"snmp_oid": "",
"hostid": "10084",
"name": "Host name of zabbixagentd running",
"key": "agent.hostname",
"delay": "1h",
"history": "1w",
"trends": "0",
"status": "0",
"value_type": "1",
"trapper_hosts": "",
"units": "",
"snmpv3_securityname": "",
"snmpv3_securitylevel": "0",
"snmpv3_authpassphrase": "",
"snmpv3_privpassphrase": ""api
## 根據指定item獲取該item全部信息,按名稱排序 注意:extend是所有的意思,"sortfield": "name"是按照名稱排序
curl -H "Content-Type: application/json-rpc" -d '{"jsonrpc": "2.0","method": "item.get","params": {"output": "extend","host":"Zabbix server","search": {"key_": "system.cpu.util[,nice]"},"sortfield": "name"},"id":0,"auth":"4f4a647dbb6d2d31a345fce2977425c5"}' http://192.168.74.133/api_jsonrpc.php數組
``` 返回值 { "jsonrpc": "2.0", "result": [{ "itemid": "23302", "type": "0", "snmp_community": "", "snmp_oid": "", "hostid": "10084", "name": "CPU nice time", "key_": "system.cpu.util[,nice]", "delay": "1m", "history": "1w", "trends": "365d", "status": "0", "value_type": "0", "trapper_hosts": "", "units": "%", "snmpv3_securityname": "", "snmpv3_securitylevel": "0", "snmpv3_authpassphrase": "", "snmpv3_privpassphrase": "", "formula": "", "error": "", "lastlogsize": "0", "logtimefmt": "", "templateid": "17358", "valuemapid": "0", "params": "", "ipmi_sensor": "", "authtype": "0", "username": "", "password": "", "publickey": "", "privatekey": "", "mtime": "0", "flags": "0", "interfaceid": "1", "port": "", "description": "The time the CPU has spent running users' processes that have been niced.", "inventory_link": "0", "lifetime": "0", "snmpv3_authprotocol": "0", "snmpv3_privprotocol": "0", "state": "0", "snmpv3_contextname": "", "evaltype": "0", "jmx_endpoint": "", "master_itemid": "0", "timeout": "3s", "url": "", "query_fields": [], "posts": "", "status_codes": "200", "follow_redirects": "1", "post_type": "0", "http_proxy": "", "headers": [], "retrieve_mode": "0", "request_method": "0", "output_format": "0", "ssl_cert_file": "", "ssl_key_file": "", "ssl_key_password": "", "verify_peer": "0", "verify_host": "0", "allow_traps": "0", "lastclock": "0", "lastns": "0", "lastvalue": "0", "prevvalue": "0" }], "id": 0 }
curl -H "Content-Type: application/json-rpc" -d '{"jsonrpc": "2.0","method": "item.get","params": {"output": ["lastvalue"],"host":"Zabbix server","search": {"key_": "system.cpu.util[,nice]"}},"id":0,"auth":"4f4a647dbb6d2d31a345fce2977425c5"}' http://192.168.74.133/api_jsonrpc.php
``` 返回值
{
"jsonrpc": "2.0",
"result": [{
"itemid": "23302",
"lastvalue": "0"
}],
"id": 0
}服務器
## 獲取全部模板ID,以groupid爲升序排列 ```curl -H "Content-Type: application/json-rpc" -d '{"jsonrpc":"2.0","method":"hostgroup.get","params":{"output":["groupid","name"],"sortfield": "groupid"},"id":0,"auth":"4f4a647dbb6d2d31a345fce2977425c5"}' http://192.168.74.133/api_jsonrpc.php
``` 返回值
{
"jsonrpc": "2.0",
"result": [{
"groupid": "1",
"name": "Templates"
}, {
"groupid": "2",
"name": "Linux servers"
}, {
"groupid": "4",
"name": "Zabbix servers"
}, {
"groupid": "5",
"name": "Discovered hosts"
}, {
"groupid": "6",
"name": "Virtual machines"
}, {
"groupid": "7",
"name": "Hypervisors"
}, {
"groupid": "8",
"name": "Templates/Modules"
}, {
"groupid": "9",
"name": "Templates/Network devices"
}, {
"groupid": "10",
"name": "Templates/Operating systems"
}, {
"groupid": "11",
"name": "Templates/Server hardware"
}, {
"groupid": "12",
"name": "Templates/Applications"
}, {
"groupid": "13",
"name": "Templates/Databases"
}, {
"groupid": "14",
"name": "Templates/Virtualization"
}],
"id": 0
}markdown
## 根據groupid建立模板,模板名稱爲Linux template3
curl -H "Content-Type: application/json-rpc" -d '
{
"jsonrpc": "2.0",
"method": "template.create",
"params": {
"host": "Linux template3", #這裏爲模板的名稱
"groups": {
"groupid": 1
}
},
"auth": "4f4a647dbb6d2d31a345fce2977425c5",
"id": 0
}' http://192.168.74.133/api_jsonrpc.phpapp
``` 返回值 { "jsonrpc": "2.0", "result": { "templateids": ["10264"] }, "id": 1 }
curl -H "Content-Type: application/json-rpc" -d ' { "jsonrpc": "2.0", "method": "hostgroup.get", "params": { "output": ["host"], "groupids": 1, "selectTemplates": ["host"]}, "auth": "4f4a647dbb6d2d31a345fce2977425c5", "id": 0 }' http://192.168.74.133/api_jsonrpc.php
```返回值
{
"jsonrpc": "2.0",
"result": [{
"groupid": "1",
"templates": [{
"host": "Linux template",
"templateid": "10262"
}, {
"host": "Linux template2",
"templateid": "10263"
}, {
"host": "Linux template3",
"templateid": "10264"
}]
}],
"id": 0
}curl
## 獲取指定主機的主機清單信息
curl -H "Content-Type: application/json-rpc" -d '
{
"jsonrpc":"2.0","method":"host.get","params":{"output":"extend","selectInventory":"extend","filter":{"host":["zabbix-agent_134"]}},"id":0,"auth":"4f4a647dbb6d2d31a345fce2977425c5"
}' http://192.168.74.133/api_jsonrpc.phpide
```返回值 { "jsonrpc": "2.0", "result": [{ "hostid": "10261", "proxy_hostid": "0", "host": "zabbix-agent_134", "status": "0", "disable_until": "0", "error": "", "available": "1", "errors_from": "0", "lastaccess": "0", "ipmi_authtype": "-1", "ipmi_privilege": "2", "ipmi_username": "", "ipmi_password": "", "ipmi_disable_until": "0", "ipmi_available": "0", "snmp_disable_until": "0", "snmp_available": "0", "maintenanceid": "0", "maintenance_status": "0", "maintenance_type": "0", "maintenance_from": "0", "ipmi_errors_from": "0", "snmp_errors_from": "0", "ipmi_error": "", "snmp_error": "", "jmx_disable_until": "0", "jmx_available": "0", "jmx_errors_from": "0", "jmx_error": "", "name": "zabbix-agent_134", "flags": "0", "templateid": "0", "description": "", "tls_connect": "1", "tls_accept": "1", "tls_issuer": "", "tls_subject": "", "tls_psk_identity": "", "tls_psk": "", "proxy_address": "", "auto_compress": "1", "inventory": { "hostid": "10261", "inventory_mode": "0", "type": "123", "type_full": "123123", "name": "123123123", "alias": "123123", "os": "Linux", "os_full": "3123", "os_short": "", "serialno_a": "", "serialno_b": "", "tag": "3123123", "asset_tag": "12312", "macaddress_a": "12312", "macaddress_b": "213123123", "hardware": "", "hardware_full": "", "software": "", "software_full": "", "software_app_a": "", "software_app_b": "", "software_app_c": "", "software_app_d": "", "software_app_e": "", "contact": "", "location": "", "location_lat": "", "location_lon": "", "notes": "", "chassis": "", "model": "", "hw_arch": "", "vendor": "", "contract_number": "", "installer_name": "", "deployment_status": "", "url_a": "", "url_b": "", "url_c": "", "host_networks": "", "host_netmask": "", "host_router": "", "oob_ip": "", "oob_netmask": "", "oob_router": "", "date_hw_purchase": "", "date_hw_install": "", "date_hw_expiry": "", "date_hw_decomm": "", "site_address_a": "", "site_address_b": "", "site_address_c": "", "site_city": "", "site_state": "", "site_country": "", "site_zip": "", "site_rack": "", "site_notes": "", "poc_1_name": "", "poc_1_email": "", "poc_1_phone_a": "", "poc_1_phone_b": "", "poc_1_cell": "", "poc_1_screen": "", "poc_1_notes": "", "poc_2_name": "", "poc_2_email": "", "poc_2_phone_a": "", "poc_2_phone_b": "", "poc_2_cell": "", "poc_2_screen": "", "poc_2_notes": "" } }], "id": 0 }
另外說一句51cto的markdown格式真麻煩,我服務器到了可能就放本身博客上了post