Skip to content

Commit

Permalink
Prevent this from hanging infinitely when the metadata api isnt present
Browse files Browse the repository at this point in the history
  • Loading branch information
apdibbo committed Oct 3, 2024
1 parent 74acad9 commit df53f71
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions os_builders/roles/vm_baseline/files/wazuh/enrich-wazuh-agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,20 @@ def dict_to_xml(tag, d):
agent_hostname = socket.getfqdn()

# Check if the host is an OpenStack VM
try:
metadata_url = "http://169.254.169.254/openstack/latest/meta_data.json"
response = requests.get(metadata_url)
openstack_metadata = response.json()
metadata_to_parse = ["uuid", "name", "hostname", "project_id"]
for vm_attr in metadata_to_parse:
labels_conf["openstack." + vm_attr] = openstack_metadata[vm_attr]
agent_hostname = agent_hostname + "-" + openstack_metadata["uuid"]
except:
print("not an openstack VM")
param = '-w 1 -c 1'
metadata_ip = "169.254.169.254"
response = os.system(f"ping {param} {metadata_ip}")
if response == 0:
try:
metadata_url = "http://169.254.169.254/openstack/latest/meta_data.json"
response = requests.get(metadata_url)
openstack_metadata = response.json()
metadata_to_parse = ["uuid", "name", "hostname", "project_id"]
for vm_attr in metadata_to_parse:
labels_conf["openstack." + vm_attr] = openstack_metadata[vm_attr]
agent_hostname = agent_hostname + "-" + openstack_metadata["uuid"]
except:
print("not an openstack VM")


if os.path.exists("/etc/ccm.conf"):
Expand Down

0 comments on commit df53f71

Please sign in to comment.