Пример #1
0
def main(filename):
    dr.load_components("insights.specs.default")
    dr.load_components("insights.specs.insights_archive")
    dr.load_components("insights.specs.sos_archive")
    dr.load_components("insights.specs.jdr_archive")
    dr.load_components("insights.parsers")
    dr.load_components("insights.combiners")

    parsers = sorted([c for c in dr.DELEGATES if is_parser(c)],
                     key=dr.get_name)
    combiners = sorted([c for c in dr.DELEGATES if is_combiner(c)],
                       key=dr.get_name)
    specs = sorted([
        c for c in dr.DELEGATES
        if is_datasource(c) and dr.get_module_name(c) == 'insights.specs'
    ],
                   key=dr.get_name)

    with open(filename, "w") as fh:
        fh.write("Components Cross-Reference\n")
        fh.write("==========================\n")

        fh.write("Specs Dependents\n")
        fh.write("----------------\n")
        for spec in specs:
            info = dict(name=dr.get_name(spec))
            info['dependents'] = []
            for d in dr.get_dependents(spec):
                info['dependents'].append({
                    'name':
                    dr.get_name(d),
                    'dependents':
                    [dr.get_name(sd) for sd in dr.get_dependents(d)]
                })
            print_spec_info(info, fh)

        blank_line(fh)
        fh.write("Parser Dependents/Dependencies\n")
        fh.write("------------------------------\n")
        for pars in parsers:
            print_info(component_info(pars), fh)

        blank_line(fh)
        fh.write("Combiner Dependents/Dependencies\n")
        fh.write("--------------------------------\n")
        for comb in combiners:
            print_info(component_info(comb), fh)
Пример #2
0
def component_info(component):
    dependents = dr.get_dependents(component)
    dependencies = dr.get_dependencies(component)
    return {
        'name': dr.get_name(component),
        'dependents': [dr.get_name(c) for c in dependents],
        'dependencies': [dr.get_name(c) for c in dependencies]
    }
Пример #3
0
def get_filters(component, filters=None):
    filters = filters or set()
    if not plugins.is_datasource(component):
        return filters

    if component in FILTERS:
        filters |= FILTERS[component]

    for d in dr.get_dependents(component):
        filters |= get_filters(d, filters)
    return filters
Пример #4
0
    def inner(c, filters=None):
        filters = filters or set()
        if not ENABLED:
            return filters

        if not plugins.is_datasource(c):
            return filters

        if c in FILTERS:
            filters |= FILTERS[c]

        for d in dr.get_dependents(c):
            filters |= inner(d, filters)
        return filters
Пример #5
0
def main():
    # config = get_config()

    dr.load_components("insights.specs.default")
    dr.load_components("insights.parsers")
    dr.load_components("insights.combiners")
    dr.load_components("telemetry.rules.plugins")
    dr.load_components("prodsec")
    ds = dr.COMPONENTS_BY_TYPE[datasource]

    specs = []
    for c in ds:
        if not is_datasource(c):
            continue
        if not any(is_datasource(d) for d in dr.get_dependents(c)):
            specs.append(c)

    deps = defaultdict(dict)

    pspec = ''
    for spec in sorted(specs, key=dr.get_name):

        info = dict(name=dr.get_simple_name(spec))

        f = filters.get_filters(spec)
        info['dependents'] = []

        spds = None
        d = [d for d in dr.get_dependencies(spec) if is_datasource(d)]
        for dp in d:
            c = dr.get_dependencies(dp)
            for cdeps in c:
                if is_datasource(cdeps) and '__qualname__' in cdeps.func_dict and 'DefaultSpecs' in cdeps.func_dict['__qualname__']:
                    spds = cdeps

        for d in dr.get_dependencies(spec):
            cp = ''
            lines = []

            if d.__doc__ and "Returns the first" in d.__doc__:
                lines = d.__doc__.replace(',', '\n')
                lines = lines.splitlines()
                head = [lines[0]]
                top = ["<ul>"]
                bottom = ["</ul>"]
                if spds:
                    lines = [l.replace('Command:', '') for l in lines]
                    lines = [l.replace('Path:', '') for l in lines]
                    lines = ["<li>" + l + "</li>" for l in lines[1:]]
                    # lines = ["<li>" + spds.func_doc + ',' + l + "</li>" for l in lines[1:]]
                else:
                    lines = ["<li>" + l + "</li>" for l in lines[1:]]
                cp = "\n".join(head + top + lines + bottom)
            else:
                if spds:
                    d.__doc__ = d.__doc__.replace('Command:', '')
                    d.__doc__ = d.__doc__.replace('Path:', '')
                    d.__doc__ = spds.func_doc + ', ' + d.__doc__
                cp = d.__doc__

        for d in dr.get_dependents(spec):
            if dr.get_simple_name(pspec) == dr.get_simple_name(d):
                continue
            pspec = d

            p = [dr.get_name(sd) for sd in dr.get_dependents(d)]
            rules = sorted([x.rsplit('.', 2)[1] for x in p])
            deps[info['name']][info['name'] + "_spec-def"] = cp
            deps[info['name']][info['name'] + "_rules"] = ", ".join(rules)
            deps[info['name']][info['name'] + "_filters"] = f

    report = Environment().from_string(REPORT).render(
        report_date=datetime.date.today().strftime("%B %d, %Y"), specs=deps)

    print(report)