Пример #1
0
    def VerifyHuntOutput(self, plugin, hunt):
        # Check that we get the plugin object we expected to get.
        # Actual verifiers implementations don't have to do this check.
        if not isinstance(plugin, VerifiableDummyHuntOutputPlugin):
            raise ValueError("Passed plugin must be an "
                             "VerifiableDummyHuntOutputPlugin, got: " %
                             plugin.__class__.__name__)

        VerifiableDummyHuntOutputPluginVerfier.num_calls += 1
        return output_plugin.OutputPluginVerificationResult(
            status="SUCCESS", status_message="yo")
Пример #2
0
    def _VerifyHunts(self, hunts_plugins_by_verifier):
        results_by_hunt = {}

        errors = []
        for verifier_cls, hunts_plugins in iteritems(
                hunts_plugins_by_verifier):

            if verifier_cls == self.NON_VERIFIABLE:
                for plugin_id, plugin_descriptor, plugin_obj, hunt in hunts_plugins:
                    result = output_plugin.OutputPluginVerificationResult(
                        status=output_plugin.OutputPluginVerificationResult.
                        Status.N_A,
                        status_message=("Plugin %s is not verifiable." %
                                        plugin_obj.__class__.__name__))
                    self._FillResult(result, plugin_id, plugin_descriptor)

                    results_by_hunt.setdefault(hunt.urn, []).append(result)
                    stats.STATS.IncrementCounter(
                        "hunt_output_plugin_verifications",
                        fields=[utils.SmartStr(result.status)])
                continue

            verifier = verifier_cls()

            plugins_hunts_pairs = []
            for plugin_id, plugin_descriptor, plugin_obj, hunt in hunts_plugins:
                plugins_hunts_pairs.append((plugin_obj, hunt))

            try:
                for hunt_urn, result in verifier.MultiVerifyHuntOutput(
                        plugins_hunts_pairs):
                    self._FillResult(result, plugin_id, plugin_descriptor)

                    results_by_hunt.setdefault(hunt.urn, []).append(result)
                    stats.STATS.IncrementCounter(
                        "hunt_output_plugin_verifications",
                        fields=[utils.SmartStr(result.status)])

            except output_plugin.MultiVerifyHuntOutputError as e:
                logging.exception(e)

                errors.extend(e.errors)
                stats.STATS.IncrementCounter(
                    "hunt_output_plugin_verification_errors",
                    delta=len(e.errors))

        for hunt_urn, results in iteritems(results_by_hunt):
            yield hunt_urn, results

        if errors:
            raise MultiHuntVerificationSummaryError(errors)
Пример #3
0
    def VerifyHuntOutput(self, plugin, hunt):
        if hunt.runner_args.description == "raise":
            raise RuntimeError("oh no")

        return output_plugin.OutputPluginVerificationResult(
            status_message=hunt.runner_args.description)