获取
描述
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 | 这些参数在参考说明中进行了描述。 |
| 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参数时)。
示例
查询一个主机的主机宏
查询主机"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
}
检索模板的主机宏
检索为模板“10265”定义的、宏名称中包含“STATUS”的主机宏。
请求:
{
"jsonrpc": "2.0",
"method": "usermacro.get",
"params": {
"output": "extend",
"hostids": "10265",
"search": {
"macro": "STATUS"
}
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"hostmacroid": "6709",
"hostid": "10265",
"macro": "{$APACHE.STATUS.HOST}",
"value": "",
"description": "Apache 状态页主机的主机名或 IP 地址。",
"type": "0",
"automatic": "0",
"config": {
"type": "1",
"priority": "1",
"section_name": "",
"label": "Apache 状态主机",
"description": "Apache 状态页主机的主机名或 IP 地址。",
"required": "1",
"regex": "",
"options": []
}
},
{
"hostmacroid": "814",
"hostid": "10265",
"macro": "{$APACHE.STATUS.PATH}",
"value": "server-status?auto",
"description": "Apache 状态页的 URL 路径。",
"type": "0",
"automatic": "0",
"config": {
"type": "1",
"priority": "3",
"section_name": "",
"label": "Apache 状态页路径",
"description": "Apache 状态页的 URL 路径。",
"required": "1",
"regex": "",
"options": []
}
},
{
"hostmacroid": "815",
"hostid": "10265",
"macro": "{$APACHE.STATUS.PORT}",
"value": "80",
"description": "Apache 状态页的端口。",
"type": "0",
"automatic": "0",
"config": {
"type": "1",
"priority": "2",
"section_name": "",
"label": "Apache 状态页端口",
"description": "范围为 1 到 65535(含)。",
"required": "1",
"regex": "^-?([0-9]+|(([0-9]+)\\.([0-9]+)))$",
"options": []
}
},
{
"hostmacroid": "816",
"hostid": "10265",
"macro": "{$APACHE.STATUS.SCHEME}",
"value": "http",
"description": "请求方案,可以是 HTTP 或 HTTPS。",
"type": "0",
"automatic": "0",
"config": {
"type": "2",
"priority": "4",
"section_name": "",
"label": "请求方案",
"description": "请求方案,可以是 HTTP 或 HTTPS。",
"required": "0",
"regex": "",
"options": [
{
"value": "http",
"text": "HTTP"
},
{
"value": "https",
"text": "HTTPS"
}
]
}
}
],
"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.