usermacro.get

Description

integer/array usermacro.get(object parameters)

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

This method is available to users of any type. Permissions to call the method can be revoked in user role settings. See User roles for more information.

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 or template groups.
hostidsstring/arrayReturn only macros that belong to the given hosts or templates.
hostmacroidsstring/arrayReturn only host macros with the given IDs.
inheritedbooleanIf set to true return only host prototype user macros inherited from a template.
selectHostGroupsqueryReturn host groups that the host macro belongs to in the hostgroups 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.
selectTemplateGroupsqueryReturn template groups that the template macro belongs to in the templategroups property.

Used only when retrieving template 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 values: 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
selectGroups
(deprecated)
queryThis parameter is deprecated, please use selectHostGroups or selectTemplateGroups instead.
Return host groups and template groups that the host macro belongs to in the groups property.

Used only when retrieving host macros.

Return values

(integer/array) Returns either:

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

Examples

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. "id": 1
  9. }

Response:

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

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. "id": 1
  9. }

Response:

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

Source

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