1
0

ack-watch.asciidoc 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. [role="xpack"]
  2. [[watcher-api-ack-watch]]
  3. === Ack Watch API
  4. {xpack-ref}/actions.html#actions-ack-throttle[Acknowledging a watch] enables you
  5. to manually throttle execution of the watch's actions. An action's
  6. _acknowledgement state_ is stored in the `status.actions.<id>.ack.state`
  7. structure.
  8. IMPORTANT: If the specified watch is currently being executed, this API will return
  9. an error. The reason for this is to prevent overwriting of the watch status from a watch
  10. execution.
  11. [float]
  12. ==== Request
  13. `PUT _xpack/watcher/watch/<watch_id>/_ack` +
  14. `PUT _xpack/watcher/watch/<watch_id>/_ack/<action_id>`
  15. [float]
  16. ==== Path Parameters
  17. `action_id`::
  18. (list) A comma-separated list of the action IDs to acknowledge. If you omit
  19. this parameter, all of the actions of the watch are acknowledged.
  20. `watch_id` (required)::
  21. (string) Identifier for the watch.
  22. [float]
  23. ==== Authorization
  24. You must have `manage_watcher` cluster privileges to use this API. For more
  25. information, see {xpack-ref}/security-privileges.html[Security Privileges].
  26. [float]
  27. ==== Examples
  28. To demonstrate let's create a new watch:
  29. [source,js]
  30. --------------------------------------------------
  31. PUT _xpack/watcher/watch/my_watch
  32. {
  33. "trigger": {
  34. "schedule": {
  35. "hourly": {
  36. "minute": [ 0, 5 ]
  37. }
  38. }
  39. },
  40. "input": {
  41. "simple": {
  42. "payload": {
  43. "send": "yes"
  44. }
  45. }
  46. },
  47. "condition": {
  48. "always": {}
  49. },
  50. "actions": {
  51. "test_index": {
  52. "throttle_period": "15m",
  53. "index": {
  54. "index": "test",
  55. "doc_type": "test2"
  56. }
  57. }
  58. }
  59. }
  60. --------------------------------------------------
  61. // CONSOLE
  62. // TESTSETUP
  63. The current status of a watch and the state of its actions is returned with the
  64. watch definition when you call the <<watcher-api-get-watch, Get Watch API>>:
  65. [source,js]
  66. --------------------------------------------------
  67. GET _xpack/watcher/watch/my_watch
  68. --------------------------------------------------
  69. // CONSOLE
  70. The action state of a newly-created watch is `awaits_successful_execution`:
  71. [source,js]
  72. --------------------------------------------------
  73. {
  74. "found": true,
  75. "_version": 1,
  76. "_id": "my_watch",
  77. "status": {
  78. "version": 1,
  79. "actions": {
  80. "test_index": {
  81. "ack": {
  82. "timestamp": "2015-05-26T18:04:27.723Z",
  83. "state": "awaits_successful_execution"
  84. }
  85. }
  86. },
  87. "state": ...
  88. },
  89. "watch": ...
  90. }
  91. --------------------------------------------------
  92. // TESTRESPONSE[s/"state": \.\.\./"state": "$body.status.state"/]
  93. // TESTRESPONSE[s/"watch": \.\.\./"watch": "$body.watch"/]
  94. // TESTRESPONSE[s/"timestamp": "2015-05-26T18:04:27.723Z"/"timestamp": "$body.status.actions.test_index.ack.timestamp"/]
  95. When the watch executes and the condition matches, the value of the `ack.state`
  96. changes to `ackable`. Let's force execution of the watch and fetch it again to
  97. check the status:
  98. [source,js]
  99. --------------------------------------------------
  100. POST _xpack/watcher/watch/my_watch/_execute
  101. {
  102. "record_execution" : true
  103. }
  104. GET _xpack/watcher/watch/my_watch
  105. --------------------------------------------------
  106. // CONSOLE
  107. // TEST[continued]
  108. and the action is now in `ackable` state:
  109. [source,js]
  110. --------------------------------------------------
  111. {
  112. "found": true,
  113. "_id": "my_watch",
  114. "_version": 2,
  115. "status": {
  116. "version": 2,
  117. "actions": {
  118. "test_index": {
  119. "ack": {
  120. "timestamp": "2015-05-26T18:04:27.723Z",
  121. "state": "ackable"
  122. },
  123. "last_execution" : {
  124. "timestamp": "2015-05-25T18:04:27.723Z",
  125. "successful": true
  126. },
  127. "last_successful_execution" : {
  128. "timestamp": "2015-05-25T18:04:27.723Z",
  129. "successful": true
  130. }
  131. }
  132. },
  133. "state": ...,
  134. "execution_state": "executed",
  135. "last_checked": ...,
  136. "last_met_condition": ...
  137. },
  138. "watch": ...
  139. }
  140. --------------------------------------------------
  141. // TESTRESPONSE[s/"state": \.\.\./"state": "$body.status.state"/]
  142. // TESTRESPONSE[s/"watch": \.\.\./"watch": "$body.watch"/]
  143. // TESTRESPONSE[s/"last_checked": \.\.\./"last_checked": "$body.status.last_checked"/]
  144. // TESTRESPONSE[s/"last_met_condition": \.\.\./"last_met_condition": "$body.status.last_met_condition"/]
  145. // TESTRESPONSE[s/"timestamp": "2015-05-26T18:04:27.723Z"/"timestamp": "$body.status.actions.test_index.ack.timestamp"/]
  146. // TESTRESPONSE[s/"timestamp": "2015-05-25T18:04:27.723Z"/"timestamp": "$body.status.actions.test_index.last_execution.timestamp"/]
  147. Now we can acknowledge it:
  148. [source,js]
  149. --------------------------------------------------
  150. PUT _xpack/watcher/watch/my_watch/_ack/test_index
  151. GET _xpack/watcher/watch/my_watch
  152. --------------------------------------------------
  153. // CONSOLE
  154. // TEST[continued]
  155. [source,js]
  156. --------------------------------------------------
  157. {
  158. "found": true,
  159. "_id": "my_watch",
  160. "_version": 3,
  161. "status": {
  162. "version": 3,
  163. "actions": {
  164. "test_index": {
  165. "ack": {
  166. "timestamp": "2015-05-26T18:04:27.723Z",
  167. "state": "acked"
  168. },
  169. "last_execution" : {
  170. "timestamp": "2015-05-25T18:04:27.723Z",
  171. "successful": true
  172. },
  173. "last_successful_execution" : {
  174. "timestamp": "2015-05-25T18:04:27.723Z",
  175. "successful": true
  176. }
  177. }
  178. },
  179. "state": ...,
  180. "execution_state": "executed",
  181. "last_checked": ...,
  182. "last_met_condition": ...
  183. },
  184. "watch": ...
  185. }
  186. --------------------------------------------------
  187. // TESTRESPONSE[s/"state": \.\.\./"state": "$body.status.state"/]
  188. // TESTRESPONSE[s/"watch": \.\.\./"watch": "$body.watch"/]
  189. // TESTRESPONSE[s/"last_checked": \.\.\./"last_checked": "$body.status.last_checked"/]
  190. // TESTRESPONSE[s/"last_met_condition": \.\.\./"last_met_condition": "$body.status.last_met_condition"/]
  191. // TESTRESPONSE[s/"timestamp": "2015-05-26T18:04:27.723Z"/"timestamp": "$body.status.actions.test_index.ack.timestamp"/]
  192. // TESTRESPONSE[s/"timestamp": "2015-05-25T18:04:27.723Z"/"timestamp": "$body.status.actions.test_index.last_execution.timestamp"/]
  193. Acknowledging an action throttles further executions of that action until its
  194. `ack.state` is reset to `awaits_successful_execution`. This happens when the
  195. condition of the watch is not met (the condition evaluates to `false`).
  196. You can acknowledge multiple actions by assigning the `actions` parameter a
  197. comma-separated list of action ids:
  198. [source,js]
  199. --------------------------------------------------
  200. POST _xpack/watcher/watch/my_watch/_ack/action1,action2
  201. --------------------------------------------------
  202. // CONSOLE
  203. To acknowledge all of the actions of a watch, simply omit the `actions`
  204. parameter:
  205. [source,js]
  206. --------------------------------------------------
  207. POST _xpack/watcher/watch/my_watch/_ack
  208. --------------------------------------------------
  209. // TEST[s/^/POST _xpack\/watcher\/watch\/my_watch\/_execute\n{ "record_execution" : true }\n/]
  210. // CONSOLE
  211. The response looks like a get watch response, but only contains the status:
  212. [source,js]
  213. --------------------------------------------------
  214. {
  215. "status": {
  216. "state": {
  217. "active": true,
  218. "timestamp": "2015-05-26T18:04:27.723Z"
  219. },
  220. "last_checked": "2015-05-26T18:04:27.753Z",
  221. "last_met_condition": "2015-05-26T18:04:27.763Z",
  222. "actions": {
  223. "test_index": {
  224. "ack" : {
  225. "timestamp": "2015-05-26T18:04:27.713Z",
  226. "state": "acked"
  227. },
  228. "last_execution" : {
  229. "timestamp": "2015-05-25T18:04:27.733Z",
  230. "successful": true
  231. },
  232. "last_successful_execution" : {
  233. "timestamp": "2015-05-25T18:04:27.773Z",
  234. "successful": true
  235. }
  236. }
  237. },
  238. "execution_state": "executed",
  239. "version": 2
  240. }
  241. }
  242. --------------------------------------------------
  243. // TESTRESPONSE[s/"last_checked": "2015-05-26T18:04:27.753Z"/"last_checked": "$body.status.last_checked"/]
  244. // TESTRESPONSE[s/"last_met_condition": "2015-05-26T18:04:27.763Z"/"last_met_condition": "$body.status.last_met_condition"/]
  245. // TESTRESPONSE[s/"timestamp": "2015-05-26T18:04:27.723Z"/"timestamp": "$body.status.state.timestamp"/]
  246. // TESTRESPONSE[s/"timestamp": "2015-05-26T18:04:27.713Z"/"timestamp": "$body.status.actions.test_index.ack.timestamp"/]
  247. // TESTRESPONSE[s/"timestamp": "2015-05-25T18:04:27.733Z"/"timestamp": "$body.status.actions.test_index.last_execution.timestamp"/]
  248. // TESTRESPONSE[s/"timestamp": "2015-05-25T18:04:27.773Z"/"timestamp": "$body.status.actions.test_index.last_successful_execution.timestamp"/]