#!/bin/sh workdir=/tmp/anon-nagios anon_cfg_file=anon-nagios-cfg.tar.gz nbin= ncpath= usage() { echo "Usage: $0 " exit 1 } if test "$#" -ne 2; then usage; fi nbin="$1" ncpath="$2" test -d $workdir || mkdir -p $workdir cd $workdir || exit 1 echo "Checking original timing figures and getting config file list" $nbin -v -s $ncpath > vs-output if test $? -ne 0; then echo "The current configuration is invalid, which makes it useless." echo "Thanks for trying though." exit 1 fi echo "Taking stripped nagios settings" egrep -i '^cfg_.*' $ncpath > nagios.cfg echo "Extracting config file list" sed -n "s/^Processing object config file '\([^']*\)'.*/\1/p" vs-output > oconf-files echo "Concatenating and minimizing object config" sed 's/^[\t ]*//' $(cat oconf-files) > objects.cfg echo "Anonymizing..." sed -i \ -e 's/^address[\t ].*/address ANON/' \ -e 's/^email.*/email ANON/' \ -e 's/^pager.*/pager ANON/' \ -e 's/address[1-7].*/address ANON/' \ -e 's/alias.*/alias ANON/' \ -e 's/^\(check_command\).*/\1 check_fooANONYMIZED/' \ -e 's/^\(host_notification_commands\).*/\1 host-notifyANONYMIZED/' \ -e 's/^\(service_notification_commands\).*/\1 service-notifyANONYMIZED/' \ -e 's/^\(command_line\).*/command_line ANONYMIZED/' \ objects.cfg c=$(grep -c ANON objects.cfg) echo "Anonymized $c strings" echo "Compressing..." tar cvzf $anon_cfg_file objects.cfg nagios.cfg vs-output if test $? -ne 0; then echo "Failed to create tarball of anonymized config." exit 1 fi echo "Done :)" size=$(stat $anon_cfg_file | sed -n 2p | awk '{ print $2 }') echo "Successfully created $workdir/$anon_cfg_file" if test $size -gt 10000000; then echo "The file is larger than 10MB, so please attach it to a dropbox" echo "and share your folder with ageric79@gmail.com, or put it on an" echo "ftp somewhere, and send a note to ae@op5.com" echo "detailing how to get it." else echo "Please send the file '$workdir/$anon_cfg_file' to" echo "ae@op5.com" fi echo "Thanks for helping out :)"