ack-watch.asciidoc 9.0 KB

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