阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Nagios监控ESXi硬件

171次阅读
没有评论

共计 10056 个字符,预计需要花费 26 分钟才能阅读完成。

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

这里有两种方案:

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

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

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

先看看官网介绍。

其中:

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 不采集电源信息,以下雷同。

————————————– 分割线 ————————————–

在 Ubuntu 下配置 Mrtg 监控 Nginx 和服务器系统资源 http://www.linuxidc.com/Linux/2013-08/88417.htm

使用 snmp+Mrtg 监控 Linux 系统 http://www.linuxidc.com/Linux/2012-11/73561.htm

Mrtg 服务器搭建(监控网络流量)http://www.linuxidc.com/Linux/2012-07/64315.htm

网络监控器 Nagios 全攻略 http://www.linuxidc.com/Linux/2013-07/87067.htm

Nagios 搭建与配置详解 http://www.linuxidc.com/Linux/2013-05/84848.htm

Nginx 环境下构建 Nagios 监控平台 http://www.linuxidc.com/Linux/2011-07/38112.htm

在 RHEL5.3 上配置基本的 Nagios 系统 (使用 Nagios-3.1.2) http://www.linuxidc.com/Linux/2011-07/38129.htm

CentOS 5.5+Nginx+Nagios 监控端和被控端安装配置指南 http://www.linuxidc.com/Linux/2011-09/44018.htm

Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用 http://www.linuxidc.com/Linux/2013-11/93047.htm

————————————– 分割线 ————————————–

 

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2015-06/118686p2.htm

4. 给 Esxi 主机设置只读用户

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

Nagios 监控 ESXi 硬件

(2)将 nagios 用户设置成“只读角色”。在“权限”标签中,空白处右键“添加权限”,然后按下图操作

Nagios 监控 ESXi 硬件

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) 监控效果图

Nagios 监控 ESXi 硬件

其中 href 中的链接就是我们在 check_esxi_hardware.py 中 - I 参数生成,方便我们直接查找解决方案。

Nagios 的详细介绍 :请点这里
Nagios 的下载地址 :请点这里

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2015-06/118686.htm

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

这里有两种方案:

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

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

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

先看看官网介绍。

其中:

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 不采集电源信息,以下雷同。

————————————– 分割线 ————————————–

在 Ubuntu 下配置 Mrtg 监控 Nginx 和服务器系统资源 http://www.linuxidc.com/Linux/2013-08/88417.htm

使用 snmp+Mrtg 监控 Linux 系统 http://www.linuxidc.com/Linux/2012-11/73561.htm

Mrtg 服务器搭建(监控网络流量)http://www.linuxidc.com/Linux/2012-07/64315.htm

网络监控器 Nagios 全攻略 http://www.linuxidc.com/Linux/2013-07/87067.htm

Nagios 搭建与配置详解 http://www.linuxidc.com/Linux/2013-05/84848.htm

Nginx 环境下构建 Nagios 监控平台 http://www.linuxidc.com/Linux/2011-07/38112.htm

在 RHEL5.3 上配置基本的 Nagios 系统 (使用 Nagios-3.1.2) http://www.linuxidc.com/Linux/2011-07/38129.htm

CentOS 5.5+Nginx+Nagios 监控端和被控端安装配置指南 http://www.linuxidc.com/Linux/2011-09/44018.htm

Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用 http://www.linuxidc.com/Linux/2013-11/93047.htm

————————————– 分割线 ————————————–

 

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2015-06/118686p2.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计10056字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中