Nagios Network Monitoring System Setup in Ubuntu

July 22, 2008

Nagios is a host and service monitor designed to inform you of network problems before your clients, end-users or managers do. It has been designed to run under the Linux operating system, but works fine under most *NIX variants as well. The monitoring daemon runs intermittent checks on hosts and services you specify using external “plugins” which return status information to Nagios. When problems are encountered, the daemon can send notifications out to administrative contacts in a variety of different ways (email, instant message, SMS, etc.). Current status information, historical logs, and reports can all be accessed via a web browser.

WARNING: “this tutorial is meant for users that have a good knowledge of development tools and manual installation process and will be hardly supported by the Ubuntu community. Standard supported procedure are to install packages from the official repositories, not to compile them by hand”.

Install Nagios in Ubuntu

This Tutorial is intended to provide you with simple instructions on how to install Nagios from source (code) on Ubuntu and have it monitoring your local machine inside of 20 minutes.

If you follow these instructions, here’s what you’ll end up with:

Nagios and the plugins will be installed underneath /usr/local/nagios

Nagios will be configured to monitor a few aspects of your local system (CPU load, disk usage, etc.)

The Nagios web interface will be accessible at http://localhost/nagios/

Required Packages

Make sure you’ve installed the following packages on your Ubuntu installation before continuing.

Apache 2
GCC compiler and development libraries
GD development libraries

Preparing Your System

First you need to install the following packages

sudo apt-get install apache2

sudo apt-get install build-essential

sudo apt-get install libgd2-xpm-dev

1) Create Account Information

Become the root user.

sudo -s

Create a new nagios user account and give it a password.

#/usr/sbin/useradd nagios

#passwd nagios

On Ubuntu server edition , you will need to also add a nagios group (it’s not created by default). You should be able to skip this step on desktop editions of Ubuntu.

#/usr/sbin/groupadd nagios

#/usr/sbin/usermod -G nagios nagios

Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.

#/usr/sbin/groupadd nagcmd

#/usr/sbin/usermod -G nagcmd nagios

#/usr/sbin/usermod -G nagcmd www-data

2) Download Nagios and the Plugins

Create a directory for storing the downloads.

#mkdir ~/downloads

#cd ~/downloads

Download the source code tarballs of both Nagios and the Nagios plugins (visit http://www.nagios.org/download/ for links to the latest versions). At the time of writing, the latest versions of Nagios and the Nagios plugins were 2.10 and 1.4.10, respectively.

#wget http://switch.dl.sourceforge.net/sourceforge/nagios/nagios-2.10.tar.gz

#wget http://kent.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.10.tar.gz

3) Compile and Install Nagios

Extract the Nagios source code tarball.

#cd ~/downloads

#tar xzf nagios-2.10.tar.gz

#cd nagios-2.10

Run the Nagios configure script, passing the name of the group you created earlier like so:

#./configure --with-command-group=nagcmd

Compile the Nagios source code.

#make all

Install binaries, init script, sample config files and set permissions on the external command directory.

#make install

#make install-init

#make install-config

#make install-commandmode

Don’t start Nagios yet – there’s still more that needs to be done…

4) Customize Configuration

Sample configuration files have now been installed in the /usr/local/nagios/etc directory. These sample files should work fine for getting started with Nagios. You’ll need to make just one change before you proceed…

Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you’d like to use for receiving alerts.

#vi /usr/local/nagios/etc/objects/contacts.cfg

5) Configure the Web Interface

Install the Nagios web config file in the Apache conf.d directory.

#make install-webconf

Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account – you’ll need it later.

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

Restart Apache to make the new settings take effect.

#/etc/init.d/apache2 reload

6) Compile and Install the Nagios Plugins

Extract the Nagios plugins source code tarball.

#cd ~/downloads

#tar xzf nagios-plugins-1.4.10.tar.gz

#cd nagios-plugins-1.4.10

Compile and install the plugins.

#./configure --with-nagios-user=nagios --with-nagios-group=nagios

#make

#make install

7) Start Nagios

Configure Nagios to automatically start when the system boots.

#ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

Verify the sample Nagios configuration files.

#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If there are no errors, start Nagios.

#/etc/init.d/nagios start

8) Login to the Web Interface

You should now be able to access the Nagios web interface at the URL below. You’ll be prompted for the username (nagiosadmin) and password you specified earlier.

