discoveryrule.create

    This method allows to create new LLD rules.

    This method is only available to Admin and Super admin user types. Permissions to call the method can be revoked in user role settings. See for more information.

    Parameters

    (object/array) LLD rules to create.

    Additionally to the , the method accepts the following parameters.

    (object) Returns an object containing the IDs of the created LLD rules under the itemids property. The order of the returned IDs matches the order of the passed LLD rules.

    Examples

    Creating an LLD rule

    Create a Zabbix agent LLD rule to discover mounted file systems. Discovered items will be updated every 30 seconds.

    :

    Response:

    1. {
    2. "jsonrpc": "2.0",
    3. "result": {
    4. "itemids": [
    5. "27665"
    6. ]
    7. },
    8. "id": 1
    9. }

    Using a filter

    :

    1. {
    2. "jsonrpc": "2.0",
    3. "method": "discoveryrule.create",
    4. "params": {
    5. "name": "Filtered LLD rule",
    6. "key_": "lld",
    7. "hostid": "10116",
    8. "type": 0,
    9. "interfaceid": "13",
    10. "delay": "30s",
    11. "filter": {
    12. "evaltype": 1,
    13. "conditions": [
    14. {
    15. "macro": "{#MACRO1}",
    16. "value": "@regex1"
    17. },
    18. {
    19. "macro": "{#MACRO2}",
    20. "value": "@regex2",
    21. "operator": "9"
    22. },
    23. {
    24. "macro": "{#MACRO3}",
    25. "value": "",
    26. "operator": "12"
    27. },
    28. {
    29. "macro": "{#MACRO4}",
    30. "value": "",
    31. "operator": "13"
    32. }
    33. ]
    34. }
    35. },
    36. "id": 1
    37. }

    Response:

    1. {
    2. "jsonrpc": "2.0",
    3. "result": {
    4. "itemids": [
    5. "27665"
    6. ]
    7. },
    8. "id": 1
    9. }

    Creating a LLD rule with macro paths

    :

    1. {
    2. "jsonrpc": "2.0",
    3. "method": "discoveryrule.create",
    4. "params": {
    5. "name": "LLD rule with LLD macro paths",
    6. "key_": "lld",
    7. "hostid": "10116",
    8. "type": 0,
    9. "interfaceid": "13",
    10. "delay": "30s",
    11. "lld_macro_paths": [
    12. {
    13. "lld_macro": "{#MACRO1}",
    14. "path": "$.path.1"
    15. },
    16. {
    17. "lld_macro": "{#MACRO2}",
    18. "path": "$.path.2"
    19. }
    20. ]
    21. },
    22. "id": 1
    23. }

    Response:

    Using a custom expression filter

    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.

    :

    1. {
    2. "jsonrpc": "2.0",
    3. "method": "discoveryrule.create",
    4. "params": {
    5. "name": "Filtered LLD rule",
    6. "key_": "lld",
    7. "hostid": "10116",
    8. "type": 0,
    9. "interfaceid": "13",
    10. "delay": "30s",
    11. "filter": {
    12. "formula": "(A and B) and (C or D)",
    13. "conditions": [
    14. {
    15. "macro": "{#MACRO1}",
    16. "value": "@regex1",
    17. },
    18. {
    19. "macro": "{#MACRO1}",
    20. "value": "@regex2",
    21. "formulaid": "B"
    22. },
    23. {
    24. "macro": "{#MACRO2}",
    25. "value": "@regex3",
    26. "formulaid": "C"
    27. },
    28. {
    29. "macro": "{#MACRO2}",
    30. "value": "@regex4",
    31. "formulaid": "D"
    32. }
    33. ]
    34. }
    35. },
    36. "id": 1
    37. }

    Response:

    1. {
    2. "jsonrpc": "2.0",
    3. "result": {
    4. "itemids": [
    5. "27665"
    6. ]
    7. },
    8. "id": 1
    9. }

    Using custom query fields and headers

    Create LLD rule with custom query fields and headers.

    1. {
    2. "jsonrpc": "2.0",
    3. "method": "discoveryrule.create",
    4. "params": {
    5. "hostid": "10257",
    6. "interfaceid": "5",
    7. "type": 19,
    8. "name": "API HTTP agent",
    9. "key_": "api_discovery_rule",
    10. "value_type": 3,
    11. "delay": "5s",
    12. "url": "http://127.0.0.1?discoverer.php",
    13. "query_fields": [
    14. {
    15. "mode": "json"
    16. },
    17. {
    18. "elements": "2"
    19. }
    20. ],
    21. "headers": {
    22. "X-Type": "api",
    23. "Authorization": "Bearer mF_A.B5f-2.1JcM"
    24. },
    25. "allow_traps": 1,
    26. "trapper_hosts": "127.0.0.1"
    27. },
    28. "id": 1
    29. }

    Response:

    1. {
    2. "jsonrpc": "2.0",
    3. "result": {
    4. "itemids": [
    5. "28336"
    6. ]
    7. },
    8. "id": 1
    9. }

    Creating a LLD rule with preprocessing

    Request:

    Response:

    1. {
    2. "jsonrpc": "2.0",
    3. "result": {
    4. "itemids": [
    5. "44211"
    6. ]
    7. },
    8. "id": 1
    9. }

    Creating a LLD rule with overrides

    Request:

    1. {
    2. "jsonrpc": "2.0",
    3. "method": "discoveryrule.create",
    4. "params": {
    5. "name": "Discover database host",
    6. "key_": "lld.with.overrides",
    7. "hostid": "10001",
    8. "type": 0,
    9. "value_type": 3,
    10. "delay": "60s",
    11. "interfaceid": "1155",
    12. "overrides": [
    13. {
    14. "name": "Discover MySQL host",
    15. "step": "1",
    16. "stop": "1",
    17. "filter": {
    18. "evaltype": "2",
    19. "conditions": [
    20. {
    21. "value": "^mysqld\\.service$"
    22. },
    23. {
    24. "macro": "{#UNIT.NAME}",
    25. "operator": "8",
    26. "value": "^mariadb\\.service$"
    27. }
    28. ]
    29. },
    30. "operations": [
    31. {
    32. "operationobject": "3",
    33. "operator": "2",
    34. "value": "Database host",
    35. "opstatus": {
    36. "status": "0"
    37. },
    38. "optemplate": [
    39. {
    40. "templateid": "10170"
    41. }
    42. ],
    43. "optag": [
    44. {
    45. "tag": "Database",
    46. "value": "MySQL"
    47. }
    48. ]
    49. }
    50. ]
    51. },
    52. {
    53. "name": "Discover PostgreSQL host",
    54. "step": "2",
    55. "stop": "1",
    56. "filter": {
    57. "evaltype": "0",
    58. "conditions": [
    59. {
    60. "macro": "{#UNIT.NAME}",
    61. "operator": "8",
    62. "value": "^postgresql\\.service$"
    63. }
    64. ]
    65. },
    66. "operations": [
    67. {
    68. "operationobject": "3",
    69. "operator": "2",
    70. "value": "Database host",
    71. "opstatus": {
    72. "status": "0"
    73. },
    74. "optemplate": [
    75. {
    76. "templateid": "10263"
    77. }
    78. ],
    79. "optag": [
    80. {
    81. "tag": "Database",
    82. "value": "PostgreSQL"
    83. }
    84. ]
    85. }
    86. ]
    87. }
    88. ]
    89. },
    90. "id": 1
    91. }

    Response:

    1. {
    2. "jsonrpc": "2.0",
    3. "result": {
    4. "itemids": [
    5. "30980"
    6. ]
    7. },
    8. "id": 1
    9. }

    Create script LLD rule

    Create a simple data collection using a script LLD rule.

    Request:

    1. {
    2. "jsonrpc": "2.0",
    3. "method": "discoveryrule.create",
    4. "params": {
    5. "name": "Script example",
    6. "key_": "custom.script.lldrule",
    7. "hostid": "12345",
    8. "type": 21,
    9. "value_type": 4,
    10. "params": "var request = new HttpRequest();\nreturn request.post(\"https://postman-echo.com/post\", JSON.parse(value));",
    11. "parameters": [{
    12. "name": "host",
    13. "value": "{HOST.CONN}"
    14. }],
    15. "timeout": "6s",
    16. "delay": "30s"
    17. },
    18. "id": 1

    Response:

    Source