Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 订阅下发支持动态分组 (closed #2507) #2527

Open
wants to merge 1 commit into
base: v2.4.8-dev
Choose a base branch
from

Conversation

ping15
Copy link
Collaborator

@ping15 ping15 commented Dec 25, 2024

Reviewed, transaction id: 27764

PR

CheckList(PR Assigners)

确认已完成以下操作:

  • 已将分支与当前合入分支同步
  • 已在关联 Issue 中补充「功能自测」部分内容
  • 已更新关联 Issue 的状态 backlog -> todo -> for test -> tested(需通过测试同学测试) -> done
  • 将 PR 添加上 pr/reviewable

CheckList(PR Reviewers)

确认已完成以下操作:

  • 检查关联 Issue 「功能自测」部分内容
  • 必要时打回 pr/reviewable,要求重新修改
  • 及时 Approve

@ping15 ping15 requested a review from Huayeaaa December 25, 2024 08:34
@ping15 ping15 changed the base branch from _V2.4.X/dev_issue#2507 to v2.4.8-dev December 25, 2024 08:43
@ping15 ping15 removed the request for review from Huayeaaa December 25, 2024 08:56
@ping15 ping15 force-pushed the _V2.4.X/dev_issue#2507 branch 2 times, most recently from 1dc3c7c to edb7ec9 Compare December 26, 2024 08:00
@ping15 ping15 requested a review from Huayeaaa December 26, 2024 08:01
@ping15 ping15 force-pushed the _V2.4.X/dev_issue#2507 branch from edb7ec9 to 0c8f211 Compare December 26, 2024 08:39
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 25.00000% with 36 lines in your changes missing coverage. Please review.

Project coverage is 75.09%. Comparing base (4f86151) to head (0c8f211).
Report is 2 commits behind head on v2.4.8-dev.

Files with missing lines Patch % Lines
apps/backend/subscription/tools.py 12.82% 34 Missing ⚠️
apps/backend/subscription/views.py 0.00% 1 Missing ⚠️
apps/node_man/constants.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##           v2.4.8-dev    #2527      +/-   ##
==============================================
- Coverage       75.16%   75.09%   -0.08%     
==============================================
  Files             407      407              
  Lines           29544    29584      +40     
==============================================
+ Hits            22208    22217       +9     
- Misses           7336     7367      +31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ping15 ping15 force-pushed the _V2.4.X/dev_issue#2507 branch from e0c36a7 to 9564f6e Compare December 26, 2024 09:12
@ping15
Copy link
Collaborator Author

ping15 commented Dec 26, 2024

ObjectType为HOST,NodeType为DYNAMIC_GROUP,分组目标为host

create_subscription输入参数

{
    "scope": {
        "bk_biz_id": 5, 
        "object_type": "HOST", 
        "node_type": "DYNAMIC_GROUP",
        "nodes": [
            {"bk_inst_id": "c9fa6cc4-c33e-11ef-9ead-fa9249cab81d", "bk_obj_id": "host"}
        ]
    }, 
    "steps": [
        {
            "id": "cd_test", 
            "type": "PLUGIN", 
            "config": {
                "plugin_name": "cd_test", 
                "plugin_version": "1.1", 
                "config_templates": [
                    {"name": "env.yaml", "version": "1"}
                ]
            }, 
            "params": {
                "context": {"cmd_args": ""}
            }
        }, 
        {
            "id": "bkmonitorbeat", 
            "type": "PLUGIN", 
            "config": {
                "plugin_name": "bkmonitorbeat", 
                "plugin_version": "latest", 
                "config_templates": [
                    {
                        "name": "bkmonitorbeat_script.conf", 
                        "version": "latest"
                    }
                ]
            }, 
            "params": {
                "context": {
                    "period": "60", 
                    "timeout": "60", 
                    "metric_relabel_configs": [], 
                    "task_id": "273", 
                    "bk_biz_id": "5", 
                    "config_name": "cd_test",
                    "config_version": "1.0", 
                    "namespace": "cd_test", 
                    "max_timeout": "60", 
                    "dataid": "1573677", 
                    "labels": {"$for": "cmdb_instance.scope", "$item": "scope", "$body": {"bk_target_host_id": "{{ cmdb_instance.host.bk_host_id }}", "bk_target_ip": "{{ cmdb_instance.host.bk_host_innerip }}", "bk_target_cloud_id": "{{ cmdb_instance.host.bk_cloud_id[0].id if cmdb_instance.host.bk_cloud_id is iterable and cmdb_instance.host.bk_cloud_id is not string else cmdb_instance.host.bk_cloud_id }}", "bk_target_topo_level": "{{ scope.bk_obj_id }}", "bk_target_topo_id": "{{ scope.bk_inst_id }}", "bk_target_service_category_id": "{{ cmdb_instance.service.service_category_id | default('', true) }}", "bk_target_service_instance_id": "{{ cmdb_instance.service.id }}", "bk_collect_config_id": 273}},
                    "command": "{{ step_data.cd_test.control_info.setup_path }}/{{ step_data.cd_test.control_info.start_cmd }}"
                }
            }
        }
    ], 
    "run_immediately": true
}

debug接口返回

{
    "result": true,
    "data": [
        {
            "task_id": 252,
            "task_scope": {
                "nodes": [
                    {
                        "ip": null,
                        "bk_obj_id": "host",
                        "bk_inst_id": "c9fa6cc4-c33e-11ef-9ead-fa9249cab81d"
                    }
                ],
                "bk_biz_id": 5,
                "node_type": "DYNAMIC_GROUP",
                "object_type": "HOST",
                "need_register": false,
                "instance_selector": null
            },
            "task_actions": {
                "host|instance|host|59": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|88": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|89": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|168": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|169": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|173": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|191": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|209": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|220": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|455": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|458": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|459": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|481": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|482": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|483": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|484": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|485": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|487": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|488": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                }
            },
            "is_auto_trigger": false,
            "create_time": "2024-12-26 17:21:44+0800",
            "details": "http://xxx/api/debug/fetch_task_details?subscription_id=202&task_id=252"
        }
    ],
    "code": 0,
    "message": ""
}

