def runmaguiandplugs(sosreports, citellusplugins, filename=dooutput, extranames=None, serveruri=False, onlysave=False, result=None, anon=False): """ Runs magui and magui plugins :param serveruri: :param sosreports: sosreports to process :param citellusplugins: citellusplugins to run :param filename: filename to save to :param extranames: additional filenames used :param onlysave: Bool: Defines if we just want to save results :param result: Results to write to disk :return: results of execution """ start_time = time.time() if not onlysave and not result: # 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: plugstart_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() - plugstart_time, 'category': category, 'subcategory': subcategory} result.append(mydata) if filename: branding = _(" ") citellus.write_results(results=result, filename=filename, source='magui', path=sosreports, time=time.time() - start_time, branding=branding, web=True, extranames=extranames, serveruri=serveruri, anon=anon) return result
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 runmaguiandplugs( sosreports, citellusplugins, filename=dooutput, extranames=None, serveruri=False, onlysave=False, result=None, anon=False, grouped={}, ): """ Runs magui and magui plugins :param grouped: Grouped results from sosreports to speedup processing (domagui) :param anon: anonymize results on execution :param serveruri: Server uri to POST the analysis :param sosreports: sosreports to process :param citellusplugins: citellusplugins to run :param filename: filename to save to :param extranames: additional filenames used :param onlysave: Bool: Defines if we just want to save results :param result: Results to write to disk :return: results of execution """ start_time = time.time() if not onlysave and not result: # Run with all plugins so that we get all data back grouped = domagui(sosreports=sosreports, citellusplugins=citellusplugins, grouped=grouped) # Run Magui plugins result = [] for plugin in magplugs: plugstart_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.sha512( plugin.__file__.replace( maguidir, "").encode("UTF-8")).hexdigest(), "description": plugin.help(), "long_name": plugin.help(), "result": updates, "time": time.time() - plugstart_time, "category": category, "subcategory": subcategory, } result.append(mydata) if filename: branding = _(" ") citellus.write_results( results=result, filename=filename, source="magui", path=sosreports, time=time.time() - start_time, branding=branding, web=True, extranames=extranames, serveruri=serveruri, anon=anon, ) return result, grouped
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)