Monitoring Asterisk with SNMP, Nagios and Nagios Administrator using Ubuntu LTS 8.0.4 Server

Gone are the days of tedious console only configuration of Nagios. While it’s an excellent system monitoring tool, it can be a little daunting to configure and setup. Not to mention editing 5 or 6 configuration files when adding one host.

In April 2008, Nagios Administrator was released, which promises to deliver an easy to use administration interface for configuring your Nagios installation with ease. The interface allows for adding contacts, contact groups, services, operating systems, and other settings. The one thing we noticed that was missing was service groups, but we’re not sure that really matters.

Using this article in conjunction with our previous Monitoring Asterisk with SNMP article will yeild you great results and awesome statistics.

Since there is already a demo running of the Nagios Administrator, I don’t think I need to show you screenshots, instead here is a link from their site.

NagiosAdministrator: http://demo.nagiosadmin.de
Nagios: http://demo.nagiosadmin.de/nagios

Username: nagiosadmin
Password: nagiosadmin

We installed this on a VMWare Appliance, running Ubuntu Server Edition LTS 8.04, so you may have to change the instructions to suit your particular flavour of Linux. Or Microsoft Windows if you’re brave enough to try this on that OS.

Anyhow, now on to the tutorial on getting Nagios 3.0 running with Nagios Administrator on your Ubuntu Server.

First, with the help of Michel Sigloch, we have this from a script of his that we’ve edited. This will install Nagios 3.0 from source on your ubuntu server, since the apt tree still holds an older version.

Installing Nagios

Start with the preliminaries:

# sudo apt-get install apache2 build-essential wget perl libgd2-xpm-dev openssl libssl-dev openssh-server openssh-client ntpdate snmp smbclient libldap-2.3-0 libldap2-dev mysql-server libmysqlclient15-dev qstat libnet-snmp-perl mrtg nut unzip
# sudo userdel -f nagios
# sudo useradd -c “Nagios Admin” nagios
# sudo groupadd nagcmd
# sudo usermod -G nagcmd nagios
# sudo usermod -G nagcmd www-data
# sudo usermod -a -G nagios www-data

Then We’ll setup the Nagios directories and configure Nagios.

# sudo mkdir /usr/local/src
# cd /usr/local/src
# sudo wget http://nagios.sourceforge.net/download/cvs/nagios-cvs.tar.gz
# sudo tar xvzf nagios-cvs.tar.gz
# sudo rm nagios-cvs.tar.gz
# cd nagios-cvs
# sudo ./configure –with-command-group=nagcmd

Now lets install Nagios and update the default boot programs, while restarting apache and Nagios

# sudo make all
# sudo make install
# sudo make install-init
# sudo make install-commandmode
# sudo make install-config
# sudo ln -sf /usr/local/nagios/etc/ /etc/nagios
# sudo make install-webconf

Next we’ll setup our htaccess file:

# sudo htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
# sudo chown www-data htpasswd.users
# sudo chmod 600 htpasswd.users

Download and configure nagios plugins. The plugins are what let you monitor things like your Asterisk PBX using SNMP or other methods.

# cd /usr/local/src
# sudo wget http://heanet.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz
# sudo tar xvzf nagios-plugins-1.4.11.tar.gz
# cd nagios-plugins-1.4.11
# sudo ./configure –with-nagios-user=nagios –with-nagios-group=nagios
# sudo make
# sudo make install

Now we are pretty much done with Nagios setup. We can move on to setting up Nagios Administrator. This part of the process can be a little confusing since their documentation is in german. I taught myself a bit of german last night reading this, but I decyphered it for us to use it. Keep reading for the Nagios Administrator Setup portion.

Configuring and installing Nagios Administrator

First, we’ll have to install any pre-requisite packages for Nagios Administrator:

# sudo apt-get install php5-common traceroute php5-cli php5-gd

Now lets create our web directory

# sudo mkdir /var/www/nagiosadmin

Now we can download our Nagios Administrator files and drop them into the web directory on our server.

# cd /usr/src
# sudo wget http://www.nagiosadmin.de/nagiosadmin-0.9.1.tar.bz2
# sudo tar xjpf nagiosadmin-0.9.1.tar.bz2 -C /var/www/nagiosadmin/

Now we’ll create the mysql database. Like this

# mysqladmin -u root -p create nagiosadmin
# mysql -u root -p

mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,ALTER,INDEX,DROP
ON nagiosadmin.*
TO ‘nagiosadmin’@'localhost’
IDENTIFIED BY ‘somepassword’;

Now we have to configure Nagios Administrator to connect to our Database.

# cd /var/www/nagiosadmin
# nano config/propel.ini

and set

propel.database.url = mysql://nagiosadmin:yourpassword@localhost/nagiosadmin

Now we edit the databases file and enter our database settings

# sudo nano config/databases.yml

and set

database: nagiosadmin
username: nagiosadmin
password: yourpassword

Now we have to make sure our Nagios shell commands are set properly in Nagios Administrator.

# sudo nano apps/backend/modules/generator/config/module.yml

and make sure your paths are correct for these two lines

config_check_command: /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg 2>&1
reload_nagios_command: /usr/bin/sudo /usr/bin/killall -HUP nagios

Now we have to enter visudo to set up the permissions for our Nagios user, done like this:

# sudo visudo

then add

# for nagios
%nagcmd ALL= NOPASSWD: /usr/bin/killall -HUP nagios

Exit visudo by hitting the ESC key, and then typing “:wq” hitting enter.

Now, We have to do a few things that are pretty self explanitory with the Nagios Administrator control file.

# cd /var/www/nagiosadmin
# sudo ./symfony fix-perms
# sudo ./symfony propel-insert-sql
# sudo ./symfony propel-load-data backend
# sudo ./symfony check

Next we’ll have to insert our Apache virtual host.

# sudo nano /etc/apache2/conf.d/nagios.conf

Make sure you enter this line, and change the path to match your install if you changed the above instructions

Alias /nagios/images/logos/nagiosimages /var/www/nagiosadmin/web/uploads/os_images

Also, in the default settings, make sure to change all of the references to the htpasswd file to the following

AuthUserFile /etc/nagios/htpasswd.users

Now, lets setup the new virtual host for our Nagios Administrator and Nagios site.

# sudo mv /etc/apache2/sites-enabled/000-default ~/000-default.backup
# sudo rm /etc/apache2/sites-enabled/000-default

Now we have to add our new default virtual host configuration like so

# sudo touch /etc/apache2/sites-enabled/nagios.conf

Enter the following, changing any paths as according to your configuration if you deviated from above.

<VirtualHost *:80>

ServerAdmin root@yourdomain.com
ServerName monitor.yourdomain.com
DocumentRoot “/var/www/nagiosadmin/web”
php_admin_flag magic_quotes_gpc 0
php_admin_value memory_limit “32M”

<Directory “/var/www/nagiosadmin/web”>
AllowOverride All
Order allow,deny
Allow from all
</Directory>

<Files index.php>
AuthType Basic
AuthName “NagiosAdmin”
AuthUserFile /etc/nagios/htpasswd.users
require user nagiosadmin
</Files>

Alias /phpmyadmin /var/www/phpmyadmin
<Directory /var/www/phpmyadmin>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Now we have to enable mod rewrite like this

# sudo mod_rewrite aktivieren

And next lets restart Apache

# sudo /etc/init.d/apache2 restart

Configuring Nagios 3.0 to work with Nagios Administrator

Now we have to make some quick edits to the nagios configuration and we’ll be up and running in no time.

First lets edit the Nagios configuration file

# nano /etc/nagios/nagios.cfg

Now make sure yours looks like the following, commenting out the ones that are on by default and adding the new Nagios Administrator directory at the bottom.

#cfg_file=/usr/local/nagios/etc/objects/commands.cfg
#cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
#cfg_file=/usr/local/nagios/etc/objects/templates.cfg

# Definitions for monitoring the local (Linux) host
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

#cfg_dir=/usr/local/nagios/etc/servers
#cfg_dir=/usr/local/nagios/etc/printers
#cfg_dir=/usr/local/nagios/etc/switches
#cfg_dir=/usr/local/nagios/etc/routers
cfg_dir=/var/www/nagiosadmin/data/nagios

Now, before starting nagios for the first time, lets go into the configuration interface and set up some default values.

Open a web browser and hit this url:

http://monitor.yourdomain.com/

You should see the login box for your Nagios Administrator site, which you can login with “nagiosadmin” and the password you entered earlier.

Once you login to the site, you will have to configure the following things:

contacts -> create -> make one or two contacts
contact groups -> create -> create a contact group, and assign some contacts to it
host groups -> create -> create a host group
host -> create -> create some hosts

Now, go to the “Generator” Menu, and click on “Save”.

Now, go back to your command prompt, and start Nagios. It should start with no errors.

# sudo /etc/init.d/nagios start

Now, go back to the web interface, you should be able to save and generate your configuration file with no errors.

Finally, add Nagios to your default runlevel

# sudo update-rc.d nagios defaults

Congratulations, we’re finished!

We are now finished with the setup. It’s up to you to setup proper security measures for the Nagios Administrator and Nagios site.

You can visit the Nagios Administrator panel here:

http://monitor.yourdomain.com/

and you can visit Nagios here

http://monitor.yourdomain.com/nagios/

Remember, you can also take a look at our Monitoring Asterisk with SNMP Howto for information on getting even more statistics from your Asterisk PBX than you ever thought possible. We hope you like this article, and welcome comments.

above comments



Leave a Reply