109 lines
2.6 KiB
Plaintext
109 lines
2.6 KiB
Plaintext
[[api-rest-get-watch]]
|
|
==== Get Watch API
|
|
|
|
This API retrieves a watch by its id.
|
|
|
|
The following example gets a watch with `my-watch` id:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
GET _watcher/watch/my-watch
|
|
--------------------------------------------------
|
|
// AUTOSENSE
|
|
|
|
This is an example of the output:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
{
|
|
"found": true,
|
|
"_id": "my_watch",
|
|
"_status": { <1>
|
|
"last_checked": "2015-05-26T18:21:08.630Z",
|
|
"last_met_condition": "2015-05-26T18:21:08.630Z",
|
|
"actions": {
|
|
"email_admin": {
|
|
"ack_status": {
|
|
"timestamp": "2015-05-26T18:21:09.982Z",
|
|
"state": "acked"
|
|
},
|
|
"last_execution": {
|
|
"timestamp": "2015-05-26T18:21:04.106Z",
|
|
"successful": true
|
|
},
|
|
"last_successful_execution": {
|
|
"timestamp": "2015-05-26T18:21:04.106Z",
|
|
"successful": true
|
|
},
|
|
"last_throttle": {
|
|
"timestamp": "2015-05-26T18:21:08.630Z",
|
|
"reason": "throttling interval is set to [5 seconds] but time elapsed since last execution is [4 seconds and 530 milliseconds]"
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"watch": {
|
|
"input": {
|
|
"search": {
|
|
"request": {
|
|
"search_type": "query_then_fetch",
|
|
"indices": [
|
|
"logstash*"
|
|
],
|
|
"types": [],
|
|
"body": {
|
|
"query": {
|
|
"filtered": {
|
|
"filter": {
|
|
"range": {
|
|
"@timestamp": {
|
|
"from": "{{ctx.trigger.scheduled_time}}||-5m",
|
|
"to": "{{ctx.trigger.triggered_time}}"
|
|
}
|
|
}
|
|
},
|
|
"query": {
|
|
"match": {
|
|
"response": 404
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"condition": {
|
|
"script": {
|
|
"type": "inline",
|
|
"lang": "groovy",
|
|
"params": {},
|
|
"script": "ctx.payload.hits.total > 1"
|
|
}
|
|
},
|
|
"trigger": {
|
|
"schedule": {
|
|
"cron": "0 0/1 * * * ?"
|
|
}
|
|
},
|
|
"actions": {
|
|
"email_admin": {
|
|
"email": {
|
|
"subject": {
|
|
"type": "inline",
|
|
"lang": "mustache",
|
|
"params": {},
|
|
"script": "404 recently encountered"
|
|
},
|
|
"attach_data": false,
|
|
"to": [
|
|
"someone@domain.host.com"
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
<1> The retrieved watch will return with its current status |