Greetings,
I recently had the need to rip all server information(Linux and Windows) out of the Zenoss Zope DB so that i could do other stuff with it(like insert into SQL tables). Here is a copy of my script prior to adding the SQL stuff. All it does is rip through the 'Server' device tree and print hardware and software data to STDOUT. You can specify a device's shortname as an arg or leave it blank to dump all device info.
Obviously, adjust the shabang to reflect where your zenoss python interpreter is. Also, dont forget to su to the zenoss user before running.
Have fun!
#written by Nicholas Nachefski (nicholas <underscore> nachefski <at> hotmail <dot> com)
import Globals, re, sys
import Acquisition
from transaction import commit
dmd = ZenScriptBase(connect=True).dmd
#disk serial number regex
dSerial = re.compile(".*Serial Number (\S+)$")
linux_rpms = []
linux_rpms.append(re.compile("^httpd-\d.*"))
linux_rpms.append(re.compile("^mysql.*", re.IGNORECASE))
linux_rpms.append(re.compile("^postfix.*"))
linux_rpms.append(re.compile("^redhat-release-\d.*"))
linux_rpms.append(re.compile("^varnish-\d.*"))
linux_rpms.append(re.compile("^net-snmp-\d.*"))
linux_rpms.append(re.compile("^dovecot-\d.*"))
#convert Bytes to Human-readable
def sizeof_fmt(num):
for x in ['bytes','KB','MB','GB','TB']:
if num < 1024.0:
return "%3.1f%s" % (num, x)
num /= 1024.0
for dev in dmd.Devices.getSubDevices():
osType = dev.getPrimaryPath()[5]
if sys.argv[1] != dev.id:
continue
print "%s\t\t%s\t%s\t%s" % (dev.id, dev.getHWManufacturerName(), dev.getHWProductName(), dev.getHWSerialNumber())
print " %s" % dev.getOSProductName()
print "\n CPU Info:"
cpu_count = 1
for c in dev.hw.cpus():
L2cache = sizeof_fmt((c.cacheSizeL2*1000))
print " #%s %s\t%s (%s)" % (cpu_count, c.getManufacturerName(), c.clockspeed, L2cache) #c.productClass().id
cpu_count = cpu_count + 1
print "\n Physical Memory: %s" % sizeof_fmt(c.totalMemory)
print "\n Disk Info:"
for f in dev.os.filesystems():
size=f.totalBlocks*f.blockSize
if osType == "Windows":
m = re.match("\w\_\_", f.id)
vol = m.group(0).replace ( '__', ':' )
m = dSerial.match(f.id)
serial = m.group(1)
print " %s (%s)\t\t%s" % (vol, serial, sizeof_fmt(size))
if osType == "Linux":
print " %s\t%s" % (f.mount, sizeof_fmt(size))
print "\n Additional Hardware:"
for p in dev.hw.cards():
print " -%s\t%s" % (p.getManufacturerName(), p.getProductName()) #(p.id
print "\n Interfaces:"
for int in dev.os.interfaces():
print " " + int.id,
if len(int.macaddress) != 0:
print "(%s)" % int.macaddress
else:
print " "
for ips in int.getIpAddresses():
print " -" + ips
print "\n Installed Software:"
for s in dev.os.software():
if osType == "Linux":
for i in linux_rpms:
if i.match(s.id) != None:
print " -%s" % s.id
else:
print " -%s" % s.id.replace('_', '+')
if osType == "Windows":
print "\n Active Services:"
for w in dev.os.winservices():
if w.getStatus() == 0 and w.monitor is True:
print " -%s [%s]" % (w.caption(), w.startMode)
print "\n Open Ports:"
for p in dev.os.ipservices():
if p.getStatus() == 0 and p.monitor is True:
portLabel = p.getKeyword()
portDesc = p.getDescription()
if re.match("tcp_|udp_", portLabel):
m = re.match("(tcp|udp)_0*(\d*$)", portLabel)
temp = m.group(1) + "-" + m.group(2)
portLabel = temp.upper()
if len(portDesc) != 0:
print " -%s (%s) " % (portLabel, portDesc)
else:
print " -%s " % portLabel
and here is an example of the output for a win device:
[zenoss@zenserver ~]$ ./zenGet.py testwinserver01
testwinserver01 Dell PowerEdge 2950 ******FJ1
Microsoft Windows Server 2003 R2, Standard Edition
CPU Info:
#1 Intel 2333 (11.7MB)
Physical Memory: 4.0GB
Disk Info:
C: (*************) 50.0GB
D: (*************) 182.2GB
Additional Hardware:
-Broadcom Broadcom BCM5708C NetXtreme II GigE (LOM)
-Intel 631xESB/632xESB/3100 Chipset UHCI USB Controller #1
-Intel 631xESB/632xESB IDE Controller
-Intel 6311ESB/6321ESB PCI Express Downstream Port E2
-ATI Technologies Inc Radeon Graphics Adapter
-Dell Remote Access Controller 5
-Dell Inc. (OEM_ LSI Logic, Symbios Logic, NCR) PERC 6/E Adapter
-Intel 5000X Chipset Memory Controller Hub
-Broadcom Broadcom BCM5708C NetXtreme II GigE (LOM)
-Dell Inc. (OEM_ LSI Logic, Symbios Logic, NCR) PERC 6/i Integrated
-Intel 5000 Series Chipset PCI Express x8 Port 4-5
-Intel 5000 Series Chipset PCI Express x4 Port 5
-Intel 5000 Series Chipset PCI Express x4 Port 7
Interfaces:
Broadcom BCM5708C NetXtreme II GigE (NDIS VBD Client) (**:**:**:**:**:**)
-10.*.*.*/24
-10.*.*.*/24
-10.*.*.*/24
-10.*.*.*/24
-10.*.*.*/24
Broadcom BCM5708C NetXtreme II GigE (NDIS VBD Client) _2 (**:**:**:**:**:**)
-10.*.*.*/16
MS TCP Loopback interface
-127.0.0.1/8
Microsoft Loopback Adapter (**:**:**:**:**:**)
Installed Software:
-ATI Display Driver
-Dell OpenManage Server Administrator
-Hotfix for Microsoft .NET Framework 3.5 SP1 (KB953595)
-Hotfix for Microsoft .NET Framework 3.5 SP1 (KB958484)
-Hotfix for Windows Server 2003 (KB926139-v2)
-Hotfix for Windows Server 2003 (KB961118)
-Hotfix for Windows Server 2003 (KB970653-v3)
-Hotfix for Windows XP (KB954550-v5)
-Java(TM) 6 Update 10
-LiveUpdate 3.3 (Symantec Corporation)
-MSXML 4.0 SP2 (KB954430)
-MSXML 6 Service Pack 2 (KB954459)
-Microsoft .NET Framework 2.0 Service Pack 2
-Microsoft .NET Framework 3.0 Service Pack 2
-Microsoft .NET Framework 3.5 SP1
-Microsoft .NET Framework 3.5 SP1+2
-Microsoft ASP.NET ValidatePath Module
-Microsoft Internationalized Domain Names Mitigation APIs
-Microsoft Kernel-Mode Driver Framework Feature Pack 1.5
-Microsoft National Language Support Downlevel APIs
-Microsoft Robocopy GUI
-Microsoft Visual C++ 2008 Redistributable - x86 9.0.21022
-Microsoft Windows Services for UNIX
-SNMP Informant Agent (Standard Edition)
-Security Update for Windows Internet Explorer 7 (KB938127)
-Security Update for Windows Internet Explorer 8 (KB974455)
-Security Update for Windows Media Encoder (KB954156)
-Security Update for Windows Media Player 6.4 (KB925398)
-Security Update for Windows Server 2003 (KB923561)
-Symantec Endpoint Protection
-Update for Microsoft .NET Framework 3.5 SP1 (KB963707)
-Update for Windows Internet Explorer 8 (KB973874)
-Update for Windows Server 2003 (KB925876)
-Update for Windows Server 2003 (KB927891)
-Update for Windows Server 2003 (KB936357)
-Update for Windows Server 2003 (KB948496)
-Update for Windows Server 2003 (KB951072-v2)
-Update for Windows Server 2003 (KB955839)
-Update for Windows Server 2003 (KB968389)
-Update for Windows Server 2003 (KB973815)
-Update for Windows Server 2003 (KB973825)
-WinRAR archiver
-Windows Imaging Component
-Windows Internet Explorer 7
-Windows Internet Explorer 8
-Windows Media Encoder 9 Series
-Windows Media Encoder 9 Series SDK
-Windows Media Encoder 9 Series+2
-Windows Media Rights Manager SDK
-Windows Presentation Foundation
-Windows Resource Kit Tools
-Windows Support Tools
-XML Paper Specification Shared Components Pack 1.0
-XPS Essentials Pack
-XPS Essentials Pack 1.0
Active Services:
-EVault InfoStage Agent [Auto]
-IIS Admin Service [Auto]
-FTP Publishing Service [Auto]
-OM Common Services [Auto]
-Automatic Updates [Auto]
Open Ports:
-http (World Wide Web HTTP)
-https (http protocol over TLS/SSL)
Feel free to message me if you have any questions or need assistance understanding my code.
-Nick