获取

描述

integer/array action.get(object parameters)

该方法允许根据给定的参数检索动作。

此方法对于任何用户可用。可以在用户角色设置中撤销调用该方法的权限。更多信息请查看 用户角色

参数

(object) 定义所需输出的参数。

该方法支持以下参数。

参数类型描述
actionidsstring/array只返回给定 ID 的动作。
groupidsstring/array只返回使用动作条件指定主机组的动作。
hostidsstring/array只返回使用动作条件指定主机的动作。
triggeridsstring/array只返回使用动作条件指定触发器的动作。
mediatypeidsstring/array只返回使用动作条件指定媒介类型的动作。
usrgrpidsstring/array只返回配置为发送消息给指定用户组的动作。
useridsstring/array只返回配置为发送消息给指定用户的动作。
scriptidsstring/array只返回配置为运行指定脚本的动作。
selectFilterquery返回 filter 属性中的动作条件 filter。
selectOperationsquery返回 operations 属性中的动作条件。
selectRecoveryOperationsquery返回 recovery_operations 属性中的 动作恢复操作。
selectUpdateOperationsquery返回 update_operations 属性中的动作更新操作。
sortfieldstring/array根据给定的属性排序结果。

可用值:actionid, namestatus
countOutputboolean这些参数对于所有 get 方法都是通用的,在 参数说明 进行了描述。
editableboolean
excludeSearchboolean
filterobject
limitinteger
outputquery
preservekeysboolean
searchobject
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean

返回值

(integer/array) 返回以下任一选项:

  • 对象数组;
  • 如果使用了 countOutput 参数,则检索对象的计数。

示例

检索触发器动作

检索所有已配置的触发器动作以及它们的动作条件和操作。

请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "action.get",
  4. "params": {
  5. "output": "extend",
  6. "selectOperations": "extend",
  7. "selectRecoveryOperations": "extend",
  8. "selectUpdateOperations": "extend",
  9. "selectFilter": "extend",
  10. "filter": {
  11. "eventsource": 0
  12. }
  13. },
  14. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  15. "id": 1
  16. }

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "actionid": "3",
  6. "name": "Report problems to Zabbix administrators",
  7. "eventsource": "0",
  8. "status": "1",
  9. "esc_period": "1h",
  10. "pause_suppressed": "1",
  11. "filter": {
  12. "evaltype": "0",
  13. "formula": "",
  14. "conditions": [],
  15. "eval_formula": ""
  16. },
  17. "operations": [
  18. {
  19. "operationid": "3",
  20. "actionid": "3",
  21. "operationtype": "0",
  22. "esc_period": "0",
  23. "esc_step_from": "1",
  24. "esc_step_to": "1",
  25. "evaltype": "0",
  26. "opconditions": [],
  27. "opmessage": [
  28. {
  29. "default_msg": "1",
  30. "subject": "",
  31. "message": "",
  32. "mediatypeid" => "0"
  33. }
  34. ],
  35. "opmessage_grp": [
  36. {
  37. "usrgrpid": "7"
  38. }
  39. ]
  40. }
  41. ],
  42. "recovery_operations": [
  43. {
  44. "operationid": "7",
  45. "actionid": "3",
  46. "operationtype": "11",
  47. "evaltype": "0",
  48. "opconditions": [],
  49. "opmessage": {
  50. "default_msg": "0",
  51. "subject": "{TRIGGER.STATUS}: {TRIGGER.NAME}",
  52. "message": "Trigger: {TRIGGER.NAME}\r\nTrigger status: {TRIGGER.STATUS}\r\nTrigger severity: {TRIGGER.SEVERITY}\r\nTrigger URL: {TRIGGER.URL}\r\n\r\nItem values:\r\n\r\n1. {ITEM.NAME1} ({HOST.NAME1}:{ITEM.KEY1}): {ITEM.VALUE1}\r\n2. {ITEM.NAME2} ({HOST.NAME2}:{ITEM.KEY2}): {ITEM.VALUE2}\r\n3. {ITEM.NAME3} ({HOST.NAME3}:{ITEM.KEY3}): {ITEM.VALUE3}\r\n\r\nOriginal event ID: {EVENT.ID}",
  53. "mediatypeid": "0"
  54. }
  55. }
  56. ],
  57. "update_operations": [
  58. {
  59. "operationid": "31",
  60. "operationtype": "12",
  61. "evaltype": "0",
  62. "opmessage": {
  63. "default_msg": "1",
  64. "subject": "",
  65. "message": "",
  66. "mediatypeid": "0"
  67. }
  68. },
  69. {
  70. "operationid": "32",
  71. "operationtype": "0",
  72. "evaltype": "0",
  73. "opmessage": {
  74. "default_msg": "0",
  75. "subject": "Updated: {TRIGGER.NAME}",
  76. "message": "{USER.FULLNAME} updated problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME} with the following message:\r\n{EVENT.UPDATE.MESSAGE}\r\n\r\nCurrent problem status is {EVENT.STATUS}",
  77. "mediatypeid": "1"
  78. },
  79. "opmessage_grp": [
  80. {
  81. "usrgrpid": "7"
  82. }
  83. ],
  84. "opmessage_usr": []
  85. },
  86. {
  87. "operationid": "33",
  88. "operationtype": "1",
  89. "evaltype": "0",
  90. "opcommand": {
  91. "scriptid": "3"
  92. },
  93. "opcommand_hst": [
  94. {
  95. "hostid": "10084"
  96. }
  97. ],
  98. "opcommand_grp": []
  99. }
  100. ]
  101. }
  102. ],
  103. "id": 1
  104. }

