溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

zabbix-api,待完善

發(fā)布時(shí)間:2020-07-09 08:29:18 來源:網(wǎng)絡(luò) 閱讀:293 作者:ziwenzhou 欄目:系統(tǒng)運(yùn)維

獲取zabbix登錄認(rèn)證字符串(必須)

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
}


## 獲取所有主機(jī)信息,關(guān)于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.php

``` 返回值
{
    "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
}

根據(jù)host_id獲取所有item信息

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

``` 返回值,直截取部分,因?yàn)樘?br/>{
"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": ""


## 根據(jù)指定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
}

只返回特定主機(jī)上特定item最近的一次值,但輸出值必須以數(shù)組方式呈現(xiàn),即["lastvalue"]

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
}


## 根據(jù)groupid創(chuàng)建模板,模板名稱為L(zhǎng)inux 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.php

``` 返回值
{
    "jsonrpc": "2.0",
    "result": {
        "templateids": ["10264"]
    },
    "id": 1
}

根據(jù)GROUPID查詢包含哪些模板,輸出模板名稱

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
}


## 獲取指定主機(jī)的主機(jī)清單信息

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.php

```返回值
{
    "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格式真麻煩,我服務(wù)器到了可能就放自己博客上了

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI