ack-watch.asciidoc 8.9 KB

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