import requests, json, logging from pyzabbix import ZabbixAPI token = None def getToken(): jsondoc = { "username": "", "password": "" } url = '' try: r = requests.post(url, data=jsondoc) if r.status_code == 200: response = json.loads(r.text) token = response['token'] logging.info("Token has been retrieved") return token else: logging.error("Error getting token for portal") except Exception as e: logging.error(e) def updateToken(token): try: zapi = ZabbixAPI("") zapi.login("","") jsontoken = { 'Authorization': 'Bearer '+ token } # Update your http agent checks with the token. Use the item ID number found in the URL of the http agent itself. zapi.item.update(itemid='00000', headers=jsontoken) logging.info("Apperantly the token was updated... a double check won't hurt!") except Exception as e: logging.error(e) token = getToken() updateItem = updateToken(token)