discoveryrule.create

Apraksts

object discoveryrule.create(object/array lldRules)

Šī metode ļauj izveidot jaunus LLD noteikumus.

Šī metode ir pieejama tikai Admin un Super admin lietotāju tipiem. Atļaujas izsaukt šo metodi var tikt atsauktas lietotāja lomas iestatījumos. Plašāku informāciju skatiet sadaļā Lietotāju lomas.

Parametri

(object/array) Izveidojamie LLD noteikumi.

Papildus standarta LLD noteikumu īpašībām metode pieņem šādus parametrus.

Parametrs Tips Apraksts
filter object LLD noteikuma filtrs LLD noteikumam.
preprocessing object/array LLD noteikuma priekšapstrādes opcijas.
lld_macro_paths object/array LLD noteikuma lld_macro_path opcijas.
overrides object/array LLD noteikuma ignorēšanas opcijas.

Atgrieztās vērtības

(object) Atgriež objektu, kas satur izveidoto LLD noteikumu ID īpašībā itemids. Atgriezto ID secība atbilst nodoto LLD noteikumu secībai.

Piemēri

LLD kārtulas izveide

Izveidojiet Zabbix aģenta LLD kārtulu, lai atklātu piemontētās failu sistēmas. Atklātie vienumi tiks atjaunināti ik pēc 30 sekundēm.

Pieprasījums:

{
    "jsonrpc": "2.0",
    "method": "discoveryrule.create",
    "params": {
        "name": "Mounted filesystem discovery",
        "key_": "vfs.fs.discovery",
        "hostid": "10197",
        "type": 0,
        "interfaceid": "112",
        "delay": "30s"
    },
    "id": 1
}

Atbilde:

{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "27665"
        ]
    },
    "id": 1
}

Filtra izmantošana

Izveidojiet LLD kārtulu ar nosacījumu kopu, pēc kuras filtrēt rezultātus. Nosacījumi tiks grupēti kopā, izmantojot loģisko operatoru "and".

Pieprasījums:

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

Atbilde:

{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "27665"
        ]
    },
    "id": 1
}

LLD kārtulas izveide ar makro ceļiem

Pieprasījums:

{
    "jsonrpc": "2.0",
    "method": "discoveryrule.create",
    "params": {
        "name": "LLD kārtula ar LLD makro ceļiem",
        "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"
            }
        ]
    },
    "id": 1
}

Atbilde:

{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "27665"
        ]
    },
    "id": 1
}

Pielāgotas izteiksmes filtra izmantošana

Izveidojiet LLD kārtulu ar filtru, kas nosacījumu novērtēšanai izmantos pielāgotu izteiksmi. LLD kārtulai jāatklāj tikai tie objekti, kuru "{#MACRO1}" makro vērtība atbilst gan regulārajai izteiksmei "regex1", gan "regex2", un "{#MACRO2}" vērtība atbilst vai nu "regex3", vai "regex4". Formulu ID "A", "B", "C" un "D" ir izvēlēti patvaļīgi.

Pieprasījums:

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

Atbilde:

{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "27665"
        ]
    },
    "id": 1
}

Pielāgotu vaicājuma lauku un galveņu izmantošana

Izveidojiet LLD kārtulu ar pielāgotiem vaicājuma laukiem un galvenēm.

Pieprasījums:

{
    "jsonrpc": "2.0",
    "method": "discoveryrule.create",
    "params": {
        "hostid": "10257",
        "interfaceid": "5",
        "type": 19,
        "name": "API HTTP aģents",
        "key_": "api_discovery_rule",
        "delay": "5s",
        "url": "http://127.0.0.1?discoverer.php",
        "query_fields": [
            {
                "name": "mode",
                "value": "json"
            },
            {
                "name": "elements",
                "value": "2"
            }
        ],
        "headers": [
            {
                "name": "X-Type",
                "value": "api"
            },
            {
                "name": "Authorization",
                "value": "Bearer mF_A.B5f-2.1JcM"
            }
        ],
        "allow_traps": 1,
        "trapper_hosts": "127.0.0.1"
    },
    "id": 1
}

Atbilde:

{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "28336"
        ]
    },
    "id": 1
}

LLD kārtulas izveide ar priekšapstrādi

Pieprasījums:

{
    "jsonrpc": "2.0",
    "method": "discoveryrule.create",
    "params": {
        "name": "Atklāšanas kārtula ar priekšapstrādi",
        "key_": "lld.with.preprocessing",
        "hostid": "10001",
        "ruleid": "27665",
        "type": 0,
        "delay": "60s",
        "interfaceid": "1155",
        "preprocessing": [
            {
                "type": 20,
                "params": "20",
                "error_handler": 0,
                "error_handler_params": ""
            }
        ]
    },
    "id": 1
}

Atbilde:

{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "44211"
        ]
    },
    "id": 1
}

LLD kārtulas izveide ar ignorēšanas noteikumiem

Pieprasījums:

{
    "jsonrpc": "2.0",
    "method": "discoveryrule.create",
    "params": {
        "name": "Atklāt datubāzes hostu",
        "key_": "lld.with.overrides",
        "hostid": "10001",
        "type": 0,
        "delay": "60s",
        "interfaceid": "1155",
        "overrides": [
            {
                "name": "Atklāt MySQL hostu",
                "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": "Datubāzes hosts",
                        "opstatus": {
                            "status": "0"
                        },
                        "optemplate": [
                            {
                                "templateid": "10170"
                            }
                        ],
                        "optag": [
                            {
                                "tag": "database",
                                "value": "mysql"
                            }
                        ]
                    }
                ]
            },
            {
                "name": "Atklāt PostgreSQL hostu",
                "step": "2",
                "stop": "1",
                "filter": {
                    "evaltype": "0",
                    "conditions": [
                        {
                            "macro": "{#UNIT.NAME}",
                            "operator": "8",
                            "value": "^postgresql\\.service$"
                        }
                    ]
                },
                "operations": [
                    {
                        "operationobject": "3",
                        "operator": "2",
                        "value": "Datubāzes hosts",
                        "opstatus": {
                            "status": "0"
                        },
                        "optemplate": [
                            {
                                "templateid": "10263"
                            }
                        ],
                        "optag": [
                            {
                                "tag": "database",
                                "value": "postgresql"
                            }
                        ]
                    }
                ]
            }
        ]
    },
    "id": 1
}

Atbilde:

{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "30980"
        ]
    },
    "id": 1
}

Izveidot skripta LLD kārtulu

Izveidojiet vienkāršu datu vākšanu, izmantojot skripta LLD kārtulu.

Pieprasījums:

{
    "jsonrpc": "2.0",
    "method": "discoveryrule.create",
    "params": {
        "name": "Script example",
        "key_": "custom.script.lldrule",
        "hostid": "12345",
        "type": 21,
        "params": "var request = new HttpRequest();\nreturn request.post(\"https://postman-echo.com/post\", JSON.parse(value));",
        "parameters": [{
            "name": "host",
            "value": "{HOST.CONN}"
        }],
        "timeout": "6s",
        "delay": "30s"
    },
    "id": 1
}

Atbilde:

{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "23865"
        ]
    },
    "id": 1
}

Izveidot LLD kārtulu ar norādītu atspējošanas laika periodu un bez dzēšanas

Izveidojiet LLD kārtulu ar pielāgotu laika periodu entītijas atspējošanai pēc tam, kad tā vairs netiek atklāta, ar iestatījumu, ka tā nekad netiks dzēsta.

Pieprasījums:

{
    "jsonrpc": "2.0",
    "method": "discoveryrule.create",
    "params": {
        "name": "lld disable after 1h",
        "key_": "lld.disable",
        "hostid": "10001",
        "type": 2,
        "lifetime_type": 1,
        "enabled_lifetime_type": 0, 
        "enabled_lifetime": "1h"
    },
    "id": 1
}

Atbilde:

{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "46864"
        ]
    },
    "id": 1
}

Skatiet arī

Avots

CDiscoveryRule::create() failā ui/include/classes/api/services/CDiscoveryRule.php.