diff --git a/PVE-Zabbix.py b/PVE-Zabbix.py index 2df3864..0125d00 100755 --- a/PVE-Zabbix.py +++ b/PVE-Zabbix.py @@ -5,7 +5,7 @@ from VM import VM from Storage import Storage USERNAME = "zabbix@pve" -PASSWORD = "KbCurGdt82NTgBye" +PASSWORD = "zabbix" HOST = "localhost:8006" conn = PVEApi(HOST, USERNAME, PASSWORD) diff --git a/PVEApi.py b/PVEApi.py index 20d797e..6867bd0 100755 --- a/PVEApi.py +++ b/PVEApi.py @@ -53,10 +53,15 @@ class PVEApi(object): Proxmox says ticket is valid for 2 hours. For safety we use 1 hour :return: Boolean value of True if ticket is considered expired. False if opposite. """ - with open(CACHEFILE, 'r') as f: - data = json.load(f) - timestamp = data['timestamp'] - return True if time.time() - timestamp > 3600 else False + try: + with open(CACHEFILE, 'r') as f: + data = json.load(f) + timestamp = data['timestamp'] + return True if time.time() - timestamp > 3600 else False + except: + self.csrftoken = get_auth(self.host, username, password)[0] + self.ticket = get_auth(self.host, username, password)[1] + self.write_ticketcache() def write_ticketcache(self):