Modify endpoint-tags with the use of a script
Changing/Adding endpoint-tags after initial agent installation is possible using scripts and vRx's auto action mechanism. The following article will guide you through the steps to do that.
Important notes
- Changing endpoint-tags configuration will take place only after a vRx service restart
- A command that restarts the service is included in the offered script
-
It is possible to use 2 separate scripts to change the tags - script1 which sets the endpoint tags, and a separate script 2 which restarts the vRx service so that the change will take place. For that simply make a "run script" auto action and add both scripts to it.
- Why 2 scripts? due to the restart service part of the script, the auto action will be executed (endpoint tags modified), However the status will remain “Notice”. If you need further indication that the action succeeded/failed, especially when applying it on a large scale, you are advised to separate the scripts.
-- Unified Agent (ver. 5.x) --
- To view your existing Endpoint Tags, execute toipad in read mode:
OS | Command |
Windows |
"C:\Program Files\Vicarius\Topia\topiad.exe" --config endpoint_tag |
Linux |
/usr/share/vicarius/topiad --config endpoint_tag |
Mac |
/Library/PrivilegedHelperTools/topiad --config endpoint_tag |
- To edit the Endpoint Tags, execute topiad in edit mode:
OS | Command |
Windows |
"C:\Program Files\Vicarius\Topia\topiad.exe" --config endpoint_tag <key:value> |
Linux |
/usr/share/vicarius/topiad --config endpoint_tag <key:value> |
Mac |
/Library/PrivilegedHelperTools/topiad --config endpoint_tag <key:value> |
To delete endpoint tags, pass an empty string as a parameter. For example (WIN):
"C:\Program Files\Vicarius\Topia\topiad.exe" --config endpoint_tag ""
net stop topia && net start topia
-- Legacy Agents (ver. 4.x) --
WINDOWS (PS SCRIPT):
Instructions:
-
Download this PS script
-
Create a “run script” auto action in vRx and add the script to it
Tip: Not sure how to do that? Click Here to learn how to run a PS script using vRx
3. Insert your desired tags as parameters to the command. On this example it is "US:Detroit". (Change it to whatever you need)
powershell -ExecutionPolicy Bypass -file endpointTagModification.ps1 US:Detroit
-
Use space or comma to enter more than one tag:
powershell -ExecutionPolicy Bypass -file endpointTagModification.ps1 US:Detroit Branch: Pistons
OR
powershell -ExecutionPolicy Bypass -file endpointTagModification.ps1 US:Detroit,Branch:Pistons
-
Use '_' to separate values within the same tag:
powershell -ExecutionPolicy Bypass -file endpointTagModification.ps1 US:Detroit_Michigan
4. Run the auto action
LINUX (BASH SCRIPT):
Instructions:
- Create a “run script” auto action in vRx and copy the provided script below to vRx's console
-
Edit the “PARAMS” variable - assign the wanted endpoint-tags value
- “key:value” is the syntax for one endpoint tag
- “key1:value1,key2:value2…” is the syntax for multiple endpoint tags (comma separated)
4. Run the auto action
#!/bin/bash
#Enter Endpoint-tags here:
PARAMS="key:value,key2:value2"
if ! test -f /usr/share/vicarius/args.txt; then
echo "Failed - Topia config file was not found"
exit
else
FILE=/usr/share/vicarius/args.txt
fi
if grep -q EndpointTag= "$FILE"; then
sed -i "s/EndpointTag=.*/EndpointTag=$PARAMS/g" $FILE
echo "Endpoint tags were succcesfully updated. Current tags: $PARAMS"
else
sed -i -e "1s|$| /EndpointTag=$PARAMS|" $FILE
echo "Endpoint tags were succesfully added. Current tags: $PARAMS"
fi
systemctl restart topia
macOS (SH SCRIPT):
Instructions:
- Copy the script to vRx's console
- Edit the “PARAMS” variable - assign the wanted endpoint-tags value
- “key:value” is the syntax for one endpoint tag
- “key1:value1,key2:value2…” is the syntax for multiple endpoint tags (comma separated)
- Remove the "#" from the last line to restart the vRx service. (can be also done separately)
-
#/bin/sh
PARAMS="key:value,key1:value2"
restartTopia(){
scriptPlist="/Library/LaunchDaemons/local.topia-restart.plist"
shellscript="/Library/Scripts/topia-restart.sh"
{
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
echo '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">'
echo "<plist version=\"1.0\">"
echo " <dict>"
echo " <key>Label</key>"
echo " <string>local.topia-restart</string>"
echo " <key>ProgramArguments</key>"
echo " <array>"
echo ' <string>/Library/Scripts/topia-restart.sh</string>'
echo " </array>"
echo " <key>RunAtLoad</key>"
echo " <true/>"
echo " </dict>"
echo "</plist>"
} > ${scriptPlist}
{
echo "#!/bin/sh"
echo "launchctl unload -w /Library/LaunchDaemons/io.vicarius.Topia.plist"
echo "launchctl load -w /Library/LaunchDaemons/io.vicarius.Topia.plist"
} > ${shellscript}
sudo chmod +x /Library/Scripts/topia-restart.sh
launchctl load -w /Library/LaunchDaemons/local.topia-restart.plist
sleep 10
launchctl unload /Library/LaunchDaemons/local.topia-restart.plist
}
if [[ ! -f /Library/Preferences/Topia/io.vicarius.Topia.plist ]]; then
echo "Failed - Topia config file was not found"
exit
else
FILE=/Library/Preferences/Topia/io.vicarius.Topia.plist
fi
currentTags=$(defaults read $FILE endpoint_tag)
if [[ ! -z "$currentTags" ]]; then
#updateTags="${currentTags},${PARAMS}" # Comment this line and use the next to replace instead of adding tags
updateTags="${PARAMS}"
defaults write $FILE endpoint_tag "$updateTags" # Must use double quotes around $updateTags if there are spaces in them
echo "Endpoint tags were successfully updated. Current tags: $updateTags"
else
defaults write $FILE endpoint_tag $PARAMS
echo "Endpoint tags were successfully added. Current tags: $PARAMS"
fi
#restartTopia
- Edit the “PARAMS” variable - assign the wanted endpoint-tags value