def test_plugins_have_long_name(self): global extensions extensions, exttriggers = citellus.initExtensions() # get all plugins plugins = [] # code for plugin in citellus.findplugins(folders=[ os.path.join(citellus.citellusdir, 'plugins', 'core') ]): plugins.append(plugin) # ansible for plugin in citellus.findplugins(executables=False, fileextension=".yml", extension='ansible', folders=[ os.path.join( citellus.citellusdir, 'plugins', 'ansible') ]): plugins.append(plugin) for plugin in plugins: if plugin['long_name'] == '': print(plugin) assert plugin['long_name'] != ''
def main(): """ Main code stub """ start_time = time.time() options = parse_args() # Configure logging logging.basicConfig(level=options.loglevel) if not options.quiet: show_logo() # Each argument in sosreport is a sosreport magplugs, magtriggers = initPlugins(options) if options.list_plugins: for plugin in magplugs: print("-", plugin.__name__.split(".")[-1]) if options.description: desc = plugin.help() if desc: print(citellus.indent(text=desc, amount=4)) return # Prefill enabled citellus plugins from args if not citellus.extensions: extensions, exttriggers = citellus.initExtensions() else: extensions = citellus.extensions citellusplugins = [] for extension in extensions: citellusplugins.extend(extension.listplugins(options)) global allplugins allplugins = citellusplugins # By default, flatten plugin list for all extensions newplugins = [] for each in citellusplugins: newplugins.extend(each) citellusplugins = newplugins # Grab the data sosreports = options.sosreports if options.hosts: ansible = citellus.which("ansible-playbook") if not ansible: LOG.err("No ansible-playbook support found, skipping") else: LOG.info("Grabbing data from remote hosts with Ansible") # Grab data from ansible hosts # Disable Ansible retry files creation: os.environ['ANSIBLE_RETRY_FILES_ENABLED'] = "0" if options.loglevel == 'DEBUG': # Keep ansible remote files for debug os.environ['ANSIBLE_KEEP_REMOTE_FILES'] = "1" command = "%s -i %s %s" % (ansible, options.hosts, os.path.join(maguidir, 'remote.yml')) LOG.debug("Running: %s " % command) citellus.execonshell(filename=command) # Now check the hosts we got logs from: hosts = citellus.findplugins( folders=glob.glob('/tmp/citellus/hostrun/*'), executables=False, fileextension='.json') for host in hosts: sosreports.append(os.path.dirname(host['plugin'])) grouped = domagui(sosreports=sosreports, citellusplugins=citellusplugins, options=options) # Run Magui plugins result = [] for plugin in magplugs: start_time = time.time() # Get output from plugin data = filterresults( data=grouped, triggers=magtriggers[plugin.__name__.split(".")[-1]]) returncode, out, err = plugin.run(data=data, quiet=options.quiet) updates = {'rc': returncode, 'out': out, 'err': err} adddata = True if options.quiet: if returncode in [citellus.RC_OKAY, citellus.RC_SKIPPED]: adddata = False subcategory = os.path.split(plugin.__file__)[0].replace( os.path.join(maguidir, 'plugins', ''), '') if subcategory: if len(os.path.normpath(subcategory).split(os.sep)) > 1: category = os.path.normpath(subcategory).split(os.sep)[0] else: category = subcategory subcategory = "" else: category = "" if adddata: result.append({ 'plugin': plugin.__name__.split(".")[-1], 'id': hashlib.md5( plugin.__file__.replace(maguidir, '').encode('UTF-8')).hexdigest(), 'description': plugin.help(), 'result': updates, 'time': time.time() - start_time, 'category': category, 'subcategory': subcategory }) if options.output: citellus.write_results(results=result, filename=options.output, source='magui', path=sosreports, time=time.time() - start_time) pprint.pprint(result, width=1)
def main(): """ Main code stub """ start_time = time.time() options = parse_args() # Configure ENV language before anything else os.environ['LANG'] = "%s" % options.lang # Reinstall language in case it has changed trad = gettext.translation('citellus', localedir, fallback=True, languages=[options.lang]) try: _ = trad.ugettext except AttributeError: _ = trad.gettext # Configure logging logging.basicConfig(level=options.loglevel) if not options.quiet: show_logo() # Each argument in sosreport is a sosreport magplugs, magtriggers = initPlugins(options) if options.list_plugins: for plugin in magplugs: print("-", plugin.__name__.split(".")[-1]) if options.description: desc = plugin.help() if desc: print(citellus.indent(text=desc, amount=4)) return # Prefill enabled citellus plugins from args if not citellus.extensions: extensions, exttriggers = citellus.initExtensions() else: extensions = citellus.extensions # Grab the data sosreports = options.sosreports # If we've provided a hosts file, use ansible to grab the data from them if options.hosts: ansible = citellus.which("ansible-playbook") if not ansible: LOG.err(_("No ansible-playbook support found, skipping")) else: LOG.info("Grabbing data from remote hosts with Ansible") # Grab data from ansible hosts # Disable Ansible retry files creation: os.environ['ANSIBLE_RETRY_FILES_ENABLED'] = "0" if options.loglevel == 'DEBUG': # Keep ansible remote files for debug os.environ['ANSIBLE_KEEP_REMOTE_FILES'] = "1" command = "%s -i %s %s" % (ansible, options.hosts, os.path.join(maguidir, 'remote.yml')) LOG.debug("Running: %s " % command) citellus.execonshell(filename=command) # Now check the hosts we got logs from: hosts = citellus.findplugins(folders=glob.glob('/tmp/citellus/hostrun/*'), executables=False, fileextension='.json') for host in hosts: sosreports.append(os.path.dirname(host['plugin'])) # Get all data from hosts for all plugins, etc if options.output: citellusplugins = [] # Prefill with all available plugins and the ones we want to filter for for extension in extensions: citellusplugins.extend(extension.listplugins()) global allplugins allplugins = citellusplugins # By default, flatten plugin list for all extensions newplugins = [] for each in citellusplugins: newplugins.extend(each) citellusplugins = newplugins def runmaguiandplugs(sosreports, citellusplugins, filename=options.output, extranames=None): """ Runs magui and magui plugins :param sosreports: sosreports to process :param citellusplugins: citellusplugins to run :param filename: filename to save to :param extranames: additional filenames used :return: results of execution """ # Run with all plugins so that we get all data back grouped = domagui(sosreports=sosreports, citellusplugins=citellusplugins) # Run Magui plugins result = [] for plugin in magplugs: start_time = time.time() # Get output from plugin data = filterresults(data=grouped, triggers=magtriggers[plugin.__name__.split(".")[-1]]) returncode, out, err = plugin.run(data=data, quiet=options.quiet) updates = {'rc': returncode, 'out': out, 'err': err} subcategory = os.path.split(plugin.__file__)[0].replace(os.path.join(maguidir, 'plugins', ''), '') if subcategory: if len(os.path.normpath(subcategory).split(os.sep)) > 1: category = os.path.normpath(subcategory).split(os.sep)[0] else: category = subcategory subcategory = "" else: category = "" mydata = {'plugin': plugin.__name__.split(".")[-1], 'name': "magui: %s" % os.path.basename(plugin.__name__.split(".")[-1]), 'id': hashlib.md5(plugin.__file__.replace(maguidir, '').encode('UTF-8')).hexdigest(), 'description': plugin.help(), 'long_name': plugin.help(), 'result': updates, 'time': time.time() - start_time, 'category': category, 'subcategory': subcategory} result.append(mydata) branding = _(" ") citellus.write_results(results=result, filename=filename, source='magui', path=sosreports, time=time.time() - start_time, branding=branding, web=True, extranames=extranames) return result results = runmaguiandplugs(sosreports=sosreports, citellusplugins=citellusplugins, filename=options.output) # Now we've Magui saved for the whole execution provided in 'results' var # Start working on autogroups for result in results: if result['plugin'] == 'metadata-outputs': autodata = result['result']['err'] print(_("Running magui for autogroups:\n")) groups = autogroups(autodata) processedgroups = {} filenames = [] for group in groups: basefilename = os.path.splitext(options.output) filename = basefilename[0] + "-" + group + basefilename[1] print(filename) runautogroup = True for progroup in processedgroups: if groups[group] == processedgroups[progroup]: runautogroup = False runautofile = progroup if runautogroup: # Analisys was missing for this group, run runmaguiandplugs(sosreports=groups[group], citellusplugins=citellusplugins, filename=filename, extranames=options.output) filenames.append(filename) else: # Copy file instead of run as it was already existing LOG.debug("Copying old file from %s to %s" % (runautofile, filename)) shutil.copyfile(runautofile, filename) processedgroups[filename] = groups[group] print(_("\nFinished autogroup generation.")) if len(filenames) > 0: # We've written additional files, so save again magui.json with additional references # TODO: Intead of running magui and plugins again (should be fast, but not 'smart', we should save the json with the extra data.) # As we've the extra data writing inside the function we might have to rewrite several steps so we went the code-reuse path results = runmaguiandplugs(sosreports=sosreports, citellusplugins=citellusplugins, filename=options.output, extranames=filenames) # Here preprocess output to use filtering, etc # "result" does contain all data for both all citellus plugins and all magui plugins, need to filter for output on CLI only # As we don't have a proper place to store output and we're running the full set of tests only when output is going # to be stored (and then, the screen output is based on the already cached citellus results), it's probably not worth at this point to change this citellusplugins = [] # Prefill with all available plugins and the ones we want to filter for for extension in extensions: citellusplugins.extend(extension.listplugins(options)) allplugins = citellusplugins # By default, flatten plugin list for all extensions newplugins = [] for each in citellusplugins: newplugins.extend(each) citellusplugins = newplugins # Run with only the enabled plugins so that we get all data back for printing on console grouped = domagui(sosreports=sosreports, citellusplugins=citellusplugins, options=options) # Run Magui plugins result = [] for plugin in magplugs: start_time = time.time() # Get output from plugin data = filterresults(data=grouped, triggers=magtriggers[plugin.__name__.split(".")[-1]]) returncode, out, err = plugin.run(data=data, quiet=options.quiet) updates = {'rc': returncode, 'out': out, 'err': err} adddata = True if options.quiet: if returncode in [citellus.RC_OKAY, citellus.RC_SKIPPED]: adddata = False if adddata: # If RC is to be stored, process further subcategory = os.path.split(plugin.__file__)[0].replace(os.path.join(maguidir, 'plugins', ''), '') if subcategory: if len(os.path.normpath(subcategory).split(os.sep)) > 1: category = os.path.normpath(subcategory).split(os.sep)[0] else: category = subcategory subcategory = "" else: category = "" mydata = {'plugin': plugin.__name__.split(".")[-1], 'id': hashlib.md5(plugin.__file__.replace(maguidir, '').encode('UTF-8')).hexdigest(), 'description': plugin.help(), 'result': updates, 'time': time.time() - start_time, 'category': category, 'subcategory': subcategory} result.append(mydata) pprint.pprint(result, width=1)
def main(): """ Main code stub """ start_time = time.time() options = parse_args() # Configure ENV language before anything else os.environ['LANG'] = "%s" % options.lang # Reinstall language in case it has changed trad = gettext.translation('citellus', localedir, fallback=True, languages=[options.lang]) try: _ = trad.ugettext except AttributeError: _ = trad.gettext # Configure logging logging.basicConfig(level=options.loglevel) if not options.quiet: show_logo() # Each argument in sosreport is a sosreport magplugs, magtriggers = initPlugins(options) if options.list_plugins: for plugin in magplugs: print("-", plugin.__name__.split(".")[-1]) if options.description: desc = plugin.help() if desc: print(citellus.indent(text=desc, amount=4)) return # Prefill enabled citellus plugins from args if not citellus.extensions: extensions, exttriggers = citellus.initExtensions() else: extensions = citellus.extensions # Grab the data sosreports = options.sosreports if options.hosts: ansible = citellus.which("ansible-playbook") if not ansible: LOG.err(_("No ansible-playbook support found, skipping")) else: LOG.info("Grabbing data from remote hosts with Ansible") # Grab data from ansible hosts # Disable Ansible retry files creation: os.environ['ANSIBLE_RETRY_FILES_ENABLED'] = "0" if options.loglevel == 'DEBUG': # Keep ansible remote files for debug os.environ['ANSIBLE_KEEP_REMOTE_FILES'] = "1" command = "%s -i %s %s" % (ansible, options.hosts, os.path.join(maguidir, 'remote.yml')) LOG.debug("Running: %s " % command) citellus.execonshell(filename=command) # Now check the hosts we got logs from: hosts = citellus.findplugins( folders=glob.glob('/tmp/citellus/hostrun/*'), executables=False, fileextension='.json') for host in hosts: sosreports.append(os.path.dirname(host['plugin'])) # Get all data from hosts for all plugins, etc if options.output: citellusplugins = [] # Prefill with all available plugins and the ones we want to filter for for extension in extensions: citellusplugins.extend(extension.listplugins()) global allplugins allplugins = citellusplugins # By default, flatten plugin list for all extensions newplugins = [] for each in citellusplugins: newplugins.extend(each) citellusplugins = newplugins # Run with all plugins so that we get all data back grouped = domagui(sosreports=sosreports, citellusplugins=citellusplugins) # Run Magui plugins result = [] for plugin in magplugs: start_time = time.time() # Get output from plugin data = filterresults( data=grouped, triggers=magtriggers[plugin.__name__.split(".")[-1]]) returncode, out, err = plugin.run(data=data, quiet=options.quiet) updates = {'rc': returncode, 'out': out, 'err': err} subcategory = os.path.split(plugin.__file__)[0].replace( os.path.join(maguidir, 'plugins', ''), '') if subcategory: if len(os.path.normpath(subcategory).split(os.sep)) > 1: category = os.path.normpath(subcategory).split(os.sep)[0] else: category = subcategory subcategory = "" else: category = "" mydata = { 'plugin': plugin.__name__.split(".")[-1], 'id': hashlib.md5( plugin.__file__.replace(maguidir, '').encode('UTF-8')).hexdigest(), 'description': plugin.help(), 'result': updates, 'time': time.time() - start_time, 'category': category, 'subcategory': subcategory } result.append(mydata) branding = _(" ") citellus.write_results(results=result, filename=options.output, source='magui', path=sosreports, time=time.time() - start_time, branding=branding, web=True) # Here preprocess output to use filtering, etc # "result" does contain all data for both all citellus plugins and all magui plugins, need to filter for output on CLI only # As we don't have a proper place to store output and we're running the full set of tests only when output is going # to be stored (and then, the screen output is based on the already cached citellus results), it's probably not worth at this point to change this citellusplugins = [] # Prefill with all available plugins and the ones we want to filter for for extension in extensions: citellusplugins.extend(extension.listplugins(options)) global allplugins allplugins = citellusplugins # By default, flatten plugin list for all extensions newplugins = [] for each in citellusplugins: newplugins.extend(each) citellusplugins = newplugins # Run with all plugins so that we get all data back grouped = domagui(sosreports=sosreports, citellusplugins=citellusplugins, options=options) # Run Magui plugins result = [] for plugin in magplugs: start_time = time.time() # Get output from plugin data = filterresults( data=grouped, triggers=magtriggers[plugin.__name__.split(".")[-1]]) returncode, out, err = plugin.run(data=data, quiet=options.quiet) updates = {'rc': returncode, 'out': out, 'err': err} adddata = True if options.quiet: if returncode in [citellus.RC_OKAY, citellus.RC_SKIPPED]: adddata = False if adddata: # If RC is to be stored, process further subcategory = os.path.split(plugin.__file__)[0].replace( os.path.join(maguidir, 'plugins', ''), '') if subcategory: if len(os.path.normpath(subcategory).split(os.sep)) > 1: category = os.path.normpath(subcategory).split(os.sep)[0] else: category = subcategory subcategory = "" else: category = "" mydata = { 'plugin': plugin.__name__.split(".")[-1], 'id': hashlib.md5( plugin.__file__.replace(maguidir, '').encode('UTF-8')).hexdigest(), 'description': plugin.help(), 'result': updates, 'time': time.time() - start_time, 'category': category, 'subcategory': subcategory } result.append(mydata) pprint.pprint(result, width=1)