Last active
August 29, 2015 14:21
-
-
Save komeda-shinji/40d554ec5d841307b82f to your computer and use it in GitHub Desktop.
Products/DataCollector/plugins/zenoss/cmd/linux/dpkg.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
__doc__ = """ | |
zenoss.cmd.linux.dpkg finds various software packages installed on a device. | |
Invoke dpkg command via SSH session. | |
""" | |
import re | |
from Products.DataCollector.plugins.CollectorPlugin \ | |
import LinuxCommandPlugin, SoftwareCommandPlugin | |
from Products.ZenUtils.Utils import prepId | |
from Products.DataCollector.plugins.DataMaps import MultiArgs | |
def parseResults(results): | |
pattern = re.compile(r"^([ih][i][ ])\s+(\S+)\s+(\S+)\s+(.+)") | |
""" | |
First character: | |
The possible value for the first character. | |
The first character signifies the desired state, | |
like we (or some user) is marking the package for installation | |
u: Unknown (an unknown state) | |
i: Install (marked for installation) | |
r: Remove (marked for removal) | |
p: Purge (marked for purging) | |
h: Hold | |
Second Character: | |
The second character signifies the current state, | |
whether it is installed or not. The possible values are | |
n: Not- The package is not installed | |
i: Inst- The package is successfully installed | |
c: Cfg-files- Configuration files are present | |
u: Unpacked- The package is stilled unpacked | |
f: Failed-cfg- Failed to remove configuration files | |
h: Half-inst- The package is only partially installed | |
W: trig-aWait | |
t: Trig-pend | |
Third Character: | |
This corresponds to the error state. The possible value include | |
R: Reinst-required The package must be installed. | |
""" | |
swdicts = [] | |
for line in results.split("\n"): | |
pkg = pattern.search(line) | |
if pkg: | |
name = '-'.join((pkg.group(2), pkg.group(3))) | |
vendor = 'Unknown' | |
description = pkg.group(4) | |
id = prepId(name) | |
sw = {'id': id, 'setProductKey': MultiArgs(name, prepId(vendor)), 'setDescription': description} | |
swdicts.append(sw) | |
return swdicts | |
class dpkg(LinuxCommandPlugin, SoftwareCommandPlugin): | |
maptype = "SoftwareMap" | |
modname = "Products.ZenModel.Software" | |
relname = "software" | |
compname = "os" | |
command = '[ -x /usr/bin/dpkg ] && /usr/bin/dpkg -l' | |
def __init__(self): | |
SoftwareCommandPlugin.__init__(self, parseResults) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment