How to install nagvis

Tested On

OS: CentOS 6.2 x86_64
Nagios Version: 3.5
Nagvis Version: 1.7.7
Hardware: Virtual Machine (VMware Server 2.0.0.2712)

About

Nagvis is an visualization addon for Nagios that can create beautiful maps for Nagios objects.

Prerequisite

  • Install Nagios server
Nagios Installation
  • we need to install the folllowing prerequisites packages: rrdtool perl-GD

Install and configure mk-livestatus

  • Download and install mk-livestatus
  • Add the following lines to Nagios configuration file to configure nagios to load livestatus module
  • Reload Nagios

Install Nagvis

  • Download Nagvis
  • Start Nagvis installation
  • Reload apache
Nagvis installation completed. Browse to http://nagios_server_ip_address/nagvis to configure new maps
Please visit http://www.nagvis.org/ for information about Nagvis configuration and usage.
Đọc thêm..

Nagios - User Permission

command:

htpasswd /usr/local/nagios/etc/htpasswd.users <user>

note: <user> in contacts.cfg
Đọc thêm..

Automating Nagios service checks via SSH


Expect script

Expect to the rescue! Expect is a nifty program that automates tasks based on input and output. You should have installed Expect on your computer by now.

file save to /usr/local/bin/

########################################
#!/usr/bin/expect -f

#Expect script to supply root/admin password for remote ssh server
#and execute command.
#This script needs three argument to(s) connect to remote server:
#password = Password of remote UNIX server, for root user.
#ipaddr = IP Addreess of remote UNIX server, no hostname
#scriptname = Path to remote script which will execute on remote server
#For example:
#./sshlogin.exp password 192.168.1.11 who
#------------------------------------------------------------------------
#Copyright (c) 2004 nixCraft project <http://cyberciti.biz/fb/>
#This script is licensed under GNU GPL version 2.0 or above
#-------------------------------------------------------------------------
#This script is part of nixCraft shell script collection (NSSC)
#Visit http://bash.cyberciti.biz/ for more information.
#----------------------------------------------------------------------
#set Variables

set ipaddr [lindex $argv 0]
   set password [lindex $argv 1]
   set scriptname [lindex $argv 2]
   set arg1 [lindex $argv 3]
   set arg2 [lindex $argv 4]
   set arg3 [lindex $argv 5]
   set arg4 [lindex $argv 6]
   set arg5 [lindex $argv 7]
   set arg6 [lindex $argv 8]
   set arg7 [lindex $argv 9]

#setting a timeout for the password prompt 5 seconds larger than the SSH ConnectionTimeout parameter

set timeout 35

#now connect to remote UNIX box (ipaddr) with given script to execute

set pid [spawn -noecho ssh -o "ConnectTimeout 30" -o "CheckHostIP no" -o "StrictHostKeyChecking no" $ipaddr $scriptname $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7]
match_max 5000

#look for password prompt
log_user 0
   expect {
      "denied"                       {puts "CRITICAL: wrong SSH password" ; exit 2}
      "Name or service not known"    {puts "CRITICAL: cannot resolve SSH server name $ipaddr" ; exit 2}
      "Connection refused"           {puts "CRITICAL: SSH connection to $ipaddr refused" ; exit 2}
      "Connection timed out"         {puts "CRITICAL: SSH connection to $ipaddr timed out" ; exit 2}
      timeout                        {puts "CRITICAL: SSH server timed out while prompting for password" ; exit 2}
      "?assword:"
   }

# send password

send -- "$password"

# send blank line to make sure we get back to gui

send -- "r"
   expect "r"
   log_user 1

# now we wait up to 30 seconds

set timeout 30
   expect {
       timeout                   {puts "CRITICAL: execution of $scriptname timed out after 30 seconds" ; exit 2}
       eof
   }

set waitret [wait]
   catch {close}