ObjectType为HOST,NodeType为DYNAMIC_GROUP,分组目标为set

create_subscription输入参数

{
    "scope": {
        "bk_biz_id": 5, 
        "object_type": "HOST", 
        "node_type": "DYNAMIC_GROUP",
        "nodes": [
            {"bk_inst_id": "416454dc-b2db-11ef-9ead-fa9249cab81d", "bk_obj_id": "set"},
            {"bk_inst_id": "717017fc-b2b4-11ef-9ead-fa9249cab81d", "bk_obj_id": "set"}
        ]
    }, 
    "steps": [
        {
            "id": "cd_test", 
            "type": "PLUGIN", 
            "config": {
                "plugin_name": "cd_test", 
                "plugin_version": "1.1", 
                "config_templates": [
                    {"name": "env.yaml", "version": "1"}
                ]
            }, 
            "params": {
                "context": {"cmd_args": ""}
            }
        }, 
        {
            "id": "bkmonitorbeat", 
            "type": "PLUGIN", 
            "config": {
                "plugin_name": "bkmonitorbeat", 
                "plugin_version": "latest", 
                "config_templates": [
                    {
                        "name": "bkmonitorbeat_script.conf", 
                        "version": "latest"
                    }
                ]
            }, 
            "params": {
                "context": {
                    "period": "60", 
                    "timeout": "60", 
                    "metric_relabel_configs": [], 
                    "task_id": "273", 
                    "bk_biz_id": "5", 
                    "config_name": "cd_test",
                    "config_version": "1.0", 
                    "namespace": "cd_test", 
                    "max_timeout": "60", 
                    "dataid": "1573677", 
                    "labels": {"$for": "cmdb_instance.scope", "$item": "scope", "$body": {"bk_target_host_id": "{{ cmdb_instance.host.bk_host_id }}", "bk_target_ip": "{{ cmdb_instance.host.bk_host_innerip }}", "bk_target_cloud_id": "{{ cmdb_instance.host.bk_cloud_id[0].id if cmdb_instance.host.bk_cloud_id is iterable and cmdb_instance.host.bk_cloud_id is not string else cmdb_instance.host.bk_cloud_id }}", "bk_target_topo_level": "{{ scope.bk_obj_id }}", "bk_target_topo_id": "{{ scope.bk_inst_id }}", "bk_target_service_category_id": "{{ cmdb_instance.service.service_category_id | default('', true) }}", "bk_target_service_instance_id": "{{ cmdb_instance.service.id }}", "bk_collect_config_id": 273}},
                    "command": "{{ step_data.cd_test.control_info.setup_path }}/{{ step_data.cd_test.control_info.start_cmd }}"
                }
            }
        }
    ], 
    "run_immediately": true
}

