integer/array script.get(object parameters)
此方法允许根据给定参数检索脚本。
此方法允许任何用户使用。可以在用户角色设置中撤销调用此方法的权限。更多信息见User roles。
(object)
定义所需输出的参数。
该方法支持以下参数。
参数 | 类型 | 描述 |
---|---|---|
groupids | ID/数组 | 仅返回可以在此给定主机组上运行的脚本。 |
hostids | ID/数组 | 仅返回可以在此给定主机上运行的脚本。 |
scriptids | ID/数组 | 仅返回具有给定ID的脚本。 |
usrgrpids | ID/数组 | 仅返回可以由给定用户组中的用户运行的脚本。 |
selectHostGroups | 查询 | 返回一个hostgroups 属性,包含脚本可以运行在其上的主机组。 |
selectHosts | 查询 | 返回一个hosts 属性,包含脚本可以运行在其上的主机。 |
selectActions | 查询 | 返回一个actions 属性,包含脚本关联的动作。 |
sortfield | 字符串/数组 | 根据给定属性对结果进行排序。 可能的值: scriptid ,name 。 |
countOutput | 布尔值 | 这些参数在参考说明中描述。 |
editable | 布尔值 | |
excludeSearch | 布尔值 | |
filter | 对象 | |
limit | 整数 | |
output | 查询 | |
preservekeys | 布尔值 | |
search | 对象 | |
searchByAny | 布尔值 | |
searchWildcardsEnabled | 布尔值 | |
sortorder | 字符串/数组 | |
startSearch | 布尔值 | |
selectGroups (已废弃) |
查询 | 此参数已废弃,请改用selectHostGroups 。返回一个 groups 属性,包含脚本可以运行在其上的主机组。 |
(整型/数组)
返回其中之一: - 一组对象; - 如果用到countOutput
参数,被检索到的对象数,。
检索所有配置的脚本。 请求:
响应
{
"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",
"scope": "2",
"port": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"menu_path": "",
"url": "",
"new_window": "1",
"manualinput": "0",
"manualinput_prompt": "",
"manualinput_validator": "",
"manualinput_validator_type": "0",
"manualinput_default_value": "",
"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",
"scope": "2",
"port": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"menu_path": "",
"url": "",
"new_window": "1",
"manualinput": "0",
"manualinput_prompt": "",
"manualinput_validator": "",
"manualinput_validator_type": "0",
"manualinput_default_value": "",
"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",
"scope": "2",
"port": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"menu_path": "",
"url": "",
"new_window": "1",
"manualinput": "0",
"manualinput_prompt": "",
"manualinput_validator": "",
"manualinput_validator_type": "0",
"manualinput_default_value": "",
"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",
"scope": "2",
"port": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"menu_path": "",
"url": "",
"new_window": "1",
"manualinput": "0",
"manualinput_prompt": "",
"manualinput_validator": "",
"manualinput_validator_type": "0",
"manualinput_default_value": "",
"parameters": [
{
"name": "token",
"value": "{$WEBHOOK.TOKEN}"
},
{
"name": "host",
"value": "{HOST.HOST}"
},
{
"name": "v",
"value": "2.2"
}
]
},
{
"scriptid": "5",
"name": "URL",
"command": "",
"host_access": "2",
"usrgrpid": "0",
"groupid": "0",
"description": "",
"confirmation": "Go to {HOST.NAME}?",
"type": "6",
"execute_on": "1",
"timeout": "30s",
"scope": "4",
"port": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"menu_path": "",
"url": "http://zabbix/ui/zabbix.php?action=latest.view&hostids[]={HOST.ID}",
"new_window": "0",
"manualinput": "0",
"manualinput_prompt": "",
"manualinput_validator": "",
"manualinput_validator_type": "0",
"manualinput_default_value": "",
"parameters": []
},
{
"scriptid": "6",
"name": "URL with user input",
"command": "",
"host_access": "2",
"usrgrpid": "0",
"groupid": "0",
"description": "",
"confirmation": "Open zabbix page {MANUALINPUT}?",
"type": "6",
"execute_on": "1",
"timeout": "30s",
"scope": "2",
"port": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"menu_path": "",
"url": "http://zabbix/ui/zabbix.php?action={MANUALINPUT}",
"new_window": "0",
"manualinput": "1",
"manualinput_prompt": "Select a page to open:",
"manualinput_validator": "dashboard.view,script.list,actionlog.list",
"manualinput_validator_type": "1",
"parameters": []
}
],
"id": 1
}
CScript::get() 在frontends/php/include/classes/api/services/CScript.php.