|
@@ -7,7 +7,7 @@
|
|
|
"link": "elasticsearch/indices",
|
|
|
"severity": 2100,
|
|
|
"type": "monitoring",
|
|
|
- "version_created": 7000099,
|
|
|
+ "version_created": "${monitoring.version_created}",
|
|
|
"watch": "${monitoring.watch.id}"
|
|
|
}
|
|
|
},
|
|
@@ -134,11 +134,23 @@
|
|
|
},
|
|
|
"transform": {
|
|
|
"script": {
|
|
|
- "source": "ctx.vars.email_recipient = (ctx.payload.kibana_settings.hits.total > 0 && ctx.payload.kibana_settings.hits.hits[0]._source.kibana_settings.xpack != null) ? ctx.payload.kibana_settings.hits.hits[0]._source.kibana_settings.xpack.default_admin_email : null;ctx.vars.is_new = ctx.vars.fails_check && !ctx.vars.not_resolved;ctx.vars.is_resolved = !ctx.vars.fails_check && ctx.vars.not_resolved;def state = ctx.payload.check.hits.hits[0]._source.cluster_state.status;if (ctx.vars.not_resolved){ctx.payload = ctx.payload.alert.hits.hits[0]._source;if (ctx.vars.fails_check == false) {ctx.payload.resolved_timestamp = ctx.execution_time;}} else {ctx.payload = ['timestamp': ctx.execution_time, 'metadata': ctx.metadata.xpack];}if (ctx.vars.fails_check) {ctx.payload.prefix = 'Elasticsearch cluster status is ' + state + '.';if (state == 'red') {ctx.payload.message = 'Allocate missing primary shards and replica shards.';ctx.payload.metadata.severity = 2100;} else {ctx.payload.message = 'Allocate missing replica shards.';ctx.payload.metadata.severity = 1100;}}ctx.vars.state = state.toUpperCase();ctx.payload.update_timestamp = ctx.execution_time;return ctx.payload;"
|
|
|
+ "source": "ctx.vars.email_recipient = (ctx.payload.kibana_settings.hits.total > 0 && ctx.payload.kibana_settings.hits.hits[0]._source.kibana_settings.xpack != null) ? ctx.payload.kibana_settings.hits.hits[0]._source.kibana_settings.xpack.default_admin_email : null;ctx.vars.is_new = ctx.vars.fails_check && !ctx.vars.not_resolved;ctx.vars.is_resolved = !ctx.vars.fails_check && ctx.vars.not_resolved;ctx.vars.found_state = ctx.payload.check.hits.total != 0;def state = ctx.vars.found_state ? ctx.payload.check.hits.hits[0]._source.cluster_state.status : 'unknown';if (ctx.vars.not_resolved){ctx.payload = ctx.payload.alert.hits.hits[0]._source;if (ctx.vars.fails_check == false) {ctx.payload.resolved_timestamp = ctx.execution_time;}} else {ctx.payload = ['timestamp': ctx.execution_time, 'metadata': ctx.metadata.xpack];}if (ctx.vars.fails_check) {ctx.payload.prefix = 'Elasticsearch cluster status is ' + state + '.';if (state == 'red') {ctx.payload.message = 'Allocate missing primary shards and replica shards.';ctx.payload.metadata.severity = 2100;} else {ctx.payload.message = 'Allocate missing replica shards.';ctx.payload.metadata.severity = 1100;}}ctx.vars.state = state.toUpperCase();ctx.payload.update_timestamp = ctx.execution_time;return ctx.payload;"
|
|
|
}
|
|
|
},
|
|
|
"actions": {
|
|
|
+ "log_state_not_found": {
|
|
|
+ "condition": {
|
|
|
+ "script": "!ctx.vars.found_state"
|
|
|
+ },
|
|
|
+ "logging" : {
|
|
|
+ "text" : "Watch [{{ctx.metadata.xpack.watch}}] could not determine cluster state for cluster [{{ctx.metadata.xpack.cluster_uuid}}]. This likely means the cluster has not sent any monitoring data recently.",
|
|
|
+ "level" : "debug"
|
|
|
+ }
|
|
|
+ },
|
|
|
"add_to_alerts_index": {
|
|
|
+ "condition": {
|
|
|
+ "script": "ctx.vars.found_state"
|
|
|
+ },
|
|
|
"index": {
|
|
|
"index": ".monitoring-alerts-7",
|
|
|
"doc_id": "${monitoring.watch.unique_id}"
|
|
@@ -146,7 +158,7 @@
|
|
|
},
|
|
|
"send_email_to_admin": {
|
|
|
"condition": {
|
|
|
- "script": "return ctx.vars.email_recipient != null && (ctx.vars.is_new || ctx.vars.is_resolved)"
|
|
|
+ "script": "return ctx.vars.email_recipient != null && ctx.vars.found_state && (ctx.vars.is_new || ctx.vars.is_resolved)"
|
|
|
},
|
|
|
"email": {
|
|
|
"to": "X-Pack Admin <{{ctx.vars.email_recipient}}>",
|