integer/array usermacro.get(object parameters)
该方法允许根据给定参数检索主机和全局宏。
此方法可供任何类型的用户使用。调用该方法的权限可在用户角色设置中撤销。更多信息请参阅User roles。
(object)
定义所需输出的参数。
该方法支持以下参数。
参数 | 数据类型 | 描述 |
---|---|---|
globalmacro | flag | 返回全局宏而非主机宏。 |
globalmacroids | string/array | 仅返回具有指定ID的全局宏。 |
groupids | string/array | 仅返回属于指定主机组或模板的主机宏。 |
hostids | string/array | 仅返回属于指定主机或模板的宏。 |
hostmacroids | string/array | 仅返回具有指定ID的主机宏。 |
inherited | boolean | 若设为true 则仅返回从模板继承的主机原型用户宏。 |
selectGroups | query | 在groups属性中返回主机宏所属的主机组。 仅在检索主机宏时使用。 |
selectHosts | query | 在hosts属性中返回主机宏所属的主机。 仅在检索主机宏时使用。 |
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 |
(integer/array)
返回以下两种结果之一:
countOutput
参数,则返回检索到的objects数量。获取为主机 "10198"定义的所有主机宏。
请求:
{
"jsonrpc": "2.0",
"method": "usermacro.get",
"params": {
"output": "extend",
"hostids": "10198"
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"hostmacroid": "9",
"hostid": "10198",
"macro": "{$INTERFACE}",
"value": "eth0",
"description": "",
"type": "0"
},
{
"hostmacroid": "11",
"hostid": "10198",
"macro": "{$SNMP_COMMUNITY}",
"value": "public",
"description": "",
"type": "0"
}
],
"id": 1
}
获取所有全局宏。
请求:
{
"jsonrpc": "2.0",
"method": "usermacro.get",
"params": {
"output": "extend",
"globalmacro": true
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"globalmacroid": "6",
"macro": "{$SNMP_COMMUNITY}",
"value": "public",
"description": "",
"type": "0"
}
],
"id": 1
}
ui/include/classes/api/services/CUserMacro.php 中的 CUserMacro::get() 方法