nagios監控ESXi硬體
普通的Dell伺服器硬體監控我們可以通過nagios+openmanage來實現,但是vsphere環境中的Esxi主機的硬體監控怎麼實現呢?
這裡有兩種方案:
1.通過nagios外掛check_esx來實現,這種方式需要安裝vmware vsphere sdk for perl工具包
2.通過nagios外掛check_esxi_hardware.py來實現,此外掛使用python寫的。
感人感覺第二種方式比較簡單些,python在linux天生內建,還需要更多理由嗎?
先看看官網介紹:
http://www.claudiokuenzler.com/nagios-plugins/check_esxi_hardware.php#.VWV5_JCUfTA
其中:
Requirements
- Python must be installed
- The Python extension pywbem must be installed
Windows users click here for a step-by-step guide how to install Python and PyWBEM on a Windows server.
- If there is a firewall between your monitoring and ESXi server, open ports 443 and 5989
以上是實現監控的先決條件:
1.python必須安裝
2.python的擴充套件包pywbem必須安裝
3.你的Esxi主機的443,5989埠必須對nagios監控端開放
好了,下面就趕緊實施吧!
1.安裝check_essi_hardware.py
cd /usr/local/nagios/libexec
wget http://www.claudiokuenzler.com/nagios-plugins/check_esxi_hardware.py
chown nagios.nagios check_esxi_hardware.py
chmod 755 check_esxi_hardware.py
安裝完成後,我們來檢視下這個外掛都有什麼引數:
[root@nagios libexec]# ./check_esxi_hardware.py
Traceback (most recent call last):
File "./check_esxi_hardware.py", line 222, in <module>
import pywbem
ImportError: No module named pywbem
[root@nagios libexec]# ./check_esxi_hardware.py -h
Traceback (most recent call last):
File "./check_esxi_hardware.py", line 222, in <module>
import pywbem
ImportError: No module named pywbem
哦,原來pywbem模組沒有安裝,那就趕緊裝下吧。
2.安裝python的第三方模組
cd /usr/local/src
wget http://downloads.sourceforge.net/project/pywbem/pywbem/pywbem-0.7/pywbem-0.7.0.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fpywbem%2Ffiles%2Fpywbem%2F&ts=1299742557&use_mirror=voxel
tar -zxvf pywbem-0.7.0.tar.gz
cd pywbem-0.7.0
python setup.py build
python setup.py install --record files.txt
ok,pywbem安裝完畢。
注意:(1).不要使用pywbem-0.8.0版本,這個版本有bug導致我們的外掛無法使用
(2).python setup.py install --record files.txt 記錄安裝目錄的目的就是為了方便解除安裝外掛,cat files.txt | xargs rm -rf
3.使用外掛
[root@nagios libexec]# ./check_esxi_hardware.py
no parameters specified
Usage: check_esxi_hardware.py https://hostname user password system [verbose]
example: check_esxi_hardware.py https://my-shiny-new-vmware-server root fakepassword dell
or, using new style options:
usage: check_esxi_hardware.py -H hostname -U username -P password [-V system -v -p -I XX]
example: check_esxi_hardware.py -H my-shiny-new-vmware-server -U root -P fakepassword -V auto -I uk
or, verbosely:
usage: check_esxi_hardware.py --host=hostname --user=username --pass=password [--vendor=system --verbose --perfdata --html=XX]
Options:
--version show program's version number and exit
-h, --help show this help message and exit
Mandatory parameters:
-H HOST, --host=HOST
report on HOST
-U USER, --user=USER
user to connect as
-P PASS, --pass=PASS
password, if password matches file:<path>, first line
of given file will be used as password
Optional parameters:
-V VENDOR, --vendor=VENDOR
Vendor code: auto, dell, hp, ibm, intel, or unknown
(default)
-v, --verbose print status messages to stdout (default is to be
quiet)
-p, --perfdata collect performance data for pnp4nagios (default is
not to)
-I XX, --html=XX generate html links for country XX (default is not to)
-t TIMEOUT, --timeout=TIMEOUT
timeout in seconds - no effect on Windows (default =
no timeout)
-i IGNORE, --ignore=IGNORE
comma-separated list of elements to ignore
--no-power don't collect power performance data
--no-volts don't collect voltage performance data
--no-current don't collect current performance data
--no-temp don't collect temperature performance data
--no-fan don't collect fan performance data
從上面可以看出,此外掛需要使用者名稱,密碼連線Esxi主機才能使用。當然為保證安全,只需要在Esxi主機上建立只讀的使用者名稱和密碼即可。
其中-U使用者名稱 -P密碼 -V伺服器型別,有dell,hp等,根據實際情況-v列印狀態資訊-p結合畫圖工具畫圖
-I輸出連結到dell或其他官網,方面找解決方案-t超時時間-i忽略某項監控內容
--no-power 不採集電源資訊,以下雷同。
4.給Esxi主機設定只讀使用者
(1)先登入Esxi主機,在“本地使用者和組”標籤中,空白處右鍵“新增”,即可新增使用者。
(2)將nagios使用者設定成“只讀角色”。在“許可權”標籤中,空白處右鍵“新增許可權”,然後按下圖操作
ok,只讀使用者nagios就新增完畢。
5.測試
[root@nagios libexec]# ./check_esxi_hardware.py -H 10.10.10.1 -U nagios -P nagios -V dell
UNKNOWN: Authentication Error
又報錯了,認證失敗。在網上查到原因是Esxi版本不同差異導致,例如我的本地測試機和生產環境都是5.5,但是小版本不一樣,也報錯了。
解決方案:
ssh登陸Esxi主機,編輯如下
~ # cat /etc/security/access.conf
# This file is autogenerated and must not be edited.
+:dcui:ALL
+:root:ALL
+:vpxuser:ALL
+:vslauser:ALL
-:nagios:ALL
-:ALL:ALL
將“-:nagios:ALL”去掉,在第二行加上“+:nagios:sfcb”
這種方式適合在不經常新增使用者的情況下使用,只改一次即可;但是經常加使用者可能會導致access.conf變化,需要設定計劃任務新增“+:nagios:sfcb”
再測試下:
[root@nagios libexec]# ./check_esxi_hardware.py -H 10.10.10.1 -U nagios -P nagios -V dell
OK - Server: Dell Inc. PowerEdge R610 s/n: XXXXXX System BIOS: XXXXXXXXXXX
ok,監控正常。
6.下面將將其加入到監控系統中吧。
(1)先在commands.cfg中新增命令。
vim /usr/local/nagios/etc/objects/commands.cfg
define command {
command_name check_esxi_hardware
command_line $USER1$/check_esxi_hardware.py -H $HOSTADDRESS$ -U $ARG1$ -P $ARG2$ -V $ARG3$ -I isolutions -p -t 20
}
(2)新增服務
define service{
use local-service,srv-pnp
host_name test
service_description esxi_health
check_command check_esxi_hardware!nagios!nagios!dell
service_groups hardware_health
notifications_enabled 1
}
nagioscheck
service nagios reload
(3)監控效果圖
其中href中的連結就是我們在check_esxi_hardware.py中-I引數生成,方便我們直接查詢解決方案。