Last active
April 12, 2019 13:24
-
-
Save neilellis/5958314 to your computer and use it in GitHub Desktop.
Automated install for icinga on Centos 6.4 with ichinga-web, nagios-api and nagdash - please check the script before running hey :-)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Copyright 2013 Neil Ellis | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
#Please read this script thoroughly before using it, then comment out the next two lines :-) | |
echo "Centos 6.4 install script for Icinga, Icinga Web, PNP4Nagios, Nagios API and Nagdash, please read this script before you run it :-)" | |
exit -1 | |
echo "You need to make sure SELinux is permissive (see /etc/selinux/config), temporarily disabling for this script just incase." | |
setenforce 0 | |
echo "Updating system" | |
#Comment out this if you like, but I prefer to be working against the latest version as it is an easy state to replicate. | |
yum update -y | |
echo "Installing Icinga" | |
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm | |
rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm | |
yum install -y icinga icinga-gui icinga-doc icinga-idoutils-libdbi-mysql | |
yum install -y mysql-server mysql-client libdbi libdbi-devel libdbi-drivers libdbi-dbd-mysql | |
yum install -y nagios-plugins nagios-plugins-all | |
echo "Setting up MySQL Database" | |
service mysqld start | |
chkconfig mysqld on | |
mysql <<EOF | |
CREATE DATABASE icinga; | |
GRANT USAGE ON icinga.* 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, DROP, CREATE VIEW, INDEX, EXECUTE ON icinga.* TO 'icinga'@'localhost'; | |
FLUSH PRIVILEGES; | |
CREATE DATABASE icinga_web; | |
GRANT USAGE ON *.* TO 'icinga_web'@'localhost' IDENTIFIED BY 'icinga_web' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0; | |
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, INDEX ON icinga_web.* TO 'icinga_web'@'localhost'; | |
EOF | |
mysql icinga < /usr/share/doc/icinga-idoutils-libdbi-mysql-*/db/mysql/mysql.sql | |
echo "Installing PNP4NAGIOS - required by icinga-web" | |
yum -y install php-gd gcc libdbi ruby xorg-x11-fonts-Type1 perl-Time-HiRes | |
rpm -ivh http://pkgs.repoforge.org/rrdtool/rrdtool-1.4.7-1.el6.rfx.x86_64.rpm http://pkgs.repoforge.org/rrdtool/perl-rrdtool-1.4.7-1.el6.rfx.x86_64.rpm | |
wget http://sourceforge.net/projects/pnp4nagios/files/latest/download | |
tar xzf pnp4nagios*.tar.gz | |
cd pnp4nagios* | |
useradd nagios | |
./configure | |
make all | |
make install-webconf | |
make install-config | |
make install-init | |
make fullinstall | |
cd - | |
echo "Installing PHP dependencies" | |
yum install -y php php-cli php-pear php-xmlrpc php-xsl php-pdo php-soap php-gd php-ldap php-mysql | |
#yum install -y icinga-web icinga-web-module-pnp | |
echo "Installing Icinga Web" | |
wget http://sourceforge.net/projects/icinga/files/icinga-web/1.9.0/icinga-web-1.9.0.tar.gz/download | |
tar xzvf icinga-web-1.9.0.tar.gz | |
cd icinga-web-1.9.0 | |
./configure --prefix=/usr/local/icinga-web --with-web-user=apache --with-web-group=apache --with-web-path=/icinga-web --with-web-apache-path=/etc/httpd/conf.d --with-db-type=mysql --with-db-host=localhost --with-db-port=3306 --with-db-name=icinga_web --with-db-user=icinga_web --with-db-pass=icinga_web --with-conf-dir=/etc/icinga-web/conf.d --with-log-folder=log --with-api-subtype=mysql | |
make install | |
make install-apache-config | |
make install-done | |
make testdeps | |
make db-initialize | |
cd - | |
echo "Installing Nagios API" | |
wget -O nagios-api.zip https://github.com/xb95/nagios-api/archive/master.zip | |
unzip nagios-api.zip | |
cd nagios-api-master | |
yum -y install python-devel | |
easy_install diesel | |
easy_install greenlet | |
easy_install PyOpenSSL | |
easy_install requests | |
python setup.py install | |
cat > /etc/rc.d/init.d/nagios-api <<'EOF' | |
#!/bin/bash | |
# | |
# /etc/rc.d/init.d/nagios-api | |
# | |
# Starts the Nagios API | |
# (RedHat/CentOS only!) | |
# | |
# chkconfig: 2345 90 10 | |
# description: Nagios API Daemon | |
# processname: nagios-api | |
source /etc/rc.d/init.d/functions | |
PROG="nagios-api" | |
DESC="Nagios API Daemon" | |
RETVAL=0 | |
LOGFILE="/var/log/icinga/nagios-api.log" | |
NAG_API_BIN=/usr/local/bin/nagios-api | |
NAG_API_PORT=6315 | |
NAG_API_PID=/var/run/$PROG.pid | |
NAGIOS_STATUS_FILE=/var/spool/icinga/status.dat | |
NAGIOS_COMMAND_FILE=/var/spool/icinga/cmd/icinga.cmd | |
NAGIOS_LOG_FILE=/var/log/icinga/icinga.log | |
start() { | |
echo -n "Starting $DESC ($PROG): " | |
daemon $NAG_API_BIN -p $NAG_API_PORT -s $NAGIOS_STATUS_FILE -c $NAGIOS_COMMAND_FILE -l $NAGIOS_LOG_FILE > $LOGFILE 2>&1 & | |
echo | |
RETVAL=$? | |
return $RETVAL | |
} | |
stop() { | |
echo -n "Shutting down $DESC ($PROG): " | |
killproc $PROG | |
echo | |
RETVAL=$? | |
return $RETVAL | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
start | |
RETVAL=$? | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|restart}" | |
RETVAL=1 | |
esac | |
exit $RETVAL | |
EOF | |
chmod 755 /etc/rc.d/init.d/nagios-api | |
chkconfig nagios-api on | |
service nagios-api start | |
cd - | |
echo "Installing nagdash" | |
wget -O nagdash.zip https://github.com/lozzd/Nagdash/archive/master.zip | |
unzip nagdash | |
mv Nagdash-master /var/www/html/nagdash | |
cat > /var/www/html/nagdash/config.php <<'EOF' | |
<?php | |
// Config | |
// Your Nagios hosts | |
$nagios_hosts = array( | |
array("hostname" => "localhost", "port" => "6315", "protocol" => "http", "tag" => "DC1", "tagcolour" => "#336699"), | |
// and so on... | |
// array("hostname" => "example.company.com", "port" => "6315", "protocol" => "http", "tag" => "HOST", "tagcolour" => "#FFA500"), | |
); | |
// Globally filter out hosts using a regex, if you wish, or leave blank for all. | |
$filter = ""; | |
// Default downtime duration, measured in seconds, for scheduling downtime via the Nagdash interface. | |
$duration = 60*60; | |
// End Config | |
EOF | |
cd - | |
echo "Installing check_nrpe plugin, you'll need to do a 'yum install nrpe' on the remote machines still." | |
yum -y install nagios-plugins-nrpe | |
echo "Starting Services" | |
service icinga start | |
chkconfig icinga on | |
chkconfig httpd on | |
service httpd restart | |
echo "Please check http://localhost/ichinga http://localhost/ichinga-web and http://localhost/nagdash all services should be running." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great manual/script, thanks! Minor editions:
mysql-client got replaced by mysql
Before you install rrdtool packages you need pre-requisites:
yum -y install perl-String-CRC32 perl-Crypt-Rijndael gettext
pnp4nagios can be installed from rpm, no need to compile:
rpm -hiv perl-Gearman-1.11-2.3.noarch.rpm pnp4nagios-0.6.13-17.3.x86_64.rpm
yum install -y icinga-web icinga-web-module-pnp