获取
描述
integer/array script.get(object parameters)
此方法允许根据给定参数检索脚本。
此方法允许任何用户使用。可以在用户角色设置中撤销调用此方法的权限。更多信息见User roles。
参数
(对象)
定义所需输出的参数。
此方法支持如下参数。
参数 | 类型 | 描述 |
---|---|---|
groupids | string/array | 返回可以在给定主机组上运行的脚本 |
hostids | string/array | 返回可以在给定主机上运行的脚本。 |
scriptids | string/array | 返回具有给定ID的脚本。 |
usrgrpids | string/array | 返回可以被给定用户组中用户运行的脚本 |
selectGroups | query | 返回可以在其上运行脚本的主机群组的 群组 属性。 |
selectHosts | query | 返回可以在其上运行脚本的主机的主机属性。 |
selectActions | query | 返回与脚本相关联的动作的动作属性。 |
sortfield | string/array | 根据给定属性将结果排序。 可能的值: scriptid 和 name . |
countOutput | boolean | 这些参数与所有get 方法相同,详细描述见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 |
返回值
(整型/数组)
返回其中之一: - 一组对象; - 如果用到countOutput
参数,被检索到的对象数,。
示例
检索所有脚本
检索所有配置的脚本。 请求:
{
"jsonrpc": "2.0",
"method": "script.get",
"params": {
"output": "extend"
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"scriptid": "1",
"name": "Ping",
"command": "/bin/ping -c 3 {HOST.CONN} 2>&1",
"host_access": "2",
"usrgrpid": "0",
"groupid": "0",
"description": "",
"confirmation": "",
"type": "0",
"execute_on": "1",
"timeout": "30s",
"parameters": []
},
{
"scriptid": "2",
"name": "Traceroute",
"command": "/usr/bin/traceroute {HOST.CONN} 2>&1",
"host_access": "2",
"usrgrpid": "0",
"groupid": "0",
"description": "",
"confirmation": "",
"type": "0",
"execute_on": "1",
"timeout": "30s",
"parameters": []
},
{
"scriptid": "3",
"name": "Detect operating system",
"command": "sudo /usr/bin/nmap -O {HOST.CONN} 2>&1",
"host_access": "2",
"usrgrpid": "7",
"groupid": "0",
"description": "",
"confirmation": "",
"type": "0",
"execute_on": "1",
"timeout": "30s",
"parameters": []
},
{
"scriptid": "4",
"name": "Webhook",
"command": "try {\n var request = new HttpRequest(),\n response,\n data;\n\n request.addHeader('Content-Type: application/json');\n\n response = request.post('https://localhost/post', value);\n\n try {\n response = JSON.parse(response);\n }\n catch (error) {\n response = null;\n }\n\n if (request.getStatus() !== 200 || !('data' in response)) {\n throw 'Unexpected response.';\n }\n\n data = JSON.stringify(response.data);\n\n Zabbix.Log(3, '[Webhook Script] response data: ' + data);\n\n return data;\n}\ncatch (error) {\n Zabbix.Log(3, '[Webhook Script] script execution failed: ' + error);\n throw 'Execution failed: ' + error + '.';\n}",
"host_access": "2",
"usrgrpid": "7",
"groupid": "0",
"description": "",
"confirmation": "",
"type": "5",
"execute_on": "1",
"timeout": "30s",
"parameters": [
{
"name": "token",
"value": "{$WEBHOOK.TOKEN}"
},
{
"name": "host",
"value": "{HOST.HOST}"
},
{
"name": "v",
"value": "2.2"
}
]
}
],
"id": 1
}
另外参考
源代码
CScript::get() 在frontends/php/include/classes/api/services/CScript.php.