action.create

说明

object action.create(object/array actions)

此方法用于创建新动作。

参数

(object/array) 创建新动作

除此之外 标准动作属性, 该方法接受以下参数。

参数 类说明
filterobject动作的动作过滤器对象。
operationsarray为动作创建的动作操作。
recovery_operationsarray为动作创建动作恢复操作。
acknowledge_operationsarray为动作创建动作确认操作。

返回值

(object) 返回一个对象,其中 actionids 属性下包含已创建动作的 ID。 返回的 ID 的顺序与传递的操作的顺序相匹配。

范例

创建触发器动作

创建一个动作,动作如下描述,当主机 30045 ,它的触发器中的 memory 进入问题状态时。该动作必须首先向用户组 7 中的所有用户发送消息。如果事件在 4 分钟内未被解决,它将在 2 组中的所有主机上运行脚本 3。在触发恢复中,它将通知所有接收到关于该问题的消息的用户。在触发器确认中,带有自定义主体和主体的消息将通过所有媒体类型发送给所有确认和评论的所有人。

请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "action.create",
  4. "params": {
  5. "name": "Trigger action",
  6. "eventsource": 0,
  7. "status": 0,
  8. "esc_period": "2m",
  9. "def_shortdata": "{TRIGGER.NAME}: {TRIGGER.STATUS}",
  10. "def_longdata": "{TRIGGER.NAME}: {TRIGGER.STATUS}\r\nLast value: {ITEM.LASTVALUE}\r\n\r\n{TRIGGER.URL}",
  11. "filter": {
  12. "evaltype": 0,
  13. "conditions": [
  14. {
  15. "conditiontype": 1,
  16. "operator": 0,
  17. "value": "10084"
  18. },
  19. {
  20. "conditiontype": 3,
  21. "operator": 2,
  22. "value": "memory"
  23. }
  24. ]
  25. },
  26. "operations": [
  27. {
  28. "operationtype": 0,
  29. "esc_period": "0s",
  30. "esc_step_from": 1,
  31. "esc_step_to": 2,
  32. "evaltype": 0,
  33. "opmessage_grp": [
  34. {
  35. "usrgrpid": "7"
  36. }
  37. ],
  38. "opmessage": {
  39. "default_msg": 1,
  40. "mediatypeid": "1"
  41. }
  42. },
  43. {
  44. "operationtype": 1,
  45. "esc_step_from": 3,
  46. "esc_step_to": 4,
  47. "evaltype": 0,
  48. "opconditions": [
  49. {
  50. "conditiontype": 14,
  51. "operator": 0,
  52. "value": "0"
  53. }
  54. ],
  55. "opcommand_grp": [
  56. {
  57. "groupid": "2"
  58. }
  59. ],
  60. "opcommand": {
  61. "type": 4,
  62. "scriptid": "3"
  63. }
  64. }
  65. ],
  66. "recovery_operations": [
  67. {
  68. "operationtype": "11",
  69. "opmessage": {
  70. "default_msg": 1
  71. }
  72. }
  73. ],
  74. "acknowledge_operations": [
  75. {
  76. "operationtype": "12",
  77. "opmessage": {
  78. "message": "Custom acknowledge operation message body",
  79. "subject": "Custom acknowledge operation message subject"
  80. }
  81. }
  82. ]
  83. },
  84. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  85. "id": 1
  86. }

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "actionids": [
  5. "17"
  6. ]
  7. },
  8. "id": 1
  9. }

创建发现动作

创建一个将发现的主机链接到模板 30085 的动作。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "action.create",
  4. "params": {
  5. "name": "Discovery action",
  6. "eventsource": 1,
  7. "status": 0,
  8. "esc_period": "0s",
  9. "filter": {
  10. "evaltype": 0,
  11. "conditions": [
  12. {
  13. "conditiontype": 21,
  14. "value": "1"
  15. },
  16. {
  17. "conditiontype": 10,
  18. "value": "2"
  19. }
  20. ]
  21. },
  22. "operations": [
  23. {
  24. "esc_step_from": 1,
  25. "esc_period": "0s",
  26. "optemplate": [
  27. {
  28. "templateid": "10091"
  29. }
  30. ],
  31. "operationtype": 6,
  32. "esc_step_to": 1
  33. }
  34. ]
  35. },
  36. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  37. "id": 1
  38. }

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "actionids": [
  5. "18"
  6. ]
  7. },
  8. "id": 1
  9. }

