Package DataCollector :: Module Plugins
[hide private]
[frames] | no frames]

Source Code for Module DataCollector.Plugins

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2007, Zenoss Inc. 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify it 
 7  # under the terms of the GNU General Public License version 2 as published by 
 8  # the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
11  # 
12  ########################################################################### 
13   
14  from Products.ZenUtils.Utils import importClass 
15  import sys 
16  import os 
17   
18  import logging 
19  log = logging.getLogger('dc.plugins') 
20   
21  import plugins 
22   
23  _pluginskip = ("CollectorPlugin.py", "DataMaps.py") 
24 -def _plfilter(f):
25 return f.endswith(".py") and not (f.startswith("_") or f in _pluginskip)
26
27 -def _loadPluginDir(pdir):
28 collectorPlugins = {} 29 log.info("loading collector plugins from: %s", pdir) 30 lpdir = len(pdir)+1 31 for path, dirname, filenames in os.walk(pdir): 32 path = path[lpdir:] 33 for filename in filter(_plfilter, filenames): 34 modpath = os.path.join(path,filename[:-3]).replace("/",".") 35 log.debug("loading: %s", modpath) 36 try: 37 sys.path.insert(0, pdir) 38 const = importClass(modpath) 39 sys.path.remove(pdir) 40 plugin = const() 41 collectorPlugins[plugin.name()] = plugin 42 except ImportError: 43 log.exception("problem loading plugin:%s",modpath) 44 return collectorPlugins
45 46
47 -def loadPlugins(dmd):
48 """Load plugins from the plugin directory. Returns them as a {<plugin 49 name> : plugin instance} 50 """ 51 plugins = filter(lambda x: x.startswith("plugins"), sys.modules) 52 for key in ['zenoss'] + plugins: 53 log.debug("clearing plugin %s", key) 54 if sys.modules.has_key(key): 55 del sys.modules[key] 56 pdir = os.path.join(os.path.dirname(__file__),"plugins") 57 log.info("loading collector plugins from:%s", pdir) 58 plugins = _loadPluginDir(pdir) 59 try: 60 for pack in dmd.packs(): 61 plugins.update(_loadPluginDir(pack.path('modeler', 'plugins'))) 62 except: 63 log.error('Could not load modeler plugins from zenpacks.' 64 ' One of the zenpacks is missing or broken.') 65 return plugins
66