debug接口返回

{
    "result": true,
    "data": [
        {
            "task_id": 255,
            "task_scope": {
                "nodes": [
                    {
                        "ip": null,
                        "bk_obj_id": "set",
                        "bk_inst_id": "416454dc-b2db-11ef-9ead-fa9249cab81d"
                    },
                    {
                        "ip": null,
                        "bk_obj_id": "set",
                        "bk_inst_id": "717017fc-b2b4-11ef-9ead-fa9249cab81d"
                    }
                ],
                "bk_biz_id": 5,
                "node_type": "DYNAMIC_GROUP",
                "object_type": "HOST",
                "need_register": false,
                "instance_selector": null
            },
            "task_actions": {
                "host|instance|host|88": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|89": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|209": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|220": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|226": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                }
            },
            "is_auto_trigger": false,
            "create_time": "2024-12-26 17:31:37+0800",
            "details": "http://xxx/api/debug/fetch_task_details?subscription_id=205&task_id=255"
        }
    ],
    "code": 0,
    "message": ""
}

ObjectType为HOST,NodeType为DYNAMIC_GROUP,分组目标为host + set

create_subscription输入参数

{
    "scope": {
        "bk_biz_id": 5, 
        "object_type": "HOST", 
        "node_type": "DYNAMIC_GROUP",
        "nodes": [
            {"bk_inst_id": "c9fa6cc4-c33e-11ef-9ead-fa9249cab81d", "bk_obj_id": "host"},
            {"bk_inst_id": "416454dc-b2db-11ef-9ead-fa9249cab81d", "bk_obj_id": "set"},
            {"bk_inst_id": "717017fc-b2b4-11ef-9ead-fa9249cab81d", "bk_obj_id": "set"}
        ]
    }, 
    "steps": [
        {
            "id": "cd_test", 
            "type": "PLUGIN", 
            "config": {
                "plugin_name": "cd_test", 
                "plugin_version": "1.1", 
                "config_templates": [
                    {"name": "env.yaml", "version": "1"}
                ]
            }, 
            "params": {
                "context": {"cmd_args": ""}
            }
        }, 
        {
            "id": "bkmonitorbeat", 
            "type": "PLUGIN", 
            "config": {
                "plugin_name": "bkmonitorbeat", 
                "plugin_version": "latest", 
                "config_templates": [
                    {
                        "name": "bkmonitorbeat_script.conf", 
                        "version": "latest"
                    }
                ]
            }, 
            "params": {
                "context": {
                    "period": "60", 
                    "timeout": "60", 
                    "metric_relabel_configs": [], 
                    "task_id": "273", 
                    "bk_biz_id": "5", 
                    "config_name": "cd_test",
                    "config_version": "1.0", 
                    "namespace": "cd_test", 
                    "max_timeout": "60", 
                    "dataid": "1573677", 
                    "labels": {"$for": "cmdb_instance.scope", "$item": "scope", "$body": {"bk_target_host_id": "{{ cmdb_instance.host.bk_host_id }}", "bk_target_ip": "{{ cmdb_instance.host.bk_host_innerip }}", "bk_target_cloud_id": "{{ cmdb_instance.host.bk_cloud_id[0].id if cmdb_instance.host.bk_cloud_id is iterable and cmdb_instance.host.bk_cloud_id is not string else cmdb_instance.host.bk_cloud_id }}", "bk_target_topo_level": "{{ scope.bk_obj_id }}", "bk_target_topo_id": "{{ scope.bk_inst_id }}", "bk_target_service_category_id": "{{ cmdb_instance.service.service_category_id | default('', true) }}", "bk_target_service_instance_id": "{{ cmdb_instance.service.id }}", "bk_collect_config_id": 273}},
                    "command": "{{ step_data.cd_test.control_info.setup_path }}/{{ step_data.cd_test.control_info.start_cmd }}"
                }
            }
        }
    ], 
    "run_immediately": true
}

debug接口返回

