Last active
April 20, 2020 10:08
-
-
Save veysby/cf89534dc023f668c499 to your computer and use it in GitHub Desktop.
Activemq: check health status using REST API
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
$curl http://localhost:8161/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=localhost,service=Health | |
{"timestamp":1449776947,"status":200,"request":{"mbean":"org.apache.activemq:brokerName=localhost,service=Health,type=Broker","type":"read"},"value":{"CurrentStatus":"Good"}} |
Hi,
What Can I use to replace this "jq -r" from the healthcheck?, I read somewhere that sed will do the same, but I´m not familiar with it.
Thanks.
sed /can/ do the same thing, but sed doesn't understand json. You'll have to do some regex-fu in order to get a similar result. jq is like sed but with the added luxury of understanding json, so regardless of extra lines or other possible strange formatting, jq, in this case, will output the whole value of the 'value' member of the json being fed in (or nothing/error if the json is invalid or doesn't contain a member named 'value')
I do not have jq
installed in my docker image so I use much simpler version:
curl --silent --show-error "http://localhost:8161/api/jolokia/exec/org.apache.activemq:type=Broker,brokerName=localhost,service=Health/healthStatus" | tee /dev/tty | grep --silent 'Good'
The exit status give OK/KO condition.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reading the status doesn't actually checks the status it just reads the last know status. It is better to execute the method healthStatus() that will check the status and returns the new status.
Here is the final script I'm using: