Created 08-28-2017 05:09 AM
the following API give only the hosts from the amabri server
curl -sH "X-Requested-By: ambari" -u admin:admin -i http://localhost:8080/api/v1/hosts
is it possible to change the API in way that we can get also the IP address for each host?
the following example print only the hosts :
curl -sH "X-Requested-By: ambari" -u admin:admin -i http://localhost:8080/api/v1/hosts | grep host_name | sed s'/"//g' | awk '{print $NF}'
master01
master02
master03
worker01
worker02
expected results
master01 192.9.200.12
master02 192.9.200.13
master03 192.9.200.14
worker01 192.9.200.15
worker02 192.9.200.16
Created 08-28-2017 05:31 AM
You can try something like following:
# curl -sH "X-Requested-By: ambari" -u admin:admin -i http://localhost:8080/api/v1/hosts?fields=Hosts/host_name,Hosts/ip | grep -A 1 host_name | sed s'/"//g' | awk '{print $NF}'
.
Example Output:
# curl -sH "X-Requested-By: ambari" -u admin:admin -i http://amb25101.example.com:8080/api/v1/hosts?fields=Hosts/host_name,Hosts/ip | grep -A 1 host_name | sed s'/"//g' | awk '{print $NF}' http://amb25101.example.com:8080/api/v1/hosts?fields=Hosts/host_name,Hosts/ip, [ -- amb25101.example.com, 172.10.116.149 -- amb25102.example.com, 172.10.116.148 -- amb25103.example.com, 172.10.116.151 -- amb25104.example.com, 172.10.116.150
.
Created 08-28-2017 05:31 AM
You can try something like following:
# curl -sH "X-Requested-By: ambari" -u admin:admin -i http://localhost:8080/api/v1/hosts?fields=Hosts/host_name,Hosts/ip | grep -A 1 host_name | sed s'/"//g' | awk '{print $NF}'
.
Example Output:
# curl -sH "X-Requested-By: ambari" -u admin:admin -i http://amb25101.example.com:8080/api/v1/hosts?fields=Hosts/host_name,Hosts/ip | grep -A 1 host_name | sed s'/"//g' | awk '{print $NF}' http://amb25101.example.com:8080/api/v1/hosts?fields=Hosts/host_name,Hosts/ip, [ -- amb25101.example.com, 172.10.116.149 -- amb25102.example.com, 172.10.116.148 -- amb25103.example.com, 172.10.116.151 -- amb25104.example.com, 172.10.116.150
.
Created 08-28-2017 05:41 AM
is it possible to print as the following order
amb25101.example.com 172.10.116.149
amb25102.example.com 172.10.116.15
Created 08-28-2017 06:08 AM
Please try something like following:
# curl -sH "X-Requested-By: ambari" -u admin:admin -i http://localhost:8080/api/v1/hosts?fields=Hosts/host_name,Hosts/ip | grep -A 1 host_name | awk '{print $NF}' > /tmp/hosts_details.txt; sed -e '1,2d' -e s'/--//g' -e 's/\n//g' -e 's/"//g' -e '/^$/d' /tmp/hosts_details.txt | awk 'NR%2{printf "%s ",$0;next;}1
.
Example Output:
# curl -sH "X-Requested-By: ambari" -u admin:admin -i http://amb25101.example.com:8080/api/v1/hosts?fields=Hosts/host_name,Hosts/ip | grep -A 1 host_name | awk '{print $NF}' > /tmp/hosts_details.txt; sed -e '1,2d' -e s'/--//g' -e 's/\n//g' -e 's/"//g' -e '/^$/d' /tmp/hosts_details.txt | awk 'NR%2{printf "%s ",$0;next;}1' amb25101.example.com 172.10.116.149 amb25102.example.com 172.10.116.148 amb25103.example.com 172.10.116.151 amb25104.example.com 172.10.116.150