mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 11:05:39 -04:00
[Logs onboarding] Getting elastic-agent state in a more reliably way (#165205)
Closes https://github.com/elastic/kibana/issues/163163. We were getting `elastic-agent` status using `human` [output](https://www.elastic.co/guide/en/fleet/current/elastic-agent-cmd-options.html#_options_7), this way of obtaining the state is very unreliable since human format it's more likeable to vary from one version to other. e.g - v8.0.0 <img width="1021" alt="image" src="7c8102a4
-0785-4ab1-b690-ab62ec67644d"> - v8.9.0 <img width="1026" alt="image" src="b6acdfbd
-6efa-4518-8855-0aba3662f07b"> ### Changes - Get `elastic-agent` status from json output. #### Demo ##### v8.0.06c507269
-65d5-4c8a-9e9f-420698ca995d ##### v8.9.0acdab744
-0bd7-43c8-9eb8-024e5a2eeae5
This commit is contained in:
parent
d45347cf68
commit
94bccbc6cd
1 changed files with 10 additions and 4 deletions
|
@ -124,14 +124,20 @@ waitForElasticAgentStatus
|
||||||
if [ "$?" -ne 0 ]; then
|
if [ "$?" -ne 0 ]; then
|
||||||
updateStepProgress "ea-status" "warning" "Unable to determine agent status"
|
updateStepProgress "ea-status" "warning" "Unable to determine agent status"
|
||||||
fi
|
fi
|
||||||
ELASTIC_AGENT_STATE="$(elastic-agent status | grep -m1 State | sed 's/State: //')"
|
|
||||||
ELASTIC_AGENT_MESSAGE="$(elastic-agent status | grep -m1 Message | sed 's/Message: //')"
|
# https://www.elastic.co/guide/en/fleet/current/elastic-agent-cmd-options.html#elastic-agent-status-command
|
||||||
if [ "${ELASTIC_AGENT_STATE}" = "HEALTHY" ] && [ "${ELASTIC_AGENT_MESSAGE}" = "Running" ]; then
|
ELASTIC_AGENT_STATES=(STARTING CONFIGURING HEALTHY DEGRADED FAILED STOPPING UPGRADING ROLLBACK)
|
||||||
|
|
||||||
|
# Get elastic-agent status in json format | removing extra states in the json | finding "state":value | removing , | removing "state": | trimming the result
|
||||||
|
ELASTIC_AGENT_STATE="$(elastic-agent status --output json | sed -n '/components/q;p' | grep state | sed 's/\(.*\),/\1 /' | sed 's/"state": //' | sed 's/\s//g')"
|
||||||
|
# Get elastic-agent status in json format | removing extra states in the json | finding "message":value | removing , | removing "message": | trimming the result | removing ""
|
||||||
|
ELASTIC_AGENT_MESSAGE="$(elastic-agent status --output json | sed -n '/components/q;p' | grep message | sed 's/\(.*\),/\1 /' | sed 's/"message": //' | sed 's/\s//g' | sed 's/\"//g')"
|
||||||
|
if [ "${ELASTIC_AGENT_STATE}" = "2" ] && [ "${ELASTIC_AGENT_MESSAGE}" = "Running" ]; then
|
||||||
echo "Elastic Agent running"
|
echo "Elastic Agent running"
|
||||||
echo "Download and save configuration to ${cfg}"
|
echo "Download and save configuration to ${cfg}"
|
||||||
updateStepProgress "ea-status" "complete"
|
updateStepProgress "ea-status" "complete"
|
||||||
else
|
else
|
||||||
updateStepProgress "ea-status" "warning" "Expected agent status HEALTHY / Running but got ${ELASTIC_AGENT_STATE} / ${ELASTIC_AGENT_MESSAGE}"
|
updateStepProgress "ea-status" "warning" "Expected agent status HEALTHY / Running but got ${ELASTIC_AGENT_STATES[ELASTIC_AGENT_STATE]} / ${ELASTIC_AGENT_MESSAGE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
downloadElasticAgentConfig() {
|
downloadElasticAgentConfig() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue