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.
(object)
Parameters defining the desired output.
The method supports the following parameters.
Parameter | Type | Description |
---|---|---|
globalmacro | flag | Return global macros instead of host macros. |
globalmacroids | ID/array | Return only global macros with the given IDs. |
groupids | ID/array | Return only host macros that belong to hosts or templates from the given host groups or template groups. |
hostids | ID/array | Return only macros that belong to the given hosts or templates. |
hostmacroids | ID/array | Return only host macros with the given IDs. |
inherited | boolean | If set to true return only host prototype user macros inherited from a template. |
selectHostGroups | query | Return host groups that the host macro belongs to in the hostgroups property.Used only when retrieving host macros. |
selectHosts | query | Return hosts that the host macro belongs to in the hosts property.Used only when retrieving host macros. |
selectTemplateGroups | query | Return template groups that the template macro belongs to in the templategroups property.Used only when retrieving template macros. |
selectTemplates | query | Return templates that the host macro belongs to in the templates property.Used only when retrieving host macros. |
sortfield | string/array | Sort the result by the given properties. Possible values: macro . |
countOutput | boolean | These parameters are described in the reference commentary. |
editable | boolean | |
excludeSearch | boolean | |
filter | object | |
limit | integer | |
output | query | |
preservekeys | boolean | |
search | object | |
searchByAny | boolean | |
searchWildcardsEnabled | boolean | |
sortorder | string/array | |
startSearch | boolean |
(integer/array)
Returns either:
countOutput
parameter has been used.Retrieve all host macros defined for host "10198".
{
"jsonrpc": "2.0",
"method": "usermacro.get",
"params": {
"output": "extend",
"hostids": "10198"
},
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": [
{
"hostmacroid": "9",
"hostid": "10198",
"macro": "{$INTERFACE}",
"value": "eth0",
"description": "",
"type": "0",
"automatic": "0"
},
{
"hostmacroid": "11",
"hostid": "10198",
"macro": "{$SNMP_COMMUNITY}",
"value": "public",
"description": "",
"type": "0",
"automatic": "0"
}
],
"id": 1
}
Retrieve host macros defined for template "10265" that contain "STATUS" in the macro name.
{
"jsonrpc": "2.0",
"method": "usermacro.get",
"params": {
"output": "extend",
"hostids": "10265",
"search": {
"macro": "STATUS"
}
},
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": [
{
"hostmacroid": "6709",
"hostid": "10265",
"macro": "{$APACHE.STATUS.HOST}",
"value": "",
"description": "The hostname or IP address of the Apache status page host.",
"type": "0",
"automatic": "0",
"config": {
"type": "1",
"priority": "1",
"section_name": "",
"label": "Apache status host",
"description": "Hostname or IP address of the Apache status page host.",
"required": "1",
"regex": "",
"options": []
}
},
{
"hostmacroid": "814",
"hostid": "10265",
"macro": "{$APACHE.STATUS.PATH}",
"value": "server-status?auto",
"description": "The URL path of the Apache status page.",
"type": "0",
"automatic": "0",
"config": {
"type": "1",
"priority": "3",
"section_name": "",
"label": "Apache status page path",
"description": "URL path of the Apache status page.",
"required": "1",
"regex": "",
"options": []
}
},
{
"hostmacroid": "815",
"hostid": "10265",
"macro": "{$APACHE.STATUS.PORT}",
"value": "80",
"description": "The port of the Apache status page.",
"type": "0",
"automatic": "0",
"config": {
"type": "1",
"priority": "2",
"section_name": "",
"label": "Apache status page port",
"description": "In the range from 1 to 65535 inclusive.",
"required": "1",
"regex": "^-?([0-9]+|(([0-9]+)\\.([0-9]+)))$",
"options": []
}
},
{
"hostmacroid": "816",
"hostid": "10265",
"macro": "{$APACHE.STATUS.SCHEME}",
"value": "http",
"description": "The request scheme, which may be either HTTP or HTTPS.",
"type": "0",
"automatic": "0",
"config": {
"type": "2",
"priority": "4",
"section_name": "",
"label": "Request scheme",
"description": "Request scheme, which may be either HTTP or HTTPS.",
"required": "0",
"regex": "",
"options": [
{
"value": "http",
"text": "HTTP"
},
{
"value": "https",
"text": "HTTPS"
}
]
}
}
],
"id": 1
}
Retrieve all global macros.
{
"jsonrpc": "2.0",
"method": "usermacro.get",
"params": {
"output": "extend",
"globalmacro": true
},
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": [
{
"globalmacroid": "6",
"macro": "{$SNMP_COMMUNITY}",
"value": "public",
"description": "",
"type": "0"
}
],
"id": 1
}
CUserMacro::get() in ui/include/classes/api/services/CUserMacro.php.