id: elasticsearch-unassigned-shards-cluster-health-sentinel
namespace: company.search
description: |
Audits Elasticsearch cluster health and shard allocation catalogs to detect unassigned replica shards, yellow or red cluster states, and allocation failures.
inputs:
- id: elasticsearch_url
type: STRING
displayName: Elasticsearch Endpoint URL
defaults: "http://elasticsearch.internal:9200"
description: Base HTTP or HTTPS URL exposing the target Elasticsearch cluster API.
- id: alert_on_yellow_status
type: BOOL
displayName: Alert On Yellow Status
defaults: true
description: Trigger an operational warning if cluster status is YELLOW
(unassigned replica shards).
- id: slack_channel
type: STRING
displayName: Slack Channel
defaults: "#search-alerts"
description: Destination Slack channel for search cluster health alerts and
reroute runbooks.
triggers:
- id: recurring_health_audit
type: io.kestra.plugin.core.trigger.Schedule
cron: "0 */2 * * *"
disabled: true
description: Automated schedule trigger to audit cluster health every two hours.
tasks:
- id: query_cluster_health
type: io.kestra.plugin.elasticsearch.Request
description: Queries Elasticsearch /_cluster/health API to inspect cluster
status, unassigned shards, and active data nodes.
connection:
hosts:
- "{{ inputs.elasticsearch_url }}"
basicAuth:
username: "{{ secret('ELASTICSEARCH_USERNAME') }}"
password: "{{ secret('ELASTICSEARCH_PASSWORD') }}"
method: GET
endpoint: "/_cluster/health"
- id: evaluate_cluster_status
type: io.kestra.plugin.core.flow.If
description: Evaluates whether cluster status is degraded (RED or YELLOW) or
contains unassigned shards.
condition: "{{ outputs.query_cluster_health.response.status != 'green' or
outputs.query_cluster_health.response.unassigned_shards > 0 }}"
then:
- id: alert_cluster_slack
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatches actionable operational alert to Slack detailing degraded
Elasticsearch cluster state.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "{{ inputs.slack_channel }}",
"attachments": [
{
"color": "{{ outputs.query_cluster_health.response.status == 'red' ? '#D32F2F' : '#FF9800' }}",
"title": "🚨 Elasticsearch Cluster Health Alert: {{ outputs.query_cluster_health.response.status | upper }} State",
"text": "The Kestra Elasticsearch Sentinel detected cluster degradation on `{{ inputs.elasticsearch_url }}` with unassigned shard allocation issues.",
"fields": [
{
"title": "Cluster Status",
"value": "*{{ outputs.query_cluster_health.response.status | upper }}*",
"short": true
},
{
"title": "Unassigned Shards",
"value": "*{{ outputs.query_cluster_health.response.unassigned_shards }}*",
"short": true
},
{
"title": "Active Data Nodes",
"value": "{{ outputs.query_cluster_health.response.number_of_data_nodes }} of {{ outputs.query_cluster_health.response.number_of_nodes }} nodes",
"short": true
},
{
"title": "Relocating / Initializing",
"value": "{{ outputs.query_cluster_health.response.relocating_shards }} relocating / {{ outputs.query_cluster_health.response.initializing_shards }} initializing",
"short": true
},
{
"title": "Diagnostic Runbook",
"value": "`GET /_cluster/allocation/explain` or retry allocation: `POST /_cluster/reroute?retry_failed=true`",
"short": false
}
],
"footer": "Kestra Elasticsearch Sentinel • Execution ID: {{ execution.id }}"
}
]
}
- id: log_degradation_details
type: io.kestra.plugin.core.log.Log
description: Emits diagnostic log message for search reliability engineers.
message: "Elasticsearch Degradation Alert: Cluster status is {{
outputs.query_cluster_health.response.status }}. Unassigned shards: {{
outputs.query_cluster_health.response.unassigned_shards }}. Active
data nodes: {{
outputs.query_cluster_health.response.number_of_data_nodes }}."
else:
- id: log_nominal_state
type: io.kestra.plugin.core.log.Log
description: Emits confirmation that the Elasticsearch cluster is GREEN with
zero unassigned shards.
message: "Elasticsearch cluster health nominal. Status is GREEN, 0 unassigned
shards across {{
outputs.query_cluster_health.response.number_of_data_nodes }} data
nodes."
- id: emit_audit_summary
type: io.kestra.plugin.core.log.Log
description: Records audit completion telemetry for compliance and
infrastructure tracking.
message: "Elasticsearch health audit finished for '{{ inputs.elasticsearch_url
}}'. Cluster status: {{ outputs.query_cluster_health.response.status }}.
Active primary shards: {{
outputs.query_cluster_health.response.active_primary_shards }}."
errors:
- id: alert_on_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatches high-urgency Slack alert if the sentinel execution fails.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "{{ inputs.slack_channel }}",
"text": "❌ *Elasticsearch Sentinel Execution Failed*: Execution `{{ execution.id }}` crashed during health audit for endpoint `{{ inputs.elasticsearch_url }}`."
}