http://localhost/nagios/

Click on the “Service Detail” navbar link to see details of what’s being monitored on your local machine. It will take a few minutes for Nagios to check all the services associated with your machine, as the checks are spread out over time.

9) Other Modifications

If you want to receive email notifications for Nagios alerts, you need to install the mailx (Postfix) package.

#apt-get install mailx

You’ll have to edit the Nagios email notification commands found in /usr/local/nagios/etc/commands.cfg and change any ‘/bin/mail’ references to ‘/usr/bin/mail’. Once you do that you’ll need to restart Nagios to make the configuration changes live.

#/etc/init.d/nagios restart


Ubuntu Linux + Apache2 + Virtual Hosts + Syslog Server

July 22, 2008

This tutorial will explain How to install syslog server in ubuntu using apache. Steps Involved in this tutorial
1) Install Apache2 and change the ports
2) Virtual Hosts: an example
3) Syslog Server with php and Virtual Hosts
4) Only me wants to see the log files (by using a .htacces file)

Local static ip address

Imagine yourself that eth0 is your internet interface and you want 192.168.0.102 as your local ip address. Change the /etc/network/interface file and save it. This is an excellent example then:

auto eth0
iface eth0 inet static
address 192.168.0.102
netmask 255.255.255.0
gateway 192.168.0.1
broadcast 192.168.0.255

Ofcourse you’ll have to modify it for your own needs, the above file is just an example file ofcourse.

Preparing syslog

mkdir /logs (let’s make a directory for our logs) Modify /etc/syslog.conf and add the next rule if you really would like to log everything: (don’t forget to save it) *.* /logs/logger.log

It’s possible you’re only interessed in a few things, here is the list:

auth – authentication (login) messages
cron – messages from the memory-resident scheduler
daemon – messages from resident daemons
kern – kernel messages
lpr – printer messages (used by JetDirect cards)
mail – messages from Sendmail
user – messages from user-initiated processes/apps
local0-local7 – user-defined (see below)
syslog – messages from the syslog process itself

0 – Emergency (emerg)
1 – Alerts (alert)
2 – Critical (crit)
3 – Errors (err)
4 – Warnings (warn)
5 – Notification (notice)
6 – Information (info)
7 – Debug (debug)

Would you like to log everything from auth, cron, lpr error and only syslogs warnings then you have to add next lines to /etc/syslog.conf

auth.* /logs/logger.log
cron.* /logs/logger.log
kern.* /logs/logger.log
lpr.3 /logs/logger.log
syslog.4 /logs/logger.log

Now modify /etc/init.d/ksyslogd with your favourite editor and do the next:

SYSLOGD=”” Change this line by the next line and save:
SYSLOGD=”-r -m0”

restart networking again: /etc/init.d/networking restart

Install Apache2 and stuff:

apt-get install apache2 php5 libapache2-mod-php5 mysql-server mysql-client

php5-mysql

Check cat /etc/hostname, and the hostname that you are seeing here you have to

place in your /etc/hosts file, together with your local static ip address. /etc/hosts:
192.168.0.102 myhostname Don’t forget to change the above to your own needs! I decided to host on Port 8070, my ISP (Telenet Belgium) has blocked all ports under 1024. Modify /etc/apache2/ports.conf: (Listen 80 must be replaced by Listen 8070)
Listen 8070

If you are behind a NAT, don’t forget to open this port on your router.

Now we’re going to install our virtual hosts. cd /etc/apache2/sites-available
touch myname.homelinux.com (we create our name)
Now edit your myname.homelinux.com file with your favorite editor and make sure it looks like this:

ServerAdmin you@mail.com
ServerName myname.homelinux.com
ServerAlias myname.homelinux.com
DirectoryIndex index.php
DocumentRoot /logs

Ok, now we’re going to etc/apache2/sites-enabled

cd /etc/apache2/sites-enabled
ln -s /etc/apache2/sites-available/myname.homelinux.com myname.homelinux.com This symbolic link (ln -s) is absolutely necessary. Ok, now we’re going to our logs directory and we place there an index.php file cd /logs
touch index.php
Modify index.php now with your favorite editor. This is how it should look like:

Restart apache: /etc/init.d/apache2 force-reload

Ok, go to www.dyndns.com and www.whatsmyip.org (memorize your ip)
And on dyndns you registrate yourself, you log in, then click DNS services ->

