Skip to content

Instantly share code, notes, and snippets.

@nook24
Last active April 21, 2021 17:16
Show Gist options
  • Save nook24/0e5f870f6492d6a8cbb69982654aa934 to your computer and use it in GitHub Desktop.
Save nook24/0e5f870f6492d6a8cbb69982654aa934 to your computer and use it in GitHub Desktop.
#!/bin/bash
############
#
# This script is nothing special!
# It is just copy&paste of the documentation !!
#
# Usage:
# chmod +x statusengine_development_setup.sh
# ./statusengine_development_setup.sh
#
# Run this script as root - no sudo
#
# Statusengine Test Build - Please always use the official documentation to install Statusengine for production!
# https://statusengine.org/
#
# Created: Mon Apr 19 21:22:17 CEST 2021
#
# This script is Build for Ubuntu Focal 20.04 and installes Nagios + Statusengien Broker + Statusengine Worker + Statusengien UI + MySQL
# It's recommended to go with Naemon instead of Nagios
#
# Users:
# Statusengien UI: admin:admin
# MySQL: statusengine:password
#
# License: MIT
############
set -e
set -x
# Update System
export DEBIAN_FRONTEND=noninteractive
apt-get update
#apt-get dist-upgrade -y
# Setup Nagios
# Docs: https://statusengine.org/tutorials/install-nagios4-focal/
addgroup --system nagios
adduser --system nagios
adduser nagios nagios
apt-get update
apt-get install -y build-essential libgd-dev libpng-dev unzip gearman-job-server monitoring-plugins gearman-tools
cd /tmp/
wget https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.6.tar.gz
tar xfv nagios-4.4.6.tar.gz
cd nagioscore-nagios-4.4.6/
./configure --prefix=/opt/nagios --with-nagios-user=nagios --with-nagios-group=nagios
mkdir /opt/nagios
make all
make install
make install-commandmode
make install-config
make install install-devel
cat > /lib/systemd/system/nagios.service <<EOF
[Unit]
Description=Nagios Core
Documentation=https://www.nagios.org/documentation
After=network.target local-fs.target
[Service]
Type=forking
ExecStartPre=/opt/nagios/bin/nagios -v /opt/nagios/etc/nagios.cfg
ExecStart=/opt/nagios/bin/nagios -d /opt/nagios/etc/nagios.cfg
ExecStop=/bin/kill -s TERM \${MAINPID}
ExecStopPost=/bin/rm -f /opt/nagios/var/rw/nagios.cmd
ExecReload=/bin/kill -s HUP \${MAINPID}
[Install]
WantedBy=multi-user.target
EOF
echo '$USER1$=/usr/lib/nagios/plugins' > /opt/nagios/etc/resource.cfg
# Setup Statusengine Broker
# Docs: https://statusengine.org/broker/
apt-get install -y git python3-pip gcc g++ cmake build-essential libglib2.0-dev libgearman-dev uuid-dev libuchardet-dev libjson-c-dev pkg-config libssl-dev librabbitmq-dev gearman-job-server curl
pip3 install meson ninja
cd /tmp
git clone https://github.com/statusengine/broker.git broker
cd broker/
meson setup -Dnagios=true -Dnagios_include_dir=/opt/nagios/include build
ninja -C build
mkdir -p /opt/statusengine/lib
cp build/src/libstatusengine.so /opt/statusengine/lib/libstatusengine.so
mkdir -p /opt/statusengine/etc
curl https://raw.githubusercontent.com/statusengine/broker/master/statusengine.toml > /opt/statusengine/etc/statusengine.toml
echo "broker_module=/opt/statusengine/lib/libstatusengine.so /opt/statusengine/etc/statusengine.toml" >> /opt/nagios/etc/nagios.cfg
# Setup Statusengine Worker
# Docs: https://statusengine.org/worker/
apt-get install -y git php-cli php-zip php-redis redis-server php-mysql php-json php-bcmath php-mbstring unzip php-cli curl wget mysql-server
# Install php composer
cd /tmp
curl -o composer-setup.php https://getcomposer.org/installer
php composer-setup.php
cp composer.phar /usr/local/bin/composer
export COMPOSER_ALLOW_SUPERUSER=1
# install php-gearman on Ubuntu Focal
wget https://statusengine.org/uploads/php7.4-gearman_2.1.0+1.1.2-5+ubuntu20.04.1+deb.sury.org+1_amd64.deb
dpkg -i php7.4-gearman_2.1.0+1.1.2-5+ubuntu20.04.1+deb.sury.org+1_amd64.deb
apt-get install -f -y
# Continue with Statusengine Worker
mkdir -p /opt/statusengine
cd /opt/statusengine
git clone https://github.com/statusengine/worker.git worker
cd /opt/statusengine/worker
chmod +x bin/*
composer install
DEBIANCNF=/etc/mysql/debian.cnf
mysql --defaults-extra-file=${DEBIANCNF} -e "CREATE USER 'statusengine'@'localhost' IDENTIFIED BY 'password';"
mysql --defaults-extra-file=${DEBIANCNF} -e "CREATE DATABASE IF NOT EXISTS statusengine DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;"
mysql --defaults-extra-file=${DEBIANCNF} -e "GRANT ALL PRIVILEGES ON statusengine.* TO 'statusengine'@'localhost';"
cp /opt/statusengine/worker/etc/config.yml.example /opt/statusengine/worker/etc/config.yml
# Fix config
sed -i 's/use_mysql: 0/use_mysql: 1/g' /opt/statusengine/worker/etc/config.yml
sed -i 's/use_crate: 1/use_crate: 0/g' /opt/statusengine/worker/etc/config.yml
sed -i 's/process_perfdata: 0/process_perfdata: 1/g' /opt/statusengine/worker/etc/config.yml
sed -i 's/ - crate/ - mysql/g' /opt/statusengine/worker/etc/config.yml
/opt/statusengine/worker/bin/Console.php database --update
cp /opt/statusengine/worker/lib/statusengine.service /lib/systemd/system/statusengine.service
echo "0 1 * * * /opt/statusengine/worker/bin/Console.php cleanup -q" > /etc/cron.d/statusengine
# Setup Statusengine Ui
# Docs: https://statusengine.org/ui/
apt-get install -y git php-cli php-zip php-mysql php-ldap php-json
cd /usr/share/
git clone https://github.com/statusengine/interface.git statusengine-ui
cd /usr/share/statusengine-ui
chmod +x bin/*
composer install
cp /usr/share/statusengine-ui/etc/config.yml.example /usr/share/statusengine-ui/etc/config.yml
sed -i 's/use_crate: 1/use_crate: 0/g' /usr/share/statusengine-ui/etc/config.yml
sed -i 's/use_mysql: 0/use_mysql: 1/g' /usr/share/statusengine-ui/etc/config.yml
sed -i 's/display_perfdata: 0/display_perfdata: 1/g' /usr/share/statusengine-ui/etc/config.yml
sed -i 's/perfdata_backend: crate/perfdata_backend: mysql/g' /usr/share/statusengine-ui/etc/config.yml
/usr/share/statusengine-ui/bin/Console.php users add --username "admin" --password "admin"
apt-get install -y ssl-cert apache2 libapache2-mod-php
cat > /etc/apache2/sites-available/statusengine-ui.conf <<EOF
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/\$1 [R,L]
DocumentRoot "/usr/share/statusengine-ui/public/"
RedirectMatch 404 /\.git
ErrorLog "/var/log/apache2/statusengine-ui-error.log"
CustomLog "/var/log/apache2/statusengine-ui-access.log" combined
</VirtualHost>
<VirtualHost *:443>
RedirectMatch 404 /\.git
DocumentRoot "/usr/share/statusengine-ui/public/"
SSLEngine On
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
ErrorLog "/var/log/apache2/statusengine-ui-error.log"
CustomLog "/var/log/apache2/statusengine-ui-access.log" combined
</VirtualHost>
EOF
a2ensite statusengine-ui
a2enmod rewrite
a2enmod ssl
rm -f /etc/apache2/sites-enabled/000-default.conf
systemctl daemon-reload
systemctl enable statusengine nagios
systemctl restart statusengine nagios apache2
set +x
echo ""
echo ""
echo "All done - Have a nice day"
echo ""
echo ""
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment