Archived community.zenoss.org | full text search
Skip navigation
Currently Being Moderated

zendmd script to dump hardware and software info

VERSION 2  Click to view document history
Created on: Nov 12, 2009 9:43 AM by Nick Nachefski - Last Modified:  Nov 13, 2009 3:16 PM by Nick Nachefski

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!


EDIT:  Here is Version 2.  I added the part where you would filter only on 'interesting' Linux RPMs.  Also, i added sections to display running Windows Services as well as Monitored IP Services.

Apparently, Zenoss uses WMI to map windows service information, which is very cool.  The only thing is that monitoring is  disabled by default for all winservices.  I wrote a short script that rips through all of them and enables monitoring if there is at least 1 device with that service installed.  I'll post that script in another thread.

Here is zenGet2.py, also attached.....

#!/opt/zenoss/bin/python2.4
#written by Nicholas Nachefski (nicholas <underscore> nachefski <at> hotmail <dot> com)

 

#libs
import Globals, re, sys
import Acquisition

 

from Products.ZenUtils.ZenScriptBase import ZenScriptBase
from transaction import commit

 

#####init
dmd = ZenScriptBase(connect=True).dmd

 

#compile any needed regex globally to improve performance
#disk serial number regex
dSerial = re.compile(".*Serial Number (\S+)$")

 

#array of regex to match interesting software(rpms) to display for linux devices
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.*"))

 

#####subs
#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

 

#skim through the tree and dump info for each device
for dev in dmd.Devices.getSubDevices():
    osType = dev.getPrimaryPath()[5]

 

    if len(sys.argv) > 1:
    if sys.argv[1] != dev.id:
        continue

 

    #get hardware info
    print "%s\t\t%s\t%s\t%s" % (dev.id, dev.getHWManufacturerName(), dev.getHWProductName(), dev.getHWSerialNumber())
    print "  %s" % dev.getOSProductName()

 

    #get cpu info
    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

 

    #get physical mem info
    print "\n  Physical Memory: %s" % sizeof_fmt(c.totalMemory)

 

    #get filesystem information
    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))

 

    #get expansion card info
    print "\n  Additional Hardware:"
    for p in dev.hw.cards():
    print "   -%s\t%s" % (p.getManufacturerName(), p.getProductName()) #(p.id

 

    #get interface and IP info
    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

 

    #get software info
    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('_', '+')

 

    #get information on running services
    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)

 

    #get ip service info(open ports)
    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()

        #this is just for looks if the port us unknown
        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

 

#EOF

 

 

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

Attachments:
Note: binary attachments ending in .zip will need to be unzipped before use.
Comments (0)

More Like This

  • Retrieving data ...

More by Nick Nachefski