This post is mostly for my own reference, just in case I need to rebuild a server and want to save myself the Googling. These links helped:
Nagios Core 3.x Docs – The quick-start guide was great. I recommend compiling yourself instead of using yum so that your paths match the docs exactly. Of course, go ahead and use yum for dependencies.
If you’re password-protecting the web interface, however, you’ll need to add the username for authorized viewers to the /usr/local/nagios/etc/cgi.cfg file in the authorized_for sections, such as:
authorized_for_system_information=nagiosadmin,username1,username2
NPRE Docs from Nagios – Some minor mistakes, but a good place to start. Dependencies not mentioned in docs: gcc, glibc, glibc-common, openssl, mysql-devel (for MySQL monitoring only), gd, gd-devel (when installing on Ubuntu, I also needed to do apt-get libssl-dev). Errors in doc: On pg 6, only_from directive should be 127.0.0.1 only for testing the daemon locally, but should be changed to the IP address of the remote monitoring host before trying to connect remotely. On pg 8, the iptables command should have two hypens before the dport option, as in:
iptables -I RH-Firewall-1-INPUT -p tcp -m tcp --dport 5666 -j ACCEPT
In any case, I prefer to edit /etc/sysconfig/iptables manually, in which case I would use an -A instead of the -I above.
check_mem.py script – a better-than-stock memory script that takes cacheing into account
Using sudo with NRPE on CentOS
Some distros don’t have this problem, but if you’re having trouble getting nrpe commands to work, even with the nagios user added to the /etc/sudoers list, comment out the #Defaults requiretty line in /etc/sudoers as explained here. Be sure to prefix the command in nrpe.conf with sudo, as in sudo /usr/local/nagios/libexec/check_nrpe. Commenting out this line is also helpful with certain local scripts, too.
Config Test Command
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Get RAID Drivers Working
Check hardware config with cat /etc/sysconfig/hwconf to find which adapters your systems have, or even better, use lshw to build a text file with your hardware config (install with yum install lshw if you don’t have it installed).
Check tips for Dell servers here.
Tips for PERC3/Di:
- Use afacli for status checks. Do yum install compat-libstdc++-296 first, then install the afaapps rpm from Dell.
- afacli direct download link
- Nagios afacli walk-through
- a better check_raid.pl script
- Add the afa0 device by doing the following:
- grep ‘aac’ /proc/devices
- Result says something like ‘253 aac’. Note the number and use in the following command: mknod /dev/afa0 c 253 0
- To ensure the device is present after a reboot, add the previous command to /etc/rc.local
Tips for PERC4/Di:
- Install megarc (LSI Megaraid command line utility for PERC4) from
here. LSI no longer provides this download. The filename to search for is ut_linux_megarc_1.11.zip - Get Nagios plugin for Megaraid here.
- This script also works for Perc4 (with megarc installed), but I like the output of the first script better.
- Modify /etc/sudoers to allow nagios to sudo (even for local machine) and run plugin and utility as root
Tips for PERC5:
- Some good background info here.
- Install MegaCli (LSI Megaraid command line utility for PERC5) from here. By default, the rpm installs the utility in /opt/MegaRAID/MegaCli/
- Use check_megaraid_sas script here.
- Edit script for correct paths for the Nagios plugins lib and MegaCli locations.
- Modify /etc/sudoers to allow nagios to sudo (even for local machine) and run plugin and utility as root.
Nagios Notifications with Postfix
By default, Nagios wants to use the system’s default mail command. If you have Postfix as your MTA, Nagios won’t send the alerts properly. Edit the Nagios commands.cfg file and locate the following lines.
# '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/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$ } # '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/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ }
Two changes are needed to make the alerts work with Postfix’s version of sendmail. First, move the subject line parameter (-s) to the beginning of the second string that follows printf.
Second, change the path and command from /usr/bin/mail to /usr/sbin/sendmail. Here are the modified commands.
# NEW 'notify-host-by-email' command definition define command{ command_name notify-host-by-email command_line /usr/bin/printf "%b" "Subject:** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **\n***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/sbin/sendmail $CONTACTEMAIL$ } # NEW 'notify-service-by-email' command definition define command{ command_name notify-service-by-email command_line /usr/bin/printf "%b" "Subject:** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **\n***** 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/sbin/sendmail $CONTACTEMAIL$ }
Restart Nagios and you’re good to go.
Remote Event Handlers via NRPE
I followed most of the steps in this blog post to get remote event handlers working with NRPE.