-
Notifications
You must be signed in to change notification settings - Fork 10
/
test.py
54 lines (50 loc) · 1.88 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from cryptography.fernet import *
from lxml import etree
import time
from SimpliVityClass import *
from datetime import datetime
if __name__ == "__main__":
path = './'
keyfile = path + 'svtinfrastructure.key'
xmlfile = path + 'svtinfrastructure.xml'
""" Parse XML File """
tree = etree.parse(xmlfile)
u2 = (tree.find("user")).text
p2 = (tree.find("password")).text
ovc = (tree.find("ovc")).text
mintervall = int((tree.find("monitoringintervall")).text)
mresolution = (tree.find("resolution")).text
mrange = (tree.find("timerange")).text
lfile = (tree.find("logfile")).text
port = int((tree.find("port")).text)
""" Read keyfile """
f = open(keyfile, 'r')
k2 = f.readline()
f.close()
key2 = k2.encode('ASCII')
f = Fernet(key2)
svtuser = f.decrypt(u2.encode('ASCII')).decode('ASCII')
svtpassword = f.decrypt(p2.encode('ASCII')).decode('ASCII')
url = "https://"+ovc+"/api/"
svt = SimpliVity(url)
while True:
try:
datastore = svt.GetDataStore()
except SvtError as e:
if e.status == 401:
try:
svt.connect(svtuser, svtpassword)
except SvtError as e:
print("Failed to open a conection to SimplVity")
print(str(e.expression))
print(str(e.status))
print(str(e.message))
print("close SimpliVity connection")
exit(-200)
else:
print("Svt Error")
print(str(e.expression))
print(str(e.status))
print(str(e.message))
print("close SimpliVity connection")
exit(-200)