dynamic DNS -> Add Host -> and you registrate myname.homelinux.com.

Mention your remote IP (what you saw at whatsmyip.org at the ip line)

If you visit now your myname.homelinux.com/:8070 webpage you will be able to see your syslogs!

4) Only me wants to see the log files (by using a .htacces file)

Now we take measures: Only you will have the possibility to see your syslogs.

cd /logs (Yes we go again to the /logs directory)
touch .htaccess (We’ll make an .htaccess file)
Modify .htaccess with your favorite editor. This is how your .htaccess file should look like:

AuthUserFile /root/.htpasswd
AuthName ‘Access is limited here’
AuthType basic
require valid-user

cd /root (go to the /root directory)
htpasswd -c .htpasswd webmaster (let’s make a valid account)

Now modify the /etc/apache2/sites-available/default file with your favorite editor:

DocumentRoot /var/www

Options FollowSymLinks
AllowOverride None

Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2’s
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/

This AllowOverride all tells apache2 it has to deal with a .htaccess file.
Restart apache2 again: /etc/init.d/apache2 force-reload

Go to your site now, you’ll have to give a password that you’ve specified.

Conclusion

Now you have a syslog server that’s using the virtual host technique on apache2. And only you is able to read the information, caused by the .htaccess file.


Update IP addresses at dynamic DNS services Using ddclient

July 22, 2008

If you are using zoneedit.com or dyndns.org for your DNS service so that you can access your server using a URL, then you might have to update your DNS record at the service periodically whenever the IP address of your computer changes.Now here is simple solution for this ddclient.

Update IP addresses at dynamic DNS services.A perl based client to update your dynamic IP address at DynDNS.com (or other dynamic DNS services such as Hammernode, Zoneedit or EasyDNS), thus allowing you and others to use a fixed hostname (myhost.dyndns.org) to access your machine. This client supports both the dynamic and (near) static services, MX setting, and alternative host. It caches the address, and only attempts the update if the address actually changes.

Install ddclient in ubuntu

sudo aptitude install ddclient

This will complete the installation

Configuring ddclient

If you want to reconfigure you seetings use the following command

dpkg-reconfigure ddclient

You want to make sure it runs as a service and monitors changes in ppp–something that the install wizard doesn’t cover.

Edit the configuration file /etc/ddclient.conf

sudo gedit /etc/ddclient.conf

# Configuration file for ddclient generated by debconf
#
# /etc/ddclient.conf
pid=/var/run/ddclient.pid
protocol=easydns
use=web
server=members.easydns.com
login=yournamehere
password=’password’
*.your.domain

If you can’t find the public IP address, then you can have ddclient check your public IP address from the web by editing /etc/ddclient.conf and making it use the web by saying

use=web

or

use=web, web=checkip.dyndns.org/, web-skip=’IP Address’

Save and exit the file

Restart ddclient service using the following command

sudo /etc/init.d/ddclient restart


Ubuntu Networking Configuration Using Command Line

July 22, 2008

The basics for any network based on *nix hosts is the Transport Control Protocol/ Internet Protocol (TCP/IP) combination of three protocols. This combination consists of the Internet Protocol (IP),Transport Control Protocol (TCP), and Universal Datagram Protocol (UDP).

By Default most of the users configure their network card during the installation of Ubuntu. You can however, use the ifconfig command at the shell prompt or Ubuntu’s graphical network configuration tools, such as network-admin, to edit your system’s network device information or to add or remove network devices on your system

Configure Network Interface Using Command-Line

You can configure a network interface from the command line using the networking utilities. You configure your network client hosts with the command line by using commands to change your current settings or by editing a number of system files.

Configuring DHCP address for your network card

If you want to configure DHCP address you need to edit the /etc/network/interfaces and you need to enter the following lines replace eth0 with your network interface card

sudo vi /etc/network/interfaces

# The primary network interface – use DHCP to find our address
auto eth0
iface eth0 inet dhcp

Configuring Static IP address for your network card

If you want to configure Static IP address you need to edit the /etc/network/interfaces and you need to enter the following lines replace eth0 with your network interface card

sudo vi /etc/network/interfaces

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.3.90
gateway 192.168.3.1
netmask 255.255.255.0
network 192.168.3.0
broadcast 192.168.3.255

After entering all the details you need to restart networking services using the following command

