示例#1
0
    def _bulk_discovery_start(self, request):
        job = BulkDiscoveryBackgroundJob()
        if job.is_active():
            raise MKUserError(
                None,
                _("A bulk discovery job is already running. Please use the "
                  '"bulk_discovery_status" call to get the curent status.'),
            )

        discovery_mode, do_full_scan, bulk_size, ignore_errors = self._get_parameters_from_request(
            request)
        try:
            start_bulk_discovery(
                job,
                self._get_hosts_from_request(request),
                discovery_mode,
                do_full_scan,
                ignore_errors,
                bulk_size,
            )
        except Exception as e:
            logger.exception("Failed to start bulk discovery")
            raise MKUserError(None, _("Failed to start discovery: %s") % e)

        return {
            "started": True,
        }
示例#2
0
 def _bulk_discovery_status(self, request):
     job = BulkDiscoveryBackgroundJob()
     status = job.get_status()
     return {
         "is_active": job.is_active(),
         "job": {
             "state": status["state"],
             "result_msg": "\n".join(status["loginfo"]["JobResult"]),
             "output": "\n".join(status["loginfo"]["JobProgressUpdate"]),
         },
     }
示例#3
0
def execute_bulk_discovery(params) -> Response:
    """Start a bulk discovery job"""
    body = params["body"]
    job = BulkDiscoveryBackgroundJob()
    if job.is_active():
        return Response(status=409)

    hosts_to_discover = prepare_hosts_for_discovery(body["hostnames"])
    start_bulk_discovery(
        job,
        hosts_to_discover,
        body["mode"],
        body["do_full_scan"],
        body["ignore_errors"],
        body["bulk_size"],
    )

    return _serve_background_job(job)
示例#4
0
    def _bulk_discovery_start(self, request):
        job = BulkDiscoveryBackgroundJob()
        if job.is_active():
            raise MKUserError(
                None,
                _("A bulk discovery job is already running. Please use the "
                  "\"bulk_discovery_status\" call to get the curent status."))

        mode, do_scan, bulk_size, error_handling = self._get_parameters_from_request(request)
        tasks = get_tasks(self._get_hosts_from_request(request), bulk_size)

        try:
            job.set_function(job.do_execute, mode, do_scan, error_handling, tasks)
            job.start()
            return {
                "started": True,
            }
        except Exception as e:
            logger.exception("Failed to start bulk discovery")
            raise MKUserError(None, _("Failed to start discovery: %s") % e)