Setup Nagios 3 with lighttpd on your VPS

There are countless tools and software stacks out there to monitor your servers out, though some are not the easiest to setup. I went with Nagios since it's straightforward to configure and easy to setup. For reference, I used Nagios 4.0.8 on Debian 7 using Debian 7 slaves. The Nagios master node already had lighttpd and PHP set up so I'll gloss over that.

Master node

Start by downloading Nagios and Nagios plugins:




Extract, compile and install Nagios:

tar xzf nagios-4.0.8.tar.gz
cd nagios-4.0.8
sudo make all
sudo make install
sudo make install-init
sudo make install-config
sudo make install-commandmode

Extract, compile and install Nagios plugins

tar xzf nagios-plugins-2.0.3.tar.gz
cd nagios-plugins-2.0.3

sudo make
sudo make install

Everything should install nicely, with the config residing in /usr/local/nagios/etc/. Next we'll have to create a user with a password so we can login to Nagios:

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


If you have a working mail server setup, edit /usr/local/nagios/etc/objects/contacts.cfg and change email to receive email alerts.

Now onto lighttpd configuration. You'll have to add the "mod_alias", "mod_auth", "mod_setenv" and "mod_cgi" to your server.modules in lighttpd.conf. Next we'll add the proper aliases and allow us to authenticate.

alias.url  += ("/nagios/cgi-bin" => "/usr/local/nagios/sbin")
alias.url  += ("/nagios/stylesheets" => "/usr/local/nagios/share/stylesheets")
alias.url  += ("/nagios" => "/usr/local/nagios/share")

$HTTP["url"] =~ "^/nagios/cgi-bin" {
        cgi.assign = ( "" => "" )
$HTTP["url"] =~ "nagios" {
  auth.backend = "htpasswd"
  auth.backend.htpasswd.userfile = "/usr/local/nagios/etc/htpasswd.users"
  auth.require = ( "" => (
    "method" => "basic",
    "realm" => "nagios",
    "require" => "user=nagiosadmin"
setenv.add-environment = ( "REMOTE_USER" => "nagiosadmin" )

Restart lighttpd to check our changes:

sudo /etc/init.d/lighttpd restart

At this point, be sure to check if http://your-server-address/nagios works.

Slave nodes

The nice thing is that once we configure our slave nodes once, we don't have to touch them again (as far as configuration goes really). On each of the nodes:

sudo apt-get install nagios-nrpe-server nagios-plugins

This will install a whack of dependencies, for me it totalled to just over 100MB. Once that is installed, we'll have to add our master node IP to each slave. Edit /etc/nagios/nrpe.cfg, find the following line and add your master node IP address:

allowed_hosts= master.node.ip.address

Once completed, restart nrpe-server

sudo /etc/init.d/nagios-nrpe-server restart

Monitoring configuration

We'll have to tell Nagios where our slave nodes configurations are, so edit /usr/local/nagios/etc/nagios.cfg and uncomment the following line:


Create the directory which will hold our slave nodes

sudo mkdir /usr/local/nagios/etc/servers

The config for the slave nodes is located at /usr/local/nagios/etc/servers/clients.cfg. Fortunately, there are other tutorials that are more in depth than mine regarding monitoring. Currently, I'm using a basic config to see if the slave node is alive, and check for HTTP/SSH. See below for an excerpt:

define host{
use                             linux-server
host_name                       your_fancy_hostname
alias                           your_fancy_hostname
address                         slave.node.ip.address
max_check_attempts              5
check_period                    24x7
notification_interval           30
notification_period             24x7

define service {
        use                             generic-service
        host_name                       your_fancy_hostname
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0
define service {
        use                             generic-service
        host_name                       bonbon
        service_description             HTTP
        check_command                   check_http
        notifications_enabled           0

And of course once we're done making changes, restart Nagios

sudo /etc/init.d/nagios restart
If all is well, you'll end up with something like this:

For me, all I'm looking for is basic application and uptime monitoring. Nagios is quite extensible, having a catalogue of plugins. There is of course more extensive documentation on monitoring configuration as well.


Nimrod language

 I have recently discovered the Nimrod programming language. I usually don't branch out on languages because, well, stuff you don't know can be scary. I'm surprised how easy it is to get going though, it reminds me quite a bit of Python. I put up a test project on Github that fetches the weather for a given location.


Building a distro that almost works

 For the most part, SnackLinux works. I've been having problems with Busybox, so I've made packages for coreutils, binutils, sed, grep and gawk. When compiling anything, I get:

segfault at 0 ip    (null) sp bfdb1cbc error 4 in busybox[8048000+e8000]

or something along the lines of that. I used the newest Buildroot, 2013.11, to create a new toolchain and cross compile uClibc 0.9.33 for SnackLinux. I have yet to recompile Busybox yet, but I'm working on getting gcc natively working on SnackLinux. Once that is completed, I should be able to compile SnackLinux from within SnackLinux.

Getting a terminal IBM Model M to work with PS/2

 I recently bought another IBM Model M (1395660) on eBay the other day, not thinking that it is actually a terminal keyboard. I thought it has a detachable SDL cable like my current Model M (1391401). I was wrong. Turns out it has a non-removable RJ-45 plug instead, thus being a terminal keyboard. Well, aftering some researching, some were able to get it to work by using an ATMega. I was able to find a pinout of the RJ45 plug on the keyboard, and simply just wire it up to a PS/2 cable. Though apparently, the colour of wire for PS/2 is not standardized, which led to testing each pin to see what it does. I cannibalized an old Microsoft keyboard for the cable and was able to hook the wires up straight to each other.

PS/2 cable wires on a breadboard, original connector above.


For this specific PS/2 cable, the pinout is as follows:
IBM -> PS/2 Cable
black -> red         +5V 
red -> white         data 
yellow -> brown  clock
white -> black     ground 
The last wire (next to the white wire) on the breadboard is ground, which I have on the metal body of the keyboard. Thankfully everything mostly works. The "Print" key on the left hand side of the board is somehow F5 and the blank key above it is CTRL+F. Next step is a neat soldering job and it's good to go!

SnackLinux, an intro to building your own distro

 I've spent the last week or two working on SnackLinux, a small Linux distro. I managed to get uClibc in there, as well as tcc, which makes it somewhat useful. The source of it all is there, so you can compile the distro yourself (sans the packages). There are also ISOs which you can download here and fire them up in a virtual machine.

Raspberry Pi as a thin client

 The processor on the Raspberry Pi isn't all that fast, so why not offload it? I have a HP ML350 that is mostly idling, except when I need to use PostgreSQL, so I thought to set it up as a desktop server for my Pi.


I set up a RDP server since it works well with Linux and also Windows. First thing's first, install xrdp and all other dependencies:


apt-get install build-essential libpam0g-dev libssl-dev x11vnc vncviewer fakeroot checkinstall x11vnc xrdp rdesktop


Then, install your desktop of choice. I chose XFCE since it's pretty lightweight

apt-get install xfce4

I've had problems getting it to start X remotely, so I fixed it with the following. Do this in the user's account (/home/pi for example)


touch .Xauthority
chmod 600 .Xauthority

And that's it!. Start up your Raspberry Pi, install rdesktop, and connect to your server:

rdesktop -g 1024x768 -P server_address

NES controller on the Raspberry Pi

Because I wanted the full experience, I wanted to hook up my NES controller to my Raspberry Pi and play NES games. I looked around and didn't find anything that fit my needs.

I wrote a script, that's up on Github now, that converts button presses on the NES controller to keyboard presses. So for example, by pressing the A button it registers as pressing the Z key on a keyboard. How to set it up is all right here.

I spliced the wires on the NES controller (thanks to this diagram) and used a breadboard to connect the appropriate wires to ground, +5V, the data, latch, and clock pin. Now I can play Mario in retroarch with a NES controller!

SNES emulator on the Raspberry Pi

 I won a Raspberry Pi for getting 3rd place in the Open 7400 Logic Competition, of which HubCityLabs donated the Raspberry Pi. My initial project idea for it was to set up a wall mounted weather station. For the time being I thought I'd mess around with it and get somehwhat familiar on what I'm dealing with.


I downloaded the Rasbian image and wrote it to an SD card. It's recommended that the SD card is a minimum of class 4.

Everything is supported 'out of the box' with Rasbian so there's no fiddling around. After purchasing a HDMI cable and connecting it to the Pi, it still output video via the RCA jack instead. I opened up /boot/config.txt and set hdmi_safe=1 and voila, HDMI worked!

To mess around with it, I discovered RetroPie. I picked the "slow" option which compiled all the binaries, rather than get the precompiled binaries. I didn't watch it intesnely, but it seemed to take about an hour. Once that's installed, you can now play SNES, NES, GBA and Atari 2600 games! RetroPie installs the emulators to ~/RetroPie/emulators and all the libraries to ~/RetroPie/emulatorcores. I downloaded Super Mario World and ran:

~/RetroPie/emulators/RetroArch/retroarch -L ~/RetroPie/emulatorcores/pocketsnes-libretro/ path_to_snes_rom.smc


To explain, it uses the RetroArch emulator and the pocketsnes library.

Here's the result:

I don't have a gamepade of any sort, so I just used the keyboard. The letters on the keyboard correspond to the controller (X is X on the controller, A is A, etc...). I had the GPU set to 128MB and it seemed to run fine. I overclocked it another 100Mhz just to see any performance gains, but I didn't notice any and it ran about 5 degrees hotter than stock. 


To get an NES/SNES controller working with it, check out the next post.