sudo /etc/init.d/networking restart

Setting up Second IP address or Virtual IP address in Ubuntu

If you are a server system administrator or normal user some time you need to assign a second ipaddress to your Ubuntu machine.For this you need to edit the /etc/network/interfaces file and you need to add the following syntax.Below one is the only example you need to chnage according to your ip address settings

sudo vi /etc/network/interfaces

auto eth0:1
iface eth0:1 inet static
address 192.168.1.60
netmask 255.255.255.0
network x.x.x.x
broadcast x.x.x.x
gateway x.x.x.x

You need to enter all the details like address,netmask,network,broadcast and gateways values after entering all the values save this file and you need to restart networking services in debian using the following command to take effect of our new ipaddress.

After entering all the details you need to restart networking services using the following command

sudo /etc/init.d/networking restart

Setting your ubuntu stytem hostname

Setting up your hostname upon a ubuntu installation is very straightforward. You can directly query, or set, the hostname with the hostname command.

As an user you can see your current hostname with

sudo /bin/hostname

Example

To set the hostname directly you can become root and run

sudo /bin/hostname newname

When your system boots it will automatically read the hostname from the file /etc/hostname

If you want to know more about how to setup host name check here

Setting up DNS

When it comes to DNS setup Ubuntu doesn’t differ from other distributions. You can add hostname and IP addresses to the file /etc/hosts for static lookups.

To cause your machine to consult with a particular server for name lookups you simply add their addresses to /etc/resolv.conf.

For example a machine which should perform lookups from the DNS server at IP address 192.168.3.2 would have a resolv.conf file looking like this

sudo vi /etc/resolv.conf

enter the following details

search test.com
nameserver 192.168.3.2


XML Introduction

July 21, 2008

What is XML?

XML is a markup language for documents containing structured information.

Structured information contains both content (words, pictures, etc.) and some indication of what role that content plays (for example, content in a section heading has a different meaning from content in a footnote, which means something different than content in a figure caption or content in a database table, etc.). Almost all documents have some structure.

A markup language is a mechanism to identify structures in a document. The XML specification defines a standard way to add markup to documents.

What’s a Document?

The number of applications currently being developed that are based on, or make use of, XML documents is truly amazing (particularly when you consider that XML is not yet a year old)! For our purposes, the word “document” refers not only to traditional documents, like this one, but also to the myriad of other XML “data formats”. These include vector graphics, e-commerce transactions, mathematical equations, object meta-data, server APIs, and a thousand other kinds of structured information.

So XML is Just Like HTML?

No. In HTML, both the tag semantics and the tag set are fixed. An <h1> is always a first level heading and the tag <ati.product.code> is meaningless. The W3C, in conjunction with browser vendors and the WWW community, is constantly working to extend the definition of HTML to allow new tags to keep pace with changing technology and to bring variations in presentation (stylesheets) to the Web. However, these changes are always rigidly confined by what the browser vendors have implemented and by the fact that backward compatibility is paramount. And for people who want to disseminate information widely, features supported by only the latest releases of Netscape and Internet Explorer are not useful.

XML specifies neither semantics nor a tag set. In fact XML is really a meta-language for describing markup languages. In other words, XML provides a facility to define tags and the structural relationships between them. Since there’s no predefined tag set, there can’t be any preconceived semantics. All of the semantics of an XML document will either be defined by the applications that process them or by stylesheets.

So XML Is Just Like SGML?

No. Well, yes, sort of. XML is defined as an application profile of SGML. SGML is the Standard Generalized Markup Language defined by ISO 8879. SGML has been the standard, vendor-independent way to maintain repositories of structured documentation for more than a decade, but it is not well suited to serving documents over the web (for a number of technical reasons beyond the scope of this article). Defining XML as an application profile of SGML means that any fully conformant SGML system will be able to read XML documents. However, using and understanding XML documents does not require a system that is capable of understanding the full generality of SGML. XML is, roughly speaking, a restricted form of SGML.

For technical purists, it’s important to note that there may also be subtle differences between documents as understood by XML systems and those same documents as understood by SGML systems. In particular, treatment of white space immediately adjacent to tags may be different.

Why XML?

In order to appreciate XML, it is important to understand why it was created. XML was created so that richly structured documents could be used over the web. The only viable alternatives, HTML and SGML, are not practical for this purpose.

