Example #1
0
    def ValidateParser(self, parser, registry):
        """Validate a parser is well defined."""
        for artifact_to_parse in parser.supported_artifacts:
            art_obj = registry.GetArtifact(artifact_to_parse)
            if art_obj is None:
                raise parsers.ParserDefinitionError(
                    "Artifact parser %s has an invalid artifact"
                    " %s. Artifact is undefined" %
                    (parser.__name__, artifact_to_parse))

        for out_type in parser.output_types:
            if out_type not in rdfvalue.RDFValue.classes:
                raise parsers.ParserDefinitionError(
                    "Artifact parser %s has an invalid output "
                    "type %s." % (parser.__name__, out_type))

        if parser.process_together:
            if not hasattr(parser, "ParseMultiple"):
                raise parsers.ParserDefinitionError(
                    "Parser %s has set process_together, but "
                    "has not defined a ParseMultiple method." %
                    parser.__name__)

        # Additional, parser specific validation.
        parser.Validate()
Example #2
0
    def testParsersRetrieval(self):
        """Check the parsers are valid."""
        for processor in parsers.Parser.classes.values():
            if (not hasattr(processor, "output_types")
                    or not isinstance(processor.output_types, (list, tuple))):
                raise parsers.ParserDefinitionError(
                    "Missing output_types on %s" % processor)

            for output_type in processor.output_types:
                if output_type not in rdfvalue.RDFValue.classes:
                    raise parsers.ParserDefinitionError(
                        "Parser %s has an output type that is an unknown type %s"
                        % (processor, output_type))
Example #3
0
 def Validate(cls):
   """Perform some extra sanity checks on the ps arguments."""
   super(PsCmdParser, cls).Validate()
   for artifact_name in cls.supported_artifacts:
     artifact = artifact_registry.REGISTRY.GetArtifact(artifact_name)
     for source in artifact.sources:
       if not cls._FindPsOutputFormat(source.attributes["cmd"],
                                      source.attributes["args"]):
         raise parsers.ParserDefinitionError(
             "Artifact parser %s can't process artifact %s. 'ps' command has "
             "unacceptable arguments." % (cls.__name__, artifact_name))