Appendix 1. Reference commentary

Notation

Data types

The Zabbix API supports the following data types as input:

TypeDescription
booleanA boolean value, accepts either true or false.
flagThe value is considered to be ​true​ if it is passed and not equal to ​null​ and ​false​ otherwise.
integerA whole number.
floatA floating point number.
stringA text string.
textA longer text string.
timestampA Unix timestamp.
arrayAn ordered sequence of values, that is, a plain array.
objectAn associative array.
queryA value which defines, what data should be returned.

Can be defined as an array of property names to return only specific properties, or as one of the predefined values:
extend - returns all object properties;
count - returns the number of retrieved records, supported only by certain subselects.

Zabbix API always returns values as strings or arrays only.

Property labels

Some of the objects properties are marked with short labels to describe their behavior. The following labels are used:

  • readonly - the value of the property is set automatically and cannot be defined or changed by the client;

  • constant - the value of the property can be set when creating an object, but cannot be changed after.

Reserved ID value “0”

Reserved ID value “0” can be used to filter elements and to remove referenced objects. For example, to remove a referenced proxy from a host, proxy_hostid should be set to 0 (“proxy_hostid”: “0”) or to filter hosts monitored by server option proxyids should be set to 0 (“proxyids”: “0”).

Common “get” method parameters

The following parameters are supported by all get methods:

ParameterTypeDescription
countOutputbooleanReturn the number of records in the result instead of the actual data.
editablebooleanIf set to true return only objects that the user has write permissions to.

Default: false.
excludeSearchbooleanReturn results that do not match the criteria given in the search parameter.
filterobjectReturn only those results that exactly match the given filter.

Accepts an array, where the keys are property names, and the values are either a single value or an array of values to match against.

Doesn’t work for text fields.
limitintegerLimit the number of records returned.
outputqueryObject properties to be returned.

Default: extend.
preservekeysbooleanUse IDs as keys in the resulting array.
searchobjectReturn results that match the given wildcard search (case-insensitive).

Accepts an array, where the keys are property names, and the values are strings to search for. If no additional options are given, this will perform a LIKE “%…%” search.

Works only for string and text fields.
searchByAnybooleanIf set to true return results that match any of the criteria given in the filter or search parameter instead of all of them.

Default: false.
searchWildcardsEnabledbooleanIf set to true enables the use of “*” as a wildcard character in the search parameter.

Default: false.
sortfieldstring/arraySort the result by the given properties. Refer to a specific API get method description for a list of properties that can be used for sorting. Macros are not expanded before sorting.

If no value is specified, data will be returned unsorted.
sortorderstring/arrayOrder of sorting. If an array is passed, each value will be matched to the corresponding property given in the sortfield parameter.

Possible values are:
ASC - (default) ascending;
DESC - descending.
startSearchbooleanThe search parameter will compare the beginning of fields, that is, perform a LIKE “…%” search instead.

Ignored if searchWildcardsEnabled is set to true.

Examples

User permission check

Does the user have permission to write to hosts whose names begin with “MySQL” or “Linux” ?

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.get",
  4. "params": {
  5. "countOutput": true,
  6. "search": {
  7. "host": ["MySQL", "Linux"]
  8. },
  9. "editable": true,
  10. "startSearch": true,
  11. "searchByAny": true
  12. },
  13. "auth": "766b71ee543230a1182ca5c44d353e36",
  14. "id": 1
  15. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": "0",
  4. "id": 1
  5. }

Zero result means no hosts with read/write permissions.

Mismatch сounting

Count the number of hosts whose names do not contain the substring “ubuntu”

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.get",
  4. "params": {
  5. "countOutput": true,
  6. "search": {
  7. "host": "ubuntu"
  8. },
  9. "excludeSearch": true
  10. },
  11. "auth": "766b71ee543230a1182ca5c44d353e36",
  12. "id": 1
  13. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": "44",
  4. "id": 1
  5. }

Searching for hosts using wildcards

Find hosts whose name contains word “server” and have interface ports “10050” or “10071”. Sort the result by host name in descending order and limit it to 5 hosts.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.get",
  4. "params": {
  5. "output": ["hostid", "host"],
  6. "selectInterfaces": ["port"],
  7. "filter": {
  8. "port": ["10050", "10071"]
  9. },
  10. "search": {
  11. "host": "*server*"
  12. },
  13. "searchWildcardsEnabled": true,
  14. "searchByAny": true,
  15. "sortfield": "host",
  16. "sortorder": "DESC",
  17. "limit": 5
  18. },
  19. "auth": "766b71ee543230a1182ca5c44d353e36",
  20. "id": 1
  21. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "50003",
  6. "host": "WebServer-Tomcat02",
  7. "interfaces": [
  8. {
  9. "port": "10071"
  10. }
  11. ]
  12. },
  13. {
  14. "hostid": "50005",
  15. "host": "WebServer-Tomcat01",
  16. "interfaces": [
  17. {
  18. "port": "10071"
  19. }
  20. ]
  21. },
  22. {
  23. "hostid": "50004",
  24. "host": "WebServer-Nginx",
  25. "interfaces": [
  26. {
  27. "port": "10071"
  28. }
  29. ]
  30. },
  31. {
  32. "hostid": "99032",
  33. "host": "MySQL server 01",
  34. "interfaces": [
  35. {
  36. "port": "10050"
  37. }
  38. ]
  39. },
  40. {
  41. "hostid": "99061",
  42. "host": "Linux server 01",
  43. "interfaces": [
  44. {
  45. "port": "10050"
  46. }
  47. ]
  48. }
  49. ],
  50. "id": 1
  51. }

Searching for hosts using wildcards with “preservekeys”

If you add the parameter “preservekeys” to the previous request, the result is returned as an associative array, where the keys are the id of the objects.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.get",
  4. "params": {
  5. "output": ["hostid", "host"],
  6. "selectInterfaces": ["port"],
  7. "filter": {
  8. "port": ["10050", "10071"]
  9. },
  10. "search": {
  11. "host": "*server*"
  12. },
  13. "searchWildcardsEnabled": true,
  14. "searchByAny": true,
  15. "sortfield": "host",
  16. "sortorder": "DESC",
  17. "limit": 5,
  18. "preservekeys": true
  19. },
  20. "auth": "766b71ee543230a1182ca5c44d353e36",
  21. "id": 1
  22. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "50003": {
  5. "hostid": "50003",
  6. "host": "WebServer-Tomcat02",
  7. "interfaces": [
  8. {
  9. "port": "10071"
  10. }
  11. ]
  12. },
  13. "50005": {
  14. "hostid": "50005",
  15. "host": "WebServer-Tomcat01",
  16. "interfaces": [
  17. {
  18. "port": "10071"
  19. }
  20. ]
  21. },
  22. "50004": {
  23. "hostid": "50004",
  24. "host": "WebServer-Nginx",
  25. "interfaces": [
  26. {
  27. "port": "10071"
  28. }
  29. ]
  30. },
  31. "99032": {
  32. "hostid": "99032",
  33. "host": "MySQL server 01",
  34. "interfaces": [
  35. {
  36. "port": "10050"
  37. }
  38. ]
  39. },
  40. "99061": {
  41. "hostid": "99061",
  42. "host": "Linux server 01",
  43. "interfaces": [
  44. {
  45. "port": "10050"
  46. }
  47. ]
  48. }
  49. },
  50. "id": 1
  51. }