nagios使用

nagios中文:http://nagios-cn.sourceforge.net/
nagiso官方網站:http://www.nagios.org/

Ununtu下Nagios信息發送方式:
1.mail
如果要接收Nagios的EMail警報,需要安裝(Postfix)包

sudo apt-get install mailx

需要編輯Nagios裏的EMail通知送出命令,它位於/usr/local/nagios/etc/commands.cfg文件中,將裏面的'/bin/mail'全部替換爲'/usr/bin/mail'。一旦設置好需要重啓動Nagios以使配置生效。

sudo /etc/init.d/nagios restart

2.MSN
用php來發送MSN信息。
wget http://downloads.fanatic.net.nz/dev/php/sendMsg.zip
unzip sendMsg.zip
mv sendMsg /path/to/web/dir/msn
可以先打開 http://server/msn/index.php 測試一下能否發送。如果沒有問題,可以寫一個腳本來執行 MSN 信息發送命令:
/usr/local/nagios/libexec/msn_send.sh:
#!/bin/sh
wget -O - -q --post-data="[email protected]&password=password&
recipient=$1&message=$2" http://server/msn/index.php > /dev/null

chmod +x /usr/local/nagios/libexec/msn_send.sh

/usr/local/nagios/etc/objects/commands.cfg:

define command{
command_name notify-host-by-msn
command_line /usr/local/nagios/libexec/msn_send.sh $CONTACTEMAIL$ "`/usr/bin/printf "%b" "***** Monitor *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n"`"
}

define command{
command_name notify-service-by-msn
command_line /usr/local/nagios/libexec/msn_send.sh $CONTACTEMAIL$ "`/usr/bin/printf "%b" "***** Monitor *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$"`"
}

/usr/local/nagios/etcobjects/contacts.cfg :

define contact{
contact_name nagios
alias Nagios Msn
use generic-contact
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-msn
host_notification_commands notify-host-by-msn
}

參考於:http://blog.bluedata.org/nagios-notification-type/
3.飛信通知

飛信官方網站:http://www.it-adv.net/
下載:fetion20080910048-linux.tar.gz 和 library32.rar(版本不斷更新)
tar xvfz fetion_linux_20080402.tar.gz
cd install
sudo cp fetion /usr/bin
fetion -h
如果出現如下錯誤:
error while loading shared libraries: libACE.so.5.4.7: cannot open shared object file: No such file or directory
說明缺少運行的庫文件。
解決方法:
a.sudo apt-get install libACE.so.5.4.7 libACE_SSL.so.5.4.7
(可能你的ubuntu已經不提供安裝這兩個庫文件,採用下面的方案)
b.unrar e library32.rar
cd library32
sudo cp *.* /lib/
sudo cp *.* /usr/lib/
重新執行 fetion -h.應該能看到所要的結果。
如果你有飛信號,可以執行一下。
fetion -u 飛信號 -p pwd 來登錄。
/usr/local/nagios/etc/objects/commands.cfg:
# 'notify-service-by-fetion' command definition
define command{
command_name notify-service-by-fetion
command_line /usr/bin/feiton -u 13888888888 -p 123456 -t $CONTACTPAGER$ -m "$HOSTNAME$ $SERVICEDESC$ is $SERVICESTATE$ on $TIME$ result is $SERVICEOUTPUT$" $CONTACTPAGER$
}
/usr/local/nagios/etcobjects/contacts.cfg :
define contact{
contact_name fetion
alias nagios admin
host_notification_period 24x7
service_notification_period 24x7
host_notification_options d,r,
service_notification_options c,w,r
service_notification_commands notify-service-by-email,notify-service-by-fetion
# service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
pager 158010775111
}


最後將定義的contact添加到contactgroup中:
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin,nagios,fetion
}
當你定義一個主機的時候:
/usr/local/nagios/etc/objects/templates:
# Linux host definition template - This is NOT a real host, just a template!

define host{
name linux-server ; The name of this host template
use generic-host ; This template inherits other values from the generic-host template
check_period 24x7 ; By default, Linux hosts are checked round the clock
check_interval 5 ; Actively check the host every 5 minutes
retry_interval 1 ; Schedule host check retries at 1 minute intervals
max_check_attempts 10 ; Check each Linux host 10 times (max)
check_command check-host-alive ; Default command to check Linux hosts
notification_period workhours ; Linux admins hate to be woken up, so we only notify during the day
; Note that the notification_period variable is being overridden from
; the value that is inherited from the generic-host template!
notification_interval 120 ; Resend notifications every 2 hours
notification_options d,u,r ; Only send notifications for specific host states
contact_groups admins ;使用的聯繫組爲admins
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}

此處參考:http://yang2001.blog.51cto.com/25307/73164
發佈了17 篇原創文章 · 獲贊 0 · 訪問量 1695
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章