创建动作

说明

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 A和(BC)。

请求:

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

创建AGNENT自动注册规则

当主机名中包含“SRV”或元数据中包含“CentOS”时,向“Linux servers”主机组中添加主机。

请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "action.create",
  4. "params": {
  5. "name": "Register Linux servers",
  6. "eventsource": "2",
  7. "status": "0",
  8. "filter": {
  9. "evaltype": "2",
  10. "formula": "A or B",
  11. "conditions": [
  12. {
  13. "conditiontype": "22",
  14. "operator": "2",
  15. "value": "SRV",
  16. "value2": "",
  17. "formulaid": "B"
  18. },
  19. {
  20. "conditiontype": "24",
  21. "operator": "2",
  22. "value": "CentOS",
  23. "value2": "",
  24. "formulaid": "A"
  25. }
  26. ]
  27. },
  28. "operations": [
  29. {
  30. "actionid": "9",
  31. "operationtype": "4",
  32. "esc_period": "0",
  33. "esc_step_from": "1",
  34. "esc_step_to": "1",
  35. "evaltype": "0",
  36. "opgroup": [
  37. {
  38. "operationid": "16",
  39. "groupid": "2"
  40. }
  41. ]
  42. }
  43. ]
  44. },
  45. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  46. "id": 1
  47. }

响应:

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

参见

来源

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