This tool will convert a design exported from a supported beta version of Management Pack Builder so to a file usable with the GA 1.0.0 release.
Export your design files from the beta version using the built-in export feature. Do not modify these exported designs in any way (including changing the spacing/reformatting the file, etc).
If you are a Linux or Mac user, use the bash script like so:
./mpb_upgrade.sh path/to/your/exported_design.json
This will likely be in your downloads directory.
The script will create a new file with the suffix _updated added to it and will be placed in the same directory as the original file.
For example, if I want to update my Rubrik design which I have exported from a previous version, I can run:
./mpb_upgrade.sh ~/Downloads/Rubrik\ For\ Upgrade_1_0_0_0_export.json
And this will save a new file ~/Downloads/Rubrik\ For\ Upgrade_1_0_0_0_export_updated.json that can be imported to the GA 1.0.0 release of the Management Pack Builder.
If you are a Windows user, use the powershell script like so:
.\mpb_upgrade.ps1 C:\path\to\your\exported_design.json
This will look something like:
.\mpb_upgrade.ps1 'C:\Users\Administrator\Downloads\Rubrik For Upgrade_1_0_0_0_export.json'
Like the Bash script, it will save the file in the same directory as the original was located in with _updated appended to the file name.
Shell script. Save the following to mpb_upgrade.sh
#!/bin/bash
# Define variables
filename="$1"
if [[ $filename != *\.json ]] # * is used for pattern matching
then
echo "File $filename must end with .json";
exit
fi
if test -f "$filename"; then
echo "File found. Converting for use with GA 1.0.0"
else
echo "File $filename does not exist."
exit
fi
# We're modifying the file directly rather than reading it as json so that the user doesn't have to
# install jq if they don't already have it. Since MPB exports the files in a specific format,
# we can find the lines we need to change without reading it as json.
# whether or not we found the version string
foundVersion=false
# the line that should exist if we have the version
versionLine=" \"version\": 1,"
# Mapping of severity label changes (0.4.0 and 0.4.1)
# Old lines that must be replaced if they exist because they reference old severity labels
debugSeverityLine=" \"vropsSeverity\": \"Debug\""
ignoreSeverityLine=" \"vropsSeverity\": \"Ignore\""
defaultDebugSeverityLine=" \"default\": \"Debug\""
defaultIgnoreSeverityLine=" \"default\": \"Ignore\""
# New lines that must replaced the old labels if they exist
newDebugSeverityLine=" \"vropsSeverity\": \"Log Only\""
newIgnoreSeverityLine=" \"vropsSeverity\": \"Discard\""
newDefaultDebugSeverityLine=" \"default\": \"Log Only\""
newDefaultIgnoreSeverityLine=" \"default\": \"Discard\""
# Script logic begins here
lines=$(cat "$filename")
IFS=''
# This might take a few seconds, but run as background tasks and wait
# for them so that it doesn't take minutes
echo "Reading lines and determining adjustments"
while read LINE; do
{
if [ "$LINE" = "$versionLine" ]; then
foundVersion=true
fi
} &
done <<<"$lines"
wait
# Handle version update when neccasary (all pre-GA versions)
if [ $foundVersion = false ]; then
echo "Adding version"
# insert it after the design id
idStr=" \"id\": null,"
lines=$(echo $lines | sed "s|$idStr|$idStr\n${versionLine}|g")
fi
# Handle chnaged severity labels (0.4.0 and 0.4.1)
echo "Resolving severities if present"
lines=$(echo $lines | sed "s|$debugSeverityLine|$newDebugSeverityLine|g")
lines=$(echo $lines | sed "s|$ignoreSeverityLine|$newIgnoreSeverityLine|g")
lines=$(echo $lines | sed "s|$defaultDebugSeverityLine|$newDefaultDebugSeverityLine|g")
lines=$(echo $lines | sed "s|$defaultIgnoreSeverityLine|$newDefaultIgnoreSeverityLine|g")
# 0.3.0 will not have the events array, however MPB interprets the events array key missing as an empty array
# so we don't have to do anything special for upgrade.
# save the file
strippedName=$(echo "${filename%%.*}")
newName="${strippedName}_updated.json"
echo "Updated file saved to: $newName"
printf "%s\n" "${lines[@]}" > "$newName"