Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AMANDA logs to Confluence
#!/bin/bash
# Daily Backup Confluence Bridge
# jesse pearson
#
# Purpose:
# Used to send the Amanda backup logs into a Confluence page and
# attach a PDF output summary to the given page.
#
# Dependencies:
# cadaver
#
# Caveats:
# - Hardcoded page name; this can be changed via a variable, but there is no logic to
# determine if the page name has changed.
#
# - Scheduled to run under amandabackup user's crontab.
#
# - Uses cadaver, a webDAV interface, to upload.
#
# - Output .txt file must be the same name as Confluence page (set by cPage).
# Changelog:
# 12.21.2007 | jp | Added trimming of excess strange/failure details to keep filesize low.
# 12.03.2007 | jp | Fixed issue with duplicate PDFs being sent to Confluence
# 11.30.2007 | jp | created basic functionality
# Pre-run cleanup
rm -rdf /tmp/amrun/*
date=`date +%Y%m%d`
logdir=`/usr/sbin/amgetconf DailySet1 logdir`
log=`ls -1t $logdir/log.*.[0-9] | head -1`
# Human readable versions of the Confluence page name and path.
# The hPath should have a trailing slash.
hPage='Amanda Backup Logs - Daily'
hPath="http://{server_name}:8080/confluence/plugins/servlet/webdav/Global/IS/Network Administration/Amanda Backup Monitoring/"
# Converted to "web" friendly URLs
cPage=`echo $hPage | sed s/' '/"%20"/g`
cPath=`echo $hPath | sed s/' '/"%20"/g`
cURL=$cPath$cPage/
# Logging
echo "Backup log for date: $date"
echo ""
echo "Basic setup variables:"
echo "Human readable page name: $hPage"
echo "Human readable path: $hPath"
echo "'Web' friendly page name: $cPage"
echo "'Web' friendly path: $cPath"
echo "'Web' friendly URL: $cURL"
echo "Latest log file: $log"
echo ""
echo "Output from various commands:"
# Run the report and convert it to PDF.
cd /etc/amanda/DailySet1/
`/usr/sbin/amreport DailySet1 -i -l $log -f "/tmp/amrun/tmp.txt" -p /tmp/amrun/Daily.ps`
`/usr/bin/ps2pdf /tmp/amrun/Daily.ps /tmp/amrun/Daily.$date.pdf`
# Trim excess failure/strange details.
declare -a tst="`cat /tmp/amrun/tmp.txt | tr '\\n' '|'`"
declare -a tst2="`cat /tmp/amrun/tmp.txt | tr '\\n' '|'`"
rm /tmp/amrun/tmp.txt
c=1
# Iterate through each line
for sID in ${tst[@]}
do
# Cut a line per.
SN=`echo "${tst[0]}" | cut -f$c -d "|"`
# Search for the beginning of our trim.
GC=`echo "${SN}" | grep -c "FAILED AND STRANGE DUMP DETAILS:"`
# Search for the end of the file.
bGC=`echo "${SN}" | grep -c "(brought to you by Amanda"`
# We found the beginning of our trim, start trimming.
if [ $((GC)) -eq 1 ]; then
# Loop through until we find the end of our trim, and count each time to get the
# position.
for tSID in ${tst2[@]}
do
# Cut a line per.
tSN=`echo "${tst2[0]}" | cut -f$c -d "|"`
# Search for the end of our trim.
tGC=`echo "${tSN}" | grep -c "DUMP SUMMARY:"`
# Found it, let's break out of our loop.
if [ $((tGC)) -eq 1 ]; then
break
fi
c=$((c+1))
done
else
# Found the end of the file, stop looping.
if [ $((bGC)) -eq 1 ]; then
break
else
# Place the contents into the file.
echo "${SN}" >> /tmp/amrun/tmp.txt
c=$((c+1))
fi
fi
done
# Build the confluence page.
cp /etc/amanda/DailySet1/template-*.txt /tmp/amrun/
cat /tmp/amrun/tmp.txt >> /tmp/amrun/template-header.txt
cat /tmp/amrun/template-footer.txt >> /tmp/amrun/template-header.txt
mv /tmp/amrun/template-header.txt "/tmp/amrun/$hPage.txt"
rm /tmp/amrun/template* /tmp/amrun/Daily.ps /tmp/amrun/tmp.txt
# Upload via webDAV
cd /tmp/amrun/
echo "mput *" | /usr/bin/cadaver $cURL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment