

def check(self, agentConfig):
    self.logger.debug('getPlugins: start')
    plugin_directory = agentConfig.get('plugin_directory', None)
    if plugin_directory:
        self.logger.info('getPlugins: plugin_directory %s', plugin_directory)
        if (not os.access(plugin_directory, os.R_OK)):
            self.logger.warning(('getPlugins: Plugin path %s is set but not readable by ' + 'agent. Skipping plugins.'), plugin_directory)
            return False
    else:
        self.logger.debug('getPlugins: plugin_directory not set')
        return False
    if (self.plugins is None):
        self.logger.debug('getPlugins: initial load from %s', plugin_directory)
        sys.path.append(plugin_directory)
        self.plugins = []
        plugins = []
        for (root, dirs, files) in os.walk(plugin_directory):
            for name in files:
                self.logger.debug('getPlugins: considering: %s', name)
                name = name.split('.', 1)
                try:
                    if (name[1] == 'py'):
                        self.logger.debug((((('getPlugins: ' + name[0]) + '.') + name[1]) + ' is a plugin'))
                        plugins.append(name[0])
                except IndexError:
                    continue
        for plugin_name in plugins:
            self.logger.debug('getPlugins: loading %s', plugin_name)
            plugin_path = os.path.join(plugin_directory, ('%s.py' % plugin_name))
            if (not os.access(plugin_path, os.R_OK)):
                self.logger.error('getPlugins: Unable to read %s so skipping this plugin.', plugin_path)
                continue
            try:
                import imp
                imported_plugin = imp.load_source(plugin_name, plugin_path)
                self.logger.debug('getPlugins: imported %s', plugin_name)
                plugin_class = getattr(imported_plugin, plugin_name, None)
                if (plugin_class is None):
                    self.logger.info('getPlugins: Unable to locate class %s in %s, skipping', plugin_name, plugin_path)
                    continue
                try:
                    plugin_obj = plugin_class(agentConfig, self.logger, self.raw_config)
                except TypeError:
                    try:
                        plugin_obj = plugin_class(agentConfig, self.logger)
                    except TypeError:
                        plugin_obj = plugin_class()
                self.logger.debug('getPlugins: instantiated %s', plugin_name)
                self.plugins.append(plugin_obj)
            except Exception:
                self.logger.error('getPlugins (%s): exception = %s', plugin_name, traceback.format_exc())
    if (self.plugins is not None):
        self.logger.debug('getPlugins: executing plugins')
        output = {
            
        }
        for plugin in self.plugins:
            self.logger.info('getPlugins: executing  %s', plugin.__class__.__name__)
            try:
                value = plugin.run()
                if value:
                    output[plugin.__class__.__name__] = value
                    self.logger.debug('getPlugins: %s output: %s', plugin.__class__.__name__, output[plugin.__class__.__name__])
                    self.logger.info('getPlugins: executed %s', plugin.__class__.__name__)
                else:
                    self.logger.info('getPlugins: executed %s but returned no data', plugin.__class__.__name__)
            except Exception:
                self.logger.error('getPlugins: exception = %s', traceback.format_exc())
        self.logger.debug('getPlugins: returning')
        return output
    else:
        self.logger.debug('getPlugins: no plugins, returning false')
        return False

dataset/ETHPy150Open serverdensity/sd-agent/checks/server_density/plugins.py Plugins.check/original