zabbix:zabbix api中hostgroup.get、host.get和host.update的详解

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34355232/article/details/83823277

1.hostgroup.get获取组信息
该方法允许根据给定的参数检索主机组。
Parameters 参数:

参数 类型 描述
graphids string/array Return only host groups that contain hosts or templates with the given graphs.只返回包含具有给定图表的主机或模板的主机组。
groupids string/array Return only host groups with the given host group IDs. 只返回具有给定主机组ID的主机组。
hostids string/array Return only host groups that contain the given hosts.只返回包含给定主机的主机组。
maintenanceids string/array Return only host groups that are affected by the given maintenances. 仅返回受指定维护影响的主机组。
monitored_hosts flag Return only host groups that contain monitored hosts.仅返回包含受监视主机的主机组。
real_hosts flag Return only host groups that contain hosts.仅返回包含主机的主机组。
templated_hosts flag Return only host groups that contain templates.只返回包含模板的主机组。
templateids string/array Return only host groups that contain the given templates.只返回包含给定模板的主机组。
triggerids string/array Return only host groups that contain hosts or templates with the given triggers.仅返回包含具有给定触发器的主机或模板的主机组。
with_applications flag Return only host groups that contain hosts with applications.仅返回包含具有应用程序主机的主机组。
with_graphs flag Return only host groups that contain hosts with graphs.仅返回包含具有图表的主机的主机组。
with_hosts_and_templates flag Return only host groups that contain hosts or templates. 只返回包含主机或模板的主机组
with_httptests flag Return only host groups that contain hosts with web checks.仅返回包含具有Web检查的主机的主机组。 Overrides the with_monitored_httptests parameter.覆盖“with_monitored_httptests”参数。
with_items flag Return only host groups that contain hosts or templates with items.仅返回包含主题或包含项目的模板的主机组。 Overrides the with_monitored_items andwith_simple_graph_items parameters.覆盖“with_monitored_items”和“with_simple_graph_items“参数。
with_monitored_httptests flag Return only host groups that contain hosts with enabled web checks.仅返回包含启用Web检查的主机的主机组。
with_monitored_items flag Return only host groups that contain hosts or templates with enabled items.仅返回包含启用项目的主机或模板的主机组。 Overrides the with_simple_graph_items parameter.覆盖with_simple_graph_items参数。
with_monitored_triggers flag Return only host groups that contain hosts with enabled triggers. All of the items used in the trigger must also be enabled. 仅返回包含启用触发器的主机的主机组。 触发器中使用的所有项目也必须启用。
with_simple_graph_items flag Return only host groups that contain hosts with numeric items. 仅返回包含具有数字项目的主机的主机组。
with_triggers flag Return only host groups that contain hosts with triggers.仅返回包含具有触发器的主机的主机组。 Overrides the with_monitored_triggers parameter. 覆盖“with_monitored_triggers”参数。
selectDiscoveryRule query Return the LLD rule that created the host group in the discoveryRule property.返回在“discoveryRule”属性中创建主机组的LLD规则。
selectGroupDiscovery query Return the host group discovery object in the groupDiscovery property. 在“groupDiscovery”属性中返回主机组发现对象。 The host group discovery object links a discovered host group to a host group prototype and has the following properties: 主机组发现对象将发现的主机组链接到主机组原型,并具有以下属性:groupid - (string) ID of the discovered host group; 发现的主机组的ID;lastcheck - (timestamp) time when the host group was last discovered;主机组最后发现的时间; name - (string) name of the host goup prototype;主机组名称原型; parent_group_prototypeid - (string) ID of the host group prototype from which the host group has been created;创建主机组的主机组原型的ID; ts_delete - (timestamp) time when a host group that is no longer discovered will be deleted.不再发现主机组将被删除的时间。
selectHosts query Return the hosts that belong to the host group in the hosts property.在“hosts”属性中返回属于主机组的主机。 Supports count.
selectTemplates query Return the templates that belong to the host group in the templates property. 在“”模板“”属性中返回属于主机组的模板。Supports count.
limitSelects integer Limits the number of records returned by subselects. 限制子选择返回的记录数。Applies to the following subselects:适用于以下子选项: selectHosts - results will be sorted by host; 结果将按“主机”排序;selectTemplates - results will be sorted by host.结果将按“主机”排序。sortfield string/array Sort the result by the given properties. 按照给定的属性对结果进行排序。Possible values are: groupid, name. 可能的值为:groupid,name。
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------

Request:

{
    "jsonrpc": "2.0",
    "method": "hostgroup.get",
    "params": {
        "output": "extend",
        "filter": {
            "name": [
                "Zabbix servers",
                "Linux servers"
            ]
        }
    },
    "auth": "6f38cddc44cfbb6c1bd186f9a220b5a0",
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "groupid": "2",
            "name": "Linux servers",
            "internal": "0"
        },
        {
            "groupid": "4",
            "name": "Zabbix servers",
            "internal": "0"
        }
    ],
    "id": 1
}

2.host.get
此方法允许根据指定的参数获取主机。
Parameters参数

