### Get Plugin Info Return Result Example Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/get_plugin_detail.md This example demonstrates a successful response from the BK-SOPS API when retrieving plugin information. It includes details about the plugin's inputs, outputs, and metadata. ```json { "result": true, "data": { "inputs": [ { "name": "Timing", "key": "bk_timing", "type": "string", "schema": { "type": "string", "description": "Timing, seconds(s) or datetime(%%Y-%%m-%%d %%H:%%M:%%S)", "enum": [] }, "required": true }, { "name": "force to be later than current time", "key": "force_check", "type": "bool", "schema": { "type": "string", "description": "", "enum": [] }, "required": true } ], "outputs": [ { "name": "Execution Result", "key": "_result", "type": "bool", "schema": { "type": "boolean", "description": "Boolean result,True or False", "enum": [] } }, { "name": "Loop Times", "key": "_loop", "type": "int", "schema": { "type": "int", "description": "Loop execution times", "enum": [] } } ], "desc": "", "code": "sleep_timer", "name": "Timing", "group_name": "BK Service(BK)", "version": "legacy", "form": "/static/components/atoms/bk/timer.js" }, "code": 0, "trace_id": "xxx" } ``` -------------------------------- ### Response Example for Getting Plugins Info Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/get_plugin_list.md This example showcases the successful response when retrieving plugin information. It contains a 'result' field indicating success and a 'data' array listing details of each plugin, such as its code, name, version, and associated form URL. ```json { "result": true, "data": [ { "inputs": [], "outputs": [ { "name": "result", "key": "_result", "type": "bool", "schema": { "type": "boolean", "description": "success", "enum": [] } }, { "name": "loop_time", "key": "_loop", "type": "int", "schema": { "type": "int", "description": "loop_time", "enum": [] } } ], "desc": "", "code": "job_push_local_files", "name": "push local file", "group_name": "(JOB)", "version": "1.0.0", "form": "/static/components/atoms/job/job_push_local_files.js" } ], "trace_id": "xxx" } ``` -------------------------------- ### Get Plugin Info Request Example Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/get_plugin_detail.md This is an example of a request payload to the BK-SOPS API to retrieve plugin information. It includes authentication details and parameters like business ID, plugin code, and version. ```json { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_username": "xxx", "bk_token": "xxx", "bk_biz_id": "2", "code": "sleep_timer", "version": "legacy", "scope": "cmdb_biz" } ``` -------------------------------- ### Start Task Return Result Example (JSON) Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/start_task.md This JSON object illustrates a successful response from the BK-SOPS API after starting a task. It indicates the success status, provides a URL to the task, and includes a trace ID for monitoring. ```json { "result": true, "task_url": "http://paas_url/taskflow/execute/xxx/?instance_id=xxx", "data": { "task_url": "http://paas_url/taskflow/execute/xxx/?instance_id=xxx" }, "message": "success", "code": 3545100, "trace_id": "xxx" } ``` -------------------------------- ### Get Mini Apps Request Example (JSON) Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/get_mini_app_list.md Example of a JSON payload for requesting a list of mini apps. It includes authentication details and filtering parameters like bk_biz_id and scope. ```json { "bk_app_code": "app_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_username": "xxx", "bk_biz_id": "2", "scope":"cmdb_biz" } ``` -------------------------------- ### Get Mini Apps Response Example (JSON) Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/get_mini_app_list.md Example of a successful JSON response when retrieving a list of mini apps. It includes a 'result' flag, a 'data' array containing mini app details, and pagination information like 'count'. ```json { "result": true, "data": [ { "auth_actions": [ "mini_app_view", "mini_app_edit", "mini_app_delete", "mini_app_create_task" ], "id": 1, "name": "new20210813065242", "code": "bk_sops20210816112820", "link": "xxxx", "category": "OpsTools", "task_template_id": 155, "template_scheme_id": "" } ], "count": 1, "code": 0, "trace_id": "xxx" } ``` -------------------------------- ### Start Celery Worker and Development Server (Bash) Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/en_docs/install/dev_deploy.md This snippet shows how to start the bk-sops project. The first command initiates a Celery worker with verbose logging, suitable for background tasks. The second command starts the development web server on port 8000 for local testing. ```bash python manage.py celery worker -l info -B python manage.py runserver 8000 ``` -------------------------------- ### Request Example for Getting Plugins Info Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/get_plugin_list.md This snippet demonstrates the structure of a request to fetch plugin information. It includes authentication details and the business ID for which plugins are being requested. The 'scope' parameter determines how 'bk_biz_id' is interpreted. ```json { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_username": "xxx", "bk_biz_id": "2", "scope": "cmdb_biz" } ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/en_docs/install/dev_deploy.md Installs the required Python packages for the project using pip from a requirements file. Ensure Python 3.6.7 and pip are installed locally before running this command. ```bash pip install -r requirements.txt ``` -------------------------------- ### BK-SOPS Request Parameters - JSON Example Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/fast_create_task.md This JSON object defines the parameters for a request to BK-SOPS, likely for creating or updating a task or workflow. It includes project identifiers, authentication credentials, task metadata, and a detailed 'pipeline_tree' structure for defining the execution flow. The 'pipeline_tree' specifies start and end events, a series of activities (like 'sleep_timer'), their connections ('flows'), and stage assignments. ```json { "project_id": "1", "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_username": "xxx", "bk_biz_id": "2", "name": "tasktest", "flow_type": "common", "description":"...", "has_common_subprocess":false, "category":"OpsTools", "pipeline_tree": { "start_event": { "incoming": "", "outgoing": "line7ed74aa679d19063b6d7037ce6db", "type": "EmptyStartEvent", "id": "node20cbeaa5379d08e8d8ed7bb44fdc", "name": "" }, "activities": { "node5310ec36c0364d3094d515f8f5ef": { "outgoing": "linec02d1e77e1076aa9c7c2c57238e4", "incoming": "line7ed74aa679d19063b6d7037ce6db", "name": "node1", "error_ignorable": false, "component": { "code": "sleep_timer", "data": { "bk_timing": { "hook": true, "value": "${bk_timing}" } } }, "stage_name": "stage1", "retryable": true, "skippable": true, "type": "ServiceActivity", "id": "node5310ec36c0364d3094d515f8f5ef" }, "node2bf42efcebe266706c3e21326dc4": { "outgoing": "linef0deadac69f769440a1b0e32587e", "incoming": "line7587c8804d34a091dae3d321f081", "name": "node2", "error_ignorable": false, "component": { "code": "sleep_timer", "data": { "bk_timing": { "hook": true, "value": "${bk_timing}" } } }, "stage_name": "stage2", "retryable": true, "skippable": true, "type": "ServiceActivity", "id": "node2bf42efcebe266706c3e21326dc4" }, "node3c7dcf31454c1e9bdc9cf1cdeacc": { "outgoing": "linebf8f91c96a8f4eb3794ca5eb9881", "incoming": "line429f64cdec5d20f368611e621ef5", "name": "node3", "error_ignorable": false, "component": { "code": "sleep_timer", "data": { "bk_timing": { "hook": false, "value": "3" } } }, "stage_name": "stage3", "retryable": true, "skippable": true, "type": "ServiceActivity", "id": "node3c7dcf31454c1e9bdc9cf1cdeacc" }, "nodedb1478a75c13f90cc400f5379949": { "outgoing": "line24d28a3f9f80e23e4a4fab7c4ffd", "incoming": "linec43c77f26af408748a9c194dbcfe", "name": "node4", "error_ignorable": false, "component": { "code": "sleep_timer", "data": { "bk_timing": { "hook": true, "value": "${bk_timing}" } } }, "stage_name": "stage3", "retryable": true, "skippable": true, "type": "ServiceActivity", "id": "nodedb1478a75c13f90cc400f5379949" } }, "end_event": { "incoming": "line6ea858554964a04d868cead4435a", "outgoing": "", "type": "EmptyEndEvent", "id": "nodebe0db4ad30cc1723c7ede37b4b5f", "name": "" }, "flows": { "line24d28a3f9f80e23e4a4fab7c4ffd": { "is_default": false, "source": "nodedb1478a75c13f90cc400f5379949", "id": "line24d28a3f9f80e23e4a4fab7c4ffd", "target": "node947e423b22e49aeb77bc77528bc0" }, "linebf8f91c96a8f4eb3794ca5eb9881": { "is_default": false, "source": "node3c7dcf31454c1e9bdc9cf1cdeacc", "id": "linebf8f91c96a8f4eb3794ca5eb9881", "target": "node947e423b22e49aeb77bc77528bc0" }, "line7587c8804d34a091dae3d321f081": { "is_default": false, "source": "node0863aab8325b84cfa3e5db52dc61", "id": "line7587c8804d34a091dae3d321f081", "target": "node2bf42efcebe266706c3e21326dc4" }, "line429f64cdec5d20f368611e621ef5": { "is_default": false, "source": "node7e97af0f55fb64276e067951dd9d", "id": "line429f64cdec5d20f368611e621ef5", "target": "node3c7dcf31454c1e9bdc9cf1cdeacc" } } } } ``` -------------------------------- ### Install npm Dependencies for SOPS Frontend Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/en_docs/install/dev_web.md Install all required Node.js dependencies for the SOPS frontend project located in the frontend/desktop directory. This command reads package.json and installs all listed dependencies and their sub-dependencies into node_modules folder. ```bash npm install ``` -------------------------------- ### Create and Initialize MySQL Database Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/en_docs/install/dev_deploy.md Creates the `bk_sops` database in MySQL with UTF8 character set and collation. It then runs Django's database migrations and creates a cache table. ```sql CREATE DATABASE `bk_sops` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; ``` ```bash python manage.py migrate python manage.py createcachetable django_cache ``` -------------------------------- ### Build Frontend Static Resources Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/en_docs/install/dev_deploy.md Installs frontend dependencies using npm, builds the frontend static resources for development, and collects all static files into the project's static directory. It also moves specific frontend resource directories to the static folder. ```bash npm install npm run build -- --STATIC_ENV=dev python manage.py collectstatic --noinput rm -rf static/dev static/images mv frontend/desktop/static/dev static/ mv frontend/desktop/static/images static/ ``` -------------------------------- ### Request Parameters Example for Get Tasks List Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/get_task_list.md This example demonstrates the structure of a request to retrieve a list of tasks. It includes authentication details, business context, filtering criteria such as keywords and task status, and pagination settings. ```json { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_username": "xxx", "bk_biz_id": "2", "keyword": "定时", "is_started": true, "limit": 5, "offset":0, "is_finished": "false", "scope":"cmdb_biz" } ``` -------------------------------- ### Request Parameters Example for Get Task Manual Intervention State Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/get_tasks_manual_intervention_state.md This snippet shows an example of the JSON payload required to request the manual intervention state for a list of tasks. It includes authentication details and the business and task IDs. ```json { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_username": "xxx", "bk_biz_id": "2", "task_id_list": [30000105, 30000101, 30000100], "scope": "cmdb_biz" } ``` -------------------------------- ### Start and Monitor Task Execution API Source: https://context7.com/tencentblueking/bk-sops/llms.txt This API allows you to start a previously created task and monitor its execution status. You can poll the status and retrieve detailed results upon completion. ```APIDOC ## POST /apigw/start_task/{task_id}/{project_id}/ ## GET /apigw/get_task_status/{task_id}/{project_id}/ ## GET /apigw/get_task_detail/{task_id}/{project_id}/ ### Description Starts a created task and monitors its execution status through polling. You can retrieve the current state and detailed results upon completion. ### Method POST (start_task) GET (get_task_status, get_task_detail) ### Endpoint - `/apigw/start_task/{task_id}/{project_id}/` - `/apigw/get_task_status/{task_id}/{project_id}/` - `/apigw/get_task_detail/{task_id}/{project_id}/` ### Parameters #### Path Parameters - **task_id** (integer) - Required - The ID of the task. - **project_id** (integer) - Required - The ID of the project. #### Query Parameters None #### Request Body (for POST /apigw/start_task/) None ### Request Example (Starting and Monitoring) ```python import requests import time def execute_and_monitor_task(task_id, project_id, auth_header): # Start the task start_response = requests.post( f'http://bk-sops-host/apigw/start_task/{task_id}/{project_id}/', headers={'X-Bkapi-Authorization': auth_header} ) if not start_response.json()['result']: print(f"Failed to start: {start_response.json()['message']}") return # Poll task status while True: status_response = requests.get( f'http://bk-sops-host/apigw/get_task_status/{task_id}/{project_id}/', headers={'X-Bkapi-Authorization': auth_header} ) data = status_response.json()['data'] state = data['state'] # CREATED, RUNNING, SUSPENDED, FINISHED, FAILED, REVOKED print(f"Task state: {state}") if state in ['FINISHED', 'FAILED', 'REVOKED']: # Get detailed results detail_response = requests.get( f'http://bk-sops-host/apigw/get_task_detail/{task_id}/{project_id}/', headers={'X-Bkapi-Authorization': auth_header} ) task_detail = detail_response.json()['data'] print(f"Execution completed. Children: {task_detail['children']}") for node_id, node_data in task_detail['children'].items(): print(f" Node {node_data['name']}: {node_data['state']}") break time.sleep(5) # Example usage: # execute_and_monitor_task(123, 456, '{"bk_username": "admin"}') ``` ### Response #### Success Response (200) for `get_task_status` - **result** (boolean) - Indicates if the operation was successful. - **data** (object) - Contains task status details. - **state** (string) - The current state of the task (e.g., 'RUNNING', 'FINISHED', 'FAILED'). - **message** (string) - A message describing the result. #### Success Response (200) for `get_task_detail` - **result** (boolean) - Indicates if the operation was successful. - **data** (object) - Contains detailed task execution information. - **children** (object) - A dictionary of child nodes and their status. - **node_id** (string) - The ID of the node. - **name** (string) - The name of the node. - **state** (string) - The state of the node. - **message** (string) - A message describing the result. #### Response Example (for get_task_status) ```json { "result": true, "data": { "state": "RUNNING" }, "message": "Task status retrieved successfully." } ``` #### Response Example (for get_task_detail) ```json { "result": true, "data": { "children": { "node_0_1": { "name": "Get DB Config", "state": "SUCCESS" }, "node_0_2": { "name": "Backup Database", "state": "RUNNING" } } }, "message": "Task details retrieved successfully." } ``` ``` -------------------------------- ### Configure Local Hosts File Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/en_docs/install/dev_deploy.md Adds an entry to the local hosts file to map `dev.{BK_PAAS_HOST}` to `127.0.0.1`. This is necessary for local development to resolve the PAAS host correctly. ```bash # For Windows: # Add "127.0.0.1 dev.{BK_PAAS_HOST}" to C:\Windows\System32\drivers\etc\host file. # For macOS: # Execute "sudo vim /etc/hosts" and add "127.0.0.1 dev.{BK_PAAS_HOST}". ``` -------------------------------- ### Get Functionalization Task List Response Example (JSON) Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/get_functionalization_task_list.md Example of a successful JSON response when retrieving the functionalization task list. It contains a 'result' boolean, a 'data' array with task objects, response metadata like 'code', 'count', and 'trace_id'. ```json { "result": true, "data": [ { "id": 6, "name": "timer_20201110041712", "creator": "admin", "create_time": "2020-11-10T04:17:15.586Z", "claimant": "", "claim_time": null, "rejecter": "", "reject_time": null, "predecessor": "", "transfer_time": null, "status": "submitted", "task": { "id": 414, "name": "timer_20201110041712", "category": "alert", "create_method": "app", "creator": "admin", "executor": "", "start_time": null, "finish_time": null, "is_started": false, "is_finished": false, "template_source": "project", "template_id": "306" } }, { "id": 5, "name": "timer_20201110034326", "creator": "admin", "create_time": "2020-11-10T03:43:29.104Z", "claimant": "", "claim_time": null, "rejecter": "", "reject_time": null, "predecessor": "", "transfer_time": null, "status": "submitted", "task": { "id": 413, "name": "timer_20201110034326", "category": "alert", "create_method": "app", "creator": "admin", "executor": "", "start_time": null, "finish_time": null, "is_started": false, "is_finished": false, "template_source": "project", "template_id": "306" } } ], "code": 0, "count": 2, "trace_id": "xxx" } ``` -------------------------------- ### Get Functionalization Task List Request Example (JSON) Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/get_functionalization_task_list.md Example of a JSON payload to request the functionalization task list. It includes authentication details (bk_app_code, bk_app_secret, bk_token) and filtering parameters like id_in, task_id_in, status, limit, and offset. ```json { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_username": "xxx", "id_in": "412,411" "task_id_in": "414,413", "status": "submitted", "limit": 50, "offset": 0 } ``` -------------------------------- ### Get Project Execution Result Example Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/get_task_detail.md Provides an example of the response structure for retrieving the execution results of a project operation. ```APIDOC ## GET /project/execution/result ### Description Retrieves the detailed execution results for a specific project operation instance. This includes information about the project, constants, outputs, and the pipeline execution tree. ### Method GET ### Endpoint /project/execution/result ### Parameters #### Query Parameters - **project_id** (integer) - Required - The ID of the project. - **instance_id** (integer) - Required - The ID of the specific execution instance. #### Request Body None ### Request Example None ### Response #### Success Response (200) - **data** (object) - Contains the execution details. - **name** (string) - The name of the execution. - **creator** (string) - The user who created the execution. - **outputs** (array) - List of outputs from the execution. - **value** (string) - The output value. - **key** (string) - The key for the output. - **name** (string) - The name of the output. - **start_time** (string) - The start time of the execution. - **project_id** (integer) - The ID of the project. - **create_time** (string) - The creation time of the execution. - **project_name** (string) - The name of the project. - **id** (integer) - The ID of the execution. - **constants** (object) - Key-value pairs of constants used in the execution. - **create_method** (string) - The method used for creation. - **elapsed_time** (integer) - The elapsed time in seconds. - **ex_data** (string) - Extended data. - **finish_time** (string) - The finish time of the execution. - **instance_name** (string) - The name of the instance. - **end_time** (string) - The end time of the execution. - **executor** (string) - The executor of the task. - **template_id** (string) - The ID of the template used. - **task_url** (string) - URL to the task. - **pipeline_tree** (object) - The structure of the execution pipeline. #### Response Example ```json { "data": { "name": "xxx", "creator": "admin", "outputs": [ { "value": "1", "key": "${job_script_type}", "name": "type" }, { "value": "127.0.0.1", "key": "${IP}", "name": "IP" }, { "value": "0", "key": "${EXIT}", "name": "EXIT" } ], "start_time": "2019-01-17 04:13:08", "project_id": 2, "create_time": "2019-01-17 04:13:03", "project_name": "blueking", "id": 10, "constants": { "${IP}": { "source_tag": "var_ip_picker.ip_picker", "source_info": {}, "name": "IP", "index": 2, "custom_type": "ip", "value": { "var_ip_custom_value": "127.0.0.1", "var_ip_method": "custom", "var_ip_tree": [] }, "show_type": "show", "source_type": "custom", "validator": [], "key": "${IP}", "desc": "", "validation": "", "is_meta": false }, "${job_script_type}": { "source_tag": "job_fast_execute_script.job_script_type", "source_info": { "node554316ea019a341f8c28cc6a7da9": [ "job_script_type" ] }, "name": "type", "index": 0, "custom_type": "", "value": "1", "show_type": "show", "source_type": "component_inputs", "key": "${job_script_type}", "validation": "", "desc": "" }, "${EXIT}": { "source_tag": "", "source_info": {}, "name": "EXIT", "index": 1, "custom_type": "input", "value": "0", "show_type": "show", "source_type": "custom", "validator": [], "key": "${EXIT}", "validation": "^.+$", "desc": "" } }, "create_method": "app", "elapsed_time": 7, "ex_data": "", "finish_time": "", "instance_name": "job_20190117121300", "end_time": "2019-01-17 04:13:15", "executor": "admin", "template_id": "266", "task_url": "http://bk_sops_host/taskflow/execute/3/?instance_id=15364", "pipeline_tree": { "activities": { "node9b5ae13799d63e179f0ce3088b62": { "outgoing": "line27bc7b4ccbcf37ddb9d1f6572a04", "incoming": "line490caa49d2a03e64829693281032", "name": "timing", "error_ignorable": false, "component": { "code": "sleep_timer", "data": { "bk_timing": { "hook": false, "value": "2" } } }, "stage_name": "stage1", "retryable": true, "skippable": true, "type": "ServiceActivity", "optional": false, "id": "node9b5ae13799d63e179f0ce3088b62", "loop": null }, "node880ded556c6c3c269be3cedc64b6": { "outgoing": "line490caa49d2a03e64829693281032", "incoming": "lineb83161d6e0593ad68d9ec73a961b", "name": "pause", "error_ignorable": false, "component": { "code": "pause_node", "data": {} }, "stage_name": "stage1", "retryable": true, "skippable": true, "type": "ServiceActivity", "optional": true, "id": "node880ded556c6c3c269be3cedc64b6", "loop": null } }, "end_event": { "type": "EmptyEndEvent", "outgoing": "", "incoming": "line27bc7b4ccbcf37ddb9d1f6572a04", "id": "node5c48f37aa9f0351e8b43ab6a2295", "name": "" }, "outputs": [], "flows": { "line490caa49d2a03e64829693281032": { "is_default": false, "source": "node880ded556c6c3c269be3cedc64b6" } } } } } ``` ``` -------------------------------- ### Collect and Deploy Static Frontend Resources Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/en_docs/install/dev_web.md Complete workflow to build frontend, collect static resources, and integrate them with Django backend. Copies built frontend assets to the main static directory, replaces the base Vue template, and cleans up temporary directories. Execute from project root directory. ```bash cd frontend/desktop npm run build cd ../.. rm -rf ./static/bk_sops cp -r ./frontend/desktop/static ./static/bk_sops rm ./gcloud/core/templates/core/base_vue.html mv ./static/bk_sops/index.html ./gcloud/core/templates/core/base_vue.html ``` -------------------------------- ### Package Frontend Static Resources for Mobile Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/en_docs/install/mobile_deploy.md Packages the frontend static resources for the mobile version of SOPS. This command should be run from the frontend/mobile/ directory and specifies the site URL and static environment settings. The output is typically placed in a 'dist' directory. ```bash npm run build -- --SITE_URL="/o/bk_sops" --STATIC_ENV="open/prod" ``` -------------------------------- ### Get Task Tree with Excluded Nodes (JSON Request Example) Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/preview_task_tree.md Example of a JSON request payload to retrieve a task tree from BK SOPs, with the option to exclude specific task nodes. This request includes business ID, template ID, version, scope, and a list of task node IDs to exclude. ```json { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_biz_id": "2", "template_id": "12", "version":"1.0.0", "scope":"cmdb_biz", "exclude_task_nodes_id": [1, 2, 3] } ``` -------------------------------- ### Django Local Settings Configuration Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/en_docs/install/dev_deploy.md Defines local database and Redis configurations within the `local_settings.py` file. This includes specifying database engine, name, user, password, host, port, and Redis connection details. ```python # -*- coding: utf-8 -*- import os DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': os.getenv('DB_NAME'), 'USER': '', # Local database account 'PASSWORD': '', # Local database password 'HOST': 'localhost', 'PORT': '3306', 'TEST_CHARSET': "utf8", 'TEST_COLLATION': "utf8_general_ci", 'TEST': { 'CHARSET': 'utf8', 'COLLATION': 'utf8_general_ci', } }, } REDIS = { 'host': 'localhost', 'port': 6379, 'db': 0 } EXTERNAL_PLUGINS_SOURCE_SECURE_RESTRICT = False BK_IAM_SYNC_TEMPLATES = False STATIC_ROOT = 'staticfiles' ``` -------------------------------- ### Return Result Example for Get Task Manual Intervention State Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/get_tasks_manual_intervention_state.md This snippet illustrates the expected JSON response when querying for the manual intervention state of tasks. It includes a success flag, a list of tasks with their intervention status, and a trace ID. ```json { "result": true, "data": [ { "id": 81, "manual_intervention_required": false }, { "id": 80, "manual_intervention_required": true }, { "id": 79, "manual_intervention_required": true }, { "id": 78, "manual_intervention_required": false }, { "id": 77, "manual_intervention_required": false } ], "code": 0, "trace_id": "xxx" } ``` -------------------------------- ### Launch Local Frontend Development Server Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/en_docs/install/dev_web.md Start the Vue.js development server on port 9000 with hot module reloading. Backend API requests are automatically proxied to the Django development server running on port 8000. Access the application via http://dev.{BK_PAAS_HOST}:9000/. ```bash npm run dev ``` -------------------------------- ### Get Template Execution Scheme List Request Example (JSON) Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/get_template_schemes.md This JSON object represents an example request to the BK-SOPS API for retrieving a list of template execution schemes. It includes authentication details and the necessary business and template identifiers. ```json { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_username": "xxx", "bk_biz_id": "2", "template_id": "12", "scope": "cmdb_biz" } ``` -------------------------------- ### Request Parameters Example for Get Task Tree Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/preview_common_task_tree.md This JSON object demonstrates the parameters required to request a task tree, including business ID, template ID, and optional exclusion of task nodes. It specifies authentication details and the scope for the business ID. ```json { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_username": "bk_username", "bk_biz_id": "2", "template_id": "10001", "scope": "cmdb_biz", "version": "xxx", "exclude_task_nodes_id": [1, 2, 3] } ``` -------------------------------- ### Get Template List and Create Task using Python Source: https://context7.com/tencentblueking/bk-sops/llms.txt This function retrieves a list of available task templates, fetches details for a specific template, extracts necessary constants, and then creates a new task instance from the selected template. It requires project ID and authentication headers. The output is the ID of the newly created task. ```python import requests def get_templates_and_create_task(project_id, auth_header): # Get template list templates_response = requests.get( f'http://bk-sops-host/apigw/get_template_list/{project_id}/', params={ 'template_source': 'project', # or 'common' for common templates 'is_deleted': False }, headers={'X-Bkapi-Authorization': auth_header} ) templates = templates_response.json()['data'] print(f"Found {len(templates)} templates:") for tmpl in templates: print(f" {tmpl['id']}: {tmpl['name']} (category: {tmpl['category_name']})") # Get template details template_id = templates[0]['id'] detail_response = requests.get( f'http://bk-sops-host/apigw/get_template_info/{template_id}/{project_id}/', headers={'X-Bkapi-Authorization': auth_header} ) template_detail = detail_response.json()['data'] print(f"\nTemplate: {template_detail['name']}") print(f"Pipeline tree has {len(template_detail['pipeline_tree']['activities'])} activities") # Extract constants (parameters) constants = {} for const_key, const_value in template_detail['pipeline_tree']['constants'].items(): if const_value['show_type'] == 'show': # Prompt for user input or use defaults constants[const_key] = const_value.get('value', '') # Create task with parameters create_response = requests.post( f'http://bk-sops-host/apigw/create_task/{template_id}/{project_id}/', json={ 'name': f"Auto-generated task from {template_detail['name']}", 'constants': constants }, headers={'X-Bkapi-Authorization': auth_header} ) return create_response.json()['data']['task_id'] # Execute task_id = get_templates_and_create_task(456, '{"bk_username": "admin"}') print(f"Created task: {task_id}") ``` -------------------------------- ### Create Clocked Task Request Example JSON Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/create_clocked_task.md Example JSON request payload for creating a clocked task. Includes authentication credentials, template and business IDs, task name, scheduled start time, and optional task parameters with constants and template scheme IDs. ```json { "bk_app_code": "app_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_username": "xxx", "template_id": "1", "bk_biz_id": "2", "scope": "cmdb_biz", "task_name": "test_clocked_task", "plan_start_time": "2022-05-16 20:26:40+0800", "task_parameters": { "constants": {}, "template_schemes_id": [] } } ``` -------------------------------- ### Create and Start Task with Custom Pipeline (Python) Source: https://context7.com/tencentblueking/bk-sops/llms.txt Initiates a new task execution based on a specified template, allowing for custom constants and callback URLs. It requires the base API host, project and pipeline IDs, and authentication headers. The response includes the task ID, state, and pipeline instance ID, or an error message. ```python import requests response = requests.post( 'http://bk-sops-host/apigw/create_and_start_task/123/456/', json={ 'name': 'Quick Deployment Task', 'template_id': 123, 'template_source': 'project', 'constants': { '${deploy_env}': 'production', '${app_version}': 'v2.1.0' }, 'exclude_task_nodes_id': [], 'callback_url': 'http://callback.example.com/webhook' }, headers={'X-Bkapi-Authorization': '{"bk_username": "admin"}'} ) if response.json()['result']: data = response.json()['data'] print(f"Task {data['task_id']} started, state: {data['state']}") print(f"Pipeline instance: {data['pipeline_instance_id']}") else: print(f"Error: {response.json()['message']}") ``` -------------------------------- ### Get User Project List Response Example Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/get_user_project_list.md JSON response payload containing the result status, list of user projects with their details (project_id, bk_biz_id, name), API response code, and OpenTelemetry trace ID. The data array contains project information when the request succeeds. ```json { "result": true, "data": [ { "project_id": 13, "bk_biz_id": 2, "name": "蓝鲸" }, { "project_id": 14, "bk_biz_id": 3, "name": "la" } ], "code": 0, "trace_id": "xxx" } ``` -------------------------------- ### POST /start_task Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/start_task.md Initiates the execution of a specified task within the BK-SOPS system. This endpoint requires business and task identifiers, with an optional scope parameter to define how the project is identified. ```APIDOC ## POST /start_task ### Description Starts a task within the BK-SOPS system. ### Method POST ### Endpoint /start_task ### Parameters #### Query Parameters - **bk_biz_id** (string) - Required - The business ID. - **task_id** (string) - Required - The task ID. - **scope** (string) - Optional - Defines the scope for identifying the project. Defaults to 'cmdb_biz'. If 'project', the project ID equal to bk_biz_id is used. ### Request Example ```json { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_username": "xxx", "bk_biz_id": "2", "task_id": "10", "scope": "cmdb_biz" } ``` ### Response #### Success Response (200) - **result** (bool) - true or false, indicates success or failure. - **data** (dict) - Data returned when result is true. - **message** (string) - Error message returned when result is false. - **task_url** (string) - URL of the task. - **trace_id** (string) - Open telemetry trace_id. #### Response Example ```json { "result": true, "task_url": "http://paas_url/taskflow/execute/xxx/?instance_id=xxx", "data": { "task_url": "http://paas_url/taskflow/execute/xxx/?instance_id=xxx" }, "message": "success", "code": 3545100, "trace_id": "xxx" } ``` ``` -------------------------------- ### Return Result Example for Get Project Detail (JSON) Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/get_user_project_detail.md A sample JSON response from the BK-SOPS API when successfully retrieving project details. It includes a success flag, the project data, and a trace ID. ```json { "result": true, "data": { "project_id": 13, "project_name": "blueking", "bk_biz_id": 2, "from_cmdb": true, "bk_biz_name": "blueking", "bk_biz_developer": "", "bk_biz_maintainer": "admin,gcloudadmin", "bk_biz_tester": "", "bk_biz_productor": "", "auth_actions": [ "project_view", "project_edit", "project_fast_create_task" ] }, "code": 0, "trace_id": "xxx" } ``` -------------------------------- ### Request Parameters Example - JSON Source: https://github.com/tencentblueking/bk-sops/blob/release_humming_bird/docs/apidoc/en/get_task_count.md This JSON object demonstrates the expected parameters for requesting the task count. It includes authentication details, business ID, search keyword, status filters, and scope. ```json { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_username": "xxx", "bk_biz_id": "2", "keyword": "定时", "is_started": true, "is_finished": "false", "scope":"cmdb_biz" } ```