Last active
April 9, 2019 16:28
-
-
Save walterra/24ff98d770da582cbc8c39ff43a9520c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"trigger": { | |
"schedule": { | |
"interval": "5s" | |
} | |
}, | |
"input": { | |
"search": { | |
"request": { | |
"search_type": "query_then_fetch", | |
"indices": [ | |
".ml-annotations-read" | |
], | |
"rest_total_hits_as_int": true, | |
"body": { | |
"size": 1, | |
"query": { | |
"range": { | |
"create_time": { | |
"gte": "now-9s" | |
} | |
} | |
}, | |
"sort": [ | |
{ | |
"create_time": { | |
"order": "desc" | |
} | |
} | |
] | |
} | |
} | |
} | |
}, | |
"condition": { | |
"compare": { | |
"ctx.payload.hits.total": { | |
"gte": 1 | |
} | |
} | |
}, | |
"actions": { | |
"notify-slack": { | |
"transform": { | |
"script": { | |
"source": "def payload = ctx.payload; DateFormat df = new SimpleDateFormat(\"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'\"); payload.timestamp_formatted = df.format(Date.from(Instant.ofEpochMilli(payload.hits.hits.0._source.timestamp))); payload.end_timestamp_formatted = df.format(Date.from(Instant.ofEpochMilli(payload.hits.hits.0._source.end_timestamp))); return payload", | |
"lang": "painless" | |
} | |
}, | |
"throttle_period_in_millis": 10000, | |
"slack": { | |
"message": { | |
"to": [ | |
"#ml-annotations-tmp" | |
], | |
"text": "New Annotation for job *{{ctx.payload.hits.hits.0._source.job_id}}*: {{ctx.payload.hits.hits.0._source.annotation}}", | |
"attachments": [ | |
{ | |
"fallback": "View in Single Metric Viewer http://localhost:5601/nqj/app/ml#/timeseriesexplorer?_g=(ml:(jobIds:!({{ctx.payload.hits.hits.0._source.job_id}})),refreshInterval:(pause:!t,value:0),time:(from:'{{ctx.payload.timestamp_formatted}}',mode:absolute,to:'{{ctx.payload.end_timestamp_formatted}}'))&_a=(filters:!(),mlSelectInterval:(interval:(display:Auto,val:auto)),mlSelectSeverity:(threshold:(color:%23d2e9f7,display:warning,val:0)),mlTimeSeriesExplorer:(zoom:(from:'{{ctx.payload.timestamp_formatted}}',to:'{{ctx.payload.end_timestamp_formatted}}')),query:(query_string:(analyze_wildcard:!t,query:'*')))", | |
"actions": [ | |
{ | |
"name": "action_name", | |
"style": "primary", | |
"type": "button", | |
"text": "View in Single Metric Viewer", | |
"url": "http://localhost:5601/nqj/app/ml#/timeseriesexplorer?_g=(ml:(jobIds:!({{ctx.payload.hits.hits.0._source.job_id}})),refreshInterval:(pause:!t,value:0),time:(from:'{{ctx.payload.timestamp_formatted}}',mode:absolute,to:'{{ctx.payload.end_timestamp_formatted}}'))&_a=(filters:!(),mlSelectInterval:(interval:(display:Auto,val:auto)),mlSelectSeverity:(threshold:(color:%23d2e9f7,display:warning,val:0)),mlTimeSeriesExplorer:(zoom:(from:'{{ctx.payload.timestamp_formatted}}',to:'{{ctx.payload.end_timestamp_formatted}}')),query:(query_string:(analyze_wildcard:!t,query:'*')))" | |
} | |
] | |
} | |
] | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment