附录 1. 参考说明

    数据类型

    Zabbix API始终仅以字符串或数组的形式返回值。

    属性标签

    一些对象属性用短标签来描述它们的行为。可使用以下标签:

    • readonly - 属性值是自动设置的,不能被客户端定义或修改;
    • constant - 属性值可以在创建对象时被设置,创建后不能被修改。

    预留ID值“0”,可以用来过滤元素和删除引用的对象。例如,从主机中删除一个引用的代理,proxy_hostid 应该设置为 0 (“proxy_hostid”: “0”), 或者要过滤被zabbix server监控的主机,proxyids 选项应该被设置为 0 (“proxyids”: “0”)。

    所有的get方法都支持以下参数:

    参数类型描述
    countOutputboolean返回结果中的记录数,而不是实际的数据。
    editableboolean如果设置为true,则只返回用户具有写权限的对象。

    默认:false
    excludeSearchboolean返回与在search参数中给定条件不匹配的结果。
    filterobject仅返回与给定过滤条件完全匹配的结果。

    接受一个数组,键是属性名,值是单个值或者要匹配值的数组。

    不适用于text 字段。
    limitinteger限制返回记录的数量。
    outputquery要返回的对象属性。

    默认:extend
    preservekeysboolean在结果数组中,用ID作为键。
    searchobject返回给定通配符(不区分大小写)匹配到的结果。

    接受一个数组,键是属性名,值是要搜索的字符串。如果没有给出其他选项,将会执行LIKE “%…%”搜索。

    仅适用于stringtext字段。
    searchByAnyboolean如果设置为true,则返回与filter or search参数中给定的任何条件匹配的结果,而不是所有条件。

    默认:false
    searchWildcardsEnabledboolean如果设置为true,则可以在search参数中使用”*”作为通配符。

    默认:false
    sortfieldstring/array按照给定的属性对结果进行排序。可用于排序的属性列表,请参考特定API get方法描述。宏在排序前不会被展开。

    如果没有给出特定的值,数据会无序返回。
    sortorderstring/array排序顺序。如果传递数组,则每个值都将与sortfield参数中给定的对应属性匹配。

    可用值:
    ASC - (默认) 升序;
    DESC - 降序。
    startSearchbooleansearch参数比较字段的开始,即执行LIKE “…%”搜索。

    如果searchWildcardsEnabled设置为true,则忽略。

    用户权限检查

    用户是否有权限修改以“MySQL”或“Linux”开头的主机?

    响应:

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

    结果0,表示没有具有读/写权限的主机。

    不匹配统计

    统计名称中不包含“ubuntu”的主机数量。

    请求:

    响应:

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

    使用通配符搜索主机

    请求:

    响应:

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

    加上 “preservekeys”参数使用通配符搜索主机

    如果将参数“preservekeys”添加到上一个请求中,结果会返回一个关联数组,键是对象的id。

    请求:

    响应:

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