参数 类型 描述
groupids string/array 仅返回指定主机组所属的主机。
applicationids string/array 仅返回含有指定应用集的主机。
dserviceids string/array 仅返回与指定自动发现服务相关的主机。
graphids string/array 仅返回含有指定图表的主机。
hostids string/array 仅返回指定主机ID的主机。
httptestids string/array 仅返回含有指定网页监测的主机。
interfaceids string/array 仅返回使用指定接口的主机。
itemids string/array 仅返回含有指定监控项的主机。
maintenanceids string/array 仅返回被指定管理影响到的主机。
monitored_hosts flag 仅返回被监控的主机。
proxy_hosts flag 仅返回代理服务器。
proxyids string/array 仅返回被代理服务器监控的主机。
templated_hosts flag 同时返回主机和模板。
templateids string/array 仅返回与指定模板链接的主机。
triggerids string/array 仅返回含有指定触发器的主机。
with_items flag 仅返回含有监控项的主机。Overrides the with_monitored_items and with_simple_graph_items parameters. 覆盖“with_monitored_items”和“with_simple_graph_items”参数。
with_applications flag 仅返回含有应用集的主机。
with_graphs flag 仅返回含有图表的主机。
with_httptests flag 仅返回含有网页监测的主机。Overrides the with_monitored_httptests parameter.覆盖“with_monitored_httptests”参数。
with_monitored_httptests flag 仅返回启用网页监测的主机。
with_monitored_items flag .仅返回启用监控项的主机。Overrides the with_simple_graph_items parameter.覆盖with_simple_graph_items参数。
with_monitored_triggers flag Return only hosts that have enabled triggers. All of the items used in the trigger must also be enabled.仅返回启用触发器的主机。所有在触发器中使用到的监控项必须也要启用。
with_simple_graph_items flag 仅返回含有数字类信息监控项的主机。with_triggers flag 仅返回含有触发器的主机。Overrides the with_monitored_triggers parameter.覆盖“with_monitored_triggers”参数。
withInventory flag 仅返回含有资产清单数据的主机。
selectGroups query 返回在groups属性中主机所属的主机组。
selectApplications query 返回在applications属性中来自主机的应用集。Supports count.支持count
selectDiscoveries query 返回在discoveries属性中来自主机的底层自动发现。Supports count.支持count。
selectDiscoveryRule query R 返回在discoveryRule属性中创建主机的底层自动发现规则。
selectGraphs query 返回在graphs属性中来自主机的图表。Supports count.支持count。
selectHostDiscovery query 返回在hostDiscovery属性中的主机自动发现对象。 主机自动发现对象将一个自动发现的主机和一个原型主机连接起来,或者把一个原型主机和一个底层自动发现规则连接起来,并且含有以下属性: host - (string) host of the host prototype;字符串)原型主机的主机。 hostid - (string) ID of the discovered host or host prototype;(字符串)自动发现的主机或原型主机的ID。 parent_hostid - (string) ID of the host prototype from which the host has been created; 字符串)创建主机的原型主机ID。parent_itemid - (string) ID of the LLD rule that created the discovered host;(字符串)创建自动发现主机的底层自动发现规则ID。 lastcheck - (timestamp) time when the host was last discovered; (时间戳)当最近一次自动发现主机时的时间。ts_delete - (timestamp) time when a host that is no longer discovered will be deleted.(时间戳)当不再自动发现的主机将被删除的时间。
selectHttpTests query Return the web scenarios from the host in the httpTests property. 返回在httpTests属性中主机里的网页应用场景Supports count.支持count。
selectInterfaces query 返回在interfaces属性中的主机接口。 Supports count.支持count。
selectInventory query 返回在inventory属性中主机里的主机资产清单。
selectItems query 返回在items属性中主机里的监控项。 Supports count. 支持count。
selectMacros query 返回在macros属性中主机里的宏。
selectParentTemplates query 返回在parentTemplates属性中与主机关联的模板。Supports count.支持count。
selectScreens query 返回在screens属性中主机里的屏幕。Supports count.支持count。
selectTriggers query 返回在triggers属性中主机里的触发器。Supports count. 支持count。
filter object 仅返回完全匹配指定筛选后的结果。接受一个数组,其键值为属性名,其值要么是一个单一的值,要么是一个匹配的数组值。 Allows filtering by interface properties.允许通过接口属性筛选。
limitSelects integer 限定由子查询返回的记录数量。 适用于以下子查询:selectParentTemplates - results will be sorted by host;结果将由host排序; selectInterfaces; selectItems - sorted by name;由name排序; selectDiscoveries - sorted by name;由name排序; selectTriggers - sorted by description;由description排序; selectGraphs - sorted by name;由name排序; selectApplications - sorted by name; 由name排序;selectScreens - sorted by name. 由name排序;
search object Return results that match the given wildcard search.返回与指定通配符搜索匹配的结果。Accepts an array, where the keys are property names, and the values are strings to search for. If no additional options are given, this will perform a LIKE “%…%” search.接受一个数组,其中键值是属性名,其值为搜索到的字符串。如果没有指定的额外选项,将会以LIKE “%…%”方式执行搜索。Allows searching by interface properties. Works only with text fields.允许通过接口属性搜索,仅对文本域产生影响。
searchInventory object 仅返回与指定通配符搜索资产清单数据匹配的主机。 This parameter is affected by the same additional parameters as search. 这个参数被相同其他参数,比如参数search所影响。
sortfield string/array 用指定的属性排序结果。Possible values are: hostid, host, name, status.可能的值为:hostid,host,name,status。
countOutput flag These parameters being common for all get methods are described in detail in the reference commentary. 在reference commentary中详细描述了所有“get”方法的共同参数.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------