set state [lindex $waitret 2]
   exit [lindex $waitret 3
#####################################

or script

#########################
#!/usr/bin/expect -f
    # Expect script to supply root/admin password for remote ssh server
    # and execute command.
    # This script needs three argument to(s) connect to remote server:
    # password = Password of remote UNIX server, for root user.
    # ipaddr = IP Addreess of remote UNIX server, no hostname
    # scriptname = Path to remote script which will execute on remote server
    # For example:
    # ./sshlogin.exp password 192.168.1.11 who
    # ------------------------------------------------------------------------
    # Copyright (c) 2004 nixCraft project <http://cyberciti.biz/fb/>
    # This script is licensed under GNU GPL version 2.0 or above
    # -------------------------------------------------------------------------
    # This script is part of nixCraft shell script collection (NSSC)
    # Visit http://bash.cyberciti.biz/ for more information.
    # ----------------------------------------------------------------------
    # set Variables
set password [lindex $argv 0]
set ipaddr [lindex $argv 1]
set scriptname [lindex $argv 2]
set arg1 [lindex $argv 3]
set arg2 [lindex $argv 4]
   set arg3 [lindex $argv 5]
   set arg4 [lindex $argv 6]
   set arg5 [lindex $argv 7]
   set arg6 [lindex $argv 8]
   set arg7 [lindex $argv 9]
set timeout -1
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn ssh huynh-tuan-anh@$ipaddr $scriptname $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7
match_max 100000
# Look for passwod prompt
expect "*?assword:*"
#expect "Password:"
# Send password aka $password
send -- "$password\r"
# send blank line (\r) to make sure we get back to gui
send -- "\r"
expect eof

###########################

Command test:

ssh.exp test 172.29.93.105 /home/huynh-tuan-anh/check_exit_status.pl -s /etc/init.d/sshd

- test: username
- 172.29.93.105: server ssh to

Đọc thêm..

Setup SSMTP để Naigos sử dụng email ID gmail gửi mail alert


Setup SSMTP để Naigos sử dụng email ID gmail gửi mail alert

- Stop dịch vụ smtp mặc định

service sendmail stop   
chkconfig sendmail off
hoặc
service postfix stop   
chkconfig postfix off

- Download và cập nhật database các phần mềm mới

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh epel-release-6-8.noarch.rpm

- Cài đặt SSMTP

yum install ssmtp mailx

- Cấu hình ssmtp
+ Edit /etc/ssmtp/ssmtp.conf

FromLineOverride=YES
root=nagios
mailhub=smtp.gmail.com:587
UseTLS=YES
UseSTARTTLS=YES
AuthUser=abc@email.com
AuthPass=<pass plaintext>

- Thay đổi MTA mặc định

alternatives --config mta

*+ 1           /usr/sbin/sendmail.postfix
  2           /usr/sbin/sendmail.ssmtp

Enter to keep the current selection[+], or type selection number:

chọn 2

- Gửi mail test

echo "Testing outgoing email" | mailx -s "Testing" abc@domain.com
Đọc thêm..

Setup Nagios 4x trên Centos 6.5


Setup Nagios 4x trên Centos 6.5
- Cài đặt các gói  packages cần thiết trước khi cài đặt nagios.

#yum install httpd php gcc glibc glibc-common gd gd-devel openssl-devel wget perl make

- Tạo user nagios/password

#useradd -m nagios
#passwd nagios    

- Tạo group nagcmd. Chuyển user nagios và apache vào groups nagcmd

#groupadd nagcmd
#usermod -a -G nagcmd nagios
#usermod -a -G nagcmd apache

- Taọ thư mục tạm để chứa gói cài đặt nagios

#mkdir nagiossource
#cd nagiossource

- Download gói cài đặt nagios và nagios plugins


- Giải nén gói cài đặt nagios

#tar zxvf nagios-4.0.2.tar.gz
#cd nagios-4.0.2

- Cài đặt nagios

#./configure --with-command-group=nagcmd
#make all
#make install
#make install-init
#make install-config
#make install-commandmode
#make install-webconf



- Tạo account nagiosadmin để login vào website

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

- Khởi động dịch vụ web

#service httpd start

- Cài đặt plugins nagios
#tar zxvf nagios-plugins-1.5.tar.gz
#cd nagios-plugins-1.5
#./configure --with-nagios-user=nagios --with-nagios-group=nagios
#make
#make install

- Cấu hình nagios autostart

#chkconfig --add nagios
#chkconfig nagios on

- Cấu hình Selinux cho nagios

#chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
#chcon -R -t httpd_sys_content_t /usr/local/nagios/share/

- Cấu hình iptables cho phép truy xuất port 80

#vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT


Cấu hình Nagios

- Cấu hình file /usr/local/nagios/etc/nagios.cfg
+ comment các dòng sau:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg



+ Thêm vào các dòng cấu hình sau:
############# Hinh Duong Dan Den Cac File Define ######################
cfg_file=/usr/local/nagios/etc/contacts.cfg
cfg_file=/usr/local/nagios/etc/commands.cfg
cfg_file=/usr/local/nagios/etc/generic-host.cfg
cfg_file=/usr/local/nagios/etc/generic-service.cfg
cfg_file=/usr/local/nagios/etc/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/services.cfg
cfg_file=/usr/local/nagios/etc/timeperiods.cfg
cfg_dir=/usr/local/nagios/etc/servers

- Tạo các file: contacts.cfg, commands.cfg, generic-host.cfg, generic-service.cfg, hostgroups.cfg, services.cfg, timeperiods.cfg (các file nay có file mẫu trong /usr/local/nagios/etc/objects/ )

- Cấu hình server cần giám sát
+ Tạo file /usr/local/nagios/etc/servers/hcm.cfg
############## Server nagios #############
define host{
              use                     generic-host            
        host_name         Nagios-server
     alias                    Nagios Server
       address              IP server
        hostgroups         hcm-servers
}
define host{
              use                     generic-host            
        host_name         Server1-hcm
     alias                    Server1 HCM
       address              IP server
        hostgroups         hcm-servers
}
+ Tạo file /usr/local/nagios/etc/servers/danang.cfg
############## Server nagios #############
define host{
              use                     generic-host            
        host_name         server1-danang
     alias                    Server1 Da Nang
       address              IP server
        hostgroups         danang-servers
}


- Cấu hình file hostgroups.cfg
define hostgroup{
     hostgroup_name         hcm-servers
alias                    HCM Servers
       members                  Nagios-server, win-server
    }

- Cấu hình file servicegroups.cfg
define servicegroup{
     servicegroup_name    ping-services
   alias                    Ping Services
     members                  win-server,PING,Nagios-server,PING
        }


- Các service check trên windows được hỗ trợ bởi Nagios

define service{
use                  generic-service
host_name            remote-windows-host
service_description NSClient++ Version
check_command        check_nt!CLIENTVERSION
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description Uptime
check_command        check_nt!UPTIME
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description CPU Load
check_command        check_nt!CPULOAD!-l 5,80,90
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description Memory Usage
check_command        check_nt!MEMUSE!-w 80 -c 90
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description C:\ Drive Space
check_command        check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description W3SVC
check_command        check_nt!SERVICESTATE!-d SHOWALL -l W3SVC  # check The Internet Information Services (IIS) World Wide Web Publishing Service
}
define service{
use                  generic-service
host_name            remote-windows-host
service_description Explorer
check_command        check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe  # có thể check các dịch vụ khác, thay explorer.exe bằng tên dịch vụ được hiển thị trong task manager
}
Đọc thêm..