-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwise_link.py
30 lines (26 loc) · 1.08 KB
/
wise_link.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
import json
class WiseLink:
def __init__(self, file_path, wise_full_mode):
self.file_path = file_path
self.wise_full_mode = wise_full_mode
self.wise_data = list()
self.ip_duplicates = dict()
try:
self.fd = open(self.file_path, 'w')
except Exception as e:
print('Error occurred: ', e)
def append(self, info):
# Wise formatting
for nicinfo in info.get("nic", []):
template = {}
template["asset"] = info.get("name", "Unknown")
if self.wise_full_mode:
template["os"] = info.get("os") if info.get("os") != None else "Unknown"
template["hostname"] = info.get("host_name") if info.get("host_name") != None else "Unknown"
template["mac"] = nicinfo.get("mac", "Unknown")
for ip in nicinfo.get("IP", []):
if len(ip) > 0 and ip is not None:
template["ip"] = ip
self.wise_data.append(template.copy())
def write(self):
json.dump(self.wise_data, self.fd)