• Update Server
sudo apt-get update && apt-get upgrade && apt-get dist-upgrade
  • Install necessary packages
sudo apt-get install \
unzip \
wget \
build-essential \
apache2 \
apache2-utils \
php5-gd \
libgd2-xpm-dev \
libapache2-mod-php5 \
postfix \
libssl-dev
  • When postfix asks, set your mail config to match your situation.
  • If you are unsure, Internet Site is probably what you are looking for.
  • Next we will need to set up the user and group that Nagios will operate as.

sudo useradd --system --home /usr/local/nagios -M nagios
sudo groupadd --system nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd www-data
  • Downloading and Unpacking Nagios
  • The current version of nagios-core is 4.1.0rc1 and the current version of the plugins is 2.0.3 Make sure you check to see what the latest is.
cd /tmp
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.1.0rc1.tar.gz
wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
tar -xzvf nagios-4.1.0rc1.tar.gz
tar -xzvf nagios-plugins-2.0.3.tar.gz
  • Building and Installing nagios-core
  • At this point you are ready to build and install the nagios-core package.
  • Make sure you pay attention to the flags on the compile and adjust them if you have customized your system.
cd /tmp/nagios-4.1.0rc1
sudo ./configure \
--with-nagios-group=nagios \
--with-command-group=nagcmd \
--with-mail=/usr/sbin/sendmail \
--with-httpd_conf=/etc/apache2/conf-available
sudo make all
sudo make install
sudo make install-init
sudo make install-config
sudo make install-commandmode
sudo make install-webconf
sudo cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
sudo chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
sudo ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
  • The last command just verifies the config, if there were any issues they would likely show up there.
  • Building and Installing nagios-plugins
  • Nagios is nothing without it’s plugins, probably not a good idea to start it until you get them installed.
  • Again, pay attention to the configure options and change if you need to.
cd /tmp/nagios-plugins-2.0.3
sudo ./configure \
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--enable-perl-modules \
--enable-extra-opts
sudo make
sudo make install
  • Now the plugins are installed and you can run checks using them.
  • Configuring Apache for Nagios
  • There are a couple of little things left to do before you start up Nagios.
  • They involve getting the right modules enabled, setting the password for Nagios and setting up the config.
sudo a2enmod cgi
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
  • Lastly you will need to edit
vi /etc/apache2/sites-enabled/000-default.conf
  • and add the line:
  • just last line before the </VirtualHost> line.
Include conf-available/nagios.conf
  • Finally you just need to restart apache and start nagios.

sudo service apache2 restart sudo service nagios start


############### EMAIL CONF ##############

How to use email id of Gmail for sending nagios email alerts

DO NOT FORGET!!!! setup gmail security setting can be send every device usage.

  • Step 2: Login into Nagios Server and install ssmtp and sendmail

In CentOS and RedHat

yum install ssmtp sendmail

In Debian and Ubuntu

sudo apt-get install ssmtp
sudo apt-get install sendmail
  • Step 3: Now I am stoping the sendmail service as well as disabling from runlevel bootup

In CentOS and Red Hat

/etc/init.d/sendmail stop
chkconfig sendmail off

In Debian and Ubuntu

sudo /etc/init.d/sendmail stop
sudo update-rc.d -f sendmail disable
  • Step 4: Now take the backup of ssmtp.conf file and configure it.
cp -p  /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.orig.`date +%F`
> /etc/ssmtp/ssmtp.conf

(now edit the ssmtp.conf file with vi editor or any editor which you like)

vi /etc/ssmtp/ssmtp.conf
[email protected]
AuthPass=password
FromLineOverride=YES
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
  • Step 5: Now take the backup of sendmail script. It is good to use which command to find exact path of sendmail script. In my case it is at /usr/sbin/sendmail. Hence I am changing directory to /usr/sbin . It might be different in your case. (To get absolute path of sendmail script) which sendmail (To get absolute path of ssmtp script) which ssmtp

(Take backup of sendmail script)

cp -p /usr/sbin/sendmail /usr/sbin/sendmail.orig.`date +%F`
rm /usr/sbin/sendmail
cd /usr/sbin
ln -s /usr/sbin/ssmtp sendmail

Below is reference from my system

[root@Nagios sbin]# ls -l sendmail
lrwxrwxrwx 1 root root 15 Jul 16 10:29 sendmail -> /usr/sbin/ssmtp
[root@Nagios sbin]#
echo "testing for nagios alerts"|mail -s "test nagiosalerts" [email protected]

Check your inbox the email should come from [email protected]. You can also check the header of email.

  • Step 6: Now find the contacts.cfg file of nagios in /etc/nagios

Note: In Red Hat based and Debian Based linux OS, the path of contacts.cfg of nagios is different(If you have installed it with yum or apt-get), hence search the contacts.cfg file.

Now edit the contacts.cfg file of nagios

Replace YourName and [email protected] as per your information.

define contact{
      contact_name                    YourName
      alias                           Your Name
      service_notification_period     24x7
      host_notification_period        24x7
      service_notification_options    c,r
      host_notification_options       d,r
      service_notification_commands   notify-by-email
      host_notification_commands      host-notify-by-email
      email                           [email protected]
      }
  • Step 7: Restart the nagios
/etc/init.d/nagios restart
  • Step 8: The setup is completed. Now you will receive the email alerts from gmail id. ([email protected])

Loading

Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.