Beispiel #1
0
    def start_script(self, config, values, user: User):
        audit_name = user.get_audit_name()

        config.set_all_param_values(values)
        normalized_values = dict(config.parameter_values)

        executor = ScriptExecutor(config, normalized_values)
        execution_id = self._id_generator.next_id()

        audit_command = executor.get_secure_command()
        LOGGER.info('Calling script #%s: %s', execution_id, audit_command)

        executor.start()
        self._executors[execution_id] = executor
        self._execution_infos[execution_id] = _ExecutionInfo(
            execution_id=execution_id,
            owner_user=user,
            audit_name=audit_name,
            audit_command=audit_command,
            config=config)
        self._active_executor_ids.add(execution_id)

        self._add_post_finish_handling(execution_id, executor, user)

        self._fire_execution_started(execution_id, user)

        return execution_id
        def finished(execution_id, user: User):
            return_code = execution_service.get_exit_code(execution_id)

            if return_code != 0:
                script_config = execution_service.get_config(execution_id, user)
                script = str(script_config.name)
                audit_name = user.get_audit_name()
                output_stream = execution_service.get_anonymized_output_stream(execution_id)

                title = script + ' FAILED'
                body = 'The script "' + script + '", started by ' + audit_name + \
                       ' exited with return code ' + str(return_code) + '.' + \
                       ' Usually this means an error, occurred during the execution.' + \
                       ' Please check the corresponding logs'

                output_stream_data = read_until_closed(output_stream)
                script_output = ''.join(output_stream_data)

                files = [File(filename='log.txt', content=script_output)]
                alert_service.send_alert(title, body, files)