integer/array usermacro.get(object parameters)
该方法允许根据给定的参数检索主机和全局宏。
此方法适用于任何类型的用户。可以在用户角色设置中撤销调用该方法的权限。更多信息请参见User roles。
(object) 定义所需输出的参数。
该方法支持以下参数。
| 参数 | 数据类型 | 描述 |
|---|---|---|
| globalmacro | flag | 返回全局宏而不是主机宏。 |
| globalmacroids | ID/array | 仅返回具有指定ID的全局宏。 |
| groupids | ID/array | 仅返回属于指定主机或模板的主机宏,或属于指定主机组或模板组的模板。 |
| hostids | ID/array | 仅返回属于指定主机或模板的宏。 |
| hostmacroids | ID/array | 仅返回具有指定ID的主机宏。 |
| inherited | boolean | 如果设置为 true,则仅返回从模板继承的主机原型用户宏。 |
| selectHostGroups | query | 在hostgroups属性中返回主机宏所属的主机组。仅在检索主机宏时使用。 |
| selectHosts | query | 在hosts属性中返回主机宏所属的主机。仅在检索主机宏时使用。 |
| selectTemplateGroups | query | 在templategroups属性中返回模板宏所属的模板组。仅在检索模板宏时使用。 |
| selectTemplates | query | 在templates属性中返回主机宏所属的模板。仅在检索主机宏时使用。 |
| sortfield | string/array | 按照指定属性对结果进行排序。 可能的值: macro。 |
| countOutput | boolean | 这些参数在通用get方法参数中有描述。 |
| editable | boolean | |
| excludeSearch | boolean | |
| filter | object | |
| limit | integer | |
| output | query | |
| preservekeys | boolean | |
| search | object | |
| searchByAny | boolean | |
| searchWildcardsEnabled | boolean | |
| sortorder | string/array | |
| startSearch | boolean | |
| selectGroups (deprecated) |
query | 此参数已弃用,请改用selectHostGroups或selectTemplateGroups。在 groups属性中返回主机宏所属的主机组和模板组。仅在检索主机宏时使用。 |
(integer/array) 返回以下之一:
countOutput 参数,则为检索到的 objects 的数量。检索为 主机宏 "10198" 定义的所有 主机。
执行请求:
{
"jsonrpc": "2.0",
"method": "usermacro.get",
"params": {
"output": "extend",
"hostids": "10198"
},
"id": 1
}响应:
{
"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
}检索所有全局宏。
执行请求:
{
"jsonrpc": "2.0",
"method": "usermacro.get",
"params": {
"output": "extend",
"globalmacro": true
},
"id": 1
}响应:
{
"jsonrpc": "2.0",
"result": [
{
"globalmacroid": "6",
"macro": "{$SNMP_COMMUNITY}",
"value": "public",
"description": "",
"type": "0"
}
],
"id": 1
}CUserMacro::get() 在 ui/include/classes/api/services/CUserMacro.php 中。