nagios整合cacti2011版(五)
生活随笔
收集整理的這篇文章主要介紹了
nagios整合cacti2011版(五)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Nagios使用NSClient++監控遠程Windows主機
下載NSClient++-Win32-0.3.8.msi并安裝。 http://files.nsclient.org/x-0.3.x/NSClient++-0.3.8-Win32.msi
到安裝目錄打開NSC.ini文件進行修改:
在[modules]模塊,將除CheckWMI.dll和RemoteConfiguration.dll外的所有dll文件明前的注釋(;)去掉。
在[Settings]模塊可以設置一個連接密碼password=PWD,為了簡單,在此不設密碼。設置allowed_hosts=127.0.0.1/32,192.168.0.19,可以連接的監控服務器的地址,如果寫成192.168.0.0/24則表示該子網內的所有機器都可以訪問;如果這個地方是空白則表示所有的主機都可以連接上來(注意在[NSClient]有allowed_hosts的同樣設置,不要設置錯了),最后不要忘記去掉前面的注釋符(;)。
運行nsclient++
NSClient++?/install
NSClient++?SysTray?install
NSClient++?/start
如果有防火墻,請開放相應端口。
創建監控配置文件,使用check_nt命令監控windows系統信息(此命令默認已定義)。
Windows監控示例配置文件:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@tech?etc]#?cat?/usr/local/nagios/etc/servers/print-w-80.cfg
###############################################################################
#?WINDOWS.CFG?-?SAMPLE?CONFIG?FILE?FOR?MONITORING?A?WINDOWS?MACHINE
#
#?Last?Modified:?06-13-2007
#
#?NOTES:?This?config?file?assumes?that?you?are?using?the?sample?configuration
#?????files?that?get?installed?with?the?Nagios?quickstart?guide.
#
###############################################################################
###############################################################################
###############################################################################
#
#?HOST?DEFINITIONS
#
###############################################################################
###############################################################################
#?Define?a?host?for?the?Windows?machine?we'll?be?monitoring
#?Change?the?host_name,?alias,?and?address?to?fit?your?situation
define?host{
????use????????windows-server????;?Inherit?default?values?from?a?template
????host_name????print80????????;?The?name?we're?giving?to?this?host
????alias????????Print80????????;?A?longer?name?associated?with?the?host
????address????????192.168.0.80????;?IP?address?of?the?host
????}
###############################################################################
###############################################################################
#
#?HOST?GROUP?DEFINITIONS
#?主機組在/usr/local/nagios/etc/servers/hostgroup.cfg中單獨配置
###############################################################################
###############################################################################
#?Define?a?hostgroup?for?Windows?machines
#?All?hosts?that?use?the?windows-server?template?will?automatically?be?a?member?of?this?group
#define?hostgroup{
#????hostgroup_name????windows-servers????;?The?name?of?the?hostgroup
#????alias????????Windows?Servers????;?Long?name?of?the?group
#????}
###############################################################################
###############################################################################
#
#?SERVICE?DEFINITIONS
#
###############################################################################
###############################################################################
#?Create?a?service?for?monitoring?the?version?of?NSCLient++?that?is?installed
#?Change?the?host_name?to?match?the?name?of?the?host?you?defined?above
define?service{
????use????????????generic-service
????host_name????????print80
????service_description????NSClient++?Version
????check_command????????check_nt!CLIENTVERSION
????}
#?Create?a?service?for?monitoring?the?uptime?of?the?server
#?Change?the?host_name?to?match?the?name?of?the?host?you?defined?above
define?service{
????use????????????generic-service
????host_name????????print80
????service_description????Uptime
????check_command????????check_nt!UPTIME
????}
#?Create?a?service?for?monitoring?CPU?load
#?Change?the?host_name?to?match?the?name?of?the?host?you?defined?above
define?service{
????use????????????generic-service
????host_name????????print80
????service_description????CPU?Load
????check_command????????check_nt!CPULOAD!-l?5,80,90
????}
#?Create?a?service?for?monitoring
#?Change?the?host_name?to?match?the?name?of?the?host?you?defined?above
define?service{
????use????????????generic-service
????host_name????????print80
????service_description????Memory?Usage
????check_command????????check_nt!MEMUSE!-w?80?-c?90
????}
#?Create?a?service?for?monitoring?C:\?disk?usage
#?Change?the?host_name?to?match?the?name?of?the?host?you?defined?above
define?service{
????use????????????generic-service
????host_name????????print80
????service_description????C_Drive_Space
????check_command????????check_nt!USEDDISKSPACE!-l?c?-w?80?-c?90
????}
#?Create?a?service?for?monitoring?the?W3SVC?service
#?Change?the?host_name?to?match?the?name?of?the?host?you?defined?above
define?service{
????use????????????generic-service
????host_name????????print80
????service_description????W3SVC
????check_command????????check_nt!SERVICESTATE!-d?SHOWALL?-l?W3SVC
????}
#?Create?a?service?for?monitoring?the?Explorer.exe?process
#?Change?the?host_name?to?match?the?name?of?the?host?you?defined?above
define?service{
????use????????????generic-service
????host_name????????print80
????service_description????Explorer
????check_command????????check_nt!PROCSTATE!-d?SHOWALL?-l?Explorer.exe
????}
#主機組配置文件
[root@tech?etc]#?cat?/usr/local/nagios/etc/servers/hostgroup.cfg
define?hostgroup{
????????hostgroup_name??linux-servers?;?The?name?of?the?hostgroup
????????alias???????????Linux?Servers?;?Long?name?of?the?group
????????members?????????localhost,wiki?????;?Comma?separated?list?of?hosts?that?belong?to?this?group
????????}
define?hostgroup{
????????hostgroup_name??windows-servers?;?The?name?of?the?hostgroup
????????alias???????????Windows?Servers?;?Long?name?of?the?group
????????members?????????print80?????;?Comma?separated?list?of?hosts?that?belong?to?this?group
????????}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #?完成監控主機配置文件的配置后使用下面命令檢查配置文件的正確性:
/usr/local/nagios/bin/nagios?-v?/usr/local/nagios/etc/nagios.cfg
#?確定無誤后重啟Nagios:
service?nagios?restart =============================================================================== 使用nagios監控網頁 在server文件夾里加入webpages.cfg并設置好用戶權限 Vim?webpages.cfg define?host{ ???????use?????????????linux-server ???????host_name???????webpages ???????alias???????????webpages ???????address?????????127.0.0.1 } define?service{ ????????use?????????????generic-service?????????;?Name?of?service?template?to?use ????????host_name???????????????????????webpages ????????service_description?????????????web_zgzb ????????check_command?????????????check_webpage!-H?test.cn?-u?/index.jsp ????????notifications_enabled???????????0 ????????} 然后在hostgroup里linux組里加入webpages主機 define?hostgroup{ ????????hostgroup_name??linux-servers?;?The?name?of?the?hostgroup ????????alias???????????Linux?Servers?;?Long?name?of?the?group ????????members?????????localhost,webpages?;?Comma?separated?list?of?hosts?that?belong?to?this?group ????????} 確認下配置文件沒有問題 /usr/local/nagios/bin/nagios?-v?/usr/local/nagios/etc/nagios.cfg OK重啟一下nagios服務,就OK了. =============================================================================== 使用139郵箱進行郵件短信報警 ????nagios發警告郵件是采用本機的smtp服務,可以查看commands.cfg中關于發郵件的命令的定義,使用本機的mail命令,這就需要開啟本機的smtp服務,為了安全可以在防火墻上設置拒絕其他的機器連本機的25號端口 ????另外由于移動增加了飛信api接口,在Linux命令行下使用飛信客戶端需要圖片驗證碼,飛信就不能用了,那么用139郵箱可以解決這個問題 ????申請139郵箱,成功申請后配置郵件到達短信通知,使用長格式。139郵件短信通知這個功能好用,而且免費:)缺點:短信報警有延時,不如linux命令行飛信報警快,但實際使用中速度還是不錯的,?基本上和郵箱同步.可以不開啟本機的smtp服務,這就需要重新定義命令使用第三方軟件sendEmail. 139郵箱申請:http://mail.10086.cn/ http://caspian.dotconf.net/menu/Software/SendEmail/ 這里郵件服務器的地址為mail.jetsum.net 用來發郵件的帳號?test@jetsum.net SMTP驗證的用戶名?test密碼?****** 以下就來介紹一下sendEmail這個軟件的使用. sendEmail的主頁http://caspian.dotconf.net/menu/Software/SendEmail/ 下載地址 wget?http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz 軟件十分小,是一個通過命令來發smtp郵件的程序.安裝也十分簡單(查看其README文件即可). 解壓縮tar?–zxvf?sendEmail-v sendEmail-v1.56.tar.gz cd?sendEmail-v1.56 將可執行程序復制cp?sendEmail?/usr/local/bin 然后給確認確實它具有執行權限 ll?/usr/local/bin/sendEmail
這樣程序就裝好了,使用也很簡單.直接運行sendEmail就會顯示詳細的用法 先看一個典型的例子 /usr/local/binsendEmail?-f?test@jetsum.net?-t?15107170098@139.com,17610376@qq.com?-s?mail.jetsum.net?-u?"send?by?nagios"?-xu?test?-xp?密碼?-m?"just?test?too" 解釋: -f表示發送者的郵箱 -t表示接收者的郵箱,發多郵箱中間用逗號隔開 -s表示SMTP服務器的域名或者ip -u表示郵件的主題 -xu表示SMTP驗證的用戶名 -xp表示SMTP驗證的密碼(注意,這個密碼貌似有限制,例如我用d!5neyland就不能被正確識別) -m表示郵件的內容 如果你不帶-m參數的話,就會提示你自行輸入
輸入完成后使用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這個命令,如下(注意其中粗體的部分)
注:其實sendEmail是一個十分有用的程序,我們在這個地方用了它,其實別的地方也可以用,典型的好處就是你不需要每臺機器都裝sendmail,開啟smtp服務.直接用現成的一臺郵件服務器就行了,這無疑很大的加強了系統的安全性,也節約了資源. 4.編寫nagios報警腳本(略),這個簡單,適當修改一下即可 參考: http://www.gaojinbo.com/nagios%E9%A3%9E%E4%BF%A1linux%E7%9F%AD%E4%BF%A1%E6%8A%A5%E8%AD%A6%E8%84%9A%E6%9C%AC%E9%85%8D%E7%BD%AE.html
下載NSClient++-Win32-0.3.8.msi并安裝。 http://files.nsclient.org/x-0.3.x/NSClient++-0.3.8-Win32.msi
到安裝目錄打開NSC.ini文件進行修改:
在[modules]模塊,將除CheckWMI.dll和RemoteConfiguration.dll外的所有dll文件明前的注釋(;)去掉。
在[Settings]模塊可以設置一個連接密碼password=PWD,為了簡單,在此不設密碼。設置allowed_hosts=127.0.0.1/32,192.168.0.19,可以連接的監控服務器的地址,如果寫成192.168.0.0/24則表示該子網內的所有機器都可以訪問;如果這個地方是空白則表示所有的主機都可以連接上來(注意在[NSClient]有allowed_hosts的同樣設置,不要設置錯了),最后不要忘記去掉前面的注釋符(;)。
運行nsclient++
NSClient++?/install
NSClient++?SysTray?install
NSClient++?/start
如果有防火墻,請開放相應端口。
創建監控配置文件,使用check_nt命令監控windows系統信息(此命令默認已定義)。
Windows監控示例配置文件:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@tech?etc]#?cat?/usr/local/nagios/etc/servers/print-w-80.cfg
###############################################################################
#?WINDOWS.CFG?-?SAMPLE?CONFIG?FILE?FOR?MONITORING?A?WINDOWS?MACHINE
#
#?Last?Modified:?06-13-2007
#
#?NOTES:?This?config?file?assumes?that?you?are?using?the?sample?configuration
#?????files?that?get?installed?with?the?Nagios?quickstart?guide.
#
###############################################################################
###############################################################################
###############################################################################
#
#?HOST?DEFINITIONS
#
###############################################################################
###############################################################################
#?Define?a?host?for?the?Windows?machine?we'll?be?monitoring
#?Change?the?host_name,?alias,?and?address?to?fit?your?situation
define?host{
????use????????windows-server????;?Inherit?default?values?from?a?template
????host_name????print80????????;?The?name?we're?giving?to?this?host
????alias????????Print80????????;?A?longer?name?associated?with?the?host
????address????????192.168.0.80????;?IP?address?of?the?host
????}
###############################################################################
###############################################################################
#
#?HOST?GROUP?DEFINITIONS
#?主機組在/usr/local/nagios/etc/servers/hostgroup.cfg中單獨配置
###############################################################################
###############################################################################
#?Define?a?hostgroup?for?Windows?machines
#?All?hosts?that?use?the?windows-server?template?will?automatically?be?a?member?of?this?group
#define?hostgroup{
#????hostgroup_name????windows-servers????;?The?name?of?the?hostgroup
#????alias????????Windows?Servers????;?Long?name?of?the?group
#????}
###############################################################################
###############################################################################
#
#?SERVICE?DEFINITIONS
#
###############################################################################
###############################################################################
#?Create?a?service?for?monitoring?the?version?of?NSCLient++?that?is?installed
#?Change?the?host_name?to?match?the?name?of?the?host?you?defined?above
define?service{
????use????????????generic-service
????host_name????????print80
????service_description????NSClient++?Version
????check_command????????check_nt!CLIENTVERSION
????}
#?Create?a?service?for?monitoring?the?uptime?of?the?server
#?Change?the?host_name?to?match?the?name?of?the?host?you?defined?above
define?service{
????use????????????generic-service
????host_name????????print80
????service_description????Uptime
????check_command????????check_nt!UPTIME
????}
#?Create?a?service?for?monitoring?CPU?load
#?Change?the?host_name?to?match?the?name?of?the?host?you?defined?above
define?service{
????use????????????generic-service
????host_name????????print80
????service_description????CPU?Load
????check_command????????check_nt!CPULOAD!-l?5,80,90
????}
#?Create?a?service?for?monitoring
#?Change?the?host_name?to?match?the?name?of?the?host?you?defined?above
define?service{
????use????????????generic-service
????host_name????????print80
????service_description????Memory?Usage
????check_command????????check_nt!MEMUSE!-w?80?-c?90
????}
#?Create?a?service?for?monitoring?C:\?disk?usage
#?Change?the?host_name?to?match?the?name?of?the?host?you?defined?above
define?service{
????use????????????generic-service
????host_name????????print80
????service_description????C_Drive_Space
????check_command????????check_nt!USEDDISKSPACE!-l?c?-w?80?-c?90
????}
#?Create?a?service?for?monitoring?the?W3SVC?service
#?Change?the?host_name?to?match?the?name?of?the?host?you?defined?above
define?service{
????use????????????generic-service
????host_name????????print80
????service_description????W3SVC
????check_command????????check_nt!SERVICESTATE!-d?SHOWALL?-l?W3SVC
????}
#?Create?a?service?for?monitoring?the?Explorer.exe?process
#?Change?the?host_name?to?match?the?name?of?the?host?you?defined?above
define?service{
????use????????????generic-service
????host_name????????print80
????service_description????Explorer
????check_command????????check_nt!PROCSTATE!-d?SHOWALL?-l?Explorer.exe
????}
#主機組配置文件
[root@tech?etc]#?cat?/usr/local/nagios/etc/servers/hostgroup.cfg
define?hostgroup{
????????hostgroup_name??linux-servers?;?The?name?of?the?hostgroup
????????alias???????????Linux?Servers?;?Long?name?of?the?group
????????members?????????localhost,wiki?????;?Comma?separated?list?of?hosts?that?belong?to?this?group
????????}
define?hostgroup{
????????hostgroup_name??windows-servers?;?The?name?of?the?hostgroup
????????alias???????????Windows?Servers?;?Long?name?of?the?group
????????members?????????print80?????;?Comma?separated?list?of?hosts?that?belong?to?this?group
????????}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #?完成監控主機配置文件的配置后使用下面命令檢查配置文件的正確性:
/usr/local/nagios/bin/nagios?-v?/usr/local/nagios/etc/nagios.cfg
#?確定無誤后重啟Nagios:
service?nagios?restart =============================================================================== 使用nagios監控網頁 在server文件夾里加入webpages.cfg并設置好用戶權限 Vim?webpages.cfg define?host{ ???????use?????????????linux-server ???????host_name???????webpages ???????alias???????????webpages ???????address?????????127.0.0.1 } define?service{ ????????use?????????????generic-service?????????;?Name?of?service?template?to?use ????????host_name???????????????????????webpages ????????service_description?????????????web_zgzb ????????check_command?????????????check_webpage!-H?test.cn?-u?/index.jsp ????????notifications_enabled???????????0 ????????} 然后在hostgroup里linux組里加入webpages主機 define?hostgroup{ ????????hostgroup_name??linux-servers?;?The?name?of?the?hostgroup ????????alias???????????Linux?Servers?;?Long?name?of?the?group ????????members?????????localhost,webpages?;?Comma?separated?list?of?hosts?that?belong?to?this?group ????????} 確認下配置文件沒有問題 /usr/local/nagios/bin/nagios?-v?/usr/local/nagios/etc/nagios.cfg OK重啟一下nagios服務,就OK了. =============================================================================== 使用139郵箱進行郵件短信報警 ????nagios發警告郵件是采用本機的smtp服務,可以查看commands.cfg中關于發郵件的命令的定義,使用本機的mail命令,這就需要開啟本機的smtp服務,為了安全可以在防火墻上設置拒絕其他的機器連本機的25號端口 ????另外由于移動增加了飛信api接口,在Linux命令行下使用飛信客戶端需要圖片驗證碼,飛信就不能用了,那么用139郵箱可以解決這個問題 ????申請139郵箱,成功申請后配置郵件到達短信通知,使用長格式。139郵件短信通知這個功能好用,而且免費:)缺點:短信報警有延時,不如linux命令行飛信報警快,但實際使用中速度還是不錯的,?基本上和郵箱同步.可以不開啟本機的smtp服務,這就需要重新定義命令使用第三方軟件sendEmail. 139郵箱申請:http://mail.10086.cn/ http://caspian.dotconf.net/menu/Software/SendEmail/ 這里郵件服務器的地址為mail.jetsum.net 用來發郵件的帳號?test@jetsum.net SMTP驗證的用戶名?test密碼?****** 以下就來介紹一下sendEmail這個軟件的使用. sendEmail的主頁http://caspian.dotconf.net/menu/Software/SendEmail/ 下載地址 wget?http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz 軟件十分小,是一個通過命令來發smtp郵件的程序.安裝也十分簡單(查看其README文件即可). 解壓縮tar?–zxvf?sendEmail-v sendEmail-v1.56.tar.gz cd?sendEmail-v1.56 將可執行程序復制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 |
| 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 |
| #?'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?test@jetsum.net?-t?15107170098@139.com,17610376@qq.com?-s?mail.jetsum.net?-u?"send?by?nagios"?-xu?test?-xp?密碼 ???????} |
轉載于:https://blog.51cto.com/17610376/543614
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的nagios整合cacti2011版(五)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jsp编码
- 下一篇: 字中字效果-html5实例