28 Oct 2024 10:08 PM
Hi there.
I want to Extract the Flexera AgentUniqueID from the config.ini file of all the Hosts in my env and assign it to the Host in DT as a Tag. I can easily get the ID from ssh in Linux:
---------------------------
sudo grep -r "AgentUniqueID" /var/opt/managesoft/etc/config.ini
The result is:
---------------------------
[ManageSoft\AgentUniqueID]
AgentUniqueID=a96abfc1ababc16bb7190ffaf965336ca7df1814dcf2c24ac3
---------------------------
Is there an easier way to do this via another mechanism?
28 Oct 2024 10:53 PM - edited 28 Oct 2024 10:55 PM
you can use the following bash script as it automate extraction to a variable then use oneagentctl to reset assigned property or tag by removing it if exists then set the new value (you can change the oneagentctl to set property not tags according to your needs).
this on each host individually or within batch for your cluster
#!/bin/bash
# Get the AgentUniqueID from the config file
agent_unique_id=$(sudo grep -Po '(?<=AgentUniqueID=).*' /var/opt/managesoft/etc/config.ini)
# Check if the AgentUniqueID was found
if [[ -z "$agent_unique_id" ]]; then
echo "AgentUniqueID not found in config file."
exit 1
fi
# Remove the existing AgentUniqueID property
./oneagentctl --remove-host-tag=AgentUniqueID
# Set the new AgentUniqueID property
./oneagentctl --set-host-tag=AgentUniqueID="$agent_unique_id"
echo "AgentUniqueID updated successfully."
references:
https://docs.dynatrace.com/docs/shortlink/oneagentctl#custom-host-metadata
https://docs.dynatrace.com/docs/shortlink/tagging-hostautotag
hope this helpful for you.
BR,
Mostafa Hussein.