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.
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

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. "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. "description": "",
  10. "type": "0"
  11. },
  12. {
  13. "hostmacroid": "11",
  14. "hostid": "10198",
  15. "macro": "{$SNMP_COMMUNITY}",
  16. "value": "public",
  17. "description": "",
  18. "type": "0"
  19. }
  20. ],
  21. "id": 1
  22. }

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. "description": "",
  9. "type": "0"
  10. }
  11. ],
  12. "id": 1
  13. }

Source

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