使用自定义表达式筛选器

创建使用自定义筛选器条件的触发器动作。该动作必须为每个触发器发送一个消息,其严重程度高于或等于主机 1008410106警告。公式 ID ABC 都是任意选择的。

请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "action.create",
  4. "params": {
  5. "name": "Trigger action",
  6. "eventsource": 0,
  7. "status": 0,
  8. "esc_period": "2m",
  9. "def_shortdata": "{TRIGGER.NAME}: {TRIGGER.STATUS}",
  10. "def_longdata": "{TRIGGER.NAME}: {TRIGGER.STATUS}\r\nLast value: {ITEM.LASTVALUE}\r\n\r\n{TRIGGER.URL}",
  11. "filter": {
  12. "evaltype": 3,
  13. "formula": "A and (B or C)",
  14. "conditions": [
  15. {
  16. "conditiontype": 4,
  17. "operator": 5,
  18. "value": "2",
  19. "formulaid": "A"
  20. },
  21. {
  22. "conditiontype": 1,
  23. "operator": 0,
  24. "value": "10084",
  25. "formulaid": "B"
  26. },
  27. {
  28. "conditiontype": 1,
  29. "operator": 0,
  30. "value": "10106",
  31. "formulaid": "C"
  32. }
  33. ]
  34. },
  35. "operations": [
  36. {
  37. "operationtype": 0,
  38. "esc_period": "0s",
  39. "esc_step_from": 1,
  40. "esc_step_to": 2,
  41. "evaltype": 0,
  42. "opmessage_grp": [
  43. {
  44. "usrgrpid": "7"
  45. }
  46. ],
  47. "opmessage": {
  48. "default_msg": 1,
  49. "mediatypeid": "1"
  50. }
  51. }
  52. ]
  53. },
  54. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  55. "id": 1
  56. }

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "actionids": [
  5. "18"
  6. ]
  7. },
  8. "id": 1
  9. }

参见

来源

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

Description

object action.create(object/array actions)

This method allows to create new actions.

Parameters

(object/array) Actions to create.

Additionally to the standard action properties, the method accepts the following parameters.

ParameterTypeDescription
filterobjectAction filter object for the action.
operationsarrayAction operations to create for the action.
recovery_operationsarrayAction recovery operations to create for the action.
acknowledge_operationsarrayAction acknowledge operations to create for the action.

Return values

(object) Returns an object containing the IDs of the created actions under the actionids property. The order of the returned IDs matches the order of the passed actions.

Examples

Create a trigger action

Create an action that will be run when a trigger from host “30045” that has the word “memory” in its name goes into problem state. The action must first send a message to all users in user group “7”. If the event is not resolved in 4 minutes, it will run script “3” on all hosts in group “2”. On trigger recovery it will notify all users who received any messages regarding the problem before. On trigger acknowledge, message with custom subject and body will be sent to all who left acknowledgements and comments via all media types.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "action.create",
  4. "params": {
  5. "name": "Trigger action",
  6. "eventsource": 0,
  7. "status": 0,
  8. "esc_period": "2m",
  9. "def_shortdata": "{TRIGGER.NAME}: {TRIGGER.STATUS}",
  10. "def_longdata": "{TRIGGER.NAME}: {TRIGGER.STATUS}\r\nLast value: {ITEM.LASTVALUE}\r\n\r\n{TRIGGER.URL}",
  11. "filter": {
  12. "evaltype": 0,
  13. "conditions": [
  14. {
  15. "conditiontype": 1,
  16. "operator": 0,
  17. "value": "10084"
  18. },
  19. {
  20. "conditiontype": 3,
  21. "operator": 2,
  22. "value": "memory"
  23. }
  24. ]
  25. },
  26. "operations": [
  27. {
  28. "operationtype": 0,
  29. "esc_period": "0s",
  30. "esc_step_from": 1,
  31. "esc_step_to": 2,
  32. "evaltype": 0,
  33. "opmessage_grp": [
  34. {
  35. "usrgrpid": "7"
  36. }
  37. ],
  38. "opmessage": {
  39. "default_msg": 1,
  40. "mediatypeid": "1"
  41. }
  42. },
  43. {
  44. "operationtype": 1,
  45. "esc_step_from": 3,
  46. "esc_step_to": 4,
  47. "evaltype": 0,
  48. "opconditions": [
  49. {
  50. "conditiontype": 14,
  51. "operator": 0,
  52. "value": "0"
  53. }
  54. ],
  55. "opcommand_grp": [
  56. {
  57. "groupid": "2"
  58. }
  59. ],
  60. "opcommand": {
  61. "type": 4,
  62. "scriptid": "3"
  63. }
  64. }
  65. ],
  66. "recovery_operations": [
  67. {
  68. "operationtype": "11",
  69. "opmessage": {
  70. "default_msg": 1
  71. }
  72. }
  73. ],
  74. "acknowledge_operations": [
  75. {
  76. "operationtype": "12",
  77. "opmessage": {
  78. "message": "Custom acknowledge operation message body",
  79. "subject": "Custom acknowledge operation message subject"
  80. }
  81. }
  82. ]
  83. },
  84. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  85. "id": 1
  86. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "actionids": [
  5. "17"
  6. ]
  7. },
  8. "id": 1
  9. }

