获取zabbix, jumpserver用户的sessionid用于单点登录

https://www.cnblogs.com/xiaozhang2014/p/7750200.html session和token的区别

获取zabbix sessionid``

		def get_zabbix_session():
		    login_url = "http://{ip}:{port}{url}index.php"
		    r_session = requests.session()
		    postData = {
		        "name": zabbix.username,
		        "password": zabbix.password,
		        "autologin": 0,
		        "enter": "Sign in"
		    }
		    r_session.post(login_url, data=postData)
		    return r_session.cookies["zbx_sessionid"]

获取jumpserver sessionid``

def get_jumpserver_sessionid():
   
    login_url = "http://{ip}:{port}/users/login/".format(ip=xxx,port=xxx)
    headers = {'Content-Type': "application/x-www-form-urlencoded"}
    conn = requests.Session()
    resp = conn.get(login_url, headers=headers)
    tree = etree.HTML(resp.content)
    csrf_token = tree.xpath('//div[@class="col-md-6"][2]//form[@class="m-t"]/input/@value')
    
    postData = {
         "username": xxx,
         "password": xxx,
         "csrfmiddlewaretoken": csrf_token[0]
     }
     conn.post(login_url, data=postData, headers=headers, allow_redirects=True)
     login_info = {}
     login_info['sessionid'] = conn.cookies["sessionid"]
     login_info['csrftoken'] = conn.cookies["csrftoken"]
     return Response(login_info, status=status.HTTP_200_OK)

request.COOKIES[“csrftoken”] # 从当前请求中获取csrftoken

你可能感兴趣的:(获取zabbix, jumpserver用户的sessionid用于单点登录)