其他分享
首页 > 其他分享> > jumpserver api 获取所有的资产

jumpserver api 获取所有的资产

作者:互联网

jms_url
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import requests, json
import datetime
from httpsig.requests_auth import HTTPSignatureAuth
import sys
jms_url = 'http://127.0.0.1' # jumpserver的地址 根据实际情况填写
def get_assets_assets(jms_url, auth):
    url = jms_url + '/api/v1/assets/assets/?offset=1&limit=2000'
    response = requests.get(url, auth=auth, headers=headers)

    hosts_info_dicts = (response.json()["results"])

    my_dict = {}
    for i , value in enumerate(hosts_info_dicts):
        my_dict[i] = value

    keys = (my_dict.keys())
    for keyss in keys:
        print(my_dict[keyss]["hostname"] + " " + my_dict[keyss]["ip"])

#需要先创建好
#key_id和secret 根据实际情况填写
auth = HTTPSignatureAuth(key_id='c016896a', secret='304d66e1',
                         algorithm='hmac-sha256', headers=['(request-target)', 'accept', 'date'])
gmt_form = '%a, %d %b %Y %H:%M:%S GMT'
headers = {
    'Accept': 'application/json',
    'X-JMS-ORG': '00000000-0000-0000-0000-000000000002',
    'Date': datetime.datetime.utcnow().strftime(gmt_form)
}

if __name__ == '__main__':
    get_assets_assets(jms_url, auth)

 

标签:assets,url,jms,auth,jumpserver,获取,api,dict,my
来源: https://www.cnblogs.com/suyj/p/16497246.html