nagios使用的問題解決ios
1.經過web界面修改某個服務時報錯web
例如對某個服務進行臨時安排其執行時間,或者不讓它發警告,web頁面上都有這樣的設置.可是經常會有錯誤信息以下:apache
Could not open command file '/usr/local/nagios/var/rw/nagios.cmd' for update!安全 The permissions on the external command file and/or directory may be incorrect. Read the FAQs on how to setup proper permissions.服務器 An error occurred while attempting to commit your command for processing.網絡 |
關於這部分在nagios.cfg中有下面的內容app
# EXTERNAL COMMAND FILEide # This is the file that Nagios checks for external command requests.url # It is also where the command CGI will write commands that are submittedspa # by users, so it must be writeable by the user that the web server # is running as (usually 'nobody'). Permissions should be set at the # directory level instead of on the file, as the file is deleted every # time its contents are processed. 這段話的核心意思是apache的運行用戶要有對文件寫的權限.權限應該設置在目錄上,由於每次文件的內容被處理後文件就會被刪掉 command_file=/usr/local/nagios/var/rw/nagios.cmd |
原本將apache2運行的用戶apache加到nagios組就應該能夠了的
可是這個卻不行,就將rw這個目錄及其子文件的權限改了777,這樣就能夠了.
後來發現nagios.cmd的權限仍是自動變回了rw-rw----,可是發命令沒有受到影響,不報錯了.(難道是用重啓nagios,讓其生效?)
2.nagios警告郵件的特殊配置
nagios發警告郵件是採用本機的smtp服務,能夠查看commands.cfg中關於發郵件的命令的定義,使用本機的mail命令,這就須要開啓本機的smtp服務,爲了安全能夠在防火牆上設置拒絕其餘的機器連本機的25號端口
如今咱們的網絡裏面有一個郵件服務器,因此要求使用這臺現有的郵件服務器,不開啓本機的smtp服務,這就須要從新定義命令使用第三方軟件sendEmail.
首先咱們固然要在郵件服務器上新建一個帳戶用來作發郵件的帳戶
這裏郵件服務器的地址爲mail.test.com
用來發郵件的賬號nagios@test.com
SMTP驗證的用戶名 nagios 密碼 p#3isoda
如下就來介紹一下sendEmail這個軟件的使用.
sendEmail的主頁[url]http://caspian.dotconf.net/menu/Software/SendEmail/[/url]
下載地址[url]http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.55.tar.gz[/url]
軟件十分小,是一個經過命令來發smtp郵件的程序.安裝也十分簡單(查看其README文件便可).
解壓縮tar –zxvf sendEmail-v1.55.tar.gz
cd sendEmail-v1.55
將可執行程序複製cp sendEmail /usr/local/bin
而後給確認確實它具備執行權限
ll /usr/local/bin/sendEmail
-rwxr-xr-x 1 root root 77882 11-03 14:23 /usr/local/bin/sendEmail |
這樣程序就裝好了,使用也很簡單.直接運行sendEmail就會顯示詳細的用法
先看一個典型的例子
/usr/local/bin/sendEmail –f nagios@test.com –t yahoon@test.com –s mail.test.com –u 「from nagios」 –xu nagios –xp p#3isoda –m happy
解釋:
-f 表示發送者的郵箱
-t 表示接收者的郵箱
-s 表示SMTP服務器的域名或者ip
-u 表示郵件的主題
-xu 表示SMTP驗證的用戶名
-xp 表示SMTP驗證的密碼(注意,這個密碼貌似有限制,例如我用d!5neyland就不能被正確識別)
-m 表示郵件的內容
若是你不帶-m參數的話,就會提示你自行輸入
Reading message body from STDIN because the ‘-m’ option was not used. If you are manually typing in a message: - First line must be received within 60 seconds. - End manual input with a CTRL-D on its own line |
輸入完成後使用CTRL-D來結束
固然咱們也能夠將一個文件的內容做爲郵件的正文發出去的
那麼就可使用:
cat 文件名 | /usr/local/bin/sendEmail –f nagios@test.com –t yahoon@test.com –s mail.test.com –u 「from nagios」 –xu nagios –xp p#3isoda
有關sendEmail的用法就講到這裏
既然nagios要使用sendEmail來發警告郵件,那麼就要修改commands.cfg中關於發郵件的命令的定義,咱們如今來修改notify-by-email這個命令,以下(注意其中粗體的部分)
# 'notify-by-email' command definition define command{ command_name notify-by-email command_line /usr/bin/printf "%b" "***** Nagios 2.9 *****\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/bin/sendEmail -f nagios@test.com -t $CONTACTEMAIL$ -s mail.test.com -u "** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu nagios -xp p#3isoda } |
注:其實sendEmail是一個十分有用的程序,咱們在這個地方用了它,其實別的地方也能夠用,典型的好處就是你不須要每臺機器都裝sendmail,開啓smtp服務.直接用現成的一臺郵件服務器就好了,這無疑很大的增強了系統的安全性,也節約了資源.