Nagios Add NRPE

NRPE Install and Configuration
This assumes nagios has been installed and configured already. I needed to add nagios monitoring for some remote linux servers. I had only dabbled with nagios before and had setup PING only for testing if a server was up or down. But we now required service testing and HD monitoring.

REMOTE CLIENT INSTALL
Installed on Ubuntu 10.04.3 LTS

Update the system

apt-get update
apt-get upgrade

Install the NRPE server

apt-get install nagios-nrpe-server
This will ask if you want to install a bunch of extra packages – hit Y

Verify the service has started

ps aux | grep nrpe
You should see a command running from /usr/sbin/nrpe

Test a command you want to run. In my case, I wanted to check the /dev/mapper/pve-data drive

/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/pve-data
DISK OK

Edit the NRPE configuration file

nano /etc/nagios/nrpe.cfg
Look for allowed_hosts=127.0.0.1
Change to allowed_hosts=127.0.0.1,IPADDRESSOFNAGIOSSERVER
I then added the following command
command[check_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/pve-data
Save the configuration, then restart the service
/etc/init.d/nagios-nrpe-server restart

NAGIOS SERVER CONFIGURATION

Download the latest version of NRPE from http://exchange.nagios.org/directory/Addons/Monitoring-Agents/NRPE–2D-Nagios-Remote-Plugin-Executor/details
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
tar zvxf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --enable-command-args
make all
make install-plugin

Verify connectivity with the remote system from Nagios

/usr/local/nagios/libexec/check_nrpe -H IP.OF.SER.VER
If this spits back NRPE v2.12 then you’re in business. If not, then it won’t connect.

We now have to make a command for Nagios to use NRPE

nano /usr/local/nagios/etc/objects/commands.cfg
Add the following
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
Save and close

Now we can create the remote machine configuration file

nano /usr/local/nagios/etc/objects/SOMENAME.cfg

Then restart the Nagios service and test

/etc/init.d/nagios restart

For CentOS/RHEL (RPM)
Navigate to http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
Find the latest release for your distribution (ie RHEL6 and CentOS6 x64 is http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm)
Copy the link location
Open a command shell terminal window on your CentOS/RHEL machine
rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
yum install nagios-nrpe nagios-plugins-nrpe

df -h
find the name of the drive you want to monitor (or drives, ie /dev/mapper/vg_centos-lv_root)
nano /etc/nagios/nrpe.cfg
Find allowed_hosts=127.0.0.1
Change to allowed_hosts=127.0.0.1,10.4.0.253
Find command[check_hda1]
Add a line underneath to be command[check_disk]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/vg_centos-lv-root (same as df -h output)
Verify your command will work:
/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/vg_centos-lv-root
nano /etc/xinetd.d/nrpe
Find allowed_hosts=127.0.0.1
Change to allowed_hosts=127.0.0.1,10.4.0.253
nano /etc/services
Add nrpe 5666/tcp # nrpe (follow along with the template)
service nrpe restart
And to have this automatically start:
chkconfig --add nrpe
chkconfig nrpe on

I ran the test from nagios (/usr/local/nagios/libexec/check_nrpe -H IP.OF.Server) and was receiving an error:
CHECK_NRPE: Error – Could not complete SSL handshake.

Change the allowed_hosts to only be the IP of the nagios server, not localhost, then service nrpe restart

Add to the nagios monitoring server
Profit!

Delete Files Older Than X Days

I was tasked with auto removing files from a linux FTP site that were older than 14 days. Unfortunately the files were all located in the ~ (home) directories.

I originally tried:
find /home/* -mtime +14 -type f
This command attempts to find ALL (*) files in the home (/home/) directory with a modified time of 14 days (-mtime +14) and only files not directories (-type f)

The command found all the files ok, but it was also listing the hidden files:

/home/user/.profile
/home/user/.bash_logout
/home/user/.bash_history
/home/user/.bashrc

So I decided to use regex:
find /home/* \( ! -regex '.*/\..*' \) -type f -mtime +14
This worked!

Now to add the removal of the files:
find /home/* \( ! -regex '.*/\..*' \) -type f -mtime +14 -exec rm {} \;

I saved this as delete_files, then made it runnable, and cron’d it up:
chmod +x delete_files
crontab -e
@daily ./delete_files #Delete Files Older Than 14 Days in Home Dirs

This worked on my Ubuntu 10.04.3 LTS system, but the commands should work on all the flavors.

Configure Nagios on Ubuntu Server

I’m assuming that you’ve already read the post on installing nagios AND have successfully installed nagios on your LAMP server. I have recently wiped out the 9.04-upgraded-to-10.04.1 server in favor of a fresh install of 10.04.2LTS. I followed my own guide and nagios is installed and running on production equipment.

I needed to add a new user to be able to access all the same admin functionality of the nagios website.
Create the login for apache:

htpasswd /usr/local/nagios/etc/htpasswd.users USERNAME
PASSWORD
PASSWORD

Add the user to the contacts list:

nano /usr/local/nagios/etc/objects/contacts.cfg
define contact{
contact_name USERNAME
use generic-contact
alias FULL NAME
email EMAIL@DOMAIN.TLD
}
Add the USERNAME after “nagiosadmin” under the define contactgroup{ area
Note, you will need to add a “, ” after nagiosadmin

Restart Nagios to re-read the configuration:

/etc/init.d/nagios restart

I would like to make a parent of an object (switch parent of server, or server hosting virtual machines etc)

define host{
use windows-server
host_name HOSTNAME
alias LONGNAME
address IPADDRESS
parents SERVER_OR_SWITCH_NAME – this must have a valid .cfg file already created
hostgroups SERVERGROUP1, SERVERGROUP3, ETC

Add Icons to Nagios Network Map
Upload your png file to /usr/local/nagios/share/images/logos/
Install the PNG to GD2 application:
apt-get install libgd-tools
Convert your PNG to a GD2:
pngtogd2 PNGFILE.png PNGFILE.gd2 cs 1

Create the host image config file:
nano /usr/local/nagios/etc/objects/hostimages.cfg

define hostextinfo{
host_name HOSTNAME, HOSTNAME2, ETC
# notes_url http://sitefornoteshere
icon_image FILENAME.png
icon_image_alt 0 ALTNAMEOFDEVICE
vrml_image FILENAME.png
statusmap_image FILENAME.gd2
}

Restart Nagios:
/etc/init.d/nagios restart

Reset MySQL Password

I setup a LAMP server for a developer a while back and he changed the passwords for root and the root mysql user to something besides my defaults. So when he asked me to give him the password for the database, I could not really help him out. Or could I?

Stop the mysql services:
/etc/init.d/mysql stop

Start mysql without the passwords:
mysqld_safe --skip-grant-tables &

Connect to the safe mysql:
mysql -u root

Set a new root password:
use mysql;
update user set password=PASSWORD("your_New_Password_here") where User='root';
flush privileges;
quit

Stop the safe mysql database:
/etc/init.d/mysql stop

Start mysql and test:
/etc/init.d/mysql start
mysql -u root -pYOURNEWPASSWORDHERE

*note – there is no space between -p and your password.

AND, in case you’re just wanting to change the password of a known user:
mysqladmin -u root -pOLDPASSWORD password NEWPASSWORD

Mount NFS on Ubuntu

Basic LAMP Ubuntu 10.04.2 LTS trying to mount NFS share from a FreeNAS 0.7.2 system. I was running the following command:

mount -t nfs 10.10.0.99:/mnt/hotswap/NFS/ /mnt/freenas/

and receiving the following error

mount: wrong fs type, bad option, bad superblock on 10.10.0.99:/mnt/hotswap/NFS/,
missing codepage or helper program, or other error
(for several filesystems (e.g. nfs, cifs) you might
need a /sbin/mount. helper program)
In some cases useful info is found in syslog – try
dmesg | tail or so

Awesome. So I tried with the -o ‘vers=3’ command just in case. Same issues persist.

It looks like the common NFS files are missing in the vanilla ubuntu server installation:
apt-get install nfs-common
Rerun the mount command is successful

And, since I like to create NFS on ubuntu as well:
apt-get install nfs-kernel-server
nano /etc/exports
Add:
/path/to/share Hostname(rw,sync,no_root_squash)
or in my case
/NFS *(rw,sync,no_root_squash)
Then restart nfs
/etc/init.d/nfs-kernel-server restart

Ramblings Of An IT Person