IPMI(Intelligent Platform Management Interface)
智能平臺管理接口 (IPMI) 是一種開放標(biāo)準(zhǔn)的硬件管理接口規(guī)格,定義了嵌入式管理子系統(tǒng)進(jìn)行通信的特定方法。IPMI 信息通過基板管理控制器 (BMC)(位于 IPMI 規(guī)格的硬件組件上)進(jìn)行交流。使用低級硬件智能管理而不使用操作系統(tǒng)進(jìn)行管理硝拧,具有兩個(gè)主要優(yōu)點(diǎn): 首先,此配置允許進(jìn)行帶外服務(wù)器管理葛假;其次障陶,操作系統(tǒng)不必負(fù)擔(dān)傳輸系統(tǒng)狀態(tài)數(shù)據(jù)的任務(wù)。IPMI的核心是一個(gè)專用芯片/控制器(叫做服務(wù)器處理器或基板管理控制器(BMC))桐款,其并不依賴于服務(wù)器的處理器咸这、BIOS或操作系統(tǒng)來工作,可謂非常地獨(dú)立魔眨,是一個(gè)單獨(dú)在系統(tǒng)內(nèi)運(yùn)行的無代理管理子系統(tǒng)媳维,
IPMI功能:
監(jiān)控服務(wù)器的物理健康特征,如溫度遏暴、電壓侄刽、風(fēng)扇工作狀態(tài)、電源狀態(tài)等朋凉;
可以通過串口州丹、Modem以及Lan等遠(yuǎn)程環(huán)境管理服務(wù)器系統(tǒng),如遠(yuǎn)程開關(guān)機(jī)杂彭;
IPMITOOL
ipmitool 是一種可用在 linux 系統(tǒng)下的命令行方式的 ipmi 平臺管理工具墓毒,它支持 ipmi 1.5 規(guī)范(最新的規(guī)范為 ipmi 2.0),通過它可以實(shí)現(xiàn)獲取傳感器的信息亲怠、顯示系統(tǒng)日志內(nèi)容所计、網(wǎng)絡(luò)遠(yuǎn)程開關(guān)機(jī)等功能。使用:
#!/usr/bin/env python
#coding:utf-8
#@author:yuanyong
#vinsion:v1.0
import subprocess
import re
import sys
import os
import threading
def IPMItool(ip,host):
p = subprocess.Popen("""ipmitool -I lanplus -H %s -U 賬號 -P "密碼" -L user sdr list""" %ip, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True)
out = p.stdout.read().decode('utf-8')
p1 = subprocess.Popen("""ipmitool -I lanplus -H %s -U 賬號 -P "密碼" -L user power status""" %ip, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True)
out1 = p1.stdout.read().decode('utf-8')
powerstat = out1.strip("\n").split(" ")[3]
num = r'([0-9.]+)'
rs = out.strip("\n").strip(" ").split("|")
rshash = {}
#取溫度
InTemp = re.search(num,rs[1]).group()
OutTemp = re.search(num,rs[3]).group()
PCHTemp = re.search(num,rs[5]).group()
Raidtemp = re.search(num,rs[63]).group()
cputemp = re.search(num,rs[15]).group()
#去電壓值
cpuv = re.search(num,rs[33]).group()
sysv1 = re.search(num,rs[27]).group()
sysv2 = re.search(num,rs[29]).group()
sysv3 = re.search(num,rs[31]).group()
#取風(fēng)扇轉(zhuǎn)速
fan1 = re.search(num,rs[47]).group()
fan2 = re.search(num,rs[51]).group()
fan3 = re.search(num,rs[55]).group()
fan4 = re.search(num,rs[59]).group()
#取功率值
power = re.search(num,rs[61]).group()
#將數(shù)據(jù)存入到結(jié)果hash表中
rshash["INlet_emp"] = InTemp
rshash["Outlet_temp"] = OutTemp
rshash["PCH_temp"] = PCHTemp
rshash["CPU_temp"] = cputemp
rshash["RAID_temp"] = Raidtemp
rshash["Sys_3.3v"] = sysv1
rshash["Sys_5v"] = sysv2
rshash["Sys_12v"] = sysv3
rshash["CPU_volt"] = cpuv
rshash["System_fan1"] = fan1
rshash["System_fan2"] = fan2
rshash["System_fan3"] = fan3
rshash["System_fan4"] = fan4
rshash["Sys_power"] = power
rshash["power_status"] = powerstat
#將結(jié)果用sender發(fā)送給zabbix-server
for item in rshash:
rslag = "/node3/zabbix-3.2.4/bin/zabbix_sender -z zabbix_server的ip -s %s -k %s -o %s" %(host,item,rshash[item])
print rslag
os.system(rslag)
if __name__=='__main__':
threadlist = []
with open("../conf/hostip.csv",'r') as f:
for line in f.readlines():
host,ip = line.strip("\n").strip("\t").split(",")
print line.strip("\n").strip("\t").split(",")
print host,ip
host = str(host.strip("\r"))
ip = str(ip.strip("\r"))
t = threading.Thread(target=IPMItool,args=(ip,host))
threadlist.append(t)
for threaditem in threadlist:
threaditem.start()
for threaditem in threadlist:
threaditem.join()