Run a watch
Generally available
This API can be used to force execution of the watch outside of its triggering logic or to simulate the watch execution for debugging purposes.
For testing and debugging purposes, you also have fine-grained control on how the watch runs. You can run the watch without running all of its actions or alternatively by simulating them. You can also force execution by ignoring the watch condition and control whether a watch record would be written to the watch history after it runs.
You can use the run watch API to run watches that are not yet registered by specifying the watch definition inline. This serves as great tool for testing and debugging your watches prior to adding them to Watcher.
When Elasticsearch security features are enabled on your cluster, watches are run with the privileges of the user that stored the watches.
If your user is allowed to read index a
, but not index b
, then the exact same set of rules will apply during execution of a watch.
When using the run watch API, the authorization data of the user that called the API will be used as a base, instead of the information who stored the watch.
Required authorization
- Cluster privileges:
manage_watcher
Body
-
Determines how to handle the watch actions as part of the watch execution.
-
When present, the watch uses this object as a payload instead of executing its own input.
-
When set to
true
, the watch execution uses the always condition. This can also be specified as an HTTP parameter. -
When set to
true
, the watch record representing the watch execution result is persisted to the.watcher-history
index for the current time. In addition, the status of the watch is updated, possibly throttling subsequent runs. This can also be specified as an HTTP parameter. -
Hide trigger_data attributes Show trigger_data attributes object
-
Hide watch attributes Show watch attributes object
-
Hide actions attribute Show actions attribute object
-
Hide * attributes Show * attributes object
-
Values are
email
,webhook
,index
,logging
,slack
, orpagerduty
. -
Hide condition attributes Show condition attributes object
-
A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
Time unit for milliseconds
-
Hide transform attributes Show transform attributes object
-
-
Hide search attributes Show search attributes object
-
Hide request attributes Show request attributes object
-
Controls how to deal with unavailable concrete indices (closed or missing), how wildcard expressions are expanded to actual indices (all, closed or open indices) and how to deal with wildcard expressions that resolve to no indices.
-
Values are
query_then_fetch
ordfs_query_then_fetch
.
-
A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.
-
-
-
Hide index attributes Show index attributes object
-
Values are
true
,false
, orwait_for
. -
Values are
index
orcreate
. -
A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.
-
Hide email attributes Show email attributes object
-
Hide pagerduty attributes Show pagerduty attributes object
-
-
Values are
trigger
,resolve
, oracknowledge
.
-
Hide slack attributes Show slack attributes object
-
Hide message attributes Show message attributes object
-
Hide webhook attributes Show webhook attributes object
-
A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
Values are
head
,get
,post
,put
, ordelete
. -
A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
Values are
http
orhttps
.
-
-
-
Hide condition attributes Show condition attributes object
-
Hide input attributes Show input attributes object
-
Hide http attributes Show http attributes object
-
Hide request attributes Show request attributes object
-
A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
Values are
head
,get
,post
,put
, ordelete
. -
A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
Values are
http
orhttps
.
-
Values are
json
,yaml
, ortext
.
-
Hide search attributes Show search attributes object
-
Hide request attributes Show request attributes object
-
Hide body attribute Show body attribute object
-
An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
External documentation
-
-
Controls how to deal with unavailable concrete indices (closed or missing), how wildcard expressions are expanded to actual indices (all, closed or open indices) and how to deal with wildcard expressions that resolve to no indices.
Hide indices_options attributes Show indices_options attributes object
-
If false, the request returns an error if any wildcard expression, index alias, or
_all
value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targetingfoo*,bar*
returns an error if an index starts withfoo
but no index starts withbar
. -
If true, missing or closed indices are not included in the response.
-
If true, concrete, expanded or aliased indices are ignored when frozen.
-
-
Values are
query_then_fetch
ordfs_query_then_fetch
. -
Hide template attributes Show template attributes object
-
An inline search template. Supports the same parameters as the search API's request body. Also supports Mustache variables. If no id is specified, this parameter is required.
-
-
A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.
-
Hide status attributes Show status attributes object
-
Hide actions attribute Show actions attribute object
-
Hide * attributes Show * attributes object
-
last_met_condition
string | number A date and time, either as a string whose format can depend on the context (defaulting to ISO 8601), or a number of milliseconds since the Epoch. Elasticsearch accepts both as input, but will generally output a string representation.
-
Hide state attributes Show state attributes object
-
-
A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
Time unit for milliseconds
-
Hide transform attributes Show transform attributes object
-
-
Hide search attributes Show search attributes object
-
Hide request attributes Show request attributes object
-
Hide body attribute Show body attribute object
-
An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
External documentation
-
-
Controls how to deal with unavailable concrete indices (closed or missing), how wildcard expressions are expanded to actual indices (all, closed or open indices) and how to deal with wildcard expressions that resolve to no indices.
Hide indices_options attributes Show indices_options attributes object
-
If false, the request returns an error if any wildcard expression, index alias, or
_all
value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targetingfoo*,bar*
returns an error if an index starts withfoo
but no index starts withbar
. -
If true, missing or closed indices are not included in the response.
-
If true, concrete, expanded or aliased indices are ignored when frozen.
-
-
Values are
query_then_fetch
ordfs_query_then_fetch
. -
Hide template attributes Show template attributes object
-
An inline search template. Supports the same parameters as the search API's request body. Also supports Mustache variables. If no id is specified, this parameter is required.
-
-
A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.
-
-
-
Hide trigger attribute Show trigger attribute object
-
Hide schedule attributes Show schedule attributes object
-
Hide daily attribute Show daily attribute object
-
A time of day, expressed either as
hh:mm
,noon
,midnight
, or an hour/minutes structure.A time of day, expressed either as
hh:mm
,noon
,midnight
, or an hour/minutes structure.
-
-
A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.
-
-
Responses
-
Hide response attributes Show response attributes object
-
Hide watch_record attributes Show watch_record attributes object
-
Hide condition attributes Show condition attributes object
-
Hide input attributes Show input attributes object
-
Hide http attributes Show http attributes object
-
Hide request attributes Show request attributes object
-
A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
Values are
head
,get
,post
,put
, ordelete
. -
A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
Values are
http
orhttps
.
-
Values are
json
,yaml
, ortext
.
-
Hide search attributes Show search attributes object
-
Hide request attributes Show request attributes object
-
Controls how to deal with unavailable concrete indices (closed or missing), how wildcard expressions are expanded to actual indices (all, closed or open indices) and how to deal with wildcard expressions that resolve to no indices.
Hide indices_options attributes Show indices_options attributes object
-
If false, the request returns an error if any wildcard expression, index alias, or
_all
value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targetingfoo*,bar*
returns an error if an index starts withfoo
but no index starts withbar
. -
If true, missing or closed indices are not included in the response.
-
If true, concrete, expanded or aliased indices are ignored when frozen.
-
-
Values are
query_then_fetch
ordfs_query_then_fetch
. -
Hide template attributes Show template attributes object
-
A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.
-
Hide result attributes Show result attributes object
-
Hide actions attributes Show actions attributes object
-
Values are
success
,failure
,simulated
, orthrottled
. -
Values are
email
,webhook
,index
,logging
,slack
, orpagerduty
. -
Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.
Hide error attributes Show error attributes object
-
The type of error
-
The server stack trace. Present only if the
error_trace=true
parameter was sent with the request. -
Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.
-
-
Time unit for milliseconds
execution_time
string | number Required A date and time, either as a string whose format can depend on the context (defaulting to ISO 8601), or a number of milliseconds since the Epoch. Elasticsearch accepts both as input, but will generally output a string representation.
-
-
Values are
awaits_execution
,checking
,execution_not_needed
,throttled
,executed
,failed
,deleted_while_queued
, ornot_executed_already_queued
. -
Hide trigger_event attributes Show trigger_event attributes object
-
Hide status attributes Show status attributes object
-
Hide actions attribute Show actions attribute object
-
Hide * attributes Show * attributes object
-
last_met_condition
string | number A date and time, either as a string whose format can depend on the context (defaulting to ISO 8601), or a number of milliseconds since the Epoch. Elasticsearch accepts both as input, but will generally output a string representation.
-
Hide state attributes Show state attributes object
-
-
curl \
--request POST 'http://api.example.com/_watcher/watch/{id}/_execute' \
--header "Authorization: $API_KEY" \
--header "Content-Type: application/json" \
--data '"{\n \"trigger_data\" : { \n \"triggered_time\" : \"now\",\n \"scheduled_time\" : \"now\"\n },\n \"alternative_input\" : { \n \"foo\" : \"bar\"\n },\n \"ignore_condition\" : true, \n \"action_modes\" : {\n \"my-action\" : \"force_simulate\" \n },\n \"record_execution\" : true \n}"'
{
"trigger_data" : {
"triggered_time" : "now",
"scheduled_time" : "now"
},
"alternative_input" : {
"foo" : "bar"
},
"ignore_condition" : true,
"action_modes" : {
"my-action" : "force_simulate"
},
"record_execution" : true
}
{
"action_modes" : {
"action1" : "force_simulate",
"action2" : "skip"
}
}
{
"watch" : {
"trigger" : { "schedule" : { "interval" : "10s" } },
"input" : {
"search" : {
"request" : {
"indices" : [ "logs" ],
"body" : {
"query" : {
"match" : { "message": "error" }
}
}
}
}
},
"condition" : {
"compare" : { "ctx.payload.hits.total" : { "gt" : 0 }}
},
"actions" : {
"log_error" : {
"logging" : {
"text" : "Found {{ctx.payload.hits.total}} errors in the logs"
}
}
}
}
}
{
"_id": "my_watch_0-2015-06-02T23:17:55.124Z",
"watch_record": {
"@timestamp": "2015-06-02T23:17:55.124Z",
"watch_id": "my_watch",
"node": "my_node",
"messages": [],
"trigger_event": {
"type": "manual",
"triggered_time": "2015-06-02T23:17:55.124Z",
"manual": {
"schedule": {
"scheduled_time": "2015-06-02T23:17:55.124Z"
}
}
},
"state": "executed",
"status": {
"version": 1,
"execution_state": "executed",
"state": {
"active": true,
"timestamp": "2015-06-02T23:17:55.111Z"
},
"last_checked": "2015-06-02T23:17:55.124Z",
"last_met_condition": "2015-06-02T23:17:55.124Z",
"actions": {
"test_index": {
"ack": {
"timestamp": "2015-06-02T23:17:55.124Z",
"state": "ackable"
},
"last_execution": {
"timestamp": "2015-06-02T23:17:55.124Z",
"successful": true
},
"last_successful_execution": {
"timestamp": "2015-06-02T23:17:55.124Z",
"successful": true
}
}
}
},
"input": {
"simple": {
"payload": {
"send": "yes"
}
}
},
"condition": {
"always": {}
},
"result": {
"execution_time": "2015-06-02T23:17:55.124Z",
"execution_duration": 12608,
"input": {
"type": "simple",
"payload": {
"foo": "bar"
},
"status": "success"
},
"condition": {
"type": "always",
"met": true,
"status": "success"
},
"actions": [
{
"id": "test_index",
"index": {
"response": {
"index": "test",
"version": 1,
"created": true,
"result": "created",
"id": "AVSHKzPa9zx62AzUzFXY"
}
},
"status": "success",
"type": "index"
}
]
},
"user": "test_admin"
}
}