forked from Hank-IT/zabbix-check_secunet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_secunet.py
executable file
·180 lines (134 loc) · 5.72 KB
/
check_secunet.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env python3
import requests, sys, getopt, json, urllib3, base64
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
eligibleCardTypes = ['HBA', 'SMC_KT', 'SMC_B', 'SMC_K']
def main(argv):
verify = True
url = ""
key = ""
username = ""
password = ""
opts, args = getopt.getopt(argv, "hk:", ["url=", "username=", "password=", "disable-cert-verify"])
for opt, arg in opts:
if opt == '-h':
print('check.py --url=<url> --username=<username> --password=<password> -k <key>')
sys.exit()
elif opt in '-k':
eligibleKeys = ['status', 'cards', 'version', 'update-status', 'performance']
if arg not in eligibleKeys:
print("Unknown key: " + arg)
sys.exit()
key = arg
elif opt in ("--url"):
url = arg
elif opt in ("--username"):
username = arg
elif opt in ("--password "):
password = arg
elif opt in ("--disable-cert-verify"):
verify = False
try:
token = login(url, username, password, verify)
match key:
case "status":
print(json.dumps(getStatus(url, token, verify)))
case "cards":
print(json.dumps(getCards(url, token, verify)))
case "version":
print(json.dumps(getVersion(url, token, verify)))
case "update-status":
print(json.dumps(getUpdateStatus(url, token, verify)))
case "performance":
print(json.dumps(getPerformance(url, token, verify)))
logout(url, token, verify)
except Exception as e:
print("Error: " + str(e))
sys.exit()
def login(url, username, password, verify):
headers = {"Content-Type": "application/json"}
r = requests.post(url + '/rest/mgmt/ak/konten/login', json={'username': username, 'password': password}, verify=verify, headers=headers, timeout=10)
if r.status_code == 204:
return r.headers.get('Authorization')
raise Exception('Error on login')
def logout(url, token, verify):
headers = {"Content-Type": "application/json", "Authorization": token}
requests.delete(url + '/rest/mgmt/ak/konten/profil/logout', verify=verify, headers=headers, timeout=10)
def getStatus(url, token, verify):
headers = {'Authorization': token}
r = requests.get(url + '/rest/mgmt/ak/dienste/status', headers=headers, verify=verify, timeout=10)
if r.status_code == 200:
json = r.json()
return {
"vpnTiConnected": 1 if json['vpnTiConnected'] else 0,
"vpnTiConnectionStateDate": round(json['vpnTiConnectionStateDate'] / 1000),
"connectorStarted": round(json['connectorStarted'] / 1000),
"restartRequired": 1 if json['restartRequired'] else 0,
}
raise Exception('Error on getStatus')
def getUpdateStatus(url, token, verify):
headers = {'Authorization': token}
r = requests.get(url + '/rest/mgmt/ak/dienste/ksr/informationen/updates-konnektor', headers=headers, verify=verify, timeout=10)
if r.status_code == 200:
json = r.json()
return {
"lastUpdateCheck": round(json['lastUpdate'] / 1000),
}
raise Exception('Error on getUpdateStatus')
def getVersion(url, token, verify):
headers = {'Authorization': token}
r = requests.get(url + '/rest/mgmt/ak/dienste/status/version', headers=headers, verify=verify, timeout=10)
if r.status_code == 200:
json = r.json()
return {
"fwVersion": json['fwVersion'],
"hwVersion": json['hwVersion'],
"productName": json['productName'],
"productType": json['productType'],
"serialNumber": json['serialNumber'],
"buildTime": json['buildTime'],
}
raise Exception('Error on getVersion')
def getPerformance(url, token, verify):
headers = {'Authorization': token}
r = requests.get(url + '/rest/mgmt/nk/status/basic', headers=headers, verify=verify, timeout=10)
if r.status_code == 200:
json = r.json()
return {
"cpuTemperature": json['cpuTemperature'],
"cpuTempStatus": json['cpuTempStatus'],
"memTotal": json['memTotal'],
"memFree": json['memFree'],
"memAvailable": json['memAvailable'],
"memBuffers": json['memBuffers'],
"memCached": json['memCached'],
"memMapped": json['memMapped'],
"memShmem": json['memShmem'],
"memSlab": json['memSlab'],
"memKernelStack": json['memKernelStack'],
"memPageTables": json['memPageTables'],
"uptime": json['uptime'],
"loadAvg1min": json['loadAvg1min'],
"loadAvg5min": json['loadAvg5min'],
"loadAvg15min": json['loadAvg15min'],
}
raise Exception('Error on getPerformance')
def getCards(url, token, verify):
headers = {'Authorization': token}
r = requests.get(url + '/rest/mgmt/ak/dienste/karten', headers=headers, verify=verify, timeout=10)
if r.status_code == 200:
cards = r.json()
eligibleCards = []
for card in cards:
if card['type'] in eligibleCardTypes:
eligibleCards.append({
"cardhandle": card['cardhandle'],
"insertTime": round(card['insertTime'] / 1000),
"expirationDate": round(card['expirationDate'] / 1000),
"type": card['type'],
"commonName": card['commonName'],
"iccsn": card['iccsn']
})
return eligibleCards
raise Exception('Error on getCards')
if __name__ == "__main__":
main(sys.argv[1:])