Esta es una traducción de la página de documentación original en español. Ayúdanos a mejorarla.

script.execute

Description

object script.execute(object parameters)

This method allows to run a script on a host or event.

This method is available to users of any type. Permissions to call the method can be revoked in user role settings. See User roles for more information.

Parameters

(object) Parameters containing the ID of the script to run and either the ID of the host or the ID of the event.

Parameter Type Description
scriptid
(required)
string ID of the script to run.
hostid string ID of the host to run the script on.
eventid string ID of the event to run the script on.

Valores de retorno

(objeto) Devuelve el resultado de la ejecución del script.

Propiedad Tipo Descripción
response cadena Si el script se ejecutó correctamente.

Valor posible: éxito.
value cadena Salida del script.
debug object Contiene un objeto de depuración si se ejecuta un script de webhook. Para otros tipos de script, contiene un objeto vacío.

Ejemplos

Run a webhook script

Run a webhook script that sends HTTP request to external service.

Request:

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

Response:

{
           "jsonrpc": "2.0",
           "result": {
               "response": "success",
               "value": "{\"status\":\"sent\",\"timestamp\":\"1611235391\"}",
               "debug": {
                   "logs": [
                        {
                            "level": 3,
                            "ms": 480,
                            "message": "[Webhook Script] HTTP status: 200."
                        }
                    ],
                    "ms": 495
               }
           },
           "id": 1
       }

Run a custom script

Run a "ping" script on a host.

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",
               "debug": []
           },
           "id": 1
       }

Fuente

CScript::execute() en ui/include/classes/api/services/CScript.php.