Nagios监控ESXI主机系统、硬件

使用Nagios的扩展插件check_esx3.pl、check_esxi_hardware.py来监控VMware
ESX服务器,check_esx3.pl主要监控系统资源,例如cpu、内存等使用情况,check——esxi_hardware.py主要监控的是硬件资源。既可以实现监控单台ESX(i)服务器,也可以监控VirtualCenter/vCenter服务器集群。当企业中已经部署虚拟数据中心(vCenter)时,应该监控vCenter而不是单台ESX/vSphere服务器。

普通的Dell服务器硬件监控我们可以通过nagios+openmanage来实现,但是vsphere环境中的Esxi主机的硬件监控怎么实现呢?

安装:
1、安装关联库文件
[root@localhost ~]# yum -y install gcc openssl libssl libssl-dev
per-doc rpm

这里有两种方案:

2、下载vmware vsphere sdk for perl工具包:
check_esx3.pl需要安装vmware vsphere sdk for perl工具包

[root@localhost src]# tar zxvf
VMware-vSphere-SDK-for-Perl-4.0.0-161974.x86_64.tar.gz
[root@localhost src]# cd vmware-vsphere-cli-distrib
[root@localhost vmware-vsphere-cli-distrib]# ./vmware-install.pl

1.通过nagios插件check_esx来实现,这种方式需要安装vmware vsphere sdk for
perl工具包

3、安装check_esx3.pl

2.通过nagios插件check_esxi_hardware.py来实现,此插件使用python写的。

check_esx3.pl存放至nagios安装目录下的libexec目录中:
 
[root@localhost src]# mv check_esx3-0.5.pl
/usr/local/nagios/libexec/
[root@localhost src]# cd /usr/local/nagios/libexec/
[root@localhost libexec]# chmod +x check_esx3-0.5.pl
[root@localhost libexec]# ./check_esx3-0.5.pl -help
Can't locate Nagios/Plugin.pm in @INC .........
[root@localhost libexec]#

感人感觉第二种方式比较简单些,python在linux天生内置,还需要更多理由吗?

安装 Nagios::Plugin插件
[root@localhost libexec]# perl -MCPAN -e 'install Nagios::Plugin'
[root@localhost libexec]# ./check_esx3-0.5.pl -help
Can't locate Nagios/Plugin.pm in @INC .........
[root@localhost libexec]#

先看看官网介绍。

安装 rpmforge-release

其中:

[root@localhost libexec]# wget 

[root@localhost libexec]# rpm -ivh
rpmforge-release-0.5.2-2.el5.rf.i386.rpm

Requirements

安装perl组件
[root@localhost libexec]# yum -y install perl-Params-Validate
perl-Math-Calc-Units perl-Regexp-Commonperl-Class-Accessor
perl-Config-Tiny perl-Nagios-Plugin.noarch
[root@localhost libexec]# ./check_esx3-0.5.pl -help
Can't locate LWP/UserAgent.pm in @INC 
[root@localhost libexec]#

  • 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

安装插件Bundle::LWP
[root@localhost libexec]# perl -MCPAN -eshell
cpan> install Bundle::LWP         
Do you want to modify/update your configuration (y|n) ? [no] no
Shall I follow them and prepend them to the queue of modules we are
processing right now? [yes] yes
cpan> exit

以上是实现监控的先决条件:

这里提示要不要对原有网络配置进行更新修改,我们选择no,这里提示须跟随他们和他们预队列中我们现在正在处理的模块吗,直接输入yes.
[root@localhost libexec]# ./check_esx3-0.5.pl -help
Can't locate Zlib/Compress.pm in @INC 
[root@localhost libexec]# perl -MCPAN -e 'install Compress::Zlib'

1.python必须安装

安装脚本使用cpan安装perl模块,会有一些perl模块安装不上,这些安装不上的模块,得手动使用cpan去安装,若还安装不上那么就用yum去安装,例如
UUID,
error:installed manuallyfor use by vSphere CLI:
UUID 0.03 or newer

2.python的扩展包pywbem必须安装

解决:
[root@localhost libexec]# yum install perl-SOAP-Lite
perl-Data-Dumpperl-Class-MethodMaker perl-Crypt-SSLeay
perl-libxml-perlperl-XML-LibXML-Common libuuid-devel  uuid-perl  -y
[root@localhost libexec]# perl -MCPAN -e'install UUID'
[root@localhost libexec]# ./check_esx3.pl  -H 10.10.2.233 -u root-p
'justin' -l cpu
CHECK_ESX3.PL CRITICAL -Server version unavailable at
''
at/usr/share/perl5/VMware/VICommon.pm line 545.
[root@localhost libexec]# vim check_esx3.pl
#!/usr/bin/perl -w$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
#
# Nagios plugin to monitor vmware esxservers
[root@nagioslibexec]# ./check_esx3.pl  -H 10.10.2.233 -u root -p
'justin' -l cpu
CHECK_ESX3.PLCRITICAL - Server version unavailable at
'' at
/usr/lib/perl5/5.8.8/VMware/VICommon.pm line 545.

3.你的Esxi主机的443,5989端口必须对nagios监控端开放

对这个问题的解决办法是添加一个参数,,以check_esx3.pl告诉LWP的,可以忽略不计,自签名的SSL证书(因为他们的ESX
/ i服务器的默认),根据提示在 check_esx3.pl中添加一行
"$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;"
[root@nagioslibexec]# vim check_esx3.pl
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
#
# Nagios plugin to monitor vmware esx servers
#
# License: GPL
[root@nagioslibexec]# ./check_esx3.pl  -H 10.10.2.233 -u root -p
'justin' -l cpu
CHECK_ESX3.PL OK -cpu usage=55.00 MHz (0.12%) |
cpu_usagemhz=55.00Mhz;; cpu_usage=0.12%;;

好了,下面就赶紧实施吧!

check_esx3.pl参数使用可以通过./check_esx3.pl --help查看

1.安装check_essi_hardware.py

4、安装check_esxi_hardware.py
check_esxi_hardware.py需要安装python、python的扩展包pywbem、你的Esxi主机的443,5989端口必须对nagios监控端开放,
[root@nagioslibexec]# wget 
[root@nagioslibexec]# chown nagios.nagios check_esxi_hardware.py
[root@nagioslibexec]# chmod 755 check_esxi_hardware.py
[root@nagioslibexec]# ./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@nagioslibexec]#  ./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</module></module>

cd /usr/local/nagios/libexec
wget

chown nagios.nagios check_esxi_hardware.py
chmod 755 check_esxi_hardware.py

pywbem模块没有安装,安装python的第三方模块

1234567 [root@nagioslibexec]# wget 
 [root@nagioslibexec]# tar -zxvf  pywbem-0.7.0.tar.gz
 [root@nagioslibexec]# cd pywbem-0.7.0
 [root@nagioslibexec]# python setup.py build
 [root@nagioslibexec]# python setup.py install --record files.txt
 [root@nagioslibexec]# ./check_esxi_hardware.py -H 10.10.2.233-U
nagios -P nagios -V dell
 OK - Server: Dell Inc. PowerEdge R610 s/n: XXXXXX System BIOS:
XXXXXXXXXXX

安装完成后,我们来查看下这个插件都有什么参数:

如果使用pywbem-0.8.0版本可能导致我们的插件无法使用,python setup.py
install --record files.txt 记录安装目录的目的就是为了方便卸载插件,cat
files.txt | xargs rm -rf

[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

使用check_esx3.pl和check_esxi_hardware.py都只需要在Esxi主机上建立只读的用户名和密码即可。使用./check——esx3.pl
-helo和check_esxi_hardware.py -help可以查看插件使用语法,
[root@localhost libexec]# ./check_esxi_hardware.py  -help
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)     
                        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
[root@localhost libexec]#

哦,原来pywbem模块没有安装,那就赶紧装下吧。

给Esxi主机设置只读用户
1)先登录Esxi主机,在“本地用户和组”标签中,空白处右键“添加”,即可添加用户。

2.安装python的第三方模块

相关文章

Comment ()
评论是一种美德,说点什么吧,否则我会恨你的。。。