Create a discovery action

Create an action that will link discovered hosts to template “30085”.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "action.create",
  4. "params": {
  5. "name": "Discovery action",
  6. "eventsource": 1,
  7. "status": 0,
  8. "esc_period": "0s",
  9. "filter": {
  10. "evaltype": 0,
  11. "conditions": [
  12. {
  13. "conditiontype": 21,
  14. "value": "1"
  15. },
  16. {
  17. "conditiontype": 10,
  18. "value": "2"
  19. }
  20. ]
  21. },
  22. "operations": [
  23. {
  24. "esc_step_from": 1,
  25. "esc_period": "0s",
  26. "optemplate": [
  27. {
  28. "templateid": "10091"
  29. }
  30. ],
  31. "operationtype": 6,
  32. "esc_step_to": 1
  33. }
  34. ]
  35. },
  36. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  37. "id": 1
  38. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "actionids": [
  5. "18"
  6. ]
  7. },
  8. "id": 1
  9. }

Using a custom expression filter

Create a trigger action that will use a custom filter condition. The action must send a message for each trigger with severity higher or equal to “Warning” for hosts “10084” and “10106”. The formula IDs “A”, “B” and “C” have been chosen arbitrarily.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "action.create",
  4. "params": {
  5. "name": "Trigger action",
  6. "eventsource": 0,
  7. "status": 0,
  8. "esc_period": "2m",
  9. "def_shortdata": "{TRIGGER.NAME}: {TRIGGER.STATUS}",
  10. "def_longdata": "{TRIGGER.NAME}: {TRIGGER.STATUS}\r\nLast value: {ITEM.LASTVALUE}\r\n\r\n{TRIGGER.URL}",
  11. "filter": {
  12. "evaltype": 3,
  13. "formula": "A and (B or C)",
  14. "conditions": [
  15. {
  16. "conditiontype": 4,
  17. "operator": 5,
  18. "value": "2",
  19. "formulaid": "A"
  20. },
  21. {
  22. "conditiontype": 1,
  23. "operator": 0,
  24. "value": "10084",
  25. "formulaid": "B"
  26. },
  27. {
  28. "conditiontype": 1,
  29. "operator": 0,
  30. "value": "10106",
  31. "formulaid": "C"
  32. }
  33. ]
  34. },
  35. "operations": [
  36. {
  37. "operationtype": 0,
  38. "esc_period": "0s",
  39. "esc_step_from": 1,
  40. "esc_step_to": 2,
  41. "evaltype": 0,
  42. "opmessage_grp": [
  43. {
  44. "usrgrpid": "7"
  45. }
  46. ],
  47. "opmessage": {
  48. "default_msg": 1,
  49. "mediatypeid": "1"
  50. }
  51. }
  52. ]
  53. },
  54. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  55. "id": 1
  56. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "actionids": [
  5. "18"
  6. ]
  7. },
  8. "id": 1
  9. }

See also

Source

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