Sidebar

2022 Zabbix中国峰会
2022 Zabbix中国峰会

script.execute

Description说明

object script.execute(object parameters)

This method allows to run a script on a host此方法允许在主机上运行脚本.

Parameters参数

(object) Parameters containing the ID of the script to run and the ID of the host包含要运行的脚本的ID和主机的ID的参数.

Parameter参数 T pe类型 Des ription说明
hostid
(required必须)
string ID of the host to run the script on要运行脚本的主机的ID.
scriptid
(required必须)
string ID of the script to run要运行的脚本的ID.

Return values返回值

(object) Returns the result of script execution返回执行脚本的结果.

Property参数 T pe类型 Des ription说明
response string Whether the script was run successfully脚本是否成功运行.

Possible values可能的值为: success or或 failed.
value string Script output脚本输出.

Examples范例

Run a script运行脚本

Run a "ping" script on a host在主机上运行"ping"脚本.

Request请求:

{
           "jsonrpc": "2.0",
           "method": "script.execute",
           "params": {
               "scriptid": "1",
               "hostid": "30079"
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response响应:

{
           "jsonrpc": "2.0",
           "result": {
               "response": "success",
               "value": "PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.\n64 bytes from 127.0.0.1: icmp_req=1 ttl=64 time=0.074 ms\n64 bytes from 127.0.0.1: icmp_req=2 ttl=64 time=0.030 ms\n64 bytes from 127.0.0.1: icmp_req=3 ttl=64 time=0.030 ms\n\n--- 127.0.0.1 ping statistics ---\n3 packets transmitted, 3 received, 0% packet loss, time 1998ms\nrtt min/avg/max/mdev = 0.030/0.044/0.074/0.022 ms\n"
           },
           "id": 1
       }

Source源码

CScript::execute() in frontends/php/include/classes/api/services/CScript.php.