#!/bin/bash
echo "Preparando o ambiente"
sudo apt update
sudo apt upgrade
sudo apt install autoconf gcc libc6 make wget unzip apache2 php libgd-dev
sudo apt install libmcrypt-dev libssl-dev bc gawk dc build-essential libnet-snmp-perl gettext
echo "Baixando o Nagios"
cd /usr/src/
sudo wget https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.3.tar.gz
sudo tar zxf nagios-*.tar.gz
cd nagioscore-nagios-*/
echo "Preparando o Apache"
sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled
sudo make all
sudo make install-groups-users
sudo usermod -a -G nagios www-data
echo "Compilando dependências"
sudo make install
sudo make install-commandmode
sudo make install-config
sudo make install-webconf
echo "Configurando o Apache"
sudo a2enmod rewrite
sudo a2enmod cgi
sudo make install-daemoninit
echo "Criando o usuário Nagios"
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
sudo systemctl restart apache2
sudo ufw allow Apache
echo "Baixando Plugins"
cd /usr/src/ sudo wget -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/archive/release-2.2.1.tar.gz
sudo tar zxf nagios-plugins.tar.gz
cd nagios-plugins-release-2.2.1
sudo ./tools/setup
sudo ./configure
echo "Compilando o Nagios"
sudo make
sudo make install
sudo systemctl start nagios
sudo systemctl status nagios
echo "http(s)://host/nagios"