大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

zabbix-api,待完善-创新互联

获取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
}

10年积累的成都网站建设、网站制作经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先建设网站后付款的网站建设流程,更有青秀免费网站建设让你可以放心的选择与我们合作。

## 获取所有主机信息,关于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格式真麻烦,我服务器到了可能就放自己博客上了

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


标题名称:zabbix-api,待完善-创新互联
分享网址:http://dzwzjz.com/article/dgdisj.html
在线咨询
服务热线
服务热线:028-86922220
TOP