{
    "result": true,
    "data": [
        {
            "task_id": 256,
            "task_scope": {
                "nodes": [
                    {
                        "ip": null,
                        "bk_obj_id": "host",
                        "bk_inst_id": "c9fa6cc4-c33e-11ef-9ead-fa9249cab81d"
                    },
                    {
                        "ip": null,
                        "bk_obj_id": "set",
                        "bk_inst_id": "416454dc-b2db-11ef-9ead-fa9249cab81d"
                    },
                    {
                        "ip": null,
                        "bk_obj_id": "set",
                        "bk_inst_id": "717017fc-b2b4-11ef-9ead-fa9249cab81d"
                    }
                ],
                "bk_biz_id": 5,
                "node_type": "DYNAMIC_GROUP",
                "object_type": "HOST",
                "need_register": false,
                "instance_selector": null
            },
            "task_actions": {
                "host|instance|host|59": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|88": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|89": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|168": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|169": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|173": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|191": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|209": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|220": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|226": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|455": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|458": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|459": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|481": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|482": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|483": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|484": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|485": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|487": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "host|instance|host|488": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                }
            },
            "is_auto_trigger": false,
            "create_time": "2024-12-26 17:32:20+0800",
            "details": "http://xxx/api/debug/fetch_task_details?subscription_id=206&task_id=256"
        }
    ],
    "code": 0,
    "message": ""
}

ObjectType为SERVICE,NodeType为DYNAMIC_GROUP,分组目标为host

create_subscription输入参数

{
    "scope": {
        "bk_biz_id": 5, 
        "object_type": "SERVICE", 
        "node_type": "DYNAMIC_GROUP",
        "nodes": [
            {"bk_inst_id": "338b8736-c358-11ef-9ead-fa9249cab81d", "bk_obj_id": "host"}
        ]
    }, 
    "steps": [
        {
            "id": "cd_test", 
            "type": "PLUGIN", 
            "config": {
                "plugin_name": "cd_test", 
                "plugin_version": "1.1", 
                "config_templates": [
                    {"name": "env.yaml", "version": "1"}
                ]
            }, 
            "params": {
                "context": {"cmd_args": ""}
            }
        }, 
        {
            "id": "bkmonitorbeat", 
            "type": "PLUGIN", 
            "config": {
                "plugin_name": "bkmonitorbeat", 
                "plugin_version": "latest", 
                "config_templates": [
                    {
                        "name": "bkmonitorbeat_script.conf", 
                        "version": "latest"
                    }
                ]
            }, 
            "params": {
                "context": {
                    "period": "60", 
                    "timeout": "60", 
                    "metric_relabel_configs": [], 
                    "task_id": "273", 
                    "bk_biz_id": "5", 
                    "config_name": "cd_test",
                    "config_version": "1.0", 
                    "namespace": "cd_test", 
                    "max_timeout": "60", 
                    "dataid": "1573677", 
                    "labels": {"$for": "cmdb_instance.scope", "$item": "scope", "$body": {"bk_target_host_id": "{{ cmdb_instance.host.bk_host_id }}", "bk_target_ip": "{{ cmdb_instance.host.bk_host_innerip }}", "bk_target_cloud_id": "{{ cmdb_instance.host.bk_cloud_id[0].id if cmdb_instance.host.bk_cloud_id is iterable and cmdb_instance.host.bk_cloud_id is not string else cmdb_instance.host.bk_cloud_id }}", "bk_target_topo_level": "{{ scope.bk_obj_id }}", "bk_target_topo_id": "{{ scope.bk_inst_id }}", "bk_target_service_category_id": "{{ cmdb_instance.service.service_category_id | default('', true) }}", "bk_target_service_instance_id": "{{ cmdb_instance.service.id }}", "bk_collect_config_id": 273}},
                    "command": "{{ step_data.cd_test.control_info.setup_path }}/{{ step_data.cd_test.control_info.start_cmd }}"
                }
            }
        }
    ], 
    "run_immediately": true
}

debug接口返回

{
    "result": true,
    "data": [
        {
            "task_id": 257,
            "task_scope": {
                "nodes": [
                    {
                        "ip": null,
                        "bk_obj_id": "host",
                        "bk_inst_id": "338b8736-c358-11ef-9ead-fa9249cab81d"
                    }
                ],
                "bk_biz_id": 5,
                "node_type": "DYNAMIC_GROUP",
                "object_type": "SERVICE",
                "need_register": false,
                "instance_selector": null
            },
            "task_actions": {
                "service|instance|service|51": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "service|instance|service|52": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "service|instance|service|68": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                }
            },
            "is_auto_trigger": false,
            "create_time": "2024-12-26 17:33:54+0800",
            "details": "http://xxx/api/debug/fetch_task_details?subscription_id=207&task_id=257"
        }
    ],
    "code": 0,
    "message": ""
}

ObjectType为SERVICE,NodeType为DYNAMIC_GROUP,分组目标为set

create_subscription输入参数

{
    "scope": {
        "bk_biz_id": 5, 
        "object_type": "SERVICE", 
        "node_type": "DYNAMIC_GROUP",
        "nodes": [
            {"bk_inst_id": "416454dc-b2db-11ef-9ead-fa9249cab81d", "bk_obj_id": "set"},
            {"bk_inst_id": "717017fc-b2b4-11ef-9ead-fa9249cab81d", "bk_obj_id": "set"}
        ]
    }, 
    "steps": [
        {
            "id": "cd_test", 
            "type": "PLUGIN", 
            "config": {
                "plugin_name": "cd_test", 
                "plugin_version": "1.1", 
                "config_templates": [
                    {"name": "env.yaml", "version": "1"}
                ]
            }, 
            "params": {
                "context": {"cmd_args": ""}
            }
        }, 
        {
            "id": "bkmonitorbeat", 
            "type": "PLUGIN", 
            "config": {
                "plugin_name": "bkmonitorbeat", 
                "plugin_version": "latest", 
                "config_templates": [
                    {
                        "name": "bkmonitorbeat_script.conf", 
                        "version": "latest"
                    }
                ]
            }, 
            "params": {
                "context": {
                    "period": "60", 
                    "timeout": "60", 
                    "metric_relabel_configs": [], 
                    "task_id": "273", 
                    "bk_biz_id": "5", 
                    "config_name": "cd_test",
                    "config_version": "1.0", 
                    "namespace": "cd_test", 
                    "max_timeout": "60", 
                    "dataid": "1573677", 
                    "labels": {"$for": "cmdb_instance.scope", "$item": "scope", "$body": {"bk_target_host_id": "{{ cmdb_instance.host.bk_host_id }}", "bk_target_ip": "{{ cmdb_instance.host.bk_host_innerip }}", "bk_target_cloud_id": "{{ cmdb_instance.host.bk_cloud_id[0].id if cmdb_instance.host.bk_cloud_id is iterable and cmdb_instance.host.bk_cloud_id is not string else cmdb_instance.host.bk_cloud_id }}", "bk_target_topo_level": "{{ scope.bk_obj_id }}", "bk_target_topo_id": "{{ scope.bk_inst_id }}", "bk_target_service_category_id": "{{ cmdb_instance.service.service_category_id | default('', true) }}", "bk_target_service_instance_id": "{{ cmdb_instance.service.id }}", "bk_collect_config_id": 273}},
                    "command": "{{ step_data.cd_test.control_info.setup_path }}/{{ step_data.cd_test.control_info.start_cmd }}"
                }
            }
        }
    ], 
    "run_immediately": true
}

debug接口返回

{
    "result": true,
    "data": [
        {
            "task_id": 258,
            "task_scope": {
                "nodes": [
                    {
                        "ip": null,
                        "bk_obj_id": "set",
                        "bk_inst_id": "416454dc-b2db-11ef-9ead-fa9249cab81d"
                    },
                    {
                        "ip": null,
                        "bk_obj_id": "set",
                        "bk_inst_id": "717017fc-b2b4-11ef-9ead-fa9249cab81d"
                    }
                ],
                "bk_biz_id": 5,
                "node_type": "DYNAMIC_GROUP",
                "object_type": "SERVICE",
                "need_register": false,
                "instance_selector": null
            },
            "task_actions": {
                "service|instance|service|30": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "service|instance|service|51": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "service|instance|service|52": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "service|instance|service|53": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "service|instance|service|54": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                }
            },
            "is_auto_trigger": false,
            "create_time": "2024-12-26 17:34:28+0800",
            "details": "http://xxx/api/debug/fetch_task_details?subscription_id=208&task_id=258"
        }
    ],
    "code": 0,
    "message": ""
}

ObjectType为SERVICE,NodeType为DYNAMIC_GROUP,分组目标为host + set