HTML, as we’ve already discussed, comes bound with a set of semantics and does not provide arbitrary structure.

SGML provides arbitrary structure, but is too difficult to implement just for a web browser. Full SGML systems solve large, complex problems that justify their expense. Viewing structured documents sent over the web rarely carries such justification.

This is not to say that XML can be expected to completely replace SGML. While XML is being designed to deliver structured content over the web, some of the very features it lacks to make this practical, make SGML a more satisfactory solution for the creation and long-time storage of complex documents. In many organizations, filtering SGML to XML will be the standard procedure for web delivery.

XML Development Goals

The XML specification sets out the following goals for XML: [Section 1.1] (In this article, citations of the form [Section 1.1], these are references to the W3C Recommendation Extensible Markup Language (XML) 1.0. If you are interested in more technical detail about a particular topic, please consult the specification)

  1. It shall be straightforward to use XML over the Internet. Users must be able to view XML documents as quickly and easily as HTML documents. In practice, this will only be possible when XML browsers are as robust and widely available as HTML browsers, but the principle remains.
  2. XML shall support a wide variety of applications. XML should be beneficial to a wide variety of diverse applications: authoring, browsing, content analysis, etc. Although the initial focus is on serving structured documents over the web, it is not meant to narrowly define XML.
  3. XML shall be compatible with SGML. Most of the people involved in the XML effort come from organizations that have a large, in some cases staggering, amount of material in SGML. XML was designed pragmatically, to be compatible with existing standards while solving the relatively new problem of sending richly structured documents over the web.
  4. It shall be easy to write programs that process XML documents. The colloquial way of expressing this goal while the spec was being developed was that it ought to take about two weeks for a competent computer science graduate student to build a program that can process XML documents.
  5. The number of optional features in XML is to be kept to an absolute minimum, ideally zero. Optional features inevitably raise compatibility problems when users want to share documents and sometimes lead to confusion and frustration.
  6. XML documents should be human-legible and reasonably clear. If you don’t have an XML browser and you’ve received a hunk of XML from somewhere, you ought to be able to look at it in your favorite text editor and actually figure out what the content means.
  7. The XML design should be prepared quickly. Standards efforts are notoriously slow. XML was needed immediately and was developed as quickly as possible.
  8. The design of XML shall be formal and concise. In many ways a corollary to rule 4, it essentially means that XML must be expressed in EBNF and must be amenable to modern compiler tools and techniques.
    There are a number of technical reasons why the SGML grammar cannot be expressed in EBNF. Writing a proper SGML parser requires handling a variety of rarely used and difficult to parse language features. XML does not.
  9. XML documents shall be easy to create. Although there will eventually be sophisticated editors to create and edit XML content, they won’t appear immediately. In the interim, it must be possible to create XML documents in other ways: directly in a text editor, with simple shell and Perl scripts, etc.
  10. Terseness in XML markup is of minimal importance. Several SGML language features were designed to minimize the amount of typing required to manually key in SGML documents. These features are not supported in XML. From an abstract point of view, these documents are indistinguishable from their more fully specified forms, but supporting these features adds a considerable burden to the SGML parser (or the person writing it, anyway). In addition, most modern editors offer better facilities to define shortcuts when entering text.

How Is XML Defined?

XML is defined by a number of related specifications:

Extensible Markup Language (XML) 1.0
Defines the syntax of XML. The XML specification is the primary focus of this article.
XML Pointer Language (XPointer) and XML Linking Language (XLink)
Defines a standard way to represent links between resources. In addition to simple links, like HTML’s <A> tag, XML has mechanisms for links between multiple resources and links between read-only resources. XPointer describes how to address a resource, XLink describes how to associate two or more resources.
Extensible Style Language (XSL)
Defines the standard stylesheet language for XML.

As time goes on, additional requirements will be addressed by other specifications. Currently (Sep, 1998), namespaces (dealing with tags from multiple tag sets), a query language (finding out what’s in a document or a collection of documents), and a schema language (describing the relationships between tags, DTDs in XML) are all being actively pursued.

Understanding the Specs

For the most part, reading and understanding the XML specifications does not require extensive knowledge of SGML or any of the related technologies.

One topic that may be new is the use of EBNF to describe the syntax of XML. Please consult the discussion of EBNF in the appendix of this article for a detailed description of how this grammar works.