查询动作

说明

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返回 过滤 属性中的动作筛选器。
selectOperationsquery返回动作属性中操作属性。
selectRecoveryOperationsquery恢复操作 属性中返回动作恢复操作。
selectAcknowledgeOperationsquery确认操作 属性中返回动作确认操作。
sortfieldstring/array根据给定的属性排序结果。

可能的值是: actionid, name and status.
countOutputboolean这些参数对于所有 get 方法都是常见的。在 reference commentary.
editableboolean
excludeSearchboolean
filterobject
limitinteger
outputquery
preservekeysboolean
searchobject
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean

返回值

(integer/array) 也返回:

  • 对象数组;

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

范例

检索触发动作

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

请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "action.get",
  4. "params": {
  5. "output": "extend",
  6. "selectOperations": "extend",
  7. "selectRecoveryOperations": "extend",
  8. "selectAcknowledgeOperations": "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. "acknowledgeOperations": [
  18. {
  19. "operationid": "31",
  20. "operationtype": "12",
  21. "evaltype": "0",
  22. "opmessage": {
  23. "default_msg": "1",
  24. "subject": "",
  25. "message": "",
  26. "mediatypeid": "0"
  27. }
  28. },
  29. {
  30. "operationid": "32",
  31. "operationtype": "0",
  32. "evaltype": "0",
  33. "opmessage": {
  34. "default_msg": "0",
  35. "subject": "Updated: {TRIGGER.NAME}",
  36. "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}",
  37. "mediatypeid": "1"
  38. },
  39. "opmessage_grp": [
  40. {
  41. "usrgrpid": "7"
  42. }
  43. ],
  44. "opmessage_usr": []
  45. },
  46. {
  47. "operationid": "33",
  48. "operationtype": "1",
  49. "evaltype": "0",
  50. "opcommand": {
  51. "type": "0",
  52. "scriptid": "0",
  53. "execute_on": "0",
  54. "port": "",
  55. "authtype": "0",
  56. "username": "",
  57. "password": "",
  58. "publickey": "",
  59. "privatekey": "",
  60. "command": "notify.sh"
  61. },
  62. "opcommand_hst": [
  63. {
  64. "hostid": "0"
  65. }
  66. ],
  67. "opcommand_grp": []
  68. }
  69. ],
  70. "operations": [
  71. {
  72. "operationid": "3",
  73. "actionid": "3",
  74. "operationtype": "0",
  75. "esc_period": "0",
  76. "esc_step_from": "1",
  77. "esc_step_to": "1",
  78. "evaltype": "0",
  79. "opconditions": [],
  80. "opmessage": [
  81. {
  82. "default_msg": "1",
  83. "subject": "",
  84. "message": "",
  85. "mediatypeid" => "0"
  86. }
  87. ],
  88. "opmessage_grp": [
  89. {
  90. "usrgrpid": "7"
  91. }
  92. ]
  93. }
  94. ],
  95. "recoveryOperations": [
  96. {
  97. "operationid": "7",
  98. "actionid": "3",
  99. "operationtype": "11",
  100. "evaltype": "0",
  101. "opconditions": [],
  102. "opmessage": {
  103. "default_msg": "0",
  104. "subject": "{TRIGGER.STATUS}: {TRIGGER.NAME}",
  105. "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}",
  106. "mediatypeid": "0"
  107. }
  108. }
  109. ]
  110. }
  111. ],
  112. "id": 1
  113. }

检索发现动作

检索所有配置的发现动作以及操作条件和操作。筛选器使用 and 评估类型,因此 formula 属性为空,自动生成 eval_formula

请求:

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

