确认监测器 API
编辑确认监测器 API编辑
确认监测器 使您能够手动限制监测器操作的执行。
描述编辑
操作的 *确认状态* 存储在 status.actions.<id>.ack.state
结构中。
如果指定的监测器当前正在执行,则此 API 将返回错误。这样做的原因是为了防止从监测器执行中覆盖监测器状态。
路径参数编辑
-
<action_id>
- (可选,列表)要确认的操作 ID 的逗号分隔列表。如果省略此参数,则确认监测器的所有操作。
-
<watch_id>
- (必填,字符串)监测器的标识符。
示例编辑
为了演示,让我们创建一个新的监测器
PUT _watcher/watch/my_watch { "trigger" : { "schedule" : { "yearly" : { "in" : "february", "on" : 29, "at" : "noon" } } }, "input": { "simple": { "payload": { "send": "yes" } } }, "condition": { "always": {} }, "actions": { "test_index": { "throttle_period": "15m", "index": { "index": "test" } } } }
当您调用 获取监测器 API 时,监测器的当前状态及其操作的状态将与监测器定义一起返回
GET _watcher/watch/my_watch
新创建的监测器的操作状态为 awaits_successful_execution
{ "found": true, "_seq_no": 0, "_primary_term": 1, "_version": 1, "_id": "my_watch", "status": { "version": 1, "actions": { "test_index": { "ack": { "timestamp": "2015-05-26T18:04:27.723Z", "state": "awaits_successful_execution" } } }, "state": ... }, "watch": ... }
当监测器执行并且条件匹配时,ack.state
的值将更改为 ackable
。让我们强制执行监测器并再次获取它以检查状态
POST _watcher/watch/my_watch/_execute { "record_execution" : true } GET _watcher/watch/my_watch
现在操作处于 ackable
状态
{ "found": true, "_id": "my_watch", "_seq_no": 1, "_primary_term": 1, "_version": 2, "status": { "version": 2, "actions": { "test_index": { "ack": { "timestamp": "2015-05-26T18:04:27.723Z", "state": "ackable" }, "last_execution" : { "timestamp": "2015-05-25T18:04:27.723Z", "successful": true }, "last_successful_execution" : { "timestamp": "2015-05-25T18:04:27.723Z", "successful": true } } }, "state": ..., "execution_state": "executed", "last_checked": ..., "last_met_condition": ... }, "watch": ... }
现在我们可以确认它
PUT _watcher/watch/my_watch/_ack/test_index GET _watcher/watch/my_watch
{ "found": true, "_id": "my_watch", "_seq_no": 2, "_primary_term": 1, "_version": 3, "status": { "version": 3, "actions": { "test_index": { "ack": { "timestamp": "2015-05-26T18:04:27.723Z", "state": "acked" }, "last_execution" : { "timestamp": "2015-05-25T18:04:27.723Z", "successful": true }, "last_successful_execution" : { "timestamp": "2015-05-25T18:04:27.723Z", "successful": true } } }, "state": ..., "execution_state": "executed", "last_checked": ..., "last_met_condition": ... }, "watch": ... }
确认操作会限制该操作的进一步执行,直到其 ack.state
重置为 awaits_successful_execution
。当监测器的条件不满足(条件评估为 false
)时,就会发生这种情况。
您可以通过为 actions
参数分配一个以逗号分隔的操作 ID 列表来确认多个操作
POST _watcher/watch/my_watch/_ack/action1,action2
要确认监测器的所有操作,只需省略 actions
参数
POST _watcher/watch/my_watch/_ack
响应看起来像获取监测器响应,但仅包含状态
{ "status": { "state": { "active": true, "timestamp": "2015-05-26T18:04:27.723Z" }, "last_checked": "2015-05-26T18:04:27.753Z", "last_met_condition": "2015-05-26T18:04:27.763Z", "actions": { "test_index": { "ack" : { "timestamp": "2015-05-26T18:04:27.713Z", "state": "acked" }, "last_execution" : { "timestamp": "2015-05-25T18:04:27.733Z", "successful": true }, "last_successful_execution" : { "timestamp": "2015-05-25T18:04:27.773Z", "successful": true } } }, "execution_state": "executed", "version": 2 } }