https://wiki.archlinux.org/api.php?action=feedcontributions&user=Alena&feedformat=atomArchWiki - User contributions [en]2024-03-29T13:29:33ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Nagios&diff=227901Nagios2012-10-10T07:57:20Z<p>Alena: </p>
<hr />
<div>[[Category:Daemons and system services]]<br />
[[Category:Networking]]<br />
{{Article summary start}}<br />
{{Article summary text|A short installation and configuration guide for the service and network monitoring program Nagios}}<br />
{{Article summary end}}<br />
<br />
[http://www.nagios.org/ Nagios] is an open source host, service and network monitoring program. It monitors specified hosts and services, alerting you to any developing issues, errors or improvements. This article describes the installation and configuration of Nagios.<br />
<br />
==Features==<br />
Some of Nagios' features [http://nagios.sourceforge.net/docs/3_0/about.html#whatis include]:<br />
*Monitoring of network services (SMTP, POP3, HTTP, NNTP, PING, etc.)<br />
*Monitoring of host resources (processor load, disk usage, etc.)<br />
*Simple plugin design that allows users to easily develop their own service checks<br />
*Parallelized service checks<br />
*Ability to define network host hierarchy using "parent" hosts, allowing detection of and distinction between hosts that are down and those that are unreachable<br />
*Contact notifications when service or host problems occur and get resolved (via email, pager, or user-defined method)<br />
*Ability to define event handlers to be run during service or host events for proactive problem resolution<br />
*Automatic log file rotation<br />
*Support for implementing redundant monitoring hosts<br />
*Optional web interface for viewing current network status, notification and problem history, log file, etc.<br />
<br />
The following installation and configuration were tested using nagios 3.2.0-1, [[Apache]] web server 2.2.14-2, and [[PHP]]5 5.3.1-3 by [http://bbs.archlinux.org/viewtopic.php?id=88461 awayand].<br />
<br />
==Webserver==<br />
According to the [http://nagios.sourceforge.net/docs/3_0/about.html official documentation] a webserver is not required, but if you wish to use any of the CGI features then a webserver (apache preferred), PHP ([[Apache#PHP|php-apache]]) for it and the gd library are required. This is assumed for this installation<br />
<br />
==Installation==<br />
Install [https://aur.archlinux.org/packages.php?ID=12306 nagios] from the [[AUR]].<br />
<br />
Users may also want to install [https://aur.archlinux.org/packages.php?ID=12307 nagios-plugins].<br />
<br />
==Nagios Configuration==<br />
Copy the sample config files as root:<br />
{{bc|<br />
cp /etc/nagios/cgi.cfg.sample /etc/nagios/cgi.cfg<br />
cp /etc/nagios/resource.cfg.sample /etc/nagios/resource.cfg<br />
cp /etc/nagios/nagios.cfg.sample /etc/nagios/nagios.cfg<br />
cp /etc/nagios/objects/commands.cfg.sample /etc/nagios/objects/commands.cfg<br />
cp /etc/nagios/objects/contacts.cfg.sample /etc/nagios/objects/contacts.cfg<br />
cp /etc/nagios/objects/localhost.cfg.sample /etc/nagios/objects/localhost.cfg<br />
cp /etc/nagios/objects/templates.cfg.sample /etc/nagios/objects/templates.cfg<br />
cp /etc/nagios/objects/timeperiods.cfg.sample /etc/nagios/objects/timeperiods.cfg<br />
}}<br />
<br />
Make owner/group for all the files you just copied and belong to root equal to nagios/nagios:<br />
<br />
{{bc|<br />
# chown -R nagios:nagios /etc/nagios<br />
}}<br />
<br />
Create htpasswd.users file with a username and password, eg. nagiosadmin and secretpass<br />
<br />
{{bc|<br />
# htpasswd -c /etc/nagios/htpasswd.users nagiosadmin<br />
}}<br />
<br />
If the owner/group of the nagios-plugins you installed are root:root, the following needs to be done:<br />
<br />
{{bc|<br />
# chown -R nagios:nagios /usr/share/nagios<br />
}}<br />
<br />
Once Nagios is configured, it is time to configure the webserver.<br />
<br />
==Apache Configuration==<br />
Edit /etc/httpd/conf/httpd.conf, add the following to the end of the file:<br />
<br />
{{bc|<br />
# Nagios<br />
Include "conf/extra/nagios.conf"<br />
<br />
# PHP<br />
Include "conf/extra/php5_module.conf"<br />
}}<br />
<br />
{{note| As of 3.4.1-4 the example conf is in etc/webapps/nagios/apache.example.conf }}<br />
<br />
To fix this run:<br />
{{bc| cp /etc/webapps/nagios/apache.example.conf /etc/httpd/conf/extra/}}<br />
<br />
Add the apache user http to the group nagios, otherwise you will get the following error when using nagios: <br />
{{bc|Could not open command file '/var/nagios/rw/nagios.cmd' for update!: <br />
}}<br />
<br />
{{bc|<br />
# usermod -G nagios -a http<br />
}}<br />
<br />
==PHP Configuration==<br />
Edit /etc/php/php.ini to include /usr/share/nagios in the open_basedir directive.<br />
<br />
Example configuration:<br />
<br />
{{bc|1=open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps:/etc/webapps:/usr/share/nagios}}<br />
<br />
==Final Steps==<br />
Start/Restart nagios:<br />
<br />
{{bc|<br />
/etc/rc.d/nagios restart<br />
}}<br />
<br />
Start/Restart apache:<br />
<br />
{{bc|<br />
/etc/rc.d/httpd restart<br />
}}<br />
<br />
Now you should be able to access nagios through your webbrowser using the username and password you have created above using htpasswd:<br />
<br />
{{bc|<br />
http://localhost/nagios<br />
}}<br />
<br />
==Plugin check_rdiff==<br />
A small guide on monitoring rdiff-backups using a plugin called check_rdiff.<br />
<br />
===Download and Install===<br />
<br />
You will need perl installed.<br />
<br />
{{bc|<br />
cd<br />
wget http://www.monitoringexchange.org/attachment/download/Check-Plugins/Software/Backup/check_rdiff/check_rdiff<br />
cp check_rdiff /usr/share/nagios/libexec<br />
chown nagios:nagios /usr/share/nagios/libexec/check_rdiff<br />
chmod 755 /usr/share/nagios/libexec/check_rdiff<br />
}}<br />
<br />
===Enable sudo for user nagios===<br />
Since the perl script check_rdiff needs to run as root, you will have to enable sudo for the nagios user:<br />
<br />
{{bc|<br />
sudoedit /etc/sudoers<br />
}}<br />
<br />
This will open the /etc/sudoers file, then paste the following at the end of the file (you should know how to use the vi editor, if that is the one being used by sudoedit):<br />
<br />
{{bc|1=<br />
nagios ALL=(root)NOPASSWD:/usr/share/nagios/libexec/check_rdiff<br />
}}<br />
<br />
===Integrate check_rdiff plugin into nagios===<br />
<br />
Edit /etc/nagios/objects/commands.cfg to include the following command definition:<br />
<br />
{{bc|<br />
# check rdiff-backup<br />
define command{<br />
command_name check_rdiff<br />
command_line sudo $USER1$/check_rdiff -r $ARG1$ -w $ARG2$ -c $ARG3$ -l $ARG4$ -p $ARG5$ <br />
}<br />
}}<br />
<br />
Edit /etc/nagios/objects/localhost.cfg to include checking of rdiff-backup on localhost, for example:<br />
<br />
{{bc|<br />
define service{<br />
use local-service ; Name of service template to use<br />
host_name localhost<br />
service_description rdiff-backup<br />
check_command check_rdiff!/home/x/rdiffbackup!8!10!500!24<br />
}<br />
}}<br />
<br />
Quote from the check_rdiff script content:<br />
<br />
''The above command checks the repository (-r) which is defined as the destination of the backup, or more specifically, the directory above the rdiff-backup-data directory. It will return warning if the backup hasn't finished by 8am and critical by 10am. It will also return warning if the TotalDestinationSizeChange is greater than 500Mb. It also get the period set to 24hrs (-p). This is important as the plugin will throw a critical if the backup doesn't start in time.''<br />
<br />
Finally, restart nagios:<br />
<br />
{{bc|<br />
/etc/rc.d/nagios restart<br />
}}<br />
<br />
You can now see the rdiff-backup status by clicking on Services on the left side of the nagios web interface control panel.<br />
<br />
==Forks==<br />
*[[Icinga]] is a Nagios fork. More details about the fork can be found at [https://www.icinga.org/faq/why-a-fork/ Icinga FAQ: Why a fork?]<br />
<br />
==See also==<br />
*[http://www.nagios.org/ nagios.org] Official website<br />
*[http://www.nagiosplugins.org/ Nagios Plugins] the home of the official plugins <br />
*[[Wikipedia:Nagios|wikipedia.org]] Wikipedia article<br />
*[http://www.nagiosexchange.org NagiosExchange] overview of plugins, addons, mailing lists for Nagios<br />
*[http://www.nagiosforge.org/ NagiosForge] a repository for ad</div>Alena