Basic Nagios Installation

Home » Computer Articles » Linux » Basic Nagios Installation
May 23, 2008 Linux No Comments

Nagios Server Installation (on CentOS)

Download:
Nagios 3.0.2 (http://www.nagios.org/download/)
Nagios plugins 1.4.11
Pnp 0.3.3 (http://www.ederdrom.de/doku.php/nagios/pnp_en)
Before starting: Make sure you have; apache, mysql (or just the libraries), oracle client, freetds.

Installing Nagios

  • Get the latest version of nagios and the plugins.
  • Create a nagios user, a nagios group and a nagcmd group.
  • Create the installation directory (ex. /usr/local/nagios) and change the owner to nagios:nagios.
  • Add the apache user (or whatever user apache is running as) to the nagcmd group.
  • Untar nagios.
  • Run the configure script "./configure --prefix=/usr/loca/nagios –with-cgiurl=/nagios/cgi-bin --with-htmurl=/nagios/ --with-nagios-user=nagios --with-nagios-group=nagios –with-command-group=nagcmd".
  • Run make.
  • Run make install.
  • Run make install-init.
  • Run make install-commandmode.
  • Run make install-config.

Configuring Nagios

  • By default a lot of configuration information is contained in localhost.cfg, so this is where you can setup stuff like the times to be monitored or the contacts.

If you wish to split this stuff up, modify nagios.cfg set the various config files/directories you want to use.

cfg_file=/usr/local/nagios/etc/contacts.cfg
cfg_file=/usr/local/nagios/etc/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/services.cfg
cfg_dir=/usr/local/nagios/etc/servers
cfg_dir=/usr/local/nagios/etc/switches
  • In order to use custom commands or to modify the behavior of you need go into the commands.cfg.

ex.

		define command{
        		command_name    check_oracle
        		command_line    $USER1$/check_oracle --tns $ARG1$
        		}

ex.

		define command{
        		command_name    check_mysql
        		command_line    $USER1$/check_mysql -H $HOSTADDRESS$ -d $ARG1$ -u $ARG2$ -p $ARG3$
        		}
  • Create your service definition templates.
The “register 0” means it's a template.
The “use” option means to inherit the properties from the service defined there.
For more information on the other options read the Nagios documentation.

ex.

		# Generic service template
		define service{
		name				generic-service-template
		active_checks_enabled		1
		passive_checks_enabled		1
		parallelize_check		1
		obsess_over_service		1
		check_freshness			0
		notifications_enabled		1
		event_handler_enabled		1
		flap_detection_enabled		1
		failure_prediction_enabled	1
		process_perf_data		1
		retain_status_information	1
		retain_nonstatus_information	1
		is_volatile			0
		register 			0
		}

ex.

		# Local service template
		define service{
		name				local-service-template
		use				generic-service-template
		check_period			24x7
		max_check_attempts		4
		normal_check_interval		5
		retry_check_interval		1
		contact_groups			admins
		notification_options		w,u,c,r
		notification_interva		60
		notification_period 		24x7
		register			0
		}
  • Create your host definition templates.

ex.

		# Generic Host Template
		define host{
		name				generichost-template
		notifications_enabled		1
		event_handler_enabled		1
		flap_detection_enabled		1
		failure_prediction_enabled	1
		process_perf_data		1
		retain_status_information	1
		retain_nonstatus_information	1
		notification_period		24x7
		register			0
		}

ex.

		# Remote Host Template
		define host{
		name				remotehost-template
		use				generichost-template
		check_period			24x7
		max_check_attempts		10
		check_command			check-host-alive
		notification_period		workhours
		notification_interval		120
		notification_options		d,u,r
		contact_groups			admins
		}

Configuring a remote host

  • Create the hosts you wish to monitor.
You can either put them all in one configuration file or split them up and make a configuration file for every single machine.
Here's an example of a configuration file for one machine which contains all it's information.

ex.

		# Host
		define host{
		use			remotehost-template
		host_name		<host's name>
		hostgroups		<host's group>
		parents			<host's parent>
		alias			<host's description>
		address			<host's ip address>
		} 

		# Host Extensions
		define hostextinfo{
		host_name		<host's name>
		icon_image		<image file>
		statusmap_image		<image file>
		} 

		#Services 

		#Check http
		define service{
		use			local-service-template
		host_name		<host's name>
		service_description	HTTP
		check_command		check_http!80!5!10 

		# Check disk space of /
		# Warning if < 10% free, Critical if < 5% free
		define service{
		use			local-service-template
		host_name		<host's name>
		service_description	Root Partition
		check_command		check_by_ssh!22!"/usr/local/nagios/libexec/check_disk -w 10% -c 5% -p /"
		} 

		# Check disk space of /boot
		# Warning if < 10% free, Critical if < 5% free
		define service{
		use			local-service-template
		host_name		<host's name>
		service_description	Boot Partition
		check_command		check_by_ssh!22!"/usr/local/nagios/libexec/check_disk -w 10% -c 5% -p /"
		} 

		# Check load
		# Warning if > 5/4/3 processes in wait , Critical if > 10/6/4 processes in wait
		# Warning/Critical configured on remote host
		define service{
		use			local-service-template
		host_name		<host's name>
		service_description	Current Load
		check_command		check_by_ssh!22!"/usr/local/nagios/libexec/check_load -w 5,4,3 -c 10,6,4"
		}

Configuring Apache

  • In order to use apache you need to tell it where the nagios cgi files are and what you want your document root to be.

ex.

		ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin

		<Directory "/usr/local/nagios/sbin">
			Options ExecCGI
			AllowOverride None
			Order allow,deny
			Allow from all
			AuthName "Nagios Access"
			AuthType Basic
			AuthUserFile /usr/local/nagios/etc/htpasswd.users
			Require valid-user
		</Directory>

		Alias /nagios /usr/local/nagios/share

		<Directory "/usr/local/nagios/share">
			Options None
			AllowOverride None
			Order allow,deny
			Allow from all
			AuthName "Nagios Access"
			AuthType Basic
			AuthUserFile /usr/local/nagios/etc/htpasswd.users
			Require valid-user
		</Directory>
  • Use htpasswd to create the authorized users file.

Installing Nagios Plugins

  • Untar nagios-plugins.
  • run the configure script "./configure".
  • Run make.
  • Run make install.

Install PnP (graphs)

  • Install perl-HiRes:
yum install perl-Time-HiRes.i386
rrdtool
perl-rrdtool
  • Untar pnp.
  • Run the configure script "./configure".
  • Run make all.
  • make install.

Configuring PnP

  • In the pnp dir (ex. /usr/loca/nagios/etc/pnp) modify config.php so that it uses rrdtool and where it will dump the performance logs.

ex.

		$conf['rrdtool'] = "/usr/bin/rrdtool"
		$conf['rrdbase'] = "/usr/local/nagios/share/perfdata/"
  • In the nagios.cfg modify the config so that it knows how to process the performance data.
This will cause the perfomance info to be updated every 30 seconds to reduce the load on the machine

ex.

		process_performance_data=1
		service_perfdata_file=/usr/local/nagios/var/service-perfdata
		service_perfdata_file_template=DATATYPE::SERVICEPERFDATAtTIMET::$TIMET$tHOSTNAME::$HOSTNAME$tSERVICEDESC::$SERVICEDESC$tSERVICEPERFDATA::$SERVICEPERFDATA$tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$tHOSTSTATE::$HOSTSTATE$tHOSTSTATETYPE::$HOSTSTATETYPE$tSERVICESTATE::$SERVICESTATE$tSERVICESTATETYPE::$SERVICESTATETYPE$
		service_perfdata_file_mode=a
		service_perfdata_file_processing_interval=30
		service_perfdata_file_processing_command=process-service-perfdata-file
  • Create the process perfdata command.

ex.

		define command{
		command_name    process-service-perfdata-file
		command_line    /usr/local/nagios/libexec/process_perfdata.pl --bulk=/usr/local/nagios/var/service-perfdata
		}
  • For each service you wish to gather performance data for add this line or add this to the service templates.

ex.

		process_perf_data 1
  • Add a service extension for each service you wish to monitor to the host's configuration.

ex.

		define serviceextinfo {
		host_name <host's name>
		service_description <service>
		notes View PNP graphic
		action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
		}

Miscellaneous

  • A lot more can be configured with Nagios, and if there's anything that you're not sure with or are wondering how it works, just consult the documentation.
Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.