Getting Dynamic Inventory for Sensu go from google cloud

68 Views Asked by At

I need suggestion to provide the host IP and port to sensu-go at runtime. Currently, we are using static inventory for our VMs which are created in google cloud which causes issues when those instances get deleted and new gets created. So, I'm looking for a solution to provide the dynamic inventory to sensu-go. However, I could not find a way to query the google cloud in sensu-go and get the host IP(s) by providing tag and project name.

I'm looking for a suggestion to get the host IPs for a given tag from google cloud without using sensu-go client in each host.

Thanks very much in advance.

1

There are 1 best solutions below

0
Sergiusz On

To get a list of IP's used by instances tagged with, say, 'sensu' you can use gcloud commands.
To get internal IP:

gcloud compute instances list --project=PROJECT_NAME --filter="tags.items=(SENSU)" --format="get(networkInterfaces[0].networkIP)"

For external IP:

gcloud compute instances list --project=PROJECT_NAME --filter="tags.items=(SENSU)" --format="get(networkInterfaces[0].accessConfigs[0].natIP)"