20130704_TWNIC_Nagios_Ezilla_openSUSE12.2

来源:互联网 发布:超级软件txt下载 编辑:程序博客网 时间:2024/05/23 01:15

EasyCloud雲端簡單龍


http://easycloud.nchc.org.tw/







請點選 用戶登入

並輸入 帳號 以及 密碼






進入 EasyCloud 後

請點選左方的虛擬機器 →  點選  新增




請輸入VM名稱 → 選取 VM的範本 → 輸入密碼 → 請點選建立





請點選 虛擬機器右方的VNC 連線圖示 或是 Remote Access (遠端桌面連線)圖示

這邊以Remote Access (遠端桌面連線) 為例, 執行完畢會出現 遠端的連接 port


請使用網頁方式連線 VNC 或是遠端桌面連線軟體連線指定的 Port

如果使用 遠端桌面連線

使用者為 登入 easycloud 的帳號

密碼為剛剛建立VM 所指定的密碼













Nagios網路監控主機架設


Nagios 是一個 opensource 的電腦系統與網路服務的監控軟體.


Nagios 可以監控主機與服務,當異常狀況發生時, 可以通知指定的聯絡人. 或是以指定的通知方式來聯繫, 另外也有眾多的 Plugin 可以使用.


官方網站

http://www.nagios.org/


openSUSE Linux 為開放社群的 openSUSE Poroject 所開發.

openSUSE 10.3 之後可以藉由 one-click Install 的方式來進行套件安裝

使用者可以在  http://software.opensuse.org/search

搜尋 想要安裝的套件, 藉由單鍵安裝, 快速安裝套件以及增加套件庫.

另外, http://software.opensuse.org/search 也提供其他 Linux 發行版本的套件下載( Fedora, Debian, Ubuntu, CentOS, RHEL, SLES)


架設環境介紹

Server

OS:openSUSE 12.2

IP:192.168.3.128(請依照實際的IP 調整)


Linux Client:192.168.3.129(請依照實際的IP 調整)

Windows Client:192.168.3.130(請依照實際的IP 調整)



Part I:Nagios伺服器的建置


Server:

1.安裝Nagios套件

server上面使用one-click install安裝Nagios套件


Nagios

http://software.opensuse.org/ymp/openSUSE:12.2/standard/nagios.ymp



(如果要使用 putty 連線SSH 到主機, 請確認SSH 服務有開 #rcsshd status )

( 啟動SSH 服務  #rcsshd  start )

(可以使用 #hostname  server 來變更主機名稱, 並請重新連線 SSH 還有 #rcxdm restart 重新啟動 X -- 如果使用 Ezilla Lab)


當然也可以使用指令的方式

# zypper   install   nagios   nagios-plugins

  


2.建立nagiosadmin密碼

第一次建立密碼的時候 請加上 -c 選項,

新增第二個使用者, 則不需要加上 -c( 會清空現有的密碼)

請於server上面

#htpasswd2   -c   /etc/nagios/htpasswd.users   nagiosadmin

輸入密碼

再次輸入


3.建立nagiosuser密碼

請於server上面

#htpasswd2   /etc/nagios/htpasswd.users   nagiosuser

輸入密碼

再次輸入


筆記補充: 預設的nagiosadmin 為管理者, 其相關設定, 設定於/etc/nagios/cgi.cfg 所以如果不想使用 nagiosadmin 為預設管理者帳號, 請修改該檔案內的設定.



4.檢視並設定開機啟動nagios

#chkconfig  nagios  --list

#chkconfig  nagios  on

#chkconfig  nagios  --list


5.重新啟動.apache2並設定開機啟動

#rcapache2  restart

#chkconfig   apache2  --list

#chkconfig   apache2  on

#chkconfig   apache2   --list


6.啟動Nagios

#rcnagios   start


7.測試Nagios主機運作

開啟瀏覽器 於URL上面輸入http://127.0.0.1/nagios/

以上的URL 請視連線的IP調整

會出現需要授權的視窗

請輸入

使用者名稱nagiosadmin

密碼之前設定的密碼





這個時候應該會出現Nagios的相關畫面



如下圖所示


可以觀察相關服務狀況

此時會發現 HTTP 呈現警告狀態

原因為 Apache2 有啟動但是沒有預設的網頁

要解除這個情形可以 建立一個預設網頁


#vi   /srv/www/htdocs/index.html

加入

<html>It works !</html>


(不習慣 vi 也可以在VM內使用 gedit  /srv/www/htdocs/index.html )


受監控的相關主機都會被紀錄在/etc/nagios/nagios.cfg

Linux的本機的監控設定也是設定於/etc/nagios/nagios.cfg內的

# Definitions for monitoring the local (Linux) host

cfg_file=/etc/nagios/objects/localhost.cfg


也可以使用資料夾的方式匯入設定檔(設定於/etc/nagios/nagios.cfg)

# You can also tell Nagios to process all config files (with a .cfg

# extension) in a particular directory by using the cfg_dir

# directive as shown below:


#cfg_dir=/etc/nagios/servers



故可以得知之後要監控的主機,

相關的設定檔都要放在/etc/nagios/objects資料夾內,

且於/etc/nagios/nagios.cfg要有cfg_file=xxxx.cfg的設定





另外如果要檢視Nagios設定有沒有問題

可以使用

#nagios  -v   /etc/nagios/nagios.cfg


來觀察匯入那些設定檔,以及有沒有問題

更多的文件也可以參考這邊


http://wiki.nagios.org/index.php/Main_Page


**修改通知 e-mail **

# vi   /etc/nagios/objects/contacts.cfg

修改預設的  e-mail

define contact{

       contact_name    nagiosadmi    ; Short name of user

       use    generic-contact         ; Inherit default values from generic-contact template (defined above)

       alias       Nagios Admin            ; Full name of user

       email  sakana@study-area.org; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

       }


當然這邊要確認 mail service 有沒有啟動

可以下 #rcpostfix  status 確認 ( 啟動請用 #rcpostfix  start )


檢視Nagios設定有沒有問題

#nagios  -v   /etc/nagios/nagios.cfg


重新啟動 Nagios

#rcnagios  restart


**以上Nagios伺服器建置完成**




Part II:Nagios用戶端-- Linux 伺服器用戶端建置


請於Client


1.安裝nagios-nrpe套件

#yast  -i  nagios-nrpe  nagios-plugins-nrpe


{  或是考慮使用 圖形介面方式安裝

請於Client端啟動YaST軟體管理

#yast2  sw_single

並搜尋nrpe應該就會看到

nagios-nrpe套件

nagios-plugins-nrpe 套件 → 安裝 → 套用

}


(根據官方的說法是 相較於 check_by_ssh的方式比較省資源)


2.設定nagios-nrpe套件

(另外最好去確認/etc/services有沒有nrpe 5666/tcp # nagios nrpe的設定)

#grep  5666  /etc/services


修改設定檔 允許 Nagios 伺服器連線

# vi  /etc/nagios/nrpe.cfg


allowed_hosts=127.0.0.1,192.168.3.128


(請依照實際的IP 作為修正, 可能為 10.x.x.x )

這邊要注意 127.0.0.1後面要加上 逗點 , 然後主機 IP 不能有空格

不然會出現沒有辦法建立 SSL HandShake

(這個部份可以解釋,如果nrpe是使用SystemV的形式啟動後面都會出現不能建立SSL Handshake ,但是以Xinetd就不會)


#rcnrpe   start


4.測試nagios-nrpe

設定完成之後 可以於本機及遠端測試



請於Client

執行check_nrpe測試,成功應該會出現NRPE的版本

# /usr/lib/nagios/plugins/check_nrpe   -H   localhost

NRPE v2.12


*************************************************************

請於Server

安裝nagios-nrpe套件

#yast  -i  nagios-nrpe  nagios-plugins-nrpe


針對nagios client測試nagios-nrpe成功應該會出現NRPE的版本

#/usr/lib/nagios/plugins/check_nrpe  -H  192.168.3.129

NRPE v2.12


(這邊請確認 firewall 是否關閉, 或是准許 nrpe 通過, 可以使用 #yast2  firewall 關閉防火牆測試  或是下指令 #rcSuSEfirewall2  stop )



*************************************************************



請於Client


接下來來測試本機相關資訊


請於Client

執行相關測試

線上使用者人數

#/usr/lib/nagios/plugins/check_nrpe-H localhost-c check_users


平均負載

#/usr/lib/nagios/plugins/check_nrpe-H localhost-c check_load


目前使用的process

#/usr/lib/nagios/plugins/check_nrpe-H localhost-c check_total_procs


Zombie Process

#/usr/lib/nagios/plugins/check_nrpe-H localhost-c check_zombie_procs


磁碟狀況

#/usr/lib/nagios/plugins/check_nrpe-H localhost-c check_hda1

(這個部份command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1

因為現在IDE的硬碟以及使用Kernel 2.6.20以前的主機越來越少,所以應該是對應到/dev/sda1)

故可以修改/etc/nagios/nrpe.cfg內的command對應

(複製原來的 hda1 改為要監控的 Partition)


#vi   /etc/nagios/nrpe.cfg

#command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1

command[check_sda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1

command[check_sda2]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda2

command[check_ssh]=/usr/lib/nagios/plugins/check_ssh   localhost

command[check_smtp]=/usr/lib/nagios/plugins/check_smtp  localhost


(針對想要加入的指令 可以參考/usr/lib/nagios/plugins目錄)

(為了防止之後 /etc/hosts 名稱對應有問題建議可以將 localhost 改為 127.0.0.1)

command[check_ssh]=/usr/lib/nagios/plugins/check_ssh   127.0.0.1

command[check_smtp]=/usr/lib/nagios/plugins/check_smtp  127.0.0.1


(這邊如果為了迅速 | 懶的改, 在ip 沒有改變的狀況底下可以下載已改好檔案#wget   https://dl.dropboxusercontent.com/u/12787647/20130704nagios/client-nrpe.cfg

覆蓋且移動原來的設定檔

#mv   client-nrpe.cfg   /etc/nagios/nrpe.cfg

這個部份就自行考量 ^^)


#vi   /etc/nagios/nrpe.cfg

(如果IP有改就改 allowed_hosts= 後面接的IP吧 !! )

(EasyCloud Lab 請將代號改成 vda1)



重新啟動 nrpe 服務( 修改完 /etc/nagios/nrpe.cfg 請記得重新啟動服務)

#rcnrpe  restart


再次測試

#/usr/lib/nagios/plugins/check_nrpe-H localhost -c check_sda1

#/usr/lib/nagios/plugins/check_nrpe-H localhost -c check_sda2


另外於Server端測試 相關的指令

#/usr/lib/nagios/plugins/check_nrpe  -c  check_sda1  -H  192.168.3.129  

#/usr/lib/nagios/plugins/check_nrpe  -c  check_sda2  -H  192.168.3.129




Part III:linux伺服器(Nagios Client)加入到Nagios監控範圍


*************************************************************


Lab: 範本 for host 與 service

新的主機範本 windows-pc 

新的群組範本 windows-pcgroup

新的群組範本 linux-servergroup

新的服務範本 generic-pc-service



請於Server上面


nagios 設定檔內可以經由套用範本 use 的方式來加速管理


用來自訂 監控的時間 或是 設定預設的群組


舉例來說 一般的 workstation 不會 24 小時開機, 只會在上班時間開機

所以先建立, windows-pc 的範本,針對一般的 PC, 指定 上班時間監控.


Nagios 範本設定檔 /etc/nagios/objects/templates.cfg

Nagios 時間範本設定檔   /etc/nagios/objects/timeperiods.cfg


修改 Nagios 的範本檔,將 windows-servers複製一份改為 windows-pc

並修改 檢查時間為 workhours


#vi   /etc/nagios/objects/templates.cfg      (此為說明建立過程不用操作)


建立新的主機範本 windows-pc

# Windows host definition template - This is NOT a real host, just a template!


define host{

       name                  windows-pc      ; The name of this host template 範本的名稱

       use                     windows-server  ; 繼承 windows-server 的所有設定

       check_period     workhours    ; 檢查的時間範圍

       notification_period     workhours            ; Send notification out at any time - day or night

       hostgroups           windows-pcgroup   ; window-pc 主機預設會歸屬的群組

       }


另外定義一個群組 為 windows-pcgroup

讓剛剛建立的主機 範本可以直接加入

# Define host group for Windows PC

define hostgroup{

   hostgroup_name  windows-pcgroup  ; The name of the hostgroup

   alias       Windows PC Group  ; Long name of the group

   }


定義一個群組 為 linux-servergroup

讓 linux-server 範本 可以直接加入


# Define host group for Linux Servers

define hostgroup{

       hostgroup_name linux-servergroup      ; The name of the hostgroup

       alias           Linux Server Group      ; Long name of the group

       }


定義一個群組 為 windows-server (原本定義在 windows.cfg)

讓 windows-server 範本 可以直接加入


# 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

       }


修改 linux-server 的範本 讓他自動加入 linux-servergroup



# 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          ; Notifications get sent to the admins by default

       hostgroups                      linux-servergroup ; Host groups that Linux servers should be a member of

       register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!

       }



建立新的服務範本 generic-pc-service 給一般PC使用

因為一般PC 只會在工作時間開機, 可以複製 generic-service 的範本來修改


# Generic PC service definition template - This is NOT a real service, just a template!


define service{

       name                            generic-pc-service     ; The 'name' of this service template

       use                               generic-service         ; 繼承generic-service的設定

       check_period                    workhours              ; The service can be checked at any time of the day

       notification_period             workhours               ; Notifications can be sent out at any time

       }



workhours 的檢查時間為 早上 9:00 到 下午 5:00


可以 參考 /etc/nagios/objects/timeperiods.cfg

設定內容如下

# 'workhours' timeperiod definition

define timeperiod{

       timeperiod_name workhours

       alias           Normal Work Hours

       monday          09:00-17:00

       tuesday         09:00-17:00

       wednesday       09:00-17:00

       thursday        09:00-17:00

       friday          09:00-17:00

       }





建立NRPE服務範本

因為日後要使用NRPE方式檢查服務以及執行指令所以先加進來


#NRPE service template 這邊加入日後要使用的 NRPE 指令


define service{

       name                    nrpe-check_users

       use                     generic-service

       service_description     Online Users

       check_command           check_nrpe!check_users

       }


define service{

       name                    nrpe-check_sda1

       use                     generic-service

       service_description     Check sda1

       check_command           check_nrpe!check_sda1

       }


define service{

       name                    nrpe-check_sda2

       use                     generic-service

       service_description     Check sda2

       check_command           check_nrpe!check_sda2

       }


define service{

       name                    nrpe-check_load

       use                     generic-service

       service_description     Check Load

       check_command           check_nrpe!check_load

       }


define service{

       name                    nrpe-check_total_procs

       use                     generic-service

       service_description     Total_Procs

       check_command           check_nrpe!check_total_procs

       }


define service{

       name                    nrpe-check_ssh

       use                     generic-service

       service_description     Check SSH

       check_command           check_nrpe!check_ssh

       }


define service{

       name                    nrpe-check_smtp

       use                     generic-service

       service_description     Check SMTP

       check_command           check_nrpe!check_smtp

       }





(這邊如果為了迅速 | 懶的改, 可以下載已改好檔案

#wget  https://dl.dropboxusercontent.com/u/12787647/20130704nagios/server-templates20130704.cfg


覆蓋且移動原來的設定檔

# mv   server-templates20130704.cfg   /etc/nagios/objects/templates.cfg


這個部份就自行考量 ^^)

(Easy Cloud 的Lab

#vi   /etc/nagios/objects/templates.cfg

請將template.cfg 內的 nrpe-check_sda1 改為 nrpe-check_vda1 把sda 對應到 vda

)








請於Server上面


複製windows的設定檔 來當成linux server的範本設定檔

# cp  /etc/nagios/objects/windows.cfg   /etc/nagios/objects/linux.cfg    (此為說明建立過程不用操作)


修改/etc/nagios/objects/linux.cfg內的設定 加上主機名稱修改為ClientIP


#vi   /etc/nagios/objects/linux.cfg    (此為說明建立過程不用操作)

將原來的

define host{

use windows-server ; Inherit default values from a template

host_name winserver ; The name we're giving to this host

alias My Windows Server ; A longer name associated with the host

address 192.168.1.2 ; IP address of the host

}


改為(定義遠端Linux主機的名稱及IP)


define host{

use  linux-server;這邊的名稱要參照template內的名稱,故不能亂取

host_name  suseserver129; The name we're giving to this host主機名稱(簡稱)

aliasopenSUSE Server2; A longer name associated with the host主機名稱()

address192.168.3.129 ; IP address of the host

}


接下來處理服務的部份, 因為所有要監控的服務都會認主機名稱

使用:%s/winserver/suseserver129/gcdefine service{ }內的

host_namewinserver

改為

host_namesuseserver129


接下來將群組註解

將原來

define hostgroup{

hostgroup_namewindows-servers ; The name of the hostgroup

aliasWindows Servers ; Long name of the group

}


改為

#define hostgroup{

#hostgroup_namewindows-servers ; The name of the hostgroup

#aliasWindows Servers ; Long name of the group

#}



設定要監控的服務,

這邊就可以套用剛剛我們於 /etc/nagios/objects/templates.cfg的設定



define service{

usegeneric-service

host_namesuseserver129

service_descriptionNSClient++ Version

check_commandcheck_nt!CLIENTVERSION

}


改為(以線上使用者為例)

define service{

use nrpe-check_users

host_name suseserver129

}


define service{

       use                     nrpe-check_sda1

       host_name          suseserver129

       }


define service{

       use                     nrpe-check_sda2

       host_name               suseserver129

       }


define service{

       use                     nrpe-check_load

       host_name               suseserver129

       }


define service{

       use                     nrpe-check_total_procs

       host_name               suseserver129

       }



define service{

       use                     nrpe-check_ssh

       host_name               suseserver129

       }


define service{

       use                     nrpe-check_smtp

       host_name               suseserver129

       }


請注意主機名稱需對應define host { }區段內的host_name



(這邊如果為了迅速 | 懶的改, 在ip 沒有改變的狀況底下可以下載已改好檔案#wget   https://dl.dropboxusercontent.com/u/12787647/20130704nagios/server-linux20130704.cfg


覆蓋且移動原來的設定檔

# # mv   server-linux20130704.cfg   /etc/nagios/objects/linux.cfg

這個部份就自行考量 ^^)

(Easy Cloud 的Lab

#vi   /etc/nagios/objects/linux.cfg

請將linux.cfg 內的 nrpe-check_sda1 改為 nrpe-check_vda1 把sda 對應到 vda

)



整理一下對應關係

Server:建立要監控對象的範本

  • /etc/nagios/object/linux.cfg


Client:設定允許監控伺服器 IP, NRPE 相對應的指令

  • /etc/nagios/nrpe.cfg



**設定 NRPE 指令對應**

請於Server上面

修改/etc/nagios/objects/commands.cfg加入check_nrpe的指令對應


# vi   /etc/nagios/objects/commands.cfg   (此為說明建立過程不用操作)


加入

# 'check_nrpe' command definition

define command{

command_name check_nrpe

command_line$USER1$/check_nrpe-H $HOSTADDRESS$-c $ARG1$

}


(這邊如果為了迅速 | 懶的改, 可以下載已改好檔案

#wget   https://dl.dropboxusercontent.com/u/12787647/20130704nagios/server-commands.cfg

覆蓋且移動原來的設定檔

# mv   server-commands.cfg   /etc/nagios/objects/commands.cfg

這個部份就自行考量 ^^)




**設定 Nagios 載入 linux.cfg **


請於Server上面

建立之後存放 Server 與 一般工作站的設定檔目錄

#mkdir   /etc/nagios/servers

#mkdir   /etc/nagios/pcs


將剛剛的 linux.cfg 複製給 linux server 使用並複製到 /etc/nagios/servers目錄 

# cp /etc/nagios/objects/linux.cfg   /etc/nagios/servers/linux129.cfg


最後修改/etc/nagios/nagios.cfg內的設定 讓linux.cfg設定載入,可以監控nagios Clinet


#vi   /etc/nagios/nagios.cfg

加入

cfg_dir=/etc/nagios/servers

cfg_dir=/etc/nagios/pcs



確認IP設定無誤

#vi   /etc/nagios/servers/linux129.cfg


(address         192.168.3.129 請改成實際的IP )


確認設定檔是否無誤

# nagios   -v   /etc/nagios/nagios.cfg


重新啟動nagios使其生效

#rcnagios   restart


(:重新啟動之後不會馬上偵測,會過幾分鐘才偵測)

Part IV:Nagios用戶端-- Windows 伺服器/ Windows PC用戶端建置


1.安裝NSClient++軟體 (4.x 版改名為 nscp)

請於Window伺服器 或是用戶端


開啟瀏覽器 連線至NSClient++的專案網頁下載軟體

http://www.nsclient.org/


依照機器的平台 x86 or x86_64 下載軟體 這邊以0.4.0-Win64 為例


http://sourceforge.net/projects/nscplus/files/nscplus/NSClient%2B%2B%200.4.0/NSCP-0.4.0.172-x64.msi/download


( 如果是 ie 增強性瀏覽, 就複製下載 link 在新頁面貼上開啟 )

出現安裝精靈

請按Next



接下來End-User License Agreement

請勾選'I accept the terms in the License Agreement' →Next



接下來Custom Setup

請按Next



NSClient會偵測是否有舊的設定檔

由於是新的安裝 請按Next




這個部份是最重要的部份

Allow hosts:輸入Nagios ServerIP (只允許這台機器連線)

針對要載入的模組 勾選Next




開始安裝

點選Install




安裝完成後

勾選Start service → Finish




Part V:Windows伺服器/PC (Nagios Client)加入到Nagios監控範圍


請於Server上面


複製windows.cfg  Windows伺服器或是PC使用


這邊設定檔的名稱 假定為windows130.cfg

(這邊個人處理方式目前以IP命名)


# cp  /etc/nagios/objects/windows.cfg   /etc/nagios/pcs/windows130.cfg


修改相關設定


# vi   /etc/nagios/pcs/windows130.cfg


Step1:

請將文件內 主機名稱(host_name)winserver改為Windows主機名稱

例如winpc130

  • 可以利用vi的取代功能:%s/winserver/winpc130/gc



Step 2:

請將預設 IP 修改為 正確的 IP位址


define host{

use windows-server ;需參考template不可以自己亂取名稱

host_name winserver ; The name we're giving to this host 主機名稱

alias My Windows Server ; A longer name associated with the host 主機名稱()

address 192.168.1.2 ; IP address of the host 用戶端IP位址

}


改為

define host{

usewindows-pc ; Inherit default values from a template

host_namewinpc130; The name we're giving to this host

aliasWindows PC 192.168.3.130; A longer name associated with the host

address192.168.3.130 ; IP address of the host

}


另外確認所有的define service內的設定host_name都是新的主機名稱(winpc130)

將服務 套用 generic-pc-service 符合一般PC 只於上班時間運作


define service{

usegeneric-pc-service

host_namewinpc130

service_description NSClient++ Version

check_command check_nt!CLIENTVERSION

}


另外一般的 PC 不會開 網頁伺服器 故註解 W3SVC


#define service{

#        use                     generic-pc-service

#        host_name               winpc130

#        service_description     W3SVC

#        check_command           check_nt!SERVICESTATE!-d SHOWALL -l W3SVC

#        }



要注意的是主機群組只能定義一次,

windowsxxx.cfg內的主機群組定義

都要註解起來,才不會發生錯誤!!

故請將設定檔內的


define hostgroup{

hostgroup_name windows-servers ; The name of the hostgroup

alias Windows Servers ; Long name of the group

}


註解起來


#define hostgroup{

# hostgroup_name windows-servers ; The name of the hostgroup

# alias Windows Servers ; Long name of the group

# }


(這邊如果為了迅速 | 懶的改, 在ip 沒有改變的狀況底下可以下載已改好檔案#wget   https://dl.dropboxusercontent.com/u/12787647/20130704nagios/server-windows.cfg

#wget   https://dl.dropboxusercontent.com/u/12787647/20130704nagios/server-windows130.cfg

(如果有改IP 就請修正 Client 的IP)


覆蓋且移動原來的設定檔

# mv  server-windows.cfg   /etc/nagios/objects/windows.cfg

# mv  server-windows130.cfg   /etc/nagios/pcs/windows130.cfg

這個部份就自行考量 ^^)


確認IP設定無誤

#vi   /etc/nagios/pcs/windows130.cfg


(address         192.168.3.130 請改成實際的IP )


確認設定檔是否無誤

# nagios  -v  /etc/nagios/nagios.cfg


重新啟動nagios使其生效

#rcnagios   restart


(:重新啟動之後不會馬上偵測,會過幾分鐘才偵測)

這樣第一份Windows機器的設定檔就設定完成

( 確認你的 Windows firewall  可以被server ping 或是 port 12489 沒有擋 )

( for win2008 在管理工具內防火牆管理File And Print Sharing (Echo Request - ICMPv4-IN) )

可以在 Server 上確認

# /usr/lib/nagios/plugins/check_nt  -H  192.168.3.130  -p  12489   -v  CLIENTVERSION

# /usr/lib/nagios/plugins/check_nt  -H  192.168.3.130  -p 12489  -v   USEDDISKSPACE  -l  c


Window Client 也可以重新啟動 nsclient++


如果要加入第二台Windows機器設定

可以複製 原來的Windows設定,例如

# cp   /etc/nagios/pcs/windows130.cfg   /etc/nagios/pcs/windows130.cfg


修改 主機名稱 及 IP即可


以上^__^大功告成

相關畫面如下







Optional Lab: 透過 即時通訊 軟體來通知

以上預設的通知方式是透過 e-mail 來傳送通知

如果希望使用更即時的通知方式, 也可以透過 即時通訊軟體來通知管理者


這邊建議使用  Jabber 的方式來通知管理者 ( 也就是透過 Google Talk )

(之前 perl 的方式目前來通知 jabber 有點問題, 我們使用 python-xmpppy)

(參考http://blogs.gnome.org/woody/2012/02/18/nagios-xmpp-notifications-for-gtalk/ )

但是要使用 Jabber (Google talk's XMPP) 的服務要安裝相關套件

這邊我們使用 OneClickInstall  的方式來安裝套件


請在Server

安裝 python-xmpppy 套件

以下這行指令在同一行

#OneClickInstallCLIhttp://software.opensuse.org/ymp/devel:languages:python/openSUSE_12.2/python-xmpppy.ymp





驗證是否有安裝

# zypper   search   xmpp

正在載入套件庫資料...

讀取已安裝的套件...


S | 名稱                      | 摘要                                                                | 類型    

--+---------------------------+---------------------------------------------------------------------+---------

 | libqxmpp-devel            | Qxmpp Development Files                                             | 套件    

 | libqxmpp1                 | Qt XMPP Library                                                     | 套件    

 | libqxmpp1-32bit           | Qt XMPP Library                                                     | 套件    

i | perl-Net-XMPP             | XMPP Perl Library                                                   | 套件    

 | python-pyxmpp             | Python Jabber/XMPP Implementation                                   | 套件    

 | python-pyxmpp             | Python Jabber/XMPP Implementation                                   | src 套件

 | python-pyxmpp-debuginfo   | Debug information for package python-pyxmpp                         | 套件    

 | python-pyxmpp-debugsource | Debug sources for package python-pyxmpp                             | 套件    

 | python-sleekxmpp          | Python XMPP (Jabber) Library that Implements Everything as a Plugin | 套件    

 | python-sleekxmpp          | Python XMPP (Jabber) Library that Implements Everything as a Plugin | src 套件

i | python-xmpppy             | Jabber Library for Python                                           | 套件    

 | python-xmpppy             | Jabber Library for Python                                           | src 套件

i | sendxmpp                  | A perl-script to send xmpp, similar to what mail does for mail      | 套件  





將網頁上的 程式儲存為  notify_via_jabber 並修改自己的 google 帳號以及google密碼 ( 以下的google 帳號必須與等等被通知的google 帳號互為 google talk 聯絡人 )


# vi   /usr/local/bin/notify-via-jabber

#!/usr/bin/python -tt


import warnings

warnings.simplefilter("ignore")


import xmpp

from xmpp.protocol import Message


from optparse import OptionParser

import ConfigParser

import sys

import os


parser = OptionParser()

opts, args = parser.parse_args()


if len(args) < 1:

   print "xmppsend message [to whom, multiple args]"

   sys.exit(1)


msg = args[0]


msg = msg.replace('\\n', '\n')


# Connect to the server

c  =  xmpp.Client('gmail.com')

c.connect( ( 'talk.google.com', 5223 ) )


# Authenticate to the server

jid  =  xmpp.protocol.JID( 'example@gmail.com' )

c.auth( jid.getNode( ), 'yourgmailpassword' )


if len(args) < 2:

   r = c.getRoster()

   for user in r.keys():

       if user == username:

           continue

       c.send(Message(user, '%s' % msg))

else:

   for user in args[1:]:

       c.send(Message(user, '%s' % msg))


懶的 vi 是吧 ^_^

#wget    https://dl.dropboxusercontent.com/u/12787647/20130704nagios/notify-via-jabber

但是再如何懶也要進去填個帳號吧


#chmod  a+x  notify-via-jabber

# mv   notify-via-jabber    /usr/local/bin/


測試 一下傳送訊息

#/usr/local/bin/notify-via-jabber  "testmesg"  被通知的google帳號  


接下來修改相關設定

將 notify-by-jabber 以及 host-notify-by-jabber  加入到/etc/nagios/objects/commands.cfg






# vi   /etc/nagios/objects/commands.cfg

加入 請複製參考網頁上面的設定


define command{

       command_name    host-notify-by-jabber

       command_line    /usr/local/bin/notify-via-jabber "Host '$HOSTALIAS$' is $HOSTSTATE$ - Info : $HOSTOUTPUT$" $CONTACTPAGER$

       }


define command{

       command_name    notify-by-jabber

       command_line    /usr/local/bin/notify-via-jabber  "$NOTIFICATIONTYPE$ $HOSTNAME$ $SERVICEDESC$ $SERVICESTATE$ $SERVICEOUTPUT$ $LONGDATETIME$" $CONTACTPAGER$

       }


由上面的指令可以看出 notify_via_jabber 後面傳送的 Google 帳號是由 $CONTACTPAGER$ 來指定


所以我們要新增 聯絡人的 PAGER, 也就是 google 帳號


# vi  /etc/nagios/objects/contacts.cfg

請加入 pager 的設定, 就是要傳送的 google 帳號

define contact{

       contact_name                    nagiosadmin             ; Short name of user

       use                             generic-contact         ; Inherit default values from generic-contact template (defined above)

       alias                           Nagios Admin            ; Full name of user

       email                           sakana@study-area.org   

       pager                           要傳送的google帳號

       }








故我們接下來修改範本設定檔 /etc/nagios/objects/templetes.cfg


# vi /etc/nagios/objects/templates.cfg

修改 generic-contact 內容, 加入 jabber 的設定


define contact{

       name                            generic-contact         ; The name of this contact template

       service_notification_period     24x7                    ; service notifications can be sent anytime

       host_notification_period        24x7                    ; host notifications can be sent anytime

       service_notification_options    w,u,c,r,f,s             ; send notifications for all service statesents

       host_notification_options       d,u,r,f,s               ; send notifications for all host states

       service_notification_commands   notify-service-by-email,notify-by-jabber; 加入設定

       host_notification_commands      notify-host-by-email,host-notify-by-jabber    ; 加入設定

       register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!

       }



確認設定檔是否無誤

# nagios  -v  /etc/nagios/nagios.cfg


重新啟動nagios使其生效

#rcnagios   restart







Optional Lab: Nagios Map icon


有關於在status的頁面要使用圖案

可以上 Nagios 的官網去抓 icon

http://exchange.nagios.org/directory/Images-and-Logos


我是去抓 Base Images

頁面如下

http://exchange.nagios.org/directory/Graphics-and-Logos/Images-and-Logos/Base-Images/details


下載下來檔案名稱為 base.zip (假設下載到 /root)


解壓縮在/usr/share/nagios/images/logos/base

#unzip  /root/base.zip

#mv   /root/base   /usr/share/nagios/images/logos



可以在該主機的設定檔內加入以下區段


define hostextinfo{

       host_name       da-1

       icon_image      base/linux40.gif;icon的圖案

       icon_image_alt  linux

       statusmap_image base/linux40.gd2 ;這個才是statusmap上面的圖案,最好用gd2省資源

       }


icon要放在安裝目錄的 images/logos目錄下


openSUSE安裝的目錄路徑就是 /usr/share/nagios/images/logos

所以路徑寫法就會是 base/linux40.gd2


但是上面的寫法

要一個一個主機設定這樣比較麻煩

所以可以使用範本的方式來解決


# vi /etc/nagios/objects/templates.cfg

將 剛剛的範本檔案

# 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          ; Notifications get sent to the admins by default

       hostgroups                      linux-servergroup ; Host groups that Linux servers should be a member of

       register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!

       }


加上相關設定

# 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          ; Notifications get sent to the admins by default

       hostgroups                      linux-servergroup ; Host groups that Linux servers should be a member of

       icon_image                      base/linux40.gif

       icon_image_alt                  linux

       statusmap_image                 base/linux40.gd2        ;這個才是statusmap 上面的圖案, 最好用gd2 省資源

       register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!

       }


這樣就可以讓所有機器都套用

windows 還有其他的機器也可以比照辦理


加完要重新啟動 nagios

#rcnagios restart     






0 0