响应:

  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. "def_shortdata": "",
  11. "def_longdata": "",
  12. "r_shortdata": "",
  13. "r_longdata": "",
  14. "pause_suppressed": "1",
  15. "filter": {
  16. "evaltype": "0",
  17. "formula": "",
  18. "conditions": [
  19. {
  20. "conditiontype": "10",
  21. "operator": "0",
  22. "value": "0",
  23. "value2": "",
  24. "formulaid": "B"
  25. },
  26. {
  27. "conditiontype": "8",
  28. "operator": "0",
  29. "value": "9",
  30. "value2": "",
  31. "formulaid": "C"
  32. },
  33. {
  34. "conditiontype": "12",
  35. "operator": "2",
  36. "value": "Linux",
  37. "value2": "",
  38. "formulaid": "A"
  39. }
  40. ],
  41. "eval_formula": "A and B and C"
  42. },
  43. "operations": [
  44. {
  45. "operationid": "1",
  46. "actionid": "2",
  47. "operationtype": "6",
  48. "esc_period": "0s",
  49. "esc_step_from": "1",
  50. "esc_step_to": "1",
  51. "evaltype": "0",
  52. "opconditions": [],
  53. "optemplate": [
  54. {
  55. "operationid": "1",
  56. "templateid": "10001"
  57. }
  58. ]
  59. },
  60. {
  61. "operationid": "2",
  62. "actionid": "2",
  63. "operationtype": "4",
  64. "esc_period": "0s",
  65. "esc_step_from": "1",
  66. "esc_step_to": "1",
  67. "evaltype": "0",
  68. "opconditions": [],
  69. "opgroup": [
  70. {
  71. "operationid": "2",
  72. "groupid": "2"
  73. }
  74. ]
  75. }
  76. ],
  77. "recoveryOperations": [
  78. {
  79. "operationid": "585",
  80. "actionid": "2",
  81. "operationtype": "11",
  82. "evaltype": "0",
  83. "opconditions": [],
  84. "opmessage": {
  85. "operationid": "585",
  86. "default_msg": "1",
  87. "subject": "{TRIGGER.STATUS}: {TRIGGER.NAME}",
  88. "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}",
  89. "mediatypeid": "0"
  90. }
  91. }
  92. ],
  93. "acknowledgeOperations": [
  94. {
  95. "operationid": "585",
  96. "operationtype": "12",
  97. "evaltype": "0",
  98. "opmessage": {
  99. "default_msg": "1",
  100. "subject": "Acknowledged: {TRIGGER.NAME}",
  101. "message": "{USER.FULLNAME} acknowledged problem at {ACK.DATE} {ACK.TIME} with the following message:\r\n{ACK.MESSAGE}\r\n\r\nCurrent problem status is {EVENT.STATUS}",
  102. "mediatypeid": "0"
  103. }
  104. },
  105. {
  106. "operationid": "586",
  107. "operationtype": "0",
  108. "evaltype": "0",
  109. "opmessage": {
  110. "default_msg": "1",
  111. "subject": "Acknowledged: {TRIGGER.NAME}",
  112. "message": "{USER.FULLNAME} acknowledged problem at {ACK.DATE} {ACK.TIME} with the following message:\r\n{ACK.MESSAGE}\r\n\r\nCurrent problem status is {EVENT.STATUS}",
  113. "mediatypeid": "0"
  114. },
  115. "opmessage_grp": [
  116. {
  117. "usrgrpid": "7"
  118. }
  119. ],
  120. "opmessage_usr": []
  121. },
  122. {
  123. "operationid": "587",
  124. "operationtype": "1",
  125. "evaltype": "0",
  126. "opcommand": {
  127. "type": "0",
  128. "scriptid": "0",
  129. "execute_on": "0",
  130. "port": "",
  131. "authtype": "0",
  132. "username": "",
  133. "password": "",
  134. "publickey": "",
  135. "privatekey": "",
  136. "command": "notify.sh"
  137. },
  138. "opcommand_hst": [
  139. {
  140. "hostid": "0"
  141. }
  142. ],
  143. "opcommand_grp": []
  144. }
  145. ]
  146. }
  147. ],
  148. "id": 1
  149. }

参见

来源

CAction::get() in frontends/php/include/classes/api/services/CAction.php.