discoveryrule.get

Descrizione

integer/array discoveryrule.get(object parameters)

Il metodo consente di recuperare le regole LLD in base ai parametri specificati.

Questo metodo è disponibile per utenti di qualsiasi tipo. Le autorizzazioni per chiamare il metodo possono essere revocate nelle impostazioni dei ruoli utente. Vedere Ruoli utente per ulteriori informazioni.

Parametri

(object) Parametri che definiscono l'output desiderato.

Il metodo supporta i seguenti parametri.

Parametro Tipo Descrizione
itemids ID/array Restituisce solo le regole LLD con gli ID specificati.
groupids ID/array Restituisce solo le regole LLD che appartengono agli host dei gruppi specificati.
hostids ID/array Restituisce solo le regole LLD che appartengono agli host specificati.
inherited boolean Se impostato su true, restituisce solo le regole LLD ereditate da un template.
interfaceids ID/array Restituisce solo le regole LLD che utilizzano le interfacce host specificate.
monitored boolean Se impostato su true, restituisce solo le regole LLD abilitate che appartengono a host monitorati.
templated boolean Se impostato su true, restituisce solo le regole LLD che appartengono ai template.
templateids ID/array Restituisce solo le regole LLD che appartengono ai template specificati.
selectDiscoveryData query Restituisce una proprietà discoveryData con i dati dell'oggetto di discovery della regola LLD. L'oggetto di discovery della regola LLD collega una regola LLD rilevata a un prototipo di regola LLD da cui è stata rilevata.
selectDiscoveryRulePrototypes query Restituisce una proprietà discoveryRulePrototypes con i prototipi di regola LLD che appartengono alla regola LLD.

Supporta count.
selectFilter query Restituisce una proprietà filter con i dati del filtro utilizzato dalla regola LLD.
selectGraphs query Restituisce una proprietà graphs con i prototipi di grafico che appartengono alla regola LLD.

Supporta count.
selectHostPrototypes query Restituisce una proprietà hostPrototypes con i prototipi di host che appartengono alla regola LLD.

Supporta count.
selectHosts query Restituisce una proprietà hosts con un array di host a cui appartiene la regola LLD.
selectItems query Restituisce una proprietà items con i prototipi di item che appartengono alla regola LLD.

Supporta count.
selectTriggers query Restituisce una proprietà triggers con i prototipi di trigger che appartengono alla regola LLD.

Supporta count.
selectLLDMacroPaths query Restituisce una proprietà lld_macro_paths con un elenco di macro LLD e dei percorsi ai valori assegnati a ciascuna macro corrispondente.
selectPreprocessing query Restituisce una proprietà preprocessing con le opzioni di preprocessing della regola LLD.
selectOverrides query Restituisce una proprietà lld_rule_overrides con un elenco di filtri di override, condizioni e operazioni eseguite sugli oggetti prototipo.
filter object Restituisce solo i risultati che corrispondono esattamente al filtro specificato.

Accetta un oggetto in cui le chiavi sono nomi di proprietà e i valori sono un singolo valore oppure un array di valori da confrontare.

Non supporta proprietà del tipo di dati text.

Supporta proprietà aggiuntive:
host - nome tecnico dell'host a cui appartiene la regola LLD.
limitSelects integer Limita il numero di record restituiti dalle sottoquery.

Si applica alle seguenti sottoquery: selectItems, selectGraphs, selectTriggers.
sortfield string/array Ordina il risultato in base alle proprietà specificate.

Valori possibili: itemid, name, key_, delay, type, status.
countOutput boolean Questi parametri sono descritti nel commento di riferimento.
editable boolean
excludeSearch boolean
limit integer
output query
preservekeys boolean
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch boolean

Valori restituiti

(integer/array) Restituisce uno dei seguenti:

  • un array di oggetti;
  • il numero di oggetti recuperati, se è stato utilizzato il parametro countOutput.

Esempi

Recupero delle discovery rule da un host

Recupera tutte le discovery rule per uno specifico ID host.

Richiesta:

{
    "jsonrpc": "2.0",
    "method": "discoveryrule.get",
    "params": {
        "output": "extend",
        "hostids": "10202"
    },
    "id": 1
}

Risposta:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "itemid": "27425",
            "type": "0",
            "snmp_oid": "",
            "hostid": "10202",
            "name": "Network interface discovery",
            "key_": "net.if.discovery",
            "delay": "1h",
            "status": "0",
            "trapper_hosts": "",
            "templateid": "22444",
            "valuemapid": "0",
            "params": "",
            "ipmi_sensor": "",
            "authtype": "0",
            "username": "",
            "password": "",
            "publickey": "",
            "privatekey": "",
            "flags": "1",
            "interfaceid": "119",
            "description": "Discovery of network interfaces as defined in global regular expression \"Network interfaces for discovery\".",
            "lifetime": "30d",
            "jmx_endpoint": "",
            "master_itemid": "0",
            "timeout": "",
            "url": "",
            "query_fields": [],
            "posts": "",
            "status_codes": "200",
            "follow_redirects": "1",
            "post_type": "0",
            "http_proxy": "",
            "headers": [],
            "retrieve_mode": "0",
            "request_method": "0",
            "ssl_cert_file": "",
            "ssl_key_file": "",
            "ssl_key_password": "",
            "verify_peer": "0",
            "verify_host": "0",
            "allow_traps": "0",
            "uuid": "",
            "lifetime_type": "0",
            "enabled_lifetime_type": "2",
            "enabled_lifetime": "0",
            "state": "0",
            "error": "",
            "parameters": []
        },
        {
            "itemid": "27426",
            "type": "0",
            "snmp_oid": "",
            "hostid": "10202",
            "name": "Mounted filesystem discovery",
            "key_": "vfs.fs.discovery",
            "delay": "1h",
            "status": "0",
            "trapper_hosts": "",
            "templateid": "22450",
            "valuemapid": "0",
            "params": "",
            "ipmi_sensor": "",
            "authtype": "0",
            "username": "",
            "password": "",
            "publickey": "",
            "privatekey": "",
            "flags": "1",
            "interfaceid": "119",
            "description": "Discovery of file systems of different types as defined in global regular expression \"File systems for discovery\".",
            "lifetime": "30d",
            "jmx_endpoint": "",
            "master_itemid": "0",
            "timeout": "",
            "url": "",
            "query_fields": [],
            "posts": "",
            "status_codes": "200",
            "follow_redirects": "1",
            "post_type": "0",
            "http_proxy": "",
            "headers": [],
            "retrieve_mode": "0",
            "request_method": "0",
            "ssl_cert_file": "",
            "ssl_key_file": "",
            "ssl_key_password": "",
            "verify_peer": "0",
            "verify_host": "0",
            "allow_traps": "0",
            "uuid": "",
            "lifetime_type": "0",
            "enabled_lifetime_type": "2",
            "enabled_lifetime": "0",
            "state": "0",
            "error": "",
            "parameters": []
        }
    ],
    "id": 1
}

Recupero delle condizioni del filtro

Recupera il nome della regola LLD "24681" e le relative condizioni del filtro. Il filtro usa il tipo di valutazione "and", quindi la proprietà formula è vuota e eval_formula viene generata automaticamente.

Request:

{
    "jsonrpc": "2.0",
    "method": "discoveryrule.get",
    "params": {
        "output": ["name"],
        "selectFilter": "extend",
        "itemids": ["24681"]
    },
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "itemid": "24681",
            "name": "Filtered LLD rule",
            "filter": {
                "evaltype": "1",
                "formula": "",
                "conditions": [
                    {
                        "macro": "{#MACRO1}",
                        "value": "@regex1",
                        "operator": "8",
                        "formulaid": "A"
                    },
                    {
                        "macro": "{#MACRO2}",
                        "value": "@regex2",
                        "operator": "9",
                        "formulaid": "B"
                    },
                    {
                        "macro": "{#MACRO3}",
                        "value": "",
                        "operator": "12",
                        "formulaid": "C"
                    },
                    {
                        "macro": "{#MACRO4}",
                        "value": "",
                        "operator": "13",
                        "formulaid": "D"
                    }
                ],
                "eval_formula": "A and B and C and D"
            }
        }
    ],
    "id": 1
}

Recupera regola LLD tramite URL

Recupera la regola LLD per l'host in base al valore del campo URL della regola. È supportata solo la corrispondenza esatta della stringa URL definita per la regola LLD.

Richiesta:

{
    "jsonrpc": "2.0",
    "method": "discoveryrule.get",
    "params": {
        "hostids": "10257",
        "filter": {
            "type": 19,
            "url": "http://127.0.0.1/discoverer.php"
        }
    },
    "id": 1
}

Risposta:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "itemid": "28336",
            "type": "19",
            "snmp_oid": "",
            "hostid": "10257",
            "name": "API HTTP agent",
            "key_": "api_discovery_rule",
            "delay": "5s",
            "status": "0",
            "trapper_hosts": "",
            "templateid": "0",
            "valuemapid": "0",
            "params": "",
            "ipmi_sensor": "",
            "authtype": "0",
            "username": "",
            "password": "",
            "publickey": "",
            "privatekey": "",
            "flags": "1",
            "interfaceid": "5",
            "description": "",
            "lifetime": "30d",
            "jmx_endpoint": "",
            "master_itemid": "0",
            "timeout": "",
            "url": "http://127.0.0.1/discoverer.php",
            "query_fields": [
                {
                    "name": "mode",
                    "value": "json"
                },
                {
                    "name": "elements",
                    "value": "2"
                }
            ],
            "posts": "",
            "status_codes": "200",
            "follow_redirects": "1",
            "post_type": "0",
            "http_proxy": "",
            "headers": [
                {
                    "name" : "X-Type",
                    "value": "api"
                },
                {
                    "name": "Authorization",
                    "value": "Bearer mF_A.B5f-2.1JcM"
                }
            ],
            "retrieve_mode": "0",
            "request_method": "1",
            "ssl_cert_file": "",
            "ssl_key_file": "",
            "ssl_key_password": "",
            "verify_peer": "0",
            "verify_host": "0",
            "allow_traps": "0",
            "uuid": "",
            "lifetime_type": "0",
            "enabled_lifetime_type": "2",
            "enabled_lifetime": "0",
            "state": "0",
            "error": "",
            "parameters": []
        }
    ],
    "id": 1
}

Recuperare una regola LLD con override

Recupera una regola LLD che ha varie impostazioni di override.

Richiesta:

{
    "jsonrpc": "2.0",
    "method": "discoveryrule.get",
    "params": {
        "output": ["name"],
        "itemids": "30980",
        "selectOverrides": ["name", "step", "stop", "filter", "operations"]
    },
    "id": 1
}

Risposta:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "name": "Discover database host",
            "overrides": [
                {
                    "name": "Discover MySQL host",
                    "step": "1",
                    "stop": "1",
                    "filter": {
                        "evaltype": "2",
                        "formula": "",
                        "conditions": [
                            {
                                "macro": "{#UNIT.NAME}",
                                "operator": "8",
                                "value": "^mysqld\\.service$",
                                "formulaid": "A"
                            },
                            {
                                "macro": "{#UNIT.NAME}",
                                "operator": "8",
                                "value": "^mariadb\\.service$",
                                "formulaid": "B"
                            }
                        ],
                        "eval_formula": "A or B"
                    },
                    "operations": [
                        {
                            "operationobject": "3",
                            "operator": "2",
                            "value": "Database host",
                            "opstatus": {
                                "status": "0"
                            },
                            "optag": [
                                {
                                    "tag": "database",
                                    "value": "mysql"
                                }
                            ],
                            "optemplate": [
                                {
                                    "templateid": "10170"
                                }
                            ]
                        }
                    ]
                },
                {
                    "name": "Discover PostgreSQL host",
                    "step": "2",
                    "stop": "1",
                    "filter": {
                        "evaltype": "0",
                        "formula": "",
                        "conditions": [
                            {
                                "macro": "{#UNIT.NAME}",
                                "operator": "8",
                                "value": "^postgresql\\.service$",
                                "formulaid": "A"
                            }
                        ],
                        "eval_formula": "A"
                    },
                    "operations": [
                        {
                            "operationobject": "3",
                            "operator": "2",
                            "value": "Database host",
                            "opstatus": {
                                "status": "0"
                            },
                            "optag": [
                                {
                                    "tag": "database",
                                    "value": "postgresql"
                                }
                            ],
                            "optemplate": [
                                {
                                    "templateid": "10263"
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ],
    "id": 1
}

Vedi anche

Sorgente

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