Wednesday, 6 July 2011

Nagios installation

Install Ubuntu with LAMP & postfix & Build essentials

Nagios User Setup

useradd -m -s /bin/bash nagios
passwd nagios
usermod -G nagios nagios
groupadd nagcmd
usermod -a -G nagcmd nagios

Download And Unzip Nagios And Nagios Plugins

cd /downloads
wget http://prdownloads.sourceforge.net/nagios/nagios-3.2.3.tar.gz
wget http://prdownloads.sourceforge.net/nagiosplug/nagios-plugins-1.4.15.tar.gz
tar -zxf /downloads/nagios-3.2.3.tar.gz
tar -zxf /downloads/nagios-plugins-1.4.15.tar.gz

Install Nagios

cd /downloads/nagios-3.2.3
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

Nagios Password

This is the password you will need to look at the nagios pages. If you install Nagios to a different directory please change this command to where the Nagios etc. folder will be.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Enter your password when prompted.
Now we will restart Apache to make sure all of the changes take effect:
/etc/init.d/apache2 restart

Nagios Plugins
cd /downloads/nagios-plugins-1.4.15/
make
make install
Now we need to make Nagios start at bootup:
ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

Change Default Email Address For Nagios Admin

Open your favorite editor and open /usr/local/nagios/etc/objects/contacts.cfg

Once you have saved your changes to the contacts.cfg we need to verify that there are no errors in the configuration of Nagios.

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


Now we are going to start nagios:
/etc/init.d/nagios start

Postfix Configuration For A Smarthost Relay

postconf -e 'relayhost=yourmailserver.com'
postconf -e 'smtp_sasl_auth_enabled = yes'
postconf -e 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd'
postconf -e 'smtp_sasl_security_options ='
echo "yourmailserver.com emailusername:emailpassword" > /etc/postfix/sasl_passwd
Now we will need to change the password file attributes so only root has access to read it.
chown root:root /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd

Now we are going to set the map that will change your outbound messages from nagios to your email server username/email address.
echo "nagios mailusername@yourmailserver.com" /etc/postfix/canonical
echo "canonical_maps = hash:/etc/postfix/canonical" >> /etc/postfix/main.cf
postmap /etc/postfix/canonical


/etc/init.d/postfix restart
Now that this all has been completed you can restart your system.
Once your system has come back up you will be able to login to the website and look at your first Nagios installation.
http://yourserver/nagios/

 source: http://www.howtoforge.com/nagios-installation-on-ubuntu-10.04-lucid-lynx-p3






Nagios check_website plugin setup

Define check_website command in commands.cfg


add commands to /usr/local/nagios/etc/objects/commands.cfg


# 'check_website' command definition

define command{

        command_name    check_website

        command_line    $USER1$/check_website -H $HOSTADDRESS$

        }


Download Plugin and copy to libexec


Download check_website plugin

Copy into /usr/local/nagios/libexec/change file permissions to chmod 775 check_website


Test Plugin


/usr/local/nagios/libexec/ ./check_website -H (hostname) -F (file)

Nagios preflight checks


Friday, 1 July 2011

htmlview


#chown -R nagios:nagios /usr/local/nagios/var/*
#htmlview http://localhost/nagios

Nagios - Check Backup Exec

****************************************************************
* check_be - Nagios plugin for Symantec BackupExec for Windows *
* by Toussaint OTTAVI (t.ottavi@medi.fr)                       * 
****************************************************************

This is a windows executable, to be run on Windows servers where BackupExec
is installed. It will process all the job history files, find the most recent
occurrence of a specified job name, then it will return the current status of
this job. It can also return a 'warning' or 'critical' status if the last job
found is older than the specified amount of days.


1/ HOW TO USE THIS SOFTWARE
---------------------------

Run check_be.exe in a Windows console, with the following syntax :

  check_be "path of XML files" "Name of the backup job"
  
- "Path of XML files" is the location where BackupExec puts its log files in
  XML format. Default locations for these files are :
    v10:  c:\program files\veritas\backup exec\nt\data
    v12: c:\Program Files\Symantec\Backup Exec\Data
  
- "Name of the backup job log" is the name of the job you want to check. It's
  case independant.

Possible switches are :

-h : Shows brief syntax help

-d : Writes detailed debug information. This can help determining what's wrong
     in case of any problem.
     
-c<n> : Return 'critical' state if the last occurrence of the job is older 
        than <n> days. This can help to determine if a scheduled job is 
        disabled, locked, paused, or any other reason.

-w<n> : Same, but for 'warning' state

Example of use :

check_be  "c:\Program Files\Symantec\Backup Exec\Data" "My tape backup" -w1 -c3

Return states are :
  'ok' for BackupExec status 2 and 19
  'critical' for BackupExec status 0,1,6,7 and 21
  'warning' for any other BackupExec status 
  'unknown' if it can not determine the BackupExec job status, for any reason.
  

2/ HOW TO USE IT WITH NAGIOS
----------------------------

2.1/ ON THE MONITORED SERVER

You should have nsclient++ installed. In your 'nsc.ini' file, you must declare
an external script like this: 

[NRPE Handlers]
;# COMMAND DEFINITIONS
check_be=check_be.exe "c:\program files\veritas\backup exec\nt\data\" "JobName" -w1 -c3
 
 
2.2. ON THE NAGIOS SERVER 

Define a service template :

define service{
  name                  template-backupexec
  use                   generic-service
  service_description    BackupExec Job Check    ; default display name in Nagios
  check_command         check_nrpe!-c check_be  ; same name as in the nsclient++ nsc.ini command definition 
  normal_check_interval 60                      ; your check intervals here
  retry_check_interval  60
  register 0                                    ; this is a template
  }
  
Then, in your object definition, add the following :

define service {
  use                 template-backupexec
  service_description BackupExec - Daily DAT backup   ; specific display name, if you need
  host_name           MYHOST
  } 

Nagios - Zimbra mail queue checks

Monitoring Zimbra Mail queue's with Nagios 

edit 
vi /usr/local/nagios/libexec/utils.pm

remove
$PATH_TO_MAILQ   = "/usr/bin/mailq";

Add
$PATH_TO_MAILQ  ="/opt/zimbra/postfix/sbin/mailq";

Test
/usr/local/nagios/libexec# /usr/local/nagios/libexec/check_mailq 10.0.0.251 -w 100 -c 150

Error
root@Nagi:/usr/local/nagios/libexec# /usr/local/nagios/libexec/check_mailq 10.0.0.251 -w 100 -c 150
ERROR: /opt/zimbra/postfix/sbin/mailq is not executable by (uid 0:gid(0 0))


Fix Error

edit 
vi /etc/sudoers

nagios ALL=(zimbra) NOPASSWD: /usr/local/nagios/libexec/check_clamav.pl

nagios ALL=(zimbra) NOPASSWD: /usr/local/nagios/libexec/check_mailq

Nagios, change web login password

SSH into Nagios
sudo -s
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin (enter)
type new password
verify password