integer/array usermacro.get(object parameters)
此方法用于根据给定参数查询主机宏和全局宏。
此方法适用于任何类型的用户。可在用户角色设置中撤销调用该方法的权限,参阅用户角色获取详情。
(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 参数时)。查询主机"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() in ui/include/classes/api/services/CUserMacro.php.