Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

jason and jq help

avatar

I need jason jq help. I have the health status, but I need to grep the few field only using jq

{ "href" : "http://xxxx:8080/api/v1/clusters/?fields=Clusters/health_report", "items" : [ { "href" : "http://xxxxx:8080/api/v1/clusters/xxxxx", "Clusters" : { "cluster_name" : "xxxx", "health_report" : { "Host/stale_config" : 0, "Host/maintenance_state" : 13, "Host/host_state/HEALTHY" : 13, "Host/host_state/UNHEALTHY" : 0, "Host/host_state/HEARTBEAT_LOST" : 0, "Host/host_state/INIT" : 0, "Host/host_status/HEALTHY" : 12, "Host/host_status/UNHEALTHY" : 1, "Host/host_status/UNKNOWN" : 0, "Host/host_status/ALERT" : 0 }, "version" : "HDP-2.6" } } ]

I only want to grep Host/host_status/UNHEALTHY and it's value. How can I do using jq command

1 ACCEPTED SOLUTION

avatar
Expert Contributor
jq '.items[].Clusters.health_report."Host/host_status/UNHEALTHY"'

should work. The key name Host/host_status/UNHEALTHY should be quoted to escape the forward slashes in the name.

View solution in original post

11 REPLIES 11

avatar
Expert Contributor

Is it possible that something in your original redirection to the file was removing a character or two? As pasted into your original question, it's invalid JSON, which would also give you an error (since jq would be trying to parse a non-parseable string). Just to be thorough, could you attach the original file?

avatar

one of them shows as unhealthy, how do I find out which component or service is unhealthy in command line.

"Host/stale_config" : 0, "Host/maintenance_state" : 13, "Host/host_state/HEALTHY" : 13, "Host/host_state/UNHEALTHY" : 0, "Host/host_state/HEARTBEAT_LOST" : 0, "Host/host_state/INIT" : 0, "Host/host_status/HEALTHY" : 12, "Host/host_status/UNHEALTHY" : 1, "Host/host_status/UNKNOWN" : 0, "Host/host_status/ALERT" : 0