object discoveryrule.create(object/array lldRules)
Este método permite crear nuevas reglas LLD.
Este método solo está disponible para los tipos de usuario Administrador y Superadministrador. Los permisos para llamar al método se pueden revocar en la configuración del rol de usuario. Ver Roles de usuario para más información.
(objeto/matriz)
Reglas LLD para crear.
Además de las [propiedades estándar de la regla LLD] (object#lld_rule), el método acepta los siguientes parámetros.
Parámetro | Tipo | Descripción |
---|---|---|
filter | objeto | Filtro de regla LLD para la regla LLD. |
preprocessing | matriz | Opciones de preprocesamiento de la regla LLD . |
lld_macro_paths | matriz | Opciones de regla LLD lld_macro_path. |
overrides | matriz | Opciones de las anulaciones de la regla LLD . |
(objeto)
Devuelve un objeto que contiene los ID de las reglas LLD creadas bajo la propiedad "itemids". El orden de los ID devueltos coincide con el orden de las reglas LLD suministradas.
Cree una regla LLD del agente Zabbix para descubrir sistemas de archivos montados. Las métricas descubiertas se actualizarán cada 30 segundos.
Solicitud:
{
"jsonrpc": "2.0",
"method": "discoveryrule.create",
"params": {
"name": "Mounted filesystem discovery",
"key_": "vfs.fs.discovery",
"hostid": "10197",
"type": 0,
"interfaceid": "112",
"delay": "30s"
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Respuesta:
Cree una regla LLD con un conjunto de condiciones para filtrar los resultados. Las condiciones se agruparán utilizando el operador "y" lógico.
Solicitud:
{
"jsonrpc": "2.0",
"method": "discoveryrule.create",
"params": {
"name": "Filtered LLD rule",
"key_": "lld",
"hostid": "10116",
"type": 0,
"interfaceid": "13",
"delay": "30s",
"filter": {
"evaltype": 1,
"conditions": [
{
"macro": "{#MACRO1}",
"value": "@regex1"
},
{
"macro": "{#MACRO2}",
"value": "@regex2",
"operator": "9"
},
{
"macro": "{#MACRO3}",
"value": "",
"operator": "12"
},
{
"macro": "{#MACRO4}",
"value": "",
"operator": "13"
}
]
}
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Respuesta:
Solicitud:
{
"jsonrpc": "2.0",
"method": "discoveryrule.create",
"params": {
"name": "LLD rule with LLD macro paths",
"key_": "lld",
"hostid": "10116",
"type": 0,
"interfaceid": "13",
"delay": "30s",
"lld_macro_paths": [
{
"lld_macro": "{#MACRO1}",
"path": "$.path.1"
},
{
"lld_macro": "{#MACRO2}",
"path": "$.path.2"
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Respuesta:
Create an LLD rule with a filter that will use a custom expression to evaluate the conditions. The LLD rule must only discover objects the "{#MACRO1}" macro value of which matches both regular expression "regex1" and "regex2", and the value of "{#MACRO2}" matches either "regex3" or "regex4". The formula IDs "A", "B", "C" and "D" have been chosen arbitrarily.
Request:
{
"jsonrpc": "2.0",
"method": "discoveryrule.create",
"params": {
"name": "Filtered LLD rule",
"key_": "lld",
"hostid": "10116",
"type": "0",
"interfaceid": "13",
"delay": "30s",
"filter": {
"evaltype": 3,
"formula": "(A and B) and (C or D)",
"conditions": [
{
"macro": "{#MACRO1}",
"value": "@regex1",
"formulaid": "A"
},
{
"macro": "{#MACRO1}",
"value": "@regex2",
"formulaid": "B"
},
{
"macro": "{#MACRO2}",
"value": "@regex3",
"formulaid": "C"
},
{
"macro": "{#MACRO2}",
"value": "@regex4",
"formulaid": "D"
}
]
}
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
Cree una regla LLD con encabezados y campos de consulta personalizados.
Solicitud:
{
"jsonrpc": "2.0",
"method": "discoveryrule.create",
"params": {
"hostid": "10257",
"interfaceid": "5",
"type": 19,
"name": "API HTTP agent",
"key_": "api_discovery_rule",
"value_type": 3,
"delay": "5s",
"url": "http://127.0.0.1?discoverer.php",
"query_fields": [
{
"mode": "json"
},
{
"elements": "2"
}
],
"headers": {
"X-Type": "api",
"Authorization": "Bearer mF_A.B5f-2.1JcM"
},
"allow_traps": 1,
"trapper_hosts": "127.0.0.1"
},
"auth": "d678e0b85688ce578ff061bd29a20d3b",
"id": 1
}
Respuesta:
Solicitud:
{
"jsonrpc": "2.0",
"method": "discoveryrule.create",
"params": {
"name": "Discovery rule with preprocessing",
"key_": "lld.with.preprocessing",
"hostid": "10001",
"ruleid": "27665",
"type": 0,
"value_type": 3,
"delay": "60s",
"interfaceid": "1155",
"preprocessing": [
{
"type": 20,
"params": "20",
"error_handler": 0,
"error_handler_params": ""
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Respuesta:
Solicitud:
{
"jsonrpc": "2.0",
"method": "discoveryrule.create",
"params": {
"name": "Discover database host",
"key_": "lld.with.overrides",
"hostid": "10001",
"type": 0,
"value_type": 3,
"delay": "60s",
"interfaceid": "1155",
"overrides": [
{
"name": "Discover MySQL host",
"step": "1",
"stop": "1",
"filter": {
"evaltype": "2",
"conditions": [
{
"macro": "{#UNIT.NAME}",
"operator": "8",
"value": "^mysqld\\.service$"
},
{
"macro": "{#UNIT.NAME}",
"operator": "8",
"value": "^mariadb\\.service$"
}
]
},
"operations": [
{
"operationobject": "3",
"operator": "2",
"value": "Database host",
"opstatus": {
"status": "0"
},
"optemplate": [
{
"templateid": "10170"
}
],
"optag": [
{
"tag": "Database",
"value": "MySQL"
}
]
}
]
},
{
"name": "Discover PostgreSQL host",
"step": "2",
"stop": "1",
"filter": {
"evaltype": "0",
"conditions": [
{
"macro": "{#UNIT.NAME}",
"operator": "8",
"value": "^postgresql\\.service$"
}
]
},
"operations": [
{
"operationobject": "3",
"operator": "2",
"value": "Database host",
"opstatus": {
"status": "0"
},
"optemplate": [
{
"templateid": "10263"
}
],
"optag": [
{
"tag": "Database",
"value": "PostgreSQL"
}
]
}
]
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Respuesta:
Cree una recopilación de datos simple utilizando una regla LLD de script.
Solicitud:
{
"jsonrpc": "2.0",
"method": "discoveryrule.create",
"params": {
"name": "Script example",
"key_": "custom.script.lldrule",
"hostid": "12345",
"type": 21,
"value_type": 4,
"params": "var request = new CurlHttpRequest();\nreturn request.Post(\"https://postman-echo.com/post\", JSON.parse(value));",
"parameters": [
{
"name": "host",
"value": "{HOST.CONN}"
}
],
"timeout": "6s",
"delay": "30s"
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 2
}
Respuesta:
-LLD rule filter -LLD macro paths -LLD rule preprocessing
CDiscoveryRule::create() en ui/include/classes/api/services/CDiscoveryRule.php.