Estic provant un soft per monitorar xarxes que pinta molt i molt bé, demoment us passo un script d’instal.lació per ubuntu….
#!/bin/bash
# Icinga Ubuntu Server Post-install Script
# Ezra Bowden
# blog.kyodium.net
# Sept 5, 2011
# Updated: Jan 04, 2012# Starts with a base server installation, no packages/groups added during OS installation.
# Running this script as root (sudo sh <scriptname>) against a base server install should
# have you up and running without any additional fiddling around. Let me know if you see a better way
# to do this, or any glaring errors.# Tested versions:
# Ubuntu Server: 10.10/11.04/11.10
# Icinga: 1.5.0/1.5.1/1.6.0/1.6.1# VARIABLES
PARAMETERS=”[-d|–debug] [–help] [-v|–version <version>] [–plugin-version <version>] [–enable-ssl] [–email <email address>] [–db-address <database ip address>]”
DEBUG=0
SSL=0
DB_ADDRESS=127.0.0.1 # Default is localhost, change this if database is hosted on a separate machine.
APTCMD=”apt-get install -y”
ICINGA_VER=”1.5.0″
PLUGIN_VER=”1.4.15″# NOTE: If installing ssl then verify the additional ssl packages (under INSTALLING PACKAGES heading).
PACKAGES=”apache2 build-essential libgd2-xpm-dev libjpeg62 libjpeg62-dev libpng12-0 libpng12-dev”# PARAMETER CHECK
while [ $# -gt 0 ]; do # Until you run out of parameters …
case “$1” in
-d|–debug)
# “-d” or “–debug” parameter?
DEBUG=1
APTCMD=`echo “$APTCMD” | sed ‘/.*/ s/[ ]-y//’`
;;
–enable-ssl)
SSL=1
;;
–email)
shift
EMAIL=”$1″
;;
–db-address)
shift
DB_ADDRESS=”$1″
;;
-v|–version)
shift
ICINGA_VER=”$1″
;;
–plugin-version)
shift
PLUGIN_VER=”$1″
;;
*)
echo “\n”
echo “Usage: `basename $0` $PARAMETERS”
echo “\n”
echo “Running this script as root \(sudo sh `basename $0`\) against a base 10.10 server install should”
echo “have you up and running without any additional fiddling around. Let me know if you see a better way”
echo “to do this, or any glaring errors.”
echo “\n”
exit 0
;;
esac
shift # Check next set of parameters.
done# VARIABLES
# Set variables that might be changed by calling parameters
# Tarball download URLs
ICINGA_URL=”https://downloads.sourceforge.net/project/icinga/icinga/$ICINGA_VER/icinga-$ICINGA_VER.tar.gz”
PLUGINS_URL=”https://downloads.sourceforge.net/project/nagiosplug/nagiosplug/$PLUGIN_VER/nagios-plugins-$PLUGIN_VER.tar.gz”# Icinga directory name
ICINGA_DIR=`echo “$ICINGA_URL” | sed ‘s/^\(.*\)\/\(.*\)\(\.tar\.gz\)/\2/’`# VERIFY DOWNLOAD URLS
if [ “$DEBUG” = 1 ]; then read -p “[Press Enter to continue]” null; fi
echo “\n\n”
echo “——— VERIFYING DOWNLOAD URLS ———”verifyURL ()
{
# Verify URLs
wget –spider -S $1if [ $? -ne 0 ]; then
echo “URL verification failed:”
echo “$1”
echo “”
echo “There was a problem verifying the file download URL.”
echo “Please check that the URL above is correct in the script and try again.”
echo “”
echo “Installation Aborted.”
exit
else
echo “URL verification succeeded:”
echo “$1”
fi
echo “\n\n”
}verifyURL $ICINGA_URL
verifyURL $PLUGINS_URLif [ “$DEBUG” = 1 ]; then read -p “[Press Enter to continue]” null; fi
echo “\n\n”
echo “——— INSTALLING PACKAGES ———”# Install ssl if specified.
if [ $SSL = 1 ]; then
PACKAGES=”$PACKAGES openssl libssl-dev”
fi$APTCMD $PACKAGES
if [ “$DEBUG” = 1 ]; then read -p “[Press Enter to continue]” null; fi
echo “\n\n”
echo “——— INSTALLING MYSQL ———”
RELEASE=`lsb_release -rs`
if [ “$RELEASE” \< “11.10” ]; then
# pre 11.10 packages
PACKAGES=”mysql-server mysql-client libdbi0 libdbi0-dev libdbd-mysql”
else
# post 11.10 packages
PACKAGES=”mysql-server mysql-client libdbi1 libdbi-dev libdbd-mysql”
fi
$APTCMD $PACKAGESif [ “$DEBUG” = 1 ]; then read -p “[Press Enter to continue]” null; fi
echo “\n\n”
echo “——— ADDING USER/GROUPS ———”
useradd -m icinga
echo “\a\a”
echo “!!!!!!!!!! The next password prompt is for the system icinga user. !!!!!!!!!!”
echo “\n”
passwd icinga
groupadd icinga-cmd
usermod -a -G icinga-cmd icinga
usermod -a -G icinga-cmd www-dataif [ “$DEBUG” = 1 ]; then read -p “[Press Enter to continue]” null; fi
echo “\n\n”
echo “——— DOWNLOADING ICINGA ———”
cd /usr/src
FILE=`echo “$ICINGA_URL” | sed ‘s/^\(.*\)\/\(.*\)\(\.tar\.gz\)/\2\3/’`
if [ -e $FILE ]; then
echo “Local copy of $FILE exists, Skipping download.”
else
wget “$ICINGA_URL”
fiecho “Extracting $FILE…”
tar -xzvf $FILE
#cd `echo “$FILE” | sed ‘s/^\(.*\)\(\.tar\.gz\)/\1/’`
cd $ICINGA_DIRif [ “$DEBUG” = 1 ]; then read -p “[Press Enter to continue]” null; fi
echo “\n\n”
echo “——— INSTALLING ICINGA ———”CONF=”./configure –with-command-group=icinga-cmd –enable-idoutils”
if [ $SSL = 1 ]; then
CONF=”$CONF –enable-ssl”
fi$CONF
make all
make fullinstall
make install-configif [ “$DEBUG” = 1 ]; then read -p “[Press Enter to continue]” null; fi
echo “\n\n”
echo “——— CONFIGURING ICINGA ———”
#Change email to the address you’d like to receive alerts.while [ -z “$EMAIL” ]; do
echo “\n\n”
echo “\a\a”
read -p “Enter the email address you want to receive icinga alerts: ” EMAIL
donesed -i ‘s/\(.*\)icinga@localhost\(.*;\).*/\1’$EMAIL’\2/’ /usr/local/icinga/etc/objects/contacts.cfg # replace email address with $EMAIL
cd /usr/local/icinga/etc/
mv idomod.cfg-sample idomod.cfg
mv ido2db.cfg-sample ido2db.cfg
mv modules/idoutils.cfg-sample modules/idoutils.cfgif [ $SSL = 1 ]; then
# Make changes to idoutils config files:# idomod.cfg
# use_ssl=1
# output_type=tcpsocket
# output=127.0.0.1 (your database address if not on localhost)sed -i ‘/^use_ssl=0/ s/0/1/’ idomod.cfg # set use_ssl=1
sed -i ‘/output_type=tcpsocket/ s/^#//’ idomod.cfg # uncomment output_type=tcpsocket
sed -i ‘/^output_type=unixsocket/ s//#&/’ idomod.cfg # comment output_type=unixsocket
sed -i ‘/^output=.*ido.sock/ s//#&/’ idomod.cfg # comment output=/usr/local/icinga/var/ido.sock
sed -i ‘/output=127.0.0.1/ s/^#//’ idomod.cfg # uncomment this line
sed -i ‘s/\(^output\=\).*/\1’$DB_ADDRESS’/’ idomod.cfg # replace localhost address with $DB_ADDRESS# ido2db.cfg
# use_ssl=1
# socket_type=tcpsed -i ‘/^use_ssl=0/ s/0/1/’ ido2db.cfg # set use_ssl=1
sed -i ‘/socket_type=tcp/ s/^#//’ ido2db.cfg # uncomment socket_type=tcp
sed -i ‘/^socket_type=unix/ s//#&/’ ido2db.cfg # comment socket_type=unix
sed -i ‘s/\(^db_host\=\).*/\1’$DB_ADDRESS’/’ idomod.cfg # replace localhost address with $DB_ADDRESS
fiif [ “$DEBUG” = 1 ]; then read -p “[Press Enter to continue]” null; fi
echo “\n\n”
echo “——— CONFIGURING MYSQL ———”
# MySQL icinga DB and user. Create idoutils tables.
echo “\a\a”
echo “!!!!!!!!!! The next two password prompts are for the MySQL root password you set previously. !!!!!!!!!!”
echo “\n”
start mysql
mysql -u root -p <<HERE
CREATE DATABASE icinga;
GRANT USAGE ON *.* TO ‘icinga’@’localhost’ IDENTIFIED BY ‘icinga’ WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0;
GRANT SELECT , INSERT , UPDATE , DELETE ON icinga.* TO ‘icinga’@’localhost’;
FLUSH PRIVILEGES;
quit
HERE
#mysql -u root -p icinga < /usr/src/icinga-1.5.0/module/idoutils/db/mysql/mysql.sql
mysql -u root -p icinga < /usr/src/$ICINGA_DIR/module/idoutils/db/mysql/mysql.sqlif [ “$DEBUG” = 1 ]; then read -p “[Press Enter to continue]” null; fi
echo “\n\n”
echo “——— INSTALLING CLASSIC INTERFACE ———”
cd /usr/src/$ICINGA_DIR
make cgis
make install-cgis
make install-html# Install classic web config in apache conf.d directory:
make install-webconf# Create icingaadmin account for logging into the classic web interface.
echo “\a\a”
echo “!!!!!!!!!! The password prompt below is to set the web UI icingaadmin password. !!!!!!!!!!”
echo “\n”
htpasswd -c /usr/local/icinga/etc/htpasswd.users icingaadmin# Restart apache to apply new settings:
sudo service apache2 restartif [ “$DEBUG” = 1 ]; then read -p “[Press Enter to continue]” null; fi
echo “\n\n”
echo “——— INSTALLING NAGIOS PLUGINS ———”
cd /usr/src
FILE=`echo “$PLUGINS_URL” | sed ‘s/^\(.*\)\/\(.*\)\(\.tar\.gz\)/\2\3/’`
if [ -e $FILE ]; then
echo “Local copy of $FILE exists, Skipping download.”
else
wget “$PLUGINS_URL”
fi
echo “Extracting…”
tar -xzvf “$FILE”
cd `echo “$FILE” | sed ‘s/^\(.*\)\(\.tar\.gz\)/\1/’`./configure –prefix=/usr/local/icinga –with-cgiurl=/icinga/cgi-bin –with-htmurl=/icinga –with-nagios-user=icinga –with-nagios-group=icinga
make
make installif [ “$DEBUG” = 1 ]; then read -p “[Press Enter to continue]” null; fi
echo “\n\n”
echo “——— STARTING SERVICES ———”
# Verify config file:
/usr/local/icinga/bin/icinga -v /usr/local/icinga/etc/icinga.cfg
service ido2db start
service icinga startif [ “$DEBUG” = 1 ]; then read -p “[Press Enter to continue]” null; fi
echo “\n\n”
echo “——— CONFIGURING SERVICE STARTUP ———”
update-rc.d ido2db defaults
update-rc.d icinga defaultsecho “\n\n”
echo “——— INSTALLATION COMPLETE ———”
echo “\a\a”
echo “go to http://`ifconfig | grep ‘inet addr:’| grep -v ‘127.0.0.1’ | cut -d: -f2 | awk ‘{ print $1}’`/icinga”
echo “and verify that Icinga is working. Use the login details below.”
echo “login: icingaadmin”
echo “password: <the password you set during installation>”
echo “\n”
read -p “[Press Enter to continue]” null
echo “\n\n”