jumpserver api 删除资产
import requests import sys import json import time # 根据实际情况填写 jumpurl = 'http://127.0.0.1' username = 'admin' password = "admin" print() if len(sys.argv) < 2: print('请输入ip') exit(2) def getBearerToken(): url = jumpurl + "/api/v1/authentication/auth/" header = { "accept": "application/json", "Content-Type": "application/json" } data = { "username": username, "password": password } res = requests.post(url, headers=header, data=json.dumps(data)) if res.status_code == 201: return res.json()['token'] else: print(res.status_code) print('用户名密码有误') exit(3) ip = sys.argv[1] token = getBearerToken() fullurl = jumpurl + '/api/v1/assets/assets/?ip=' + ip header = { "accept": "application/json", "Authorization": "Bearer " + token } res = requests.delete(headers=header,url=fullurl) if res.status_code == 204: print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),ip,'删除成功') else: print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),ip,'删除失败')