#!/bin/bash
# Integrating Nagios Business Process Addon.
#
# Usage:
#    IDK!!?@

# Copyright (c) 2010 Nagios Enterprises, LLC.  All rights reserved.
#
# $Id: NagiosXI-BPA.sh 207 2010-05-11 15:24:44Z egalstad $

export MEID='$Id: NagiosXI-BPA.sh 207 2010-05-11 15:24:44Z egalstad $'

# Check whether we have sufficient privileges
if [ $(( $(id -u) )) -ne 0 ]; then
	echo "This script needs to be run as root/superuser."
	echo "$MEID"
	exit 1
fi

# Install prerequisite packages
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
yum -yq check-update > /dev/null
yum -yq install bzr rpmdevtools perl-CGI "perl(CGI::Simple)" "perl(JSON::XS)" perl-JSON-XS-VersionOneAndTwo.noarch
bzr whoami "$0"
if [ ! -d /etc/.bzr ]; then bzr init /etc; fi
if [ ! -d /usr/local/.bzr ]; then bzr init /usr/local; fi

nbpaversion=0.9.6
wget -c "http://bp-addon.monitoringexchange.org/download/nagios-business-process-addon-${nbpaversion}.tar.gz"
tar -xzvf "nagios-business-process-addon-${nbpaversion}.tar.gz"
cd "nagios-business-process-addon-${nbpaversion}"
./configure --with-nagiosbp-user=nagios --with-nagiosbp-group=nagios
make install
bzr add /etc/httpd/conf.d/nagiosbp.conf && bzr commit -m \
		"Original Apache config file for NagiosBP." \
			/etc/httpd/conf.d/nagiosbp.conf
sed -i 's#/usr/local/nagios/etc/htpasswd.users#/usr/local/nagiosxi/etc/htpasswd.users#g' \
	/etc/httpd/conf.d/nagiosbp.conf
bzr add /etc/httpd/conf.d/nagiosbp.conf && bzr commit -m \
		"Altered by ${MEID}." /etc/httpd/conf.d/nagiosbp.conf
{ 
	cd /usr/local/nagiosbp/etc/
	rename -sample "" *-sample
	bzr add . && bzr commit -m "Original Configuration for NagiosBP." .
	sed -i -e 's/^ndodb_username=nagiosro$/ndodb_username=ndoutils/' \
		-e 's/^ndodb_password=dummy$/ndodb_password=n@gweb/' \
		ndo.cfg
	bzr add . && bzr commit -m "Altered by ${MEID}." .
}

apachectl graceful

cd # get out of wherever we were

echo ""
echo "=============================================="
echo "Nagios Business Process Installation Complete!"
echo "=============================================="

exit 0
