item.create

Description

object item.create(object/array **items**)

This method allows to create new items.

Web items cannot be created via the Zabbix API.

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 User roles for more information.

Parameters

(object/array) Items to create.

Additionally to the standard item properties, the method accepts the following parameters.

ParameterTypeDescription
applicationsarrayIDs of the applications to add the item to.
preprocessingarrayItem preprocessing options.

Return values

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

Examples

Creating an item

Create a numeric Zabbix agent item to monitor free disk space on host with ID “30074” and add it to two applications.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "item.create",
  4. "params": {
  5. "name": "Free disk space on /home/joe/",
  6. "key_": "vfs.fs.size[/home/joe/,free]",
  7. "hostid": "30074",
  8. "type": 0,
  9. "value_type": 3,
  10. "interfaceid": "30084",
  11. "applications": [
  12. "609",
  13. "610"
  14. ],
  15. "delay": "30s"
  16. },
  17. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  18. "id": 1
  19. }

Response:

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

Creating a host inventory item

Create a Zabbix agent item to populate the host’s “OS” inventory field.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "item.create",
  4. "params": {
  5. "name": "uname",
  6. "key_": "system.uname",
  7. "hostid": "30021",
  8. "type": 0,
  9. "interfaceid": "30007",
  10. "value_type": 1,
  11. "delay": "10s",
  12. "inventory_link": 5
  13. },
  14. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  15. "id": 1
  16. }

Response:

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

Creating an item with preprocessing

Create an item using custom multiplier.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "item.create",
  4. "params": {
  5. "name": "Device uptime",
  6. "key_": "sysUpTime",
  7. "hostid": "11312",
  8. "type": 4,
  9. "snmp_oid": "SNMPv2-MIB::sysUpTime.0",
  10. "value_type": 1,
  11. "delay": "60s",
  12. "units": "uptime",
  13. "interfaceid": "1156",
  14. "preprocessing": [
  15. {
  16. "type": "1",
  17. "params": "0.01",
  18. "error_handler": "1",
  19. "error_handler_params": ""
  20. }
  21. ]
  22. },
  23. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  24. "id": 1
  25. }

Response:

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

Creating dependent item

Create a dependent item for the master item with ID 24759. Only dependencies on the same host are allowed, therefore master and the dependent item should have the same hostid.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "item.create",
  4. "params": {
  5. "hostid": "30074",
  6. "name": "Dependent test item",
  7. "key_": "dependent.item",
  8. "type": "18",
  9. "master_itemid": "24759",
  10. "value_type": "2"
  11. },
  12. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  13. "id": 1
  14. }

Response:

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

Create HTTP agent item

Create POST request method item with JSON response preprocessing.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "item.create",
  4. "params": {
  5. "url":"http://127.0.0.1/http.php",
  6. "query_fields": [
  7. {
  8. "mode":"json"
  9. },
  10. {
  11. "min": "10"
  12. },
  13. {
  14. "max": "100"
  15. }
  16. ],
  17. "interfaceid": "1",
  18. "type":"19",
  19. "hostid":"10254",
  20. "delay":"5s",
  21. "key_":"json",
  22. "name":"http agent example JSON",
  23. "value_type":"0",
  24. "output_format":"1",
  25. "preprocessing": [
  26. {
  27. "type": "12",
  28. "params": "$.random"
  29. }
  30. ]
  31. },
  32. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  33. "id": 2
  34. }

Response:

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

Create script item

Create a simple data collection using a script item.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "item.create",
  4. "params": {
  5. "name": "Script example",
  6. "key_": "custom.stript.item",
  7. "hostid": "12345",
  8. "type": 21,
  9. "value_type": 4,
  10. "params": "var request = new CurlHttpRequest();\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. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  19. "id": 2
  20. }

Response:

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

Source

CItem::create() in ui/include/classes/api/services/CItem.php.