action.create

Description

object action.create(object/array actions)

This method allows to create new actions.

This method is only available to Admin and Super admin user types. Permissions to call the method can be revoked in user role settings. See User roles for more information.

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.
update_operationsarrayAction update 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 “10084” 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 update, message with custom subject and body will be sent to all who left acknowledgments 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. "filter": {
  10. "evaltype": 0,
  11. "conditions": [
  12. {
  13. "conditiontype": 1,
  14. "operator": 0,
  15. "value": "10084"
  16. },
  17. {
  18. "conditiontype": 3,
  19. "operator": 2,
  20. "value": "memory"
  21. }
  22. ]
  23. },
  24. "operations": [
  25. {
  26. "operationtype": 0,
  27. "esc_period": "0s",
  28. "esc_step_from": 1,
  29. "esc_step_to": 2,
  30. "evaltype": 0,
  31. "opmessage_grp": [
  32. {
  33. "usrgrpid": "7"
  34. }
  35. ],
  36. "opmessage": {
  37. "default_msg": 1,
  38. "mediatypeid": "1"
  39. }
  40. },
  41. {
  42. "operationtype": 1,
  43. "esc_step_from": 3,
  44. "esc_step_to": 4,
  45. "evaltype": 0,
  46. "opconditions": [
  47. {
  48. "conditiontype": 14,
  49. "operator": 0,
  50. "value": "0"
  51. }
  52. ],
  53. "opcommand_grp": [
  54. {
  55. "groupid": "2"
  56. }
  57. ],
  58. "opcommand": {
  59. "scriptid": "3"
  60. }
  61. }
  62. ],
  63. "recovery_operations": [
  64. {
  65. "operationtype": "11",
  66. "opmessage": {
  67. "default_msg": 1
  68. }
  69. }
  70. ],
  71. "update_operations": [
  72. {
  73. "operationtype": "12",
  74. "opmessage": {
  75. "default_msg": 0,
  76. "message": "Custom update operation message body",
  77. "subject": "Custom update operation message subject"
  78. }
  79. }
  80. ],
  81. "pause_suppressed": "0",
  82. "notify_if_canceled": "0"
  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 “10091”.

Request:

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

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. "filter": {
  10. "evaltype": 3,
  11. "formula": "A and (B or C)",
  12. "conditions": [
  13. {
  14. "conditiontype": 4,
  15. "operator": 5,
  16. "value": "2",
  17. "formulaid": "A"
  18. },
  19. {
  20. "conditiontype": 1,
  21. "operator": 0,
  22. "value": "10084",
  23. "formulaid": "B"
  24. },
  25. {
  26. "conditiontype": 1,
  27. "operator": 0,
  28. "value": "10106",
  29. "formulaid": "C"
  30. }
  31. ]
  32. },
  33. "operations": [
  34. {
  35. "operationtype": 0,
  36. "esc_period": "0s",
  37. "esc_step_from": 1,
  38. "esc_step_to": 2,
  39. "evaltype": 0,
  40. "opmessage_grp": [
  41. {
  42. "usrgrpid": "7"
  43. }
  44. ],
  45. "opmessage": {
  46. "default_msg": 1,
  47. "mediatypeid": "1"
  48. }
  49. }
  50. ],
  51. "pause_suppressed": "0",
  52. "notify_if_canceled": "0"
  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. }

Create agent autoregistration rule

Add a host to host group “Linux servers” when host name contains “SRV” or metadata contains “CentOS”.

Request:

  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. "conditions": [
  11. {
  12. "conditiontype": "22",
  13. "operator": "2",
  14. "value": "SRV"
  15. },
  16. {
  17. "conditiontype": "24",
  18. "operator": "2",
  19. "value": "CentOS"
  20. }
  21. ]
  22. },
  23. "operations": [
  24. {
  25. "operationtype": "4",
  26. "opgroup": [
  27. {
  28. "groupid": "2"
  29. }
  30. ]
  31. }
  32. ]
  33. },
  34. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  35. "id": 1
  36. }

Response:

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

See also

Source

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