Nagios 监控软件

下载安装Nagios及Nagios插件

过程如下:
  ——下载Nagios
  ——下载Nagios插件
  ——解压Nagios

#tar -zvxf nagios-3.2.1.tar.gz  

#cd nagios-3.2.1  

——编译
#./configure --with-command-group=nagcmd #make all  
——安装Nagios,初始化脚本及配置文件,Nagios将会被安装至/usr/local/nagios #make install #make install-init #make install-config #make install-commandmode
——安装WEB界面,界面将会安装到 /usr/local/nagios/share ( http 配置文件默认添加到 /etc/httpd/conf.d/nagios.conf,如果没有则执行:

#cp sample-config/httpd.conf /etc/apache2/conf.d/nagios.conf )  

#make install-webconf  

——创建HTTP认证用户登录Nagios,用户名nagiosadmin,密码123456
#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin  
——重启apache
#service httpd restart  
——安装Nagios插件

#tar -zvxf nagios-plugins-1.4.14.tar.gz  

#cd nagios-plugins-1.4.14  


#./configure --with-nagios-user=nagios --with-nagios-group=nagios #make && make install  

——配置Nagios管理员接受告警信息的邮箱,写入管理员邮箱 #vim /usr/local/nagios/etc/objects/contacts.cfg email [email protected] ; ——校验Nagios配置文件,验证配置是否有误 #/usr/local/nagios/bin/nagios -v
——启动Nagios,配置在系统启动时运行Nagios

#chkconfig --add nagios  

#chkconfig nagios on  

#chkconfig httpd on  

——运行Nagion
#service nagios start  
四、登陆到Web界面
输入用户名密码:nagiosadmin 123456,http://localhost/nagios/
五、相关的插件查看页面:http://exchange.nagios.org/index.php?option=com_mtree&task
=search&Itemid=74&searchword=postfix 
#!/bin/bash
#
#check_postque -w 10 -c 30 -W 1000000 -C 3000000 -p postfix"
#

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
exitstatus=3

#接受10个参数
if [ "$#" == "10" ]; then
  arg=${10}
  w=$2
  c=$4
  W=$6
  C=$8
  mail_empty="Mail queue is empty"
  mails=`postqueue -c /etc/$arg -p`
#  if []; then
    if [ "$mails" == "$mail_empty" ]; then
      exitstatus=$STATE_OK
      echo "OK : $mail_empty"
    else
      crt=`postqueue -c /etc/$arg -p | grep Kbytes | sed -e 's/^.*--.//g' | awk '{print $1}'`
      msg=`postqueue -c /etc/$arg -p | grep Kbytes | sed -e 's/^.*--.//g' | awk '{print $4}'`
      if [ $msg -gt $c -o  $crt -gt $C ]; then 
        exitstatus=$STATE_CRITICAL  
        echo "Critical : Queue has ${msg} messages in ${crt} Kbytes, higher then critical limit." 
      elif [ $msg -gt $w  -o $crt -gt $W ] ; then
        exitstatus=$STATE_WARNING
        echo "Warning : Queue has $msg messages in $crt Kbytes, higher then warning limit."
      else
        exitstatus=$STATE_OK
        echo "OK : Mail queue has $msg messages in $crt Kbytes."
      fi
    fi  
#  else
#    exitstatus=$STATE_CRITICAL
#    echo "CRITICAL : Mail system is down <!_!> "  
#  fi  
else
  echo " "
  echo "Please provide parameters to work with."
  echo "Help : ./check_postque -w 10 -c 30 -W 1000000 -C 3000000 -p postfix"
  echo "Where :"
  echo "       -w = Request Warning limit"
  echo "       -c = Request Critical limit"
  echo "       -W = Message size Warning limit"
  echo "       -C = Message size Critical limit"
  echo "       -p = Postfix instance name"
  echo " "
fi  
exit $exitstatus
接着修改邮件服务器的nrpe.cfg文件,增加如下command监控:
command[check_postque]=/App/nagios/libexec/check_postque -w 50-c 100 -W 3000000 
-C 5000000 -p postfix
#队列数大于50告警,100严重告警。邮件大小总计300M告警,邮件大小总计500M严重告警
 
注:我的nagios的程序是安装在/App/nagios目录的,如果你安装的其他目录,上面的command中的路径也需要做相应的修改.
define command{
        command_name    check_smtp
        command_line    /usr/local/nagios/libexec/check_postque -w 50-c 100 -W 3000000 -C 5000000 -p postfix
        #command_line    $USER1$/check_smtp -H $HOSTADDRESS$ $ARG1$
        } 

  


你可能感兴趣的:(nagios)