中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

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

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

zabbix-api,待完善

發布時間:2020-07-09 08:29:18 來源:網絡 閱讀:293 作者:ziwenzhou 欄目:系統運維

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

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
}


## 獲取所有主機信息,關于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
}

根據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

``` 返回值,直截取部分,因為太多
{
"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": ""


## 根據指定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
}

只返回特定主機上特定item最近的一次值,但輸出值必須以數組方式呈現,即["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
}


## 根據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.php

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

根據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
}


## 獲取指定主機的主機清單信息

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格式真麻煩,我服務器到了可能就放自己博客上了

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

吉林省| 嵊州市| 北宁市| 宁德市| 方城县| 张家口市| 安西县| 临武县| 泽州县| 增城市| 延庆县| 巫溪县| 吉林省| 万源市| 建昌县| 万安县| 宜川县| 和田县| 汉寿县| 仁寿县| 永善县| 铜川市| 连州市| 剑河县| 新源县| 阿尔山市| 哈尔滨市| 泰宁县| 黑山县| 望都县| 乌审旗| 贵阳市| 新丰县| 西青区| 霍山县| 洛阳市| 新乐市| 济南市| 琼结县| 连云港市| 昭平县|