检索发现动作

检索所有已配置的发现动作以及它们的动作条件和操作。过滤器使用 “and” 计算类型,所以 formula 属性为空且eval_formula 将自动生成。

请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "action.get",
  4. "params": {
  5. "output": "extend",
  6. "selectOperations": "extend"
  7. "selectFilter": "extend",
  8. "filter": {
  9. "eventsource": 1
  10. }
  11. },
  12. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  13. "id": 1
  14. }

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "actionid": "2",
  6. "name": "Auto discovery. Linux servers.",
  7. "eventsource": "1",
  8. "status": "1",
  9. "esc_period": "0s",
  10. "pause_suppressed": "1",
  11. "filter": {
  12. "evaltype": "0",
  13. "formula": "",
  14. "conditions": [
  15. {
  16. "conditiontype": "10",
  17. "operator": "0",
  18. "value": "0",
  19. "value2": "",
  20. "formulaid": "B"
  21. },
  22. {
  23. "conditiontype": "8",
  24. "operator": "0",
  25. "value": "9",
  26. "value2": "",
  27. "formulaid": "C"
  28. },
  29. {
  30. "conditiontype": "12",
  31. "operator": "2",
  32. "value": "Linux",
  33. "value2": "",
  34. "formulaid": "A"
  35. }
  36. ],
  37. "eval_formula": "A and B and C"
  38. },
  39. "operations": [
  40. {
  41. "operationid": "1",
  42. "actionid": "2",
  43. "operationtype": "6",
  44. "esc_period": "0s",
  45. "esc_step_from": "1",
  46. "esc_step_to": "1",
  47. "evaltype": "0",
  48. "opconditions": [],
  49. "optemplate": [
  50. {
  51. "templateid": "10001"
  52. }
  53. ]
  54. },
  55. {
  56. "operationid": "2",
  57. "actionid": "2",
  58. "operationtype": "4",
  59. "esc_period": "0s",
  60. "esc_step_from": "1",
  61. "esc_step_to": "1",
  62. "evaltype": "0",
  63. "opconditions": [],
  64. "opgroup": [
  65. {
  66. "groupid": "2"
  67. }
  68. ]
  69. }
  70. ]
  71. }
  72. ],
  73. "id": 1
  74. }

参见

来源

ui/include/classes/api/services/CAction.php 中的 CAction::get()。