software.py

place in: Products/DataCollector/plugins/zenoss/cmd/linux/
Then restart Zenoss

This only works for Gentoo systems. You need to adapt 
/usr/local/bin/zenoss_swlist.sh for other distros.

On the remote system, create a file '/usr/local/bin/zenoss_swlist.sh' with the 
following contents and make it executable: 


Code:

#! /bin/bash

for f in /var/db/pkg/*/*;
do
    if [[ -e $f/HOMEPAGE ]]; then
        MFG="`cat $f/HOMEPAGE`";
    else
        MFG="-";
    fi

    INST_DATE=`stat --printf=%Y $f/PF`
    CAT="`cat $f/CATEGORY`"
    SOFT="`cat $f/PF`"

    echo \"${CAT}/${SOFT}\" \"${MFG}\" \"${INST_DATE}\"
done




And here is the plugin:


Code:

###########################################################################
#
# This program is an addendum to Zenoss Core, an open source monitoring 
platform.
# Copyright (C) 2009, Ross R. Duncan
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published by
# the Free Software Foundation.
#
# For complete information on Zenoss please visit: http://www.zenoss.com/oss/
#
###########################################################################

from Products.DataCollector.plugins.DataMaps import ObjectMap
import string
import re
import time

from CollectorPlugin import CommandPlugin

class software(CommandPlugin):
    """
    maps output of /usr/local/bin/zenoss_swlist.sh to software list
    """
    maptype = "SoftwareMap"
    modname = "Products.ZenModel.Software"
    relname = "software"
    compname = "os"
    command = '/usr/local/bin/zenoss_swlist.sh'

    package = re.compile( "^\"(\S+)\" \"(\S+)\" \"(\S+)\"" ).search

    def condition(self, device, log):
        return device.os.uname == 'Linux'


    def process(self, device, results, log):
        log.info('Collecting installed software information for device %s' % 
device.id)

        rm = self.relMap()

        for line in results.split("\n"):
            vals = line.split()
            if len(vals) == 0:
                continue

            mpkg = self.package(line)
            idx = 0
            if mpkg:
                # installed software package, get installation status, name
                name, mfg, inst_date = mpkg.groups()
                idx = idx +1
                timetuple = time.localtime( float(inst_date) )
                inst_date = "%d/%02d/%02d %02d:%02d:%02d" % timetuple[:6]
                d = { 'index': idx, 'setProductKey': name, 'setInstallDate': 
inst_date }
                pkg = self.objectMap( d )
                rm.append(pkg)
                pkg.id = self.prepId( pkg.setProductKey )
                pkg.description = mfg
        return rm



[/b]




-------------------- m2f --------------------

Read this topic online here:
http://forums.zenoss.com/viewtopic.php?p=31020#31020

-------------------- m2f --------------------



_______________________________________________
zenoss-users mailing list
[email protected]
http://lists.zenoss.org/mailman/listinfo/zenoss-users

Reply via email to