Skip to content

Instantly share code, notes, and snippets.

@denzuko
Last active August 27, 2015 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save denzuko/9a39094b7ad0fcfd02b2 to your computer and use it in GitHub Desktop.
Save denzuko/9a39094b7ad0fcfd02b2 to your computer and use it in GitHub Desktop.
163: ==> default: ^M
164: ==> default: TASK: [(feature) Monitor Cluster Health and send email on poor health] ******** ^M
165: ==> default: fatal: [localhost] => error while evaluating conditional: payload.status == 200^M
166: ==> default: ^M
167: ==> default: FATAL: all hosts have already failed -- aborting^M
168: ==> default: ^M
169: ==> default: PLAY RECAP ******************************************************************** ^M
170: ==> default: to retry, use: --limit @/root/provisioning.retry^M
171: ==> default: ^M
{
"trigger": {
"schedule": { "interval": "10s" }
},
"input": {
"http": {
"request": {
"host": "localhost",
"port": "{{ es_http_port }}",
"path": "/_cluster/health"
}
}
},
"condition": {
"compare": {
"ctx.payload.status": {
"eq": "red"
}
}
},
"actions": {
"send_email": {
"email": {
"to": "{{ alert_email }}",
"subject": "{{ alert_subject }}",
"body": "Cluster is in poor health."
}
}
}
}
---
cluster_health_watch_body: "{{ lookup('template', 'templates/cluster_health_watch.json.j2') }}"
es_http_port: 9200
- hosts: all
tasks:
- name: (feature) Monitor Cluster Health and send email on poor health
uri:
url: http://localhost:{{ es_http_port }}/_watcher/watch/cluster_health_watch
method: PUT
user: "{{ es_admin }}"
password: "{{ es_adminpw }}"
HEADER_Content-Type: "application/json"
return_content: yes
body_format: json
body: "{{ cluster_health_watch_body | to_json }}"
status_code: 200,201
register: payload
failed_when:
- payload.status != 201
- payload.status != 200
changed_when: payload.content.find("created") == "true"
/* edited for content ..., */
{
"created": "true"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment