首页 技术 正文
技术 2022年11月16日
0 收藏 596 点赞 3,866 浏览 3314 个字

zabbix使用自动发现监控esxi的磁盘存储storage

在任意一台可以访问vcenter的zabbix-agent服务器上添加exsi的磁盘监控模板即可

创建模板过程:

custom.esxi.discovery

zabbix使用自动发现监控esxi的磁盘存储storage

zabbix使用自动发现监控esxi的磁盘存储storage

zabbix使用自动发现监控esxi的磁盘存储storage

画图:

zabbix使用自动发现监控esxi的磁盘存储storage

注意要选择浮点型,否则可能不支持

zabbix使用自动发现监控esxi的磁盘存储storage

添加触发器:当磁盘使用率超过85%时触发报警

zabbix使用自动发现监控esxi的磁盘存储storage

自动发现的脚本:
[root@wondershareID_web03:~]# cat /usr/local/zabbix_agents_3.2.0/scripts/zabbix_esxi_storage.py
#!/usr/bin/python3
#coding:utf-8
#Author: ziming"""
只用于模拟开发功能测试
"""
from pyVmomi import vim
from pyVim.connect import SmartConnect, Disconnect, SmartConnectNoSSL
import sys
import atexit
import argparse
from optparse import OptionParser
import jsonclass Exsi(object): # 获取vcenter的相关参数
def __init__(self, host = '192.168.254.69', port=443, user = 'zabbixmonitor', password='zabbixmonitor'):
self._host = host
self._port = port
self._user = user
self._password = password def get_obj(self,content, vimtype, name=None):
'''
列表返回,name 可以指定匹配的对象
'''
container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
obj = [ view for view in container.view]
return obj def get_conn(self):
# 连接vcenter
si = SmartConnectNoSSL(
host=self._host,
user=self._user,
pwd=self._password,
port=self._port)
# disconnect this thing
atexit.register(Disconnect, si)
content = si.RetrieveContent()
return content # 获取exsi的信息ip,磁盘使用情况等
def get_esxi_host(self):
esxi_host = {}
content = self.get_conn()
esxi_obj = self.get_obj(content, [vim.HostSystem])
for esxi in esxi_obj:
esxi_host[esxi.name] = {'datastore':{}} # for ds in esxi.datastore:
# esxi_host[esxi.name]['datastore'][ds.name] = {}
# esxi_host[esxi.name]['datastore'][ds.name]['总容量(G)'] = int((ds.summary.capacity)/1024/1024/1024)
# esxi_host[esxi.name]['datastore'][ds.name]['空闲容量(G)'] = int((ds.summary.freeSpace)/1024/1024/1024)
# esxi_host[esxi.name]['datastore'][ds.name]['类型'] = (ds.summary.type) total_capacity = 0
free_capacity = 0
for ds in esxi.datastore:
# esxi_host[esxi.name]['datastore'][ds.name] = {}
esxi_host[esxi.name] = {}
total_capacity += int((ds.summary.capacity)/1024/1024/1024)
free_capacity += int((ds.summary.freeSpace)/1024/1024/1024) esxi_host[esxi.name]['sotrage_used_percent'] = 100*(total_capacity - free_capacity)/total_capacity
# print(esxi_host)
return esxi_host # 获取exsi的host即ip列表
def get_esxi_iplist(self):
esxi_host = self.get_esxi_host()
data = list()
for exsi_ip in esxi_host:
data.append({"{#EXSI_IP}": exsi_ip}) return json.dumps({'data': data}, sort_keys=True, indent=7, separators=(",",":")) # 获取指定esxi的磁盘信息
def get_esxi_storageinfo(self, exsi_ip):
esxi_host = self.get_esxi_host() return esxi_host[exsi_ip]['sotrage_used_percent']def main():
try: usage = "usage: %prog [options]\ngGet exsi Stat"
parser = OptionParser(usage) # 接收参数
parser.add_option("-l", "--list",
action="store_true", dest="is_list", default=False, help="if list all exsi ip") parser.add_option("--ip", "--ipaddr",
action="store", dest="ipaddr", type="string",
default="192.168.254.56", help="execute 'exsi info' to see more infomation") (options, args) = parser.parse_args()
if 1 >= len(sys.argv):
parser.print_help()
return #exsi_ins = Exsi(options.ipaddr)
exsi_ins = Exsi()
if options.is_list == True:
print(exsi_ins.get_esxi_iplist())
return # print(redis.ins.get_esxi_storageinfo(optins.ip, exsi_ip = ip))
print(exsi_ins.get_esxi_storageinfo(options.ipaddr)) except Exception as expt:
import traceback
tb = traceback.format_exc()
print(tb)if __name__ == '__main__':
main()

配置文件

# vim /usr/local/zabbix_agents_3.2.0/conf/zabbix_agentd.conf

UserParameter=custom.esxi.discovery, /usr/bin/python3 /usr/local/zabbix_agents_3.2.0/scripts/zabbix_esxi_storage.py –list
UserParameter=custom.esxi.item[*],/usr/bin/python3 /usr/local/zabbix_agents_3.2.0/scripts/zabbix_esxi_storage.py –ip $1

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,557
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898