Annvix
Personal tools



/Documentation/nagios

From Annvix

Using nagios on Annvix

Nagios is a great system monitoring tool that does not come packaged with Annvix, but is extremely easy to install. Configuration is a different story, of course (nagios can be a bit daunting to the uninitiated).

Contents

Installing nagios

To begin with, download the latest version of nagios and nagios-plugins from the home web page. Then execute the following:

$ sudo apt-get install gd-devel traceroute
$ cd /usr/local/src
$ tar xvzf ~/nagios-2.7.tar.gz
$ cd nagios-2.7
$ ./configure --with-cgiurl=/cgi-bin --with-htmlurl=/nagios \
--with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios
$ make all
$ sudo su
# groupadd -g 501 nagios
# useradd -u 501 -g 501 -d /usr/local/nagios -s /bin/bash -c "Nagios system user" nagios
# make install
# make install-commandmode
# make install-config
# vim /etc/httpd/conf/httpd.conf

The following is what you will be adding to /etc/httpd/conf/httpd.conf (or another configuration file that gets included, if you're using this with virual hosts, etc.):

ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin

<Directory "/usr/local/nagios/sbin">
    Options ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
    AuthName "Nagios Access"
    AuthType Basic
    AuthUserFile /usr/local/nagios/etc/htpasswd.users
    Require valid-user
</Directory>

Alias /nagios /usr/local/nagios/share

<Directory "/usr/local/nagios/share">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
    AuthName "Nagios Access"
    AuthType Basic
    AuthUserFile /usr/local/nagios/etc/htpasswd.users
    Require valid-user
</Directory>

Once this is done, restart httpd and continue the configuration:

# srv --restart httpd
# cd /usr/local/nagios/etc
# htpasswd -c htpasswd.users nagiosadmin
# for f in cgi commands localhost nagios resource; do cp -f ${f}.cfg-sample ${f}.cfg; done
# vim cgi.cfg
# exit

In this file make sure that use_authentication=1 is set. Now visit http://localhost/nagios or http://yoursite/nagios to view the newly-setup nagios web interface. The next step is to configure nagios to do something useful. Via the web interface you can select the "Documentation" link to get documentation on the various configuration files and how to configure them.

Installing the nagios plugins

Download the nagios plugins (the latest version is 1.4.6) to build and install them. Nagios makes use of the ping program, however by default ping can only be executed by root or via sudo. Instead, install and use fping from ports instead:

$ builder -u
$ builder -p fping
$ sudo apt-get install fping

NOTE: fping is installed suid root.

If you want support for some of the various plugins, read the README file that comes with the nagios-plugins; it will indicate what requirements are necessary to build things such as MySQL support or LDAP support, etc. Use apt-get to install any additional packages you need to satisfy these requirements and then configure and build the plugins.

$ cd /usr/local/src
$ tar xvzf ~/nagios-plugins-1.4.6.tar.gz
$ cd nagios-plugins-1.4.6
$ less README
$ sudo apt-get install libmysql libldap net-snmp mysql-devel openssl-devel perl-NetSNMP openldap-devel
$ ./configure --prefix=/usr/local/nagios --without-ipv6  \
--with-trusted-path=/usr/local/nagios/bin:/bin:/sbin:/usr/bin:/usr/sbin \
--with-fping-command=/usr/local/bin/fping
$ make
$ perl -pi -e 's|plugins-root po|plugins-root|' Makefile
$ sudo su
# make install
# cp command.cfg /usr/local/nagios/etc/

The little bit of perl magic there simply modifies the Makefile so that it doesn't error out when trying to install locale files (the error is harmless, so you can omitt that particular command, just don't worry when you see the error).

Creating the nagios service script

To start the nagios daemon to collect information, first check that your configuration is ok:

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

The output of this command does a status check on the configuration and will alert you if it discovers any errors. You should execute this command every time you make changes to your configuration files, prior to restarting the service.

Next, create a run service for nagios:

# cd /var/service
# mkdir -p nagios/log
# chmod 0750 nagios
# cat sshd/log/run |perl -pi -e 's|sshd|nagios|g' >nagios/log/run
# chmod 0700 nagios/log/run
# cat <<EOF >nagios/run
#!/bin/execlineb

/bin/fdmove -c 2 1

/bin/export PATH "/usr/local/nagios/bin:/sbin:/bin:/usr/sbin:/usr/bin"

/usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg
[CTRL-D]

# chmod 0700 nagios/run
# chown -R root:admin nagios

Note that the [CTRL-D] noted above is the actual key press CTRL-D and not something to be typed verbatim.

When this is done, add the service:

# srv --add nagios

Remove installed -devel packages

The last step is to remove any installed -devel packages (you can keep them if you want them, but there largely isn't a point until you want to upgrade nagios or some other application again):

$ sudo apt-get remove openssl-devel mysql-devel gd-devel jpeg-devel png-devel xpm-devel expat-devel X11-devel \
fontconfig-devel zlib-devel openldap-devel libsasl-devel