[comment]: # translation:outdated

[comment]: # ({02ea8022-02ea8022})
# usermacro.get

[comment]: # ({/02ea8022-02ea8022})

[comment]: # ({78b5ab06-28befc82})
### Descrizione

`integer/array usermacro.get(object parameters)`

Questo metodo consente di recuperare le macro del host e globali in base ai
parametri specificati.

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

[comment]: # ({/78b5ab06-28befc82})

[comment]: # ({0f02ef4c-141835f9})
### Parametri

`(object)` Parametri che definiscono l'output desiderato.

Il metodo supporta i seguenti parametri.

|Parametro|[Tipo](/manual/api/reference_commentary#data-types)|Descrizione|
|--|--|------|
|globalmacro|flag|Restituisce le macro globali invece delle macro host.|
|globalmacroids|ID/array|Restituisce solo le macro globali con gli ID specificati.|
|groupids|ID/array|Restituisce solo le macro host che appartengono a host o template dei gruppi host o gruppi template specificati.|
|hostids|ID/array|Restituisce solo le macro che appartengono agli host o template specificati.|
|hostmacroids|ID/array|Restituisce solo le macro host con gli ID specificati.|
|inherited|boolean|Se impostato su `true`, restituisce solo le macro utente dei prototipi host ereditate da un template.|
|selectHostGroups|query|Restituisce i gruppi host a cui appartiene la macro host nella proprietà [`hostgroups`](/manual/api/reference/hostgroup/object).<br><br>Utilizzato solo durante il recupero delle macro host.|
|selectHosts|query|Restituisce gli host a cui appartiene la macro host nella proprietà [`hosts`](/manual/api/reference/host/object).<br><br>Utilizzato solo durante il recupero delle macro host.|
|selectTemplateGroups|query|Restituisce i gruppi template a cui appartiene la macro template nella proprietà [`templategroups`](/manual/api/reference/templategroup/object).<br><br>Utilizzato solo durante il recupero delle macro template.|
|selectTemplates|query|Restituisce i template a cui appartiene la macro host nella proprietà [`templates`](/manual/api/reference/template/object).<br><br>Utilizzato solo durante il recupero delle macro host.|
|sortfield|string/array|Ordina il risultato in base alle proprietà specificate.<br><br>Valori possibili: `macro`.|
|countOutput|boolean|Questi parametri sono descritti nel [commento di riferimento](/manual/api/reference_commentary#common-get-method-parameters).|
|editable|boolean|^|
|excludeSearch|boolean|^|
|filter|object|^|
|limit|integer|^|
|output|query|^|
|preservekeys|boolean|^|
|search|object|^|
|searchByAny|boolean|^|
|searchWildcardsEnabled|boolean|^|
|sortorder|string/array|^|
|startSearch|boolean|^|

[comment]: # ({/0f02ef4c-141835f9})

[comment]: # ({7223bab1-7223bab1})
### Valori restituiti

`(integer/array)` Restituisce o:

- una matrice di oggetti;
- il conteggio degli oggetti recuperati, se il parametro `countOutput` è
    stato usato.

[comment]: # ({/7223bab1-7223bab1})

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

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

[comment]: # ({4540e2f0-7089e052})
#### Recupero delle macro host per un host

Recupera tutte le macro host definite per l'host "10198".

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

```json
{
    "jsonrpc": "2.0",
    "method": "usermacro.get",
    "params": {
        "output": "extend",
        "hostids": "10198"
    },
    "id": 1
}
```

Risposta:

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostmacroid": "9",
            "hostid": "10198",
            "macro": "{$INTERFACE}",
            "value": "eth0",
            "description": "",
            "type": "0",
            "automatic": "0"
        },
        {
            "hostmacroid": "11",
            "hostid": "10198",
            "macro": "{$SNMP_COMMUNITY}",
            "value": "public",
            "description": "",
            "type": "0",
            "automatic": "0"
        }
    ],
    "id": 1
}
```

[comment]: # ({/4540e2f0-7089e052})

[comment]: # ({885a2441-f0872791})
#### Recupero delle macro host per un template

Recupera le macro host definite per il template "10265" che contengono "STATUS" nel nome della macro.

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

```json
{
    "jsonrpc": "2.0",
    "method": "usermacro.get",
    "params": {
        "output": "extend",
        "hostids": "10265",
        "search": {
            "macro": "STATUS"
        }
    },
    "id": 1
}
```

Risposta:

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostmacroid": "6709",
            "hostid": "10265",
            "macro": "{$APACHE.STATUS.HOST}",
            "value": "",
            "description": "Il nome host o l'indirizzo IP dell'host della pagina di stato di Apache.",
            "type": "0",
            "automatic": "0",
            "config": {
                "type": "1",
                "priority": "1",
                "section_name": "",
                "label": "Host stato Apache",
                "description": "Nome host o indirizzo IP dell'host della pagina di stato di Apache.",
                "required": "1",
                "regex": "",
                "options": []
            }
        },
        {
            "hostmacroid": "814",
            "hostid": "10265",
            "macro": "{$APACHE.STATUS.PATH}",
            "value": "server-status?auto",
            "description": "Il percorso URL della pagina di stato di Apache.",
            "type": "0",
            "automatic": "0",
            "config": {
                "type": "1",
                "priority": "3",
                "section_name": "",
                "label": "Percorso pagina di stato Apache",
                "description": "Percorso URL della pagina di stato di Apache.",
                "required": "1",
                "regex": "",
                "options": []
            }
        },
        {
            "hostmacroid": "815",
            "hostid": "10265",
            "macro": "{$APACHE.STATUS.PORT}",
            "value": "80",
            "description": "La porta della pagina di stato di Apache.",
            "type": "0",
            "automatic": "0",
            "config": {
                "type": "1",
                "priority": "2",
                "section_name": "",
                "label": "Porta pagina di stato Apache",
                "description": "Nell'intervallo da 1 a 65535 inclusi.",
                "required": "1",
                "regex": "^-?([0-9]+|(([0-9]+)\\.([0-9]+)))$",
                "options": []
            }
        },
        {
            "hostmacroid": "816",
            "hostid": "10265",
            "macro": "{$APACHE.STATUS.SCHEME}",
            "value": "http",
            "description": "Lo schema della richiesta, che può essere HTTP o HTTPS.",
            "type": "0",
            "automatic": "0",
            "config": {
                "type": "2",
                "priority": "4",
                "section_name": "",
                "label": "Schema della richiesta",
                "description": "Schema della richiesta, che può essere HTTP o HTTPS.",
                "required": "0",
                "regex": "",
                "options": [
                    {
                        "value": "http",
                        "text": "HTTP"
                    },
                    {
                        "value": "https",
                        "text": "HTTPS"
                    }
                ]
            }
        }
    ],
    "id": 1
}
```

[comment]: # ({/885a2441-f0872791})

[comment]: # ({93c3e1f5-29b64a7a})
#### Recupero delle macro globali

Recupera tutte le macro globali.

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

```json
{
    "jsonrpc": "2.0",
    "method": "usermacro.get",
    "params": {
        "output": "extend",
        "globalmacro": true
    },
    "id": 1
}
```

Risposta:

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "globalmacroid": "6",
            "macro": "{$SNMP_COMMUNITY}",
            "value": "public",
            "description": "",
            "type": "0"
        }
    ],
    "id": 1
}
```

[comment]: # ({/93c3e1f5-29b64a7a})

[comment]: # ({26db0ec2-26db0ec2})
### Fonte

CUserMacro::get() in *ui/include/classes/api/services/CUserMacro.php*.

[comment]: # ({/26db0ec2-26db0ec2})
