Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

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