create_subscription输入参数

{
    "scope": {
        "bk_biz_id": 5, 
        "object_type": "SERVICE", 
        "node_type": "DYNAMIC_GROUP",
        "nodes": [
            {"bk_inst_id": "416454dc-b2db-11ef-9ead-fa9249cab81d", "bk_obj_id": "set"},
            {"bk_inst_id": "717017fc-b2b4-11ef-9ead-fa9249cab81d", "bk_obj_id": "set"},
            {"bk_inst_id": "338b8736-c358-11ef-9ead-fa9249cab81d", "bk_obj_id": "host"}
        ]
    }, 
    "steps": [
        {
            "id": "cd_test", 
            "type": "PLUGIN", 
            "config": {
                "plugin_name": "cd_test", 
                "plugin_version": "1.1", 
                "config_templates": [
                    {"name": "env.yaml", "version": "1"}
                ]
            }, 
            "params": {
                "context": {"cmd_args": ""}
            }
        }, 
        {
            "id": "bkmonitorbeat", 
            "type": "PLUGIN", 
            "config": {
                "plugin_name": "bkmonitorbeat", 
                "plugin_version": "latest", 
                "config_templates": [
                    {
                        "name": "bkmonitorbeat_script.conf", 
                        "version": "latest"
                    }
                ]
            }, 
            "params": {
                "context": {
                    "period": "60", 
                    "timeout": "60", 
                    "metric_relabel_configs": [], 
                    "task_id": "273", 
                    "bk_biz_id": "5", 
                    "config_name": "cd_test",
                    "config_version": "1.0", 
                    "namespace": "cd_test", 
                    "max_timeout": "60", 
                    "dataid": "1573677", 
                    "labels": {"$for": "cmdb_instance.scope", "$item": "scope", "$body": {"bk_target_host_id": "{{ cmdb_instance.host.bk_host_id }}", "bk_target_ip": "{{ cmdb_instance.host.bk_host_innerip }}", "bk_target_cloud_id": "{{ cmdb_instance.host.bk_cloud_id[0].id if cmdb_instance.host.bk_cloud_id is iterable and cmdb_instance.host.bk_cloud_id is not string else cmdb_instance.host.bk_cloud_id }}", "bk_target_topo_level": "{{ scope.bk_obj_id }}", "bk_target_topo_id": "{{ scope.bk_inst_id }}", "bk_target_service_category_id": "{{ cmdb_instance.service.service_category_id | default('', true) }}", "bk_target_service_instance_id": "{{ cmdb_instance.service.id }}", "bk_collect_config_id": 273}},
                    "command": "{{ step_data.cd_test.control_info.setup_path }}/{{ step_data.cd_test.control_info.start_cmd }}"
                }
            }
        }
    ], 
    "run_immediately": true
}

debug接口返回

{
    "result": true,
    "data": [
        {
            "task_id": 259,
            "task_scope": {
                "nodes": [
                    {
                        "ip": null,
                        "bk_obj_id": "set",
                        "bk_inst_id": "416454dc-b2db-11ef-9ead-fa9249cab81d"
                    },
                    {
                        "ip": null,
                        "bk_obj_id": "set",
                        "bk_inst_id": "717017fc-b2b4-11ef-9ead-fa9249cab81d"
                    },
                    {
                        "ip": null,
                        "bk_obj_id": "host",
                        "bk_inst_id": "338b8736-c358-11ef-9ead-fa9249cab81d"
                    }
                ],
                "bk_biz_id": 5,
                "node_type": "DYNAMIC_GROUP",
                "object_type": "SERVICE",
                "need_register": false,
                "instance_selector": null
            },
            "task_actions": {
                "service|instance|service|30": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "service|instance|service|51": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "service|instance|service|52": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "service|instance|service|53": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "service|instance|service|54": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                },
                "service|instance|service|68": {
                    "cd_test": "INSTALL",
                    "bkmonitorbeat": "INSTALL"
                }
            },
            "is_auto_trigger": false,
            "create_time": "2024-12-26 17:34:57+0800",
            "details": "http://xxx/api/debug/fetch_task_details?subscription_id=209&task_id=259"
        }
    ],
    "code": 0,
    "message": ""
}

@ping15 ping15 requested a review from wyyalt December 26, 2024 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants