批量获取服务器服务编码(序列号)

网友投稿 1964 2022-09-10

批量获取服务器服务编码(序列号)

批量获取服务器服务编码(序列号)

背景

近期收到IDC团队的通知,可以将IT团队的一些老服务器进行批量更换,可以统计一下要更换的老服务器。 可是公司的服务器都是IDC团队分发的,IT从来没有做过序列号和生命周期的管理,怎么统计出这些服务器呢。

思路

服务器出厂日期是最直观的,可是我们又没有每台服务器的SN,这么多服务器怎么获取这些SN呢。总不能真的一台一台登陆远控卡去查询吧。

因此,我们需要想办法批量获取这些服务器的SN。然后根据SN去固资部门或者官网查询出厂日期。

IT这边的服务器运行的清一色windows server,所以可以利用的手段有:

IPMItool工具 PowerShell脚本

实现

方式一:IPMItool

ipmitool 基本用法,三大块:

optinos interfaces: 如lan、lanplus,需要在服务器上启用。 command

[root@office-server001~]# ipmitool -h ipmitool version 1.8.18 usage: ipmitool [options...] -h This help -V Show version information -v Verbose (can use multiple times) -c Display output in comma separated format -d N Specify a /dev/ipmiN device to use (default=0) -I intf Interface to use -H hostname Remote host name for LAN interface -p port Remote RMCP port [default=623] -U username Remote session username -f file Read remote session password from file -z size Change Size of Communication Channel (OEM) -S sdr Use local file for remote SDR cache -D tty:b[:s] Specify the serial device, baud rate to use and, optionally, specify that interface is the system one -4 Use only IPv4 -6 Use only IPv6 -a Prompt for remote password -Y Prompt for the Kg key for IPMIv2 authentication -e char Set SOL escape character -C ciphersuite Cipher suite to be used by lanplus interface -k key Use Kg key for IPMIv2 authentication -y hex_key Use hexadecimal-encoded Kg key for IPMIv2 authentication -L level Remote session privilege level [default=ADMINISTRATOR] Append a '+' to use name/privilege lookup in RAKP1 -A authtype Force use of auth type NONE, PASSWORD, MD2, MD5 or OEM -P password Remote session password -E Read password from IPMI_PASSWORD environment variable -K Read kgkey from IPMI_KGKEY environment variable -m address Set local IPMB address -b channel Set destination channel for bridged request -t address Bridge request to remote target address -B channel Set transit channel for bridged request (dual bridge) -T address Set transit address for bridge request (dual bridge) -l lun Set destination lun for raw commands -o oemtype Setup for OEM (use 'list' to see available OEM types) -O seloem Use file for OEM SEL event descriptions -N seconds Specify timeout for lan [default=2] / lanplus [default=1] interface -R retry Set the number of retries for lan/lanplus interface [default=4] Interfaces: open Linux OpenIPMI Interface [default] imb Intel IMB Interface lan IPMI v1.5 LAN Interface lanplus IPMI v2.0 RMCP+ LAN Interface serial-terminal Serial Interface, Terminal Mode serial-basic Serial Interface, Basic Mode usb IPMI USB Interface(OEM Interface for AMI Devices) Commands: raw Send a RAW IPMI request and print response i2c Send an I2C Master Write-Read command and print response spd Print SPD info from remote I2C device lan Configure LAN Channels chassis Get chassis status and set power state power Shortcut to chassis power commands event Send pre-defined events to MC mc Management Controller status and global enables sdr Print Sensor Data Repository entries and readings sensor Print detailed sensor information fru Print built-in FRU and scan SDR for FRU locators gendev Read/Write Device associated with Generic Device locators sdr sel Print System Event Log (SEL) pef Configure Platform Event Filtering (PEF) sol Configure and connect IPMIv2.0 Serial-over-LAN tsol Configure and connect with Tyan IPMIv1.5 Serial-over-LAN isol Configure IPMIv1.5 Serial-over-LAN user Configure Management Controller users channel Configure Management Controller channels session Print session information dcmi Data Center Management Interface nm Node Manager Interface sunoem OEM Commands for Sun servers kontronoem OEM Commands for Kontron devices picmg Run a PICMG/ATCA extended cmd fwum Update IPMC using Kontron OEM Firmware Update Manager firewall Configure Firmware Firewall delloem OEM Commands for Dell systems shell Launch interactive IPMI shell exec Run list of commands from file set Set runtime variable for shell and exec hpm Update HPM components using PICMG HPM.1 file ekanalyzer run FRU-Ekeying analyzer using FRU files ime Update Intel Manageability Engine Firmware vita Run a VITA 46.11 extended cmd lan6 Configure IPv6 LAN Channels

fru怎么使用呢?

[root@office-server001 ~]# ipmitool fru help FRU Commands: print read write upgEkey edit internaluse get

我们首先通过impitool获取服务器的fru信息,在考虑从中过滤出SN,如图中绿色标注部分。

我们写个python脚本:

#!/bin/env python3 import os iplists = ['172.16.xxx.xxx','172.16.xxx.xxx','172.16.xxx.xxx','172.16.xxx.xxx','172.16.xxx.xxx','172.16.xxx.xxx'] for ip in iplists: try: dict1= {} datas = os.popen('ipmitool -H %s -I lanplus -Uusername -Ppassword -L user fru print 0'%ip).readlines() for i in datas: j = i.strip('\n') key, value = j.split(':',1)[0].strip(),j.split(':',1)[-1].strip() dict1[key] = value print(dict1['Product Manufacturer'],ip,dict1['Product Serial']) except: print('{} 获取失败!'.format(ip))

执行结果:

大部分都正常获取到了,失败的两台是因为其中1台密码不同,另1台没有在LAN上启用IPMI功能。

方式二: PowerShell

通过wmiobject 获取bios信息,从而进一步获取SN信息。

最终形成脚本:

$hostlists = "BJ-x-Hyper-V01","BJ-x-Hyper-V02","BJ-x-Hyper-V03","BJ-x-Hyper-V04" Foreach($h in $hostlists){ $info = Invoke-Command -ComputerName $h -ScriptBlock { Get-WmiObject -Class Win32_BIOS} $sn = $info.SerialNumber $man = $info.Manufacturer Write-Output "$h $man $sn" }

执行结果:

如果都是windows系统,且在域内,powershell更为便利。 如果大部分都是linux系统,python脚本更便利。

获取到SN之后,就可以进一步查询服务器的生命周期了,同时也进一步完善了服务器管理信息。

脚本中,我们只需维护一个IP或主机列表。列表也可以通过命令去生成。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:django之模型层(django模块详解)
下一篇:windows远程控制
相关文章

 发表评论

暂时没有评论,来抢沙发吧~