兼容jumpserver3.x,支持同步ECS到jms3.x

pull/72/head 0.12.7
starsliao 1 year ago
parent 1744974658
commit 710bbadd4a

@ -22,7 +22,7 @@ def create_node(jms_url,headers,now,node_id,cloud,account):
new_node_dict = {i['value']:i['id'] for i in reget_node_list}
return new_node_dict
def update_jms_ecs(jms_url,headers,new_node_dict,node_id,cloud,account,ecs_info,custom_ecs_info):
def update_jms_ecs(jms_ver,jms_url,headers,new_node_dict,node_id,cloud,account,ecs_info,custom_ecs_info):
#比较云主机与JMS中对应node的主机列表删除jms中多余的主机
ecs_url = f"{jms_url}/api/v1/assets/assets/"
reget_ecs_list = requests.request("GET", f'{ecs_url}?node={node_id}', headers=headers).json()
@ -56,11 +56,24 @@ def update_jms_ecs(jms_url,headers,new_node_dict,node_id,cloud,account,ecs_info,
protocols = custom_info[ostype][0]
platform = ostype.title()
admin_user = custom_info[ostype][1]
payload = {
"ip": ip,
"hostname": iname,
if jms_ver == 'V3':
ecs_url = f"{jms_url}/api/v1/assets/hosts/"
proto,port = protocols[0].split('/')
payload = {
"address": ip,
"name": iname,
"protocols": [{"name": proto,"port": port}],
"platform": '5' if platform == 'Windows' else '1',
"is_active": True,
"domain": "",
"accounts":[{"template": admin_user.strip()}],
"nodes": [nodes],
"comment": comment
}
else:
payload = {
"ip": ip,
"hostname": iname,
"protocols": protocols,
"platform": platform,
"is_active": True,
@ -68,7 +81,7 @@ def update_jms_ecs(jms_url,headers,new_node_dict,node_id,cloud,account,ecs_info,
"admin_user": admin_user.strip(),
"nodes": [nodes],
"comment": comment
}
}
try:
if ip in jms_ecs_dict.keys():
jms_group = '' if jms_ecs_dict[ip]['node'].split('/')[-1] == '未分组' else jms_ecs_dict[ip]['node'].split('/')[-1]
@ -131,11 +144,12 @@ def run(cloud,account):
jms = consul_kv.get_value('ConsulManager/jms/jms_info')
jms_url = jms.get('url')
jms_ver = jms.get('ver','V2')
token = myaes.decrypt(jms.get('token'))
headers = {'Content-Type': 'application/json','Authorization': f"Token {token}"}
new_node_dict = create_node(jms_url,headers,now,node_id,cloud,account)
ecs_ip_dict = update_jms_ecs(jms_url,headers,new_node_dict,node_id,cloud,account,ecs_info,custom_ecs_info)
ecs_ip_dict = update_jms_ecs(jms_ver,jms_url,headers,new_node_dict,node_id,cloud,account,ecs_info,custom_ecs_info)
del_jms_repip(jms_url,headers,node_id,ecs_ip_dict)
del_node(jms_url,headers,now,node_id,cloud,account)
logger.info(f'【JOB】===>{cloud},{account},JMS同步完成')

@ -84,7 +84,7 @@ class Jms(Resource):
winuid = ecs_info['windows'][-1]
token = myaes.decrypt(jms_info['token'])
custom_ecs_json = json.dumps(custom_ecs_info, indent=8) if custom_ecs_info != {} else ''
jms_config = {'url': jms_info['url'], 'token': token,
jms_config = {'url': jms_info['url'], 'token': token, 'ver': jms_info.get('ver','V2'),
'linuxport': linuxport, 'linuxuid': linuxuid,
'winport': winport, 'winuid': winuid, 'custom_ecs_info':custom_ecs_json}
else:
@ -95,7 +95,7 @@ class Jms(Resource):
args = parser.parse_args()
jms_config = args['jms_config']
token = myaes.encrypt(jms_config['token'])
jms_info = {'url': jms_config['url'], 'token': token}
jms_info = {'url': jms_config['url'], 'token': token, 'ver': jms_config.get('ver','V2')}
consul_kv.put_kv('ConsulManager/jms/jms_info', jms_info)
ecs_info = {"linux": [[f"ssh/{jms_config['linuxport']}"],jms_config['linuxuid']],
"windows": [[f"rdp/{jms_config['winport']}"],jms_config['winuid']]}

@ -22,6 +22,12 @@
<el-form-item label="JumpServer URL">
<el-input v-model="jms_config.url" placeholder="http开头" style="width: 390px;" />
</el-form-item>
<el-form-item label="JumpServer 版本">
<el-select v-model="jms_config.ver" placeholder="版本" style="width: 100px" class="filter-item">
<el-option key="V2" label="V2" value="V2" />
<el-option key="V3" label="V3" value="V3" />
</el-select>
</el-form-item>
<el-form-item label="JumpServer Token">
<el-input v-model="jms_config.token" type="password" placeholder="请输入Admin Token" style="width: 390px;" />
</el-form-item>
@ -107,7 +113,7 @@ import { getJmsList, getJmsConfig, postJmsConfig, postJmsSwitch, postJmsSync } f
export default {
data() {
return {
jms_config: { url: '', token: '', linuxport: '22', linuxuid: '', winport: '3389', winuid: '', custom_ecs_info: '' },
jms_config: { ver: 'V2', url: '', token: '', linuxport: '22', linuxuid: '', winport: '3389', winuid: '', custom_ecs_info: '' },
listLoading: false,
dialogFormVisible: false,
query: { vendor: '', account: '' },

Loading…
Cancel
Save