Nagios: Installing Vshell on Debian Squeeze

27 Mar 2012

As I said in a previous post I want to look into running Nagios on a raspberry pi. The problem I think there might be is that there is a very limited amount of memory we can use (256 MB). So I'm want to run things as light as possible. So I decided to take a look at the Nagios V-Shell. It is a PHP web interface to Nagios Core that is designed to be lightweight and easy to install.

What is V-Shell?

From the Nagios website: Nagios V-Shell is a PHP web interface to Nagios Core that is designed to be lightweight, easy to install and use, and customizable. As of v1.7, V-Shell now has gettext support for internationalization. Version 1.9 has now been overhauled for substantial performance increases. Recommended to use with PHP's APC caching. See INSTALL.txt for more details. So why is it so interesting? In the future I want to run Nagios on a Raspberry Pi. Everything needs to be lightweight, since there are very limited resources on the Raspberry Pi I want the whole setup to be as lightweight as possible. So a lighter alternative for Nagios-core is a big plus. I was looking around and found VShell as a featured program on the Nagios website, so I gave it a go and was quite satisfied.

Installing V-Shell

First of all we need to install php-apc (more on that later):

 sudo apt-get install php-apc

Get the Nagios V-shell here. Look for the download URL. Download it into a temporary folder and unpack it.

wget http://assets.nagios.com/downloads/exchange/nagiosvshell/vshell.tar.gz
tar -zxf vhsell.tar.gz
cd vshell

Now open install.php in your favorite editor and look for these lines:

//target directory where vshell's web files will be stored
define('TARGETDIR',"/usr/local/vshell");
//target directory where your current apache configuration directory is located
define('APACHECONF',"/etc/httpd/conf.d");

Change these two variables to your liking, I changed

/usr/local/vshell

to

/var/www/vshel

. The Apache2 conf.d folder on Debian/Ubuntu is located at

/etc/apache2/conf.d

. So it should look like this:

define('TARGETDIR',"/var/www/vshell");
define('APACHECONF',"/etc/apache2/conf.d");

Make sure the /var/www/vshell exists, otherwise create it with

mkdir /var/www/vshell

. Add execute rights to the install.php script and execute it as root:

chmod +x install.php
sudo ./install.php

For some reason the vhost isn't correctly made by the install script, so if you changed the TARGETDIR variable, have a look at

/etc/apache2/conf.d/vshell.conf

You will notice that they are still using /usr/local/vshell change it to your directory. So change it to the right directory manually. Also look at this line:

AuthUserFile /usr/local/nagios/etc/htpasswd.users

You have to change the location to where your htpasswd.users resides on your system. Mine is located at:

/etc/nagios3/htpasswd.users

Changing Vshell config to Debian's

I installed Nagios through the repositories as you can see here. Now Vshell's default config has different parameters because it's meant for CentOS. So I made this /etc/vshell.conf:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;                                                            ;;;;;;;;;;
;;;;;;;;;;             Nagios V-Shell Configuration File              ;;;;;;;;;;
;;;;;;;;;;                                                            ;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; The Apache URL path to V-Shell.
; If you want to access V-Shell in the browser at http://<yourserver>/vshell/,
; then set this to "vshell".
BASEURL = "vshell"
; The Apache URL path to your Nagios Core installation
; If you access Nagios by visiting http://<yourserver>/nagios/,
; then set this to "nagios".
COREURL = "nagios3"
; Full filesystem path to the Nagios status file
STATUSFILE = "/var/cache/nagios3/status.dat"
; Full filesystem path to the Nagios object cache file
OBJECTSFILE = "/var/cache/nagios3/objects.cache"
; Full filesystem path to the Nagios CGI permissions configuration file
CGICFG = "/etc/nagios3/cgi.cfg"
; Full filesystem path to the Nagios command pipe
NAGCMD = "/var/lib/nagios3/rw/nagios.cmd"
; Full filesystem path to the Nagios lock file (when Nagios is running)
NAGLOCK = "/var/run/nagios3/nagios3.pid"
; The default number of maximum results to display in a table before paging
RESULTLIMIT= 100
;Language Set:  usually these options are located in the /usr/lib/locale directory
; currently only UTF-8 languages supported
LANG = "en_GB"
;Max Time To Live for APC cached data.  If you're using APC caching, this setting
; controls the length of time status data will be cached before reading fresh from
; the status file
TTL = 90

Now you should be able to access the site at example.com/vshell.

PHP APC

You've noticed there is an APC option. PHP is an interpreted language, APC is made to cache the results of interpreting a script and reusing them in feature requests. It speeds up a website a lot.

Final Word

I like Vshell a lot, when it works. I noticed that some of the paths are using a BASEURL and for some reason I couldn't get the

$_SERVER['SERVER_NAME']

working properly, so it always did a backfall to my IP. The problem is that my site was being hosted behind a proxy, so it has a LAN IP. Therefor breaking the whole site (I fixed this by hardcoding my FQDN, but that's not really flexible). If you are not in this situation and your server is just IP accessible, there will be no problem. Hopefully I can get my hands on a Raspberry Pi soon enough to start fiddling around with it.