nagios監控安裝esxi的服務器(宿主機)


 

首先,該博文大部分內容來自網絡,少部分是自己監控過程中遇到的問題。如果有侵權,請聯系告知!!!

現在互聯網公司,有能力的都是自己研發監控系統,要么就是zabbix或者小米的監控,還都二次開發等等,可能使用nagios的不是那么多。哈哈,做個記錄,僅供參考!!!

<准備部署使用open-Falcon(小米開源)>

 

以下內容大部分來自網絡:

 

普通的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

  1. 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
安裝完成后,我們來查看下這個插件都有什么參數:
  1. [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的第三方模塊
  1. 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 
或者可以直接使用yum:(推薦使用)
  1. yum install pywbem -y
再試一下,還是報錯:
  1. [root@cscc libexec]# ./check_esxi_hardware.py
    Traceback (most recent call last):
    File "./check_esxi_hardware.py", line 251, in <module>
    import pkg_resources
    ImportError: No module named pkg_resources
    [root@cscc libexec]#
      
解決:
  1. [root@cscc libexec]# yum install python-setuptools -y
出現缺少模塊的錯誤,國內很多文章都是源碼安裝插件模塊,也可以,但是問題比較多;建議直接使用yum,這樣簡單並且不會出現依賴的問題
 
我自己是centos 6.x的系統,直接使用yum安裝時沒有問題,centos 7.x沒有測試,請自行測試。

 

 使用yum基本上不會涉及下面的問題。

 

注意:(1).不要使用pywbem-0.8.0版本,這個版本有bug導致我們的插件無法使用

 

    (2).python setup.py install --record files.txt 記錄安裝目錄的目的就是為了方便卸載插件,cat files.txt | xargs rm -rf

3.正常使用插件

  1. [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主機設置只讀用戶

如果使用的是Vcenter,首先需要打開監控esxi主機的ssh;

 

 


 

 

通過VMware vSphere Client連接主機,創建用戶(只讀),注:密碼有復雜度要求!

(1)先登錄Esxi主機,在“本地用戶和組”標簽中,空白處右鍵“添加”,即可添加用戶。

 

(2)將nagios用戶設置成“只讀角色”。在“權限”標簽中,空白處右鍵“添加權限”,然后按下圖操作

ok,只讀用戶nagios就添加完畢。

  1. [root@nagios-server-176 libexec]# ./check_esxi_hardware.py -H 192.168.0.100 -U nagios -P nagios -V dell
    Traceback (most recent call last):
    File "./check_esxi_hardware.py", line 617, in <module>
    wbemclient = pywbem.WBEMConnection(hosturl, (user,password), no_verification=True)
    TypeError: __init__() got an unexpected keyword argument 'no_verification'

     

出現這種情況,編輯check_esxi_hardware.py文件
 
 
 刪除“no_verification=True”
 
接着測試:
  1. [root@nagios-server-176 libexec]# ./check_esxi_hardware.py -H 192.168.0.100 -U nagios -P qwe123,./,./ -V dell
    UNKNOWN: Authentication Error

     

出現“UNKNOWN: Authentication Error”,繼續處理
通過ssh登錄esxi主機,編輯如下:
  1. ~ # 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”
  1. [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: XXXXXXXXXX
ok,監控正常。

6.下面將將其加入到監控系統中吧。

(1)先在commands.cfg中添加命令。

  1. 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)添加服務
 
  1. define service{
    ==>根據自己公司配置,定義監控服務項;
    }
 
重啟nagios!!!


(3)監控效果圖

 

其中href中的鏈接就是我們在check_esxi_hardware.py中-I參數生成,方便我們直接查找解決方案。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM