Sanitize / Obfuscate Networker Logs (like daemon.raw)
There was a need to sanitize/obfuscate the names and information my company used in the logs generated by EMC Legato Networker (i.e. daemon.raw). As Preston points out, nsr_render_log -z does not work properly. It occurred to me that this could be scripted fairly easily by querying nsradmin. Here is a stripped version of our script I developed. Be sure to run this as an executable BASH script with privileges to pull from nsradmin.
#!/bin/bash
#Fill in these variables
SERVER=”"
LOGFILE=”"
OUTPUTFILE=”"begin()
{
#Make a backup of LOGFILE … this is file we are using!
cp $LOGFILE $OUTPUTFILE
#Make new legend file, clear out old
KEYFILE=”${OUTPUTFILE}.key”
touch $KEYFILE
echo “Key for file ${OUTPUTFILE} generated on ${DATE}” > $KEYFILE
echo “” >> $KEYFILE
#Send to Sanitize Function
sanitize server
sanitize client
sanitize savesets
sanitize group
sanitize pool
sanitize jukebox
echo “Congratulations! Your log was successfully sanitized!”
echo “You can find your sanitized log residing at: ”
echo $OUTPUTFILE
echo “You can also reference the sanitizing key at: ”
echo $KEYFILE
exit
}sanitize()
{
#Setup sanitation
#Changes array breakpoint to new line! VERY IMPORTANT!
IFS=$’\n’
#We have to specify how to handle the server…
if [ "$1" == "server" ]; then
LIST=`printf “show name\nprint type:nsr \n” | nsradmin -s ${SERVER} -i – | grep “name:” | sed -e “s/name://g” -e ’s/;//g’ | uniq | sort`
LIST[0]=”${LIST}”
LIST[1]=”${SERVER}”
UNAME=`echo $1 | tr ‘[:lower:]‘ ‘[:upper:]‘`
#…and specify how to do savesets…
elif [ "$1" == "savesets" ]; then
LIST=(`printf “show save set\nprint type:nsr client\n” | nsradmin -s ${SERVER} -i – | grep “save set:” | sed -e “s/save set://g” -e ’s/;//g’ | uniq | sort | sed -e “s/, /\n/g” -e “s:\/\n::g” -e “s:\/:\\\\\/:g” -e ’s/”//g’ | uniq | sort -nr | cut -f2-`)
UNAME=”SAVESET”
#..everything else can be pulled using default settings
else
#Sort by length in order to remove longest strings first
LIST=(`printf “show name\nprint type:nsr ${1}\n” | nsradmin -s ${SERVER} -i – | grep “name:” | sed -e “s/name://g” -e ’s/;//g’ | uniq | sort | awk ‘{print length”\t”$0}’ | uniq | sort -nr | cut -f2-`)
UNAME=`echo $1 | tr ‘[:lower:]‘ ‘[:upper:]‘`
fi
#Process sanitation
echo “*** BEGIN ${1} ***” >> $KEYFILE
j=0
for L in “${LIST[@]}”; do
#TRIM WHITESPACE ON EITHER SIDE
L=`expr “$L” : ‘[[:space:]]*\(.*\)[[:space:]]*$’`
#Find out how many occurrences going to replace
G=`grep ${L} $LOGFILE | wc -l`
#Do the sanitization
sed -i “s/${L}/${UNAME}${j}/g” $OUTPUTFILE
#Map out the key/legend
echo -e “${UNAME}${j} = ${L} = ${G} Occurances” >> $KEYFILE
j=$((j + 1))
done
echo “*** END ${1} ***” >> $KEYFILE
echo “” >> $KEYFILE
}begin
