Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save realtebo/8d6a489932eae341600bc76c4baea94a to your computer and use it in GitHub Desktop.
Save realtebo/8d6a489932eae341600bc76c4baea94a to your computer and use it in GitHub Desktop.
Nagios Core 4.4.6 + Nagios plugins 2.3.3 on Debian 10 with Nginx
# Source of truth
# https://support.nagios.com/kb/article/nagios-core-installing-nagios-core-from-source-96.html#Debian
# About nginx installation
# https://olivertappin.com/command-line-tools/installing-nagios-nginx-php-fpm-nagiosgraph-ubuntu-16-04/
# All steps on debian require root AND `-` to use full env
su -
# Prerequisites
apt-get update
apt-get install -y autoconf gcc make unzip apache2-utils php libgd-dev
# Nagios Core Download
cd /tmp
wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.6.tar.gz
tar xzf nagioscore.tar.gz
rm nagioscore.tar.gz
# Nagios Core Build from source and install
cd /tmp/nagioscore-nagios-4.4.6/
./configure --with-httpd-conf=/etc/apache2/sites-enabled
make all
# On a new server, now it's time to create nagios user
make install-groups-users
usermod -a -G nagios www-data
make install
make install-daemoninit
make install-commandmode
make install-config
make install-webconf
# If using Apache
# a2enmod rewrite
# a2enmod cgi
# Configurare firewall
iptables -I INPUT -p tcp --destination-port 80 -j ACCEPT
apt-get install -y iptables-persistent
# This is needed both with apache2 and with nginx to password protect admin panel
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
# If using Apache 2
# systemctl restart apache2
# Nagios Plugin Prerequisites
apt-get install -y autoconf gcc libc6 libmcrypt-dev make libssl-dev wget bc gawk dc build-essential snmp libnet-snmp-perl gettext
# Nagios Plugin Download
cd /tmp
wget --no-check-certificate -O nagios-plugins.tar.gz https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
tar zxf nagios-plugins.tar.gz
rm nagios-plugins.tar.gz
# Nagios Plugin Installation
cd nagios-plugins-2.3.3
./configure
make
make install
# If you want to use nginx, now
# Now create /etc/nginx/sites-available/nagios.conf
# See attached nagios.conf
# else go on and you have alrighgt apache2
# Enable the site
# ln -s /etc/nginx/sites-available/nagios.conf /etc/nginx/sites-enabled/nagios.conf
# Restart Nginx (it's automatically gracefully)
# systemctl restart nginx
######################################################
# Local configuration for a remote host #
# Execute the following steps on controller machine, #
# not on remote host #
######################################################
# Create directory where to setup info about remote machines
mkdir /usr/local/nagios/etc/servers
# Open /usr/local/nagios/etc/nagios.cfg and uncomment the following line (simply remove the '#')
# #cfg_dir=/usr/local/nagios/etc/servers
#########################################################
# Install check_nrpe on nagios server #
# use nrpe only for old servers when you canno use ncpa #
#########################################################
# prereq
apt-get install -y autoconf automake gcc libc6 libmcrypt-dev make libssl-dev wget
cd /tmp
wget --no-check-certificate -O nrpe.tar.gz https://github.com/NagiosEnterprises/nrpe/archive/nrpe-4.0.3.tar.gz
tar xzf nrpe.tar.gz
rm nrpe.tar.gz
cd nrpe-nrpe-4.0.3/
./configure --enable-command-args
make all
make install
make install-config
#########################################################
# Install check_ncpa on nagios server #
#########################################################
cd /usr/local/nagios/libexec#
wget https://raw.githubusercontent.com/NagiosEnterprises/ncpa/master/client/check_ncpa.py
chmo ugo+x check_ncpa.py
########################################################
# Install SendEmail perl script to send notifications #
# Execute on controller, not on remote hosts #
########################################################
# Install
# - Please be aure to install sendemail (note that 'e')
# and not sendmail !!!!
apt install sendemail
# Open /usr/local/nagios/etc/resource.cfg
# Add following lines (without '#')
#
# from
# $USER5$=from@domain.tld
# smtp user
# $USER7$=smtpuser@smtpdomain.it
# smtp password
# $USER8$=your|Smtp|Password!
# smtp server and port
# $USER9$=smtp.smtpdomain.tld:25
# Edit /usr/local/nagios/etc/objects/commands.cfg
# Replace the following 2 command definition
# Verified the use of sendemail switch and appropriate $USERx$ variabile number
# -s the smtp ($USER9$ in my case)
# -xu the smtp username ($USER7$)
# -xp the smatp password ($USER8$)
# -t the 'to' address (leave $CONTACTEMAIL$ untouched)
# -f the 'from' address ($USER5$)
# -u email title, the subject
# 'notify-host-by-email' command definition
define command {
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/sendemail -s $USER9$ -xu $USER7$ -xp $USER8$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n"
}
# 'notify-service-by-email' command definition
define command {
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/bin/sendemail -s $USER9$ -xu $USER7$ -xp $USER8$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$"
}
# Edit nagios contacts
# /usr/local/nagios/etc/objects/contacts.cfg
# and change the email
email receiver_of_nagios_notifications@domain.tld ; <<***** CHANGE THIS TO EMAIL ADDRESS WHICH MUST RECEIVED NOTIFICATIONS ******
# Always test before apply changes !
cd /usr/local/nagios
bin/nagios -v etc/nagios.cfg
# Restart service
systemctl restart nagios
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment