SNMP Monitoring using Nagios

Nagios is very good and commonly used monitoring tool for systems and network equipments. It can monitor and report availability statistics as well as provide alerts in case of host or service incidents. I am going to discuss on how to use the SNMP capabilities of Nagios and GNU/Linux to enable monitoring without special agents installed on the hosts.

Usually, Nagios will need you to install NRPE addons to report disk space and so many other updates about the system that need to be monitored. This needs you to install additional software on the target machines which is not always possible/recommended practice. Instead, we are going to use the SNMP software that comes as part of the GNU/Linux OS to provide information for Nagios. I am not going to brief about how to install Nagios and Plugins. You could read that in a beautiful how-to here : http://nagios.sourceforge.net/docs/3_0/quickstart-ubuntu.html

There are two steps in enabling SNMP Monitoring.

Configure SNMP in the host to be monitored.

  • Edit /etc/snmp/snmpd.conf and add one line. ( rocommunity public )
  • Restart snmpd service ( sudo /etc/init.d/snmpd restart )

Configure Nagios to check free RAM in the host via SNMP .
First, add a host entry like this to your .cfg file.

define host {
use linux-server
host_name linuxserver01
alias MyLinuxServer
address 192.168.1.24
}

Now we will add a service to check free RAM

define service{
use generic-service
host_name linuxserver01
service_description Free RAM
check_command snmp_freeram_linux
}

Next, we will define the snmp_freeram_linux command to use snmp_check plugin that comes as part of Nagios Plugins installation.

define command{
command_name  snmp_freeram_linux
command_line /usr/local/nagios/libexec/check_snmp -H $HOSTNAME$ -C public -o .1.3.6.1.4.1.2021.4.11.0
}

After this, restart Nagios. ( sudo /etc/init.d/nagios restart )

You should be now able to see a new service added to host and SNMP getting the data. With some efforts, you would be able to configure SNMP for other operating systems and network equipments too. If you have queries, please let me know. πŸ™‚

Making Ubuntu Better !

Here’s a few things I do just after installing Ubuntu Linux. While this step is not mandatory, it sure makes a lot of good additions to the experience. With these few simple commands, your new Ubuntu system will get lot of additional things that is going to make it feature packed, shinier and a pleasure to use.

Before we start
Having a internet connection is necessary to do these tricks. Before we start, update your system by running the following commands one by one.

sudo apt-get update 
sudo apt-get upgrade

Multimedia
Adding VLC Player, Lots of different codecs for playing variety of Media formats like MP3, MP4 etc is so easy. This command will also install some of the fonts used commonly in Microsoft Office Documents for compatibility. avidemux is a simple but capable Video Editor.

sudo apt-get install vlc ubuntu-restricted-extras avidemux

Graphics Applications
Scribus is a Desktop Publishing Software. InkScape is a Vector Graphics application just like Corel Draw. Gimp could compete well with Photoshop.

sudo apt-get install gimp scribus inkscape

Windows Programs
You want to run Windows Programs in Ubuntu ? Sure. Let’s install Wine. After installing wine, you could just double click any .exe files just like you did earlier to run them. You could even install Windows Software packages on Ubuntu. They will appear under Applications -> Wine -> Programs Menu after installation.

sudo apt-get install wine

Sun Java Support
If any of your programs are not running because Sun Java is not installed or the OpenJDK is not able to run them, install Sun Java.

sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts

Skype, Acrobat Reader, Flash and lot more..
You want to customize it further and add lots of more softwares like Skype, Acrobat Reader, Google Chrome and much more ? Install Ubuntu Tweak. Download the package and double click on the file to install. Once installed, this tool appears under the Applications menu. There are a huge number of things you could do with this very handy application. For example, if you dont like the “close” button on the left side of your windows, this tool will help you to change it back to the right corner..

For GUI Lovers
All the above apt-get commands can be done via GUI using applications -> software center. Just search for the package name and click install. Like I always say, it’s all about choice. πŸ™‚

Side Note : Some of these commands actually makes you install non-open-source applications or libraries to your system. You have been warned. πŸ™‚

MySQL Database : Quick & Easy Backup / Restore

MySQL is a great Open Source Software that is easy to setup and manage. It is available for both Windows and Unix/Linux Operating Systems ( and many others) . If you are using MySQL, here is a quick and easy way to backup and restore your MySQL databases.

This time, we are going to discuss about backup and restore using command line utilities. If you want a GUI to do this, you might as well read about the famous MySQL web administration tool, phpMyAdmin. For me, both are useful and I use them as per my convenience. This article assumes that you have shell access to MySQL server or at least remote access using mysql client from your computer to a MySQL DB Server.

Backing up the DB
We could use the mysqldump command like the one below :

For a full backup of all DBs :

 $ mysqldump  --all-databases > backup.sql 

Creating backup of a single DB:

 $ mysqldump  my_db_name > backup.sql 

This will create a text file with all data and structure of the DB. Remember, this is a quick and dirty way to do this, there are many options available to this command.

Creating backup of a single DB and using your password to login :

 $ mysqldump  --password=mypassword my_db_name > backup.sql 

For more examples and available options, run the command man mysqldump. You may also need to encrypt the backup.sql for security.

Restoring the DB
Restoring also is pretty easy. We could use the mysql command like the one below :

Run this command from where the backup.sql file is stored.

 $ mysql my_db_name < backup .sql 

Side Note : If you have shell access, you could add a cron job for running the backup command on every night or so. :)

wget & shell scripting for automated downloads

GNU Logo - OpenSouceMy friend Leo came up with this interesting problem. He found a site where a lot of religious videos are hosted for free and he wanted to download them all. The problem is, that the site has a navigation system and you need to click 3 times to go to download page of each video. Considering that the site has about 400 videos to download, this seemed a huge task.

I knew that wget can be used for downloading files from web sites. Checking the download links of 2-3 videos revealed that the videos are stored in a particular folder (http://webserver/folder/ ) inside the webserver. The video links were all like : 1.avi , 2.avi, 3.avi and so on. Then it was all just a matter of minutes to write a small shell script. Here is the code :

#!/bin/bash
counter=0
while (($counter < 450 ));
do
echo Downloading Video $counter..
wget http://webserver/folder/$counter.avi
let counter++
done

echo "Done !"

I saved it as download.sh in my Ubuntu Linux machine and ran it using the below command.
rajesh@ubuntubox:~$ ./download.sh

The script took it's time downloading files one after one .We could do parallel downloads, but that will cause trouble for the web site admins, we are nice people you know πŸ™‚ . Open Source saves the day !

Side Note: if you are using windows, you could probably use cygwin to do this in windows. This script is not perfect, but this did the job for us. One can easily use this as a base for developing it further for other tasks.