nagios监控安装esxi的服务器(宿主机)

摘要:
以下内容大部分来自网络:普通的Dell服务器硬件监控我们可以通过nagios+openmanage来实现,但是vsphere环境中的Esxi主机的硬件监控怎么实现呢?这里有两种方案:1.通过nagios插件check_esx来实现,这种方式需要安装vmwarevspheresdkforperl工具包2.通过nagios插件check_esxi_hardware.py来实现,此插件使用python写的。我自己是centos6.x的系统,直接使用yum安装时没有问题,centos7.x没有测试,请自行测试。

首先,该博文大部分内容来自网络,少部分是自己监控过程中遇到的问题。如果有侵权,请联系告知!!!

现在互联网公司,有能力的都是自己研发监控系统,要么就是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.0python 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 newstyle 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 thishelp 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 aspassword
    Optional parameters:
    -V VENDOR, --vendor=VENDOR
    Vendor code: auto, dell, hp, ibm, intel, or unknown
    (default)
    -v, --verbose print status messages to stdout (default isto be
    quiet)
    -p, --perfdata collect performance data for pnp4nagios (default isnot to)
    -I XX, --html=XX generate html links for country XX (default isnot 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;

nagios监控安装esxi的服务器(宿主机)第1张


nagios监控安装esxi的服务器(宿主机)第2张

通过VMware vSphere Client连接主机,创建用户(只读),注:密码有复杂度要求!

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

nagios监控安装esxi的服务器(宿主机)第3张

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

nagios监控安装esxi的服务器(宿主机)第4张

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文件
nagios监控安装esxi的服务器(宿主机)第5张
删除“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 isautogenerated 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)监控效果图

nagios监控安装esxi的服务器(宿主机)第6张

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

免责声明:文章转载自《nagios监控安装esxi的服务器(宿主机)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇CSS遮罩maskVba+access+Excel编程下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

centos83+django3.1+ASGI+nginx部署.

上一篇,在windows下尝试使用ASGI部署django3.1,部署失败一半,为什么说失败一半呢?因为按照官方文档, Gunicorn是在生产环境中运行和管理Uvicorn的最简单方法, 但是比如用 gunicorn -w 4 -k uvicorn.workers.UvicornWorker 以四个工作进程启动Gunicorn的时候,UvicornWor...

Windows下Python虚拟环境安装及新建django项目及简单流程

---恢复内容开始--- (1-7)为第一种创建虚拟环境的方法 1. 安装Python 2. 在cmd命令行中使用pip安装:pip install virtualenv 3. 新建虚拟环境:virtualenv testvir 4. 进入该虚拟环境:cd testvir 5. cd Scripts 6. activate.bat就进入了该虚拟环境 如图所...

python的整数没有补码一说

在刷题过程中,发现Python有一个和其他语言完全不一样的地方,就是对负数的二进制表示。Python里的数是无所谓Overflow的,即没有位数限制,因此也就无所谓补码,因为补码都是相对于位数来说的,32位补码和16位补码,肯定是不一样的。但是这样就导致了一个问题,就是无法直接得到32位二进制补码。 >>> bin(1) '0b1'...

python 中文字数统计/分词

因为想把一段文字分词,所以,需要明确一定的词语关系。 在网上随便下载了一篇中文小说。随便的txt小说,就1mb多。要数数这1mb多的中文到底有多少字,多少分词,这些分词的词性是什么样的。 这里是思路 1)先把小说读到内存里面去。 2)再把小说根据正则表达法开始分词,获得小说中汉字总数 3)将内存中的小说每段POST到提供分词服务的API里面去,获取分词结果...

Robot Framework安装环境与导入自定义py模块

①安装python2.7 虽然python2.7据说已经停止更新,但是还是要继续用。 官网下载: https://www.python.org/downloads/windows/ 添加环境变量,将C:Python27和C:Python27Scripts(python2.7安装路径)添加到系统环境变量Path后面。 ②安装Robot Framework...

supervisor的command执行两条命令

如下supervisor的进程的comand配置参数只能写一个命令 1、要执行多条命令,可以写个sh文件包含多条命令,然后sh -x xxxx.sh,但这样又多了一个文件, 2、把所有命令放在字符串,然后用eval来执行,这样在shell窗口可以执行,但放在supervisor报找不到eval命令。比如: command = eval "python -u...