Category Archives: Monitoring

nagios-nrpe-server: Ignores dont_blame_nrpe=1

We have Debian Wheezy running on all our production machines. Debian Jessie is out there for a while and I wanted to give it a try...
An upgrade like this should be painless and without any major problems.

I installed a machine with Debian Jessie and made it ready for production by playing some ansible playbooks against it. More or less everything was fine, but the nagios nrpe server. This is what I noticed in the log:

Oct 30 17:08:36 was1 nrpe[14125]: Error: Request contained command arguments!
Oct 30 17:08:36 was1 nrpe[14125]: Client request was invalid, bailing out...

After digging a little bit I kinda figured out what happened.
nagios-nrpe-server debian package was compiled without --enable-command-args because there are security problems and that this feature is often used wrong.

The quickest fix for this was to recompile it with --enable-command-args and reinstall it.

  • Get the source.

[codesyntax lang="bash"]

apt-get source nagios-nrpe-server
apt-get install libssl-dev dpatch debhelper libwrap0-dev autotools-dev build-essential fakeroot
apt-get build-dep collectd collectd-core
ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/libssl.so

[/codesyntax]

  • Edit nagios-nrpe-2.15/debian/rules and just after --enable-ssl \ insert --enable-command-args \ (it should be line number 16)

[codesyntax lang="bash"]

sed '16i\\t\t--enable-command-args \\' nagios-nrpe-2.15/debian/rules

[/codesyntax]

  • Build the package

[codesyntax lang="bash"]

cd nagios-nrpe-2.15/
dpkg-buildpackage -rfakeroot

[/codesyntax]

  • Install the newly created package

[codesyntax lang="bash"]

cd ..
dpkg -i nagios-nrpe-server_2.15-1_amd64.deb

[/codesyntax]

Note: in case you're interested in the whole story, please read this.

How to fix "ERROR: Connecting to daemon at /var/run/collectd-unixsock failed"

Sometimes connecting to the collectd unixsocket is not possible giving a connection refused.

This can be fixed manually by removing manually the socket file

[codesyntax lang="bash"]

rm /var/run/collectd-unixsock

[/codesyntax]

and then restart collectd

[codesyntax lang="bash"]

/etc/init.d/collectd restart

[/codesyntax]

collectd does not create a new socket file when there is already such a file. But the old file, which is not connected to any process certainly refuses connections all the time. Probably it is enough to remove that file if it exists whenever collectd will be started.

This is easily reproduceable:

[codesyntax lang="bash"]

killall -9 collectd
/etc/init.d/collectd restart

[/codesyntax]

not accepting anymore

How to install Nagios Grapher on debian squeeze

In case you don't have nagios installed, you need to install it as described here

After installing nagios, please install the following packages:
[codesyntax lang="bash"]

apt-get install autoconf rrdtool perl perl-base perl-modules libcalendar-simple-perl libgd-gd2-perl perlmagick librrds-perl liburi-perl

[/codesyntax]

Download Nagios Grapher source code:
[codesyntax lang="bash"]

wget -c http://downloads.sourceforge.net/project/nagiosgrapher/nagiosgrapher/NagiosGrapher-1.7.1/NagiosGrapher-1.7.1.tar.gz

[/codesyntax]

Extract the archive
[codesyntax lang="bash"]

tar xfvz NagiosGrapher-1.7.1.tar.gz

[/codesyntax]

Run the NagiosGrapher configure script
[codesyntax lang="bash"]

cd NagiosGrapher-1.7.1
autoconf
./configure

[/codesyntax]

Check the output
checking for a BSD-compatible install... /usr/bin/install -c
checking for gawk... no
checking for mawk... mawk
checking for perl... /usr/bin/perl
checking distribution... found debian
checking for layout... debian
checking layout: directory prefix... set to '/usr/local/nagios'
checking for init_scripts/nagios_grapher.debian... yes
checking if user www-data exists... found
checking if group www-data exists... found
configure: creating ./config.status
config.status: creating Makefile
config.status: creating bin/collect2.pl
config.status: creating bin/fifo_write.pl
config.status: creating lib/NagiosGrapher.pm
config.status: creating lib/NagiosGrapher/HTML.pm
config.status: creating lib/NagiosGrapher/Hooks/Generic.pm
config.status: creating lib/NagiosGrapher/Hooks/SrvExtWriteHostextInfo.pm
config.status: creating sbin/graphs.cgi
config.status: creating sbin/rrd2-graph.cgi
config.status: creating sbin/rrd2-system.cgi
config.status: creating nagios_grapher
config.status: creating cfg/ngraph.ncfg
config.status: creating cfg/logrotate/nagios_grapher

The important options are distribution, layout, directory prefix and init_scripts
checking distribution... found debian
checking for layout... debian
checking layout: directory prefix... set to '/usr/local/nagios'
checking for init_scripts/nagios_grapher.debian... yes

Checking the required perl-libs
[codesyntax lang="bash"]

make testdeps

[/codesyntax]

/usr/bin/perl ./tools/testdeps.pl
Checking Data::Dumper ... found
Checking File::Copy ... found
Checking File::Basename ... found
Checking Carp ... found
Checking POSIX ... found
Checking Time::HiRes ... found
Checking Time::Local ... found
Checking Storable ... found
Checking GD ... found
Checking Image::Magick ... found
Checking RRDs ... found
Checking CGI ... found
Checking CGI::Carp ... found
Checking IO::Handle ... found
Checking URI::Escape ... found
Checking Calendar::Simple ... found

If you have a not found you can install the required perl modules with CPAN, or your distributions software management system.

Installing the NagiosGrapher
[codesyntax lang="bash"]

make install

[/codesyntax]

Source: https://www.monitoringexchange.org/wiki/HowTos:BestPractice:NagiosGrapher

How to install nagios3 from source on debian squeeze

1. First we will need to install the prereq’s by running:
[codesyntax lang="bash"]

apt-get install apache2 build-essential libgd2-xpm-dev libperl-dev openssl gcc make autoconf automake mailutils libssl-dev libmysqld-dev libmysqlclient-dev libldap2-dev libradiusclient-ng-dev libapache2-mod-php5 libsnmp-perl nfs-common nfs-kernel-server libnet-dns-perl libnet-snmp-perl libdbi-perl libapache2-request-perl libdbd-mysql-perl libcrypt-ssleay-perl mysql-client libnet-tftp-perl snmp

[/codesyntax]

2. Adding the Nagios user:
[codesyntax lang="bash"]

groupadd -g 9000 nagios && groupadd -g 9001 nagcmd && useradd -u 9000 -g nagios -G nagcmd -d /usr/local/nagios -c "Nagios User" nagios

[/codesyntax]

3. Download Nagios and Nagios plugins:
[codesyntax lang="bash"]

wget -c http://downloads.sourceforge.net/project/nagios/nagios-3.x/nagios-3.5.0/nagios-3.5.0.tar.gz
wget -c http://downloads.sourceforge.net/project/nagiosplug/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz

[/codesyntax]

4. Untar the archives:
[codesyntax lang="bash"]

tar xfvz nagios-3.5.0.tar.gz
tar xfvz nagios-plugins-1.4.16.tar.gz

[/codesyntax]

5. Compile Nagios
[codesyntax lang="bash"]

cd nagios
./configure --enable-nanosleep --enable-embedded-perl --with-command-group=nagcmd --with-gd-lib=/usr/lib --with-gd-inc=/usr/include

make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
cd ..

[/codesyntax]
6. Compile Nagios plugins:
[codesyntax lang="bash"]

cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
cd ..

[/codesyntax]
7. Add nagiosadmin user to the apache2
[codesyntax lang="bash"]

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

[/codesyntax]

8. Restart apache2 webserver
[codesyntax lang="bash"]

/etc/init.d/apache2 restart

[/codesyntax]

9. Add www-data user to nagcmd group

[codesyntax lang="bash"]

usermod -a -G nagcmd www-data

[/codesyntax]

10. Install nrpe server

[codesyntax lang="bash"]

wget -c http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz
tar xfvz nrpe-2.14.tar.gz
cd nrpe-2.14
./configure --enable-command-args
make all
make install
cp init-script.debian /etc/init.d/nrpe-server
chmod 755 /etc/init.d/nrpe-server

[/codesyntax]

11. Configure nrpe server

[codesyntax lang="bash"]

cp -a sample-config/nrpe.cfg /usr/local/nagios/etc/

[/codesyntax]

12. Start services

[codesyntax lang="bash"]

/etc/init.d/nagios start
/etc/init.d/nrpe-server start

[/codesyntax]

Troubleshooting

If you get something like bellow:

Error: Could not stat() command file ‘/usr/local/nagios/var/rw/nagios.cmd’!
The external command file may be missing, Nagios may not be running, and/or Nagios may not be checking external commands.
An error occurred while attempting to commit your command for processing.

Return from whence you came

Just do the following:

[codesyntax lang="bash"]

ls -l /usr/local/nagios/var/rw/nagios.cmd

[/codesyntax]
prw-rw---- 1 nagios nagios 0 Aug 11 22:27 /usr/local/nagios/var/rw/nagios.cmd

[codesyntax lang="bash"]

chmod -R g+x /usr/local/nagios/var/rw
ls -l /usr/local/nagios/rw/nagios.cmd

[/codesyntax]
prw-rwx--- 1 nagios nagios 0 Aug 11 22:27 /usr/local/nagios/var/rw/nagios.cmd

[codesyntax lang="bash"]

/etc/init.d/nagios restart

[/codesyntax]

Also change group of the file
[codesyntax lang="bash"]

ls -l /usr/local/nagios/var/rw/nagios.cmd

[/codesyntax]
prw-rw---- 1 nagios nagios 0 Aug 11 22:27 /usr/local/nagios/var/rw/nagios.cmd

[codesyntax lang="bash"]

chown nagios:www-data /usr/local/nagios/var/rw/nagios.cmd

[/codesyntax]

And also, you may need to do the following and restart apache afterwards (I am pretty sure that you skipped by accident the step 9)
[codesyntax lang="bash"]

usermod -G nagios www-data
/etc/init.d/apache2 restart

[/codesyntax]