usermacro.get

说明

integer/array usermacro.get(object **parameters**) 该方法允许根据给定的参数检索主机和全局宏。

Description

integer/array usermacro.get(object **parameters**)

The method allows to retrieve host and global macros according to the given parameters.

参数

(object) 定义所需输出的参数。 该方法支持以下参数。

属性类型说明
globalmacroflag返回全局宏而不是主机宏。
globalmacroidsstring/array仅返回具有给定ID的全局宏。
groupidsstring/array只返回属于主机的主机宏或来自给定主机组的模板。
hostidsstring/array仅返回属于给定主机的主机宏。
hostmacroidsstring/array只返回具有给定ID的主机宏。
templateidsstring/array只返回属于给定模板的主机宏。
selectGroupsquerygroups属性中返回主机宏所属的主机组。

仅在检索主机宏时使用。
selectHostsqueryhosts属性中返回主机宏所属的主机。

仅在检索主机宏时使用。
selectTemplatesquerytemplate属性中返回主机宏所属的模板。

仅在检索主机宏时使用。
sortfieldstring/array按照给定的属性对结果进行排序。

可能的值:macro
countOutputboolean这些参数对于所有的“获取”方法是常见的,在页 参考评论 page. 中有详细描述。
editableboolean
excludeSearchboolean
filterobject
limitinteger
outputquery
preservekeysboolean
searchobject
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean

Parameters

(object) Parameters defining the desired output.

The method supports the following parameters.

ParameterTypeDescription
globalmacroflagReturn global macros instead of host macros.
globalmacroidsstring/arrayReturn only global macros with the given IDs.
groupidsstring/arrayReturn only host macros that belong to hosts or templates from the given host groups.
hostidsstring/arrayReturn only macros that belong to the given hosts or templates.
hostmacroidsstring/arrayReturn only host macros with the given IDs.
selectGroupsqueryReturn host groups that the host macro belongs to in the groups property.

Used only when retrieving host macros.
selectHostsqueryReturn hosts that the host macro belongs to in the hosts property.

Used only when retrieving host macros.
selectTemplatesqueryReturn templates that the host macro belongs to in the templates property.

Used only when retrieving host macros.
sortfieldstring/arraySort the result by the given properties.

Possible value: macro.
countOutputbooleanThese parameters being common for all get methods are described in detail in the reference commentary page.
editableboolean
excludeSearchboolean
filterobject
limitinteger
outputquery
preservekeysboolean
searchobject
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean

返回值

(integer/array) 返回:

  • 一组对象;

  • 如果已经使用“countOutput”参数,则检索到的对象的计数。

Return values

(integer/array) Returns either:

  • an array of objects;

  • the count of retrieved objects, if the countOutput parameter has been used.

示例

Examples

检索主机的主机宏

检索主机 “10198” 定义的所有主机宏。

Retrieving host macros for a host

Retrieve all host macros defined for host “10198”.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "usermacro.get",
  4. "params": {
  5. "output": "extend",
  6. "hostids": "10198"
  7. },
  8. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  9. "id": 1
  10. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostmacroid": "9",
  6. "hostid": "10198",
  7. "macro": "{$INTERFACE}",
  8. "value": "eth0"
  9. },
  10. {
  11. "hostmacroid": "11",
  12. "hostid": "10198",
  13. "macro": "{$SNMP_COMMUNITY}",
  14. "value": "public"
  15. }
  16. ],
  17. "id": 1
  18. }

检索全局宏

检索所有全局宏。

Retrieving global macros

Retrieve all global macros.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "usermacro.get",
  4. "params": {
  5. "output": "extend",
  6. "globalmacro": true
  7. },
  8. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  9. "id": 1
  10. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "globalmacroid": "6",
  6. "macro": "{$SNMP_COMMUNITY}",
  7. "value": "public"
  8. }
  9. ],
  10. "id": 1
  11. }

来源

CUserMacro::get() in frontends/php/include/classes/api/services/CUserMacro.php.