action.create

描述

object action.create(object/array actions)

此方法用来创建新的动作

参数

(object/array) 创建新动作

除此之外 standard action properties, 该方法接受以下参数。

参数 类型 描述
filter object 这个动作的动作过滤器对象。
operations array 为这个动作创建的动作操作。
recovery_operations array 为这个动作创建恢复操作。
acknowledge_operations array 为这个操作创建确认操作。

返回值

返回一个对象,其中包含 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. }
  70. ],
  71. "acknowledge_operations": [
  72. {
  73. "operationtype": "12",
  74. "opmessage": {
  75. "message": "Custom acknowledge operation message body",
  76. "subject": "Custom acknowledge operation message subject"
  77. }
  78. }
  79. ]
  80. },
  81. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  82. "id": 1
  83. }

响应:

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

创建一个发现动作

创建将已发现的主机链接到模板 “30085” 的操作。

请求:

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

使用自定义表达式过滤器

创建将使用自定义筛选条件的触发器动作。 对于主机 “10084” 和 “10106”,操作必须为每个触发器发送一条消息,其严重性大于或等于 “警告”。 公式ID “A”,“B”和 “C”是任意选择的。

请求:

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

参见

Source

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