用例:
Request:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": "extend",
        "filter": {
            "host": [
                "Zabbix server",
                "Linux server"
            ]
        }
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "maintenances": [],
            "hostid": "10160",
            "proxy_hostid": "0",
            "host": "Zabbix server",
            "status": "0",
            "disable_until": "0",
            "error": "",
            "available": "0",
            "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 server",
            "description": "The Zabbix monitoring server.",
            "tls_connect": "1",
            "tls_accept": "1",
            "tls_issuer": "",
            "tls_subject": "",
            "tls_psk_identity": "",
            "tls_psk": ""
        },
        {
            "maintenances": [],
            "hostid": "10167",
            "proxy_hostid": "0",
            "host": "Linux server",
            "status": "0",
            "disable_until": "0",
            "error": "",
            "available": "0",
            "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": "Linux server",
            "description": "",
            "tls_connect": "1",
            "tls_accept": "1",
            "tls_issuer": "",
            "tls_subject": "",
            "tls_psk_identity": "",
            "tls_psk": ""
        }
    ],
    "id": 1
}

检索主机组:
Request:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid"],
        "selectGroups": "extend",
        "filter": {
            "host": [
                "Zabbix server"
            ]
        }
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 2
}

Response:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10085",
            "groups": [
                {
                    "groupid": "2",
                    "name": "Linux servers",
                    "internal": "0",
                    "flags": "0"
                },
                {
                    "groupid": "4",
                    "name": "Zabbix servers",
                    "internal": "0",
                    "flags": "0"
                }
            ]
        }
    ],
    "id": 2
}

检索相关模板:

Request:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid"],
        "selectParentTemplates": [
            "templateid",
            "name"
        ],
        "hostids": "10084"
    },
    "id": 1,
    "auth": "70785d2b494a7302309b48afcdb3a401"
}

Response:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10084",
            "parentTemplates": [
                {
                    "name": "Template OS Linux",
                    "templateid": "10001"
                },
                {
                    "name": "Template App Zabbix Server",
                    "templateid": "10047"
                }
            ]
        }
    ],
    "id": 1
}

3.host.update
该方法允许更新目前的主机。
Parameters参数:
每一个主机的hostid属性必须已定义过,其他属性为可选项。仅指定属性会被更新,其他属性保持不变。

参数 类型 说明
groups object/array Host groups to replace the current host groups the host belongs to. 替换当前主机所属主机组。The host groups must have the groupid property defined.主机组必须已定义过groupid属性
interfaces object/array Host interfaces to replace the current host interfaces. 替换当前主机接口。
inventory object Host inventory properties.主机资产清单属性。
macros object/array User macros to replace the current user macros.替换当前用户宏。
templates object/array Templates to replace the currently linked templates. Templates that are not passed are only unlinked. 替换当前链接的模板。 模板没有传递仅删除链接。The templates must have the templateid property defined.模板必须已定义过templateid属性。
templates_clear object/array Templates to unlink and clear from the host. 从主机中删除模板链接并清除。The templates must have the templateid property defined.模板必须已定义过templateid属性。
--------------------------------------------------- ---------------------------------------------------------------------------

用例:

Enabling a host启用一个主机
Enable host monitoring, i.e. set its status to 0.启用主机监控,例如,把主机状态设置为0。

Request:

{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10092",
        "status": 0
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10126"
        ]
    },
    "id": 1
}

Unlinking templates 删除模板链接
Unlink and clear two templates from host.从主机中删除链接并清除两个模板。

Request:

{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10126",
        "templates_clear": [
            {
                "templateid": "10124"
            },
            {
                "templateid": "10125"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10126"
        ]
    },
    "id": 1
}

Updating host macros更新主机的宏
Replace all host macros with two new ones.用两个新的宏替换主机所有的宏。

Request:

{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10126",
        "macros": [
            {
                "macro": "{$PASS}",
                "value": "password"
            },
            {
                "macro": "{$DISC}",
                "value": "sda"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10126"
        ]
    },
    "id": 1
}

Updating host inventory 更新主机资产清单
Change inventory mode and add location更改资产清单模式并添加地点。

Request:

{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10387",
        "inventory_mode": 0,
        "inventory": {
            "location": "Latvia, Riga"
        }
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10387"
        ]
    },
    "id": 2
}

猜你喜欢

转载自blog.csdn.net/qq_34355232/article/details/83823277