action.get

说明

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 属性中的动作筛选器。
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 参数,则检索对象的计数。

范例

检索发现动作

Retrieve all configured discovery actions together with action conditions and operations. The filter uses the “and” evaluation type, so the formula property is empty and eval_formula is generated automatically. 检索所有配置的发现动作以及操作条件和操作。筛选器使用 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.

Description

integer/array action.get(object **parameters**)

The method allows to retrieve actions according to the given parameters.

Parameters

(object) Parameters defining the desired output.

The method supports the following parameters.

ParameterTypeDescription
actionidsstring/arrayReturn only actions with the given IDs.
groupidsstring/arrayReturn only actions that use the given host groups in action conditions.
hostidsstring/arrayReturn only actions that use the given hosts in action conditions.
triggeridsstring/arrayReturn only actions that use the given triggers in action conditions.
mediatypeidsstring/arrayReturn only actions that use the given media types to send messages.
usrgrpidsstring/arrayReturn only actions that are configured to send messages to the given user groups.
useridsstring/arrayReturn only actions that are configured to send messages to the given users.
scriptidsstring/arrayReturn only actions that are configured to run the given scripts.
selectFilterqueryReturns the action filter in the filter property.
selectOperationsqueryReturn action operations in the operations property.
selectRecoveryOperationsqueryReturn action recovery operations in the recoveryOperations property.
selectAcknowledgeOperationsqueryReturn action acknowledge operations in the acknowledgeOperations property.
sortfieldstring/arraySort the result by the given properties.

Possible values are: actionid, name and status.
countOutputbooleanThese parameters being common for all get methods are described in the reference commentary.
editableboolean
excludeSearchboolean
filterobject
limitinteger
outputquery
preservekeysboolean
searchobject
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean

Return values

(integer/array) Returns either:

  • an array of objects;

  • the count of retrieved objects, if the countOutput parameter has been used.

Examples

Retrieve discovery actions

Retrieve all configured discovery actions together with action conditions and operations. The filter uses the “and” evaluation type, so the formula property is empty and eval_formula is generated automatically.

Request:

  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. }

Response:

  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. }

See also

Source

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