Hi,
Here is a script I've been running to do the Internet Plugins. It uses the same idea that Josh had, and adds the data to the Application Inventory plist before submitting it to MWA. It doesn't actually capture Java but does get Flash, Silverlight, et al. I have a second script that adds munki's version, and the OS version to the app inventory as well, as I found it easier to search for that info when it was in the Inventory. If people are interested let me know and I'll share that as well.
----
#!/usr/bin/python
# encoding: utf-8
# Adds Internet Plug-Ins to the Application Inventory data that is reported
# to MunkiWebAdmin. It is a basic copy of the code from munkicommon.py that
# creates the application data.
import sys
import os
import plistlib
import LaunchServices
from Foundation import NSDate, NSMetadataQuery, NSPredicate, NSRunLoop
sys.path.append('/usr/local/munki')
from munkilib import munkicommon
# Change the following as needed
managed_installs_dir = "/Library/Managed Installs"
def findPluginsInDirs(dirlist):
"""Do spotlight search for type plug-in within list of directories
provided. Returns a list of paths to plug-ins these appear to always
be some form of unicode string.
"""
applist = []
query = NSMetadataQuery.alloc().init()
query.setPredicate_(NSPredicate.predicateWithFormat_(
'(kMDItemKind = "Plug-in")'))
query.setSearchScopes_(dirlist)
query.startQuery()
# Spotlight isGathering phase - this is the initial search. After the
# isGathering phase Spotlight keeps running returning live results from
# filesystem changes, we are not interested in that phase.
# Run for 0.3 seconds then check if isGathering has completed.
runtime = 0
maxruntime = 20
while query.isGathering() and runtime <= maxruntime:
runtime += 0.3
NSRunLoop.currentRunLoop().runUntilDate_(
NSDate.dateWithTimeIntervalSinceNow_(0.3))
query.stopQuery()
if runtime >= maxruntime:
display_warning('Spotlight search for Internet Plug-ins terminated '
'due to excessive time. Possible causes: Spotlight indexing is '
'turned off for a volume; Spotlight is reindexing a volume.')
for item in query.results():
p = item.valueForAttribute_('kMDItemPath')
if p and not munkicommon.isExcludedFilesystem(p) and "Internet Plug-Ins" in p:
applist.append(p)
return applist
def getSpotlightInstalledInternetPlugins():
"""Get paths of currently installed Internet Plug-ins per Spotlight.
Return value is list of paths.
Excludes most non-boot volumes.
In future may include local r/w volumes.
"""
dirlist = []
applist = []
for f in munkicommon.listdir(u'/'):
p = os.path.join(u'/', f)
if os.path.isdir(p) and not os.path.islink(p) \
and not munkicommon.isExcludedFilesystem(p):
dirlist.append(p)
applist.extend(findPluginsInDirs(dirlist))
return applist
def main():
app_data_plist = os.path.join(managed_installs_dir, \
"ApplicationInventory.plist")
if os.path.exists(app_data_plist):
app_data = plistlib.readPlist(app_data_plist)
else:
print ' Application Inventory not found.'
sys.exit(0)
applist = set(getSpotlightInstalledInternetPlugins())
for pathname in applist:
iteminfo = {}
iteminfo['name'] = os.path.splitext(os.path.basename(pathname))[0]
iteminfo['path'] = pathname
plistpath = os.path.join(pathname, 'Contents', 'Info.plist')
if os.path.exists(plistpath):
try:
plist = plistlib.readPlist(plistpath)
iteminfo['bundleid'] = plist.get('CFBundleIdentifier','')
iteminfo['version'] = munkicommon.getExtendedVersion(pathname)
app_data.append(iteminfo)
except Exception:
pass
try:
plistlib.writePlist(app_data, app_data_plist)
except FoundationPlist.NSPropertyListSerializationException, err:
print ' Unable to update inventory report: %s' % err
print ' Internet Plug-Ins added to Application Inventory Data'
if __name__ == '__main__':
main()