[comment]: # translation:outdated

[comment]: # ({e5a46c74-e5a46c74})
# script.getscriptsbyhosts

[comment]: # ({/e5a46c74-e5a46c74})

[comment]: # ({6280d197-dfaa829b})
### Descrizione

`object script.getscriptsbyhosts(object parameters)`

Questo metodo consente di recuperare tutti gli script disponibili sull'host specificato
oppure uno script specifico se viene fornito l'ID dello script. Quando viene fornito manualinput,
sostituisce la macro {MANUALINPUT} con il valore specificato.

::: noteclassic
Questo metodo è disponibile per utenti di qualsiasi tipo. Le autorizzazioni
per chiamare il metodo possono essere revocate nelle impostazioni del ruolo utente. Vedere [Ruoli
utente](/manual/web_interface/frontend_sections/users/user_roles)
per ulteriori informazioni.
:::

[comment]: # ({/6280d197-dfaa829b})

[comment]: # ({82b7325d-080ad0f7})
### Parametri

`(object/array)` Il metodo accetta un oggetto o un array di oggetti con i seguenti parametri.

|Parametro|[Type](/manual/api/reference_commentary#data-types)|Descrizione|
|--|--|------|
|hostid|ID|ID dell'host per cui restituire gli script.<br>Deve essere univoco.<br><br>[Comportamento del parametro](/manual/api/reference_commentary#parameter-behavior):<br>- *obbligatorio*|
|scriptid|ID|ID dello script da restituire.|
|manualinput|string|Valore della macro {MANUALINPUT} fornita dall'utente.|

[comment]: # ({/82b7325d-080ad0f7})

[comment]: # ({44148ff1-1c891d1a})
### Valori restituiti

`(object)` Restituisce un oggetto con gli ID degli host come proprietà e array di
script disponibili come valori. Se viene fornito l'ID dello script, il valore associato
è un array contenente lo script specifico.

::: notetip
Il metodo espanderà automaticamente le macro nel testo di `confirmation`,
nel testo del prompt di `manualinput` e nell'`url`.

Se viene fornito il parametro manualinput, la macro {MANUALINPUT} verrà risolta nel valore specificato.
:::

[comment]: # ({/44148ff1-1c891d1a})

[comment]: # ({b41637d2-b41637d2})
### Esempi

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({6d1a1d83-4b630539})
#### Recuperare gli script per ID host

Recupera tutti gli script disponibili sugli host "30079" e "30073".

[Richiesta](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "script.getscriptsbyhosts",
    "params": [
       {
          "hostid":  "30079"
       },
       {
          "hostid":  "30073"
       }
    ],
    "id": 1
}
```

Risposta:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "30079": [
            {
                "scriptid": "3",
                "name": "Rileva il sistema operativo",
                "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_type": "0",
                "manualinput_validator": "",
                "manualinput_default_value": "",
                "parameters": []
            },
            {
                "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_type": "0",
                "manualinput_validator": "",
                "manualinput_default_value": "",
                "parameters": []
            },
            {
                "scriptid": "4",
                "name": "Apri la pagina Zabbix",
                "command": "",
                "host_access": "2",
                "usrgrpid": "0",
                "groupid": "0",
                "description": "",
                "confirmation": "Sei sicuro di voler aprire la pagina *UNKNOWN*?",
                "type": "6",
                "execute_on": "2",
                "timeout": "30s",
                "scope": "2",
                "port": "",
                "authtype": "0",
                "username": "",
                "password": "",
                "publickey": "",
                "privatekey": "",
                "menu_path": "",
                "url": "http://localhost/ui/zabbix.php?action=*UNKNOWN*",
                "new_window": "1",
                "manualinput": "0",
                "manualinput_prompt": "Pagina Zabbix da aprire:",
                "manualinput_validator_type": "0",
                "manualinput_validator": "dashboard.view,discovery.view",
                "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_type": "0",
                "manualinput_validator": "",
                "manualinput_default_value": "",
                "parameters": []
            }
        ],
        "30073": [
            {
                "scriptid": "3",
                "name": "Rileva il sistema operativo",
                "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_type": "0",
                "manualinput_validator": "",
                "manualinput_default_value": "",
                "parameters": []
            },
            {
                "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_type": "0",
                "manualinput_validator": "",
                "manualinput_default_value": "",
                "parameters": []
            },
            {
                "scriptid": "4",
                "name": "Apri la pagina Zabbix",
                "command": "",
                "host_access": "2",
                "usrgrpid": "0",
                "groupid": "0",
                "description": "",
                "confirmation": "Sei sicuro di voler aprire la pagina *UNKNOWN*?",
                "type": "6",
                "execute_on": "2",
                "timeout": "30s",
                "scope": "2",
                "port": "",
                "authtype": "0",
                "username": "",
                "password": "",
                "publickey": "",
                "privatekey": "",
                "menu_path": "",
                "url": "http://localhost/ui/zabbix.php?action=*UNKNOWN*",
                "new_window": "1",
                "manualinput": "1",
                "manualinput_prompt": "Pagina Zabbix da aprire:",
                "manualinput_validator_type": "1",
                "manualinput_validator": "dashboard.view,discovery.view",
                "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_type": "0",
                "manualinput_validator": "",
                "manualinput_default_value": "",
                "parameters": []
            }
        ]
    },
    "id": 1
}
```

[comment]: # ({/6d1a1d83-4b630539})

[comment]: # ({909d5ac3-64ccaa90})
#### Recuperare uno script specifico con valore manualinput.

Recupera lo script con ID "4" sull'host "30079" con valore manualinput "dashboard.view".

[Richiesta](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "script.getscriptsbyhosts",
    "params": [
      {
        "hostid":  "30079",
        "scriptid": "4",
        "manualinput": "dashboard.view"
      }
  ],
    "id": 1
}
```

Risposta:

```json
{
    "jsonrpc": "2.0",
    "result": {
      "30079": [
        {
          "scriptid": "4",
          "name": "Open Zabbix page",
          "command": "",
          "host_access": "2",
          "usrgrpid": "0",
          "groupid": "0",
          "description": "",
          "confirmation": "Are you sure you want to open page dashboard.view?",
          "type": "6",
          "execute_on": "2",
          "timeout": "30s",
          "scope": "2",
          "port": "",
          "authtype": "0",
          "username": "",
          "password": "",
          "publickey": "",
          "privatekey": "",
          "menu_path": "",
          "url": "http://localhost/ui/zabbix.php?action=dashboard.view",
          "new_window": "1",
          "manualinput": "1",
          "manualinput_prompt": "Zabbix page to open:",
          "manualinput_validator_type": "1",
          "manualinput_validator": "dashboard.view,discovery.view",
          "manualinput_default_value": "",
          "parameters": []
        }
      ]
    },
    "id": 1
}
```

[comment]: # ({/909d5ac3-64ccaa90})

[comment]: # ({a62657e4-a62657e4})
### Fonte

CScript::getScriptsByHosts() in
*ui/include/classes/api/services/CScript.php*.

[comment]: # ({/a